summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSon Ho2022-01-18 22:51:47 +0100
committerSon Ho2022-01-18 22:51:47 +0100
commitcdef093fedaadcc5694cb9f7d63a4bf9814d5573 (patch)
tree81461f89a141d61d06b764a7ae2974740c6bd18d
parent3223123aa5736cfe83168313e501fd4927f107ef (diff)
Implement ty_has_borrows and ty_has_nested_borrows
-rw-r--r--src/TypesUtils.ml21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/TypesUtils.ml b/src/TypesUtils.ml
index 431ae8d8..10bd286c 100644
--- a/src/TypesUtils.ml
+++ b/src/TypesUtils.ml
@@ -1,5 +1,6 @@
open Types
open Utils
+module TA = TypesAnalysis
(** Retrieve the list of fields for the given variant of a [type_def].
@@ -114,6 +115,26 @@ let ty_has_regions (ty : 'r ty) : bool =
false
with Found -> true
+(** Retuns true if a type contains borrows.
+
+ Note that we can't simply explore the type and look for regions: sometimes
+ we erase the lists of regions (by replacing them with `[]` when using `ety`,
+ and when a type uses 'static this region doesn't appear in the region parameters.
+ *)
+let ty_has_borrows (infos : TA.type_infos) (ty : 'r ty) : bool =
+ let info = TA.analyze_ty infos ty in
+ info.TA.contains_borrow
+
+(** Retuns true if a type contains nested borrows.
+
+ Note that we can't simply explore the type and look for regions: sometimes
+ we erase the lists of regions (by replacing them with `[]` when using `ety`,
+ and when a type uses 'static this region doesn't appear in the region parameters.
+ *)
+let ty_has_nested_borrows (infos : TA.type_infos) (ty : 'r ty) : bool =
+ let info = TA.analyze_ty infos ty in
+ info.TA.contains_nested_borrows
+
(** Check if a [ty] contains regions from a given set *)
let ty_has_regions_in_set (rset : RegionId.Set.t) (ty : rty) : bool =
let obj =