diff options
-rw-r--r-- | src/Substitute.ml | 4 | ||||
-rw-r--r-- | src/TypesUtils.ml | 25 |
2 files changed, 4 insertions, 25 deletions
diff --git a/src/Substitute.ml b/src/Substitute.ml index ad896c41..13e0b583 100644 --- a/src/Substitute.ml +++ b/src/Substitute.ml @@ -34,6 +34,10 @@ let rec ty_substitute (rsubst : 'r1 -> 'r2) | Str -> Str | TypeVar vid -> tsubst vid +(** Convert an [rty] to an [ety] by erasing the region variables *) +let erase_regions (ty : T.rty) : T.ety = + ty_substitute (fun _ -> T.Erased) (fun vid -> T.TypeVar vid) ty + (** Erase the regions in a type and substitute the type variables *) let erase_regions_substitute_types (tsubst : T.TypeVarId.id -> T.ety) (ty : T.rty) : T.ety = diff --git a/src/TypesUtils.ml b/src/TypesUtils.ml index 0e6040b2..0b8364a8 100644 --- a/src/TypesUtils.ml +++ b/src/TypesUtils.ml @@ -1,30 +1,5 @@ open Types -(** Convert an [rty] to an [ety] by erasing the region variables - - TODO: this can be done through a substitution -*) -let rec erase_regions (ty : rty) : ety = - match ty with - | Adt (def_id, regions, tys) -> - let regions = List.map (fun _ -> Erased) regions in - let tys = List.map erase_regions tys in - Adt (def_id, regions, tys) - | Tuple tys -> Tuple (List.map erase_regions tys) - | TypeVar vid -> TypeVar vid - | Bool -> Bool - | Char -> Char - | Never -> Never - | Integer int_ty -> Integer int_ty - | Str -> Str - | Array ty -> Array (erase_regions ty) - | Slice ty -> Slice (erase_regions ty) - | Ref (_, ty, ref_kind) -> Ref (Erased, erase_regions ty, ref_kind) - | Assumed (aty, regions, tys) -> - let regions = List.map (fun _ -> Erased) regions in - let tys = List.map erase_regions tys in - Assumed (aty, regions, tys) - (** Retrieve the list of fields for the given variant of a [type_def]. Raises [Invalid_argument] if the arguments are incorrect. |