summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSon Ho2024-04-07 14:47:36 +0200
committerSon Ho2024-04-07 14:47:36 +0200
commita9a2f81e365eeef4fd157fb56cd5107f95c91163 (patch)
tree96fb3a03ae2dc598b518a8606bf9f3c3eea3f824
parent581d5c0cb8e618382fa41e5a42175560283ff0a1 (diff)
Improve the error messages further
Diffstat (limited to '')
-rw-r--r--compiler/Interpreter.ml12
-rw-r--r--compiler/InterpreterStatements.ml13
-rw-r--r--compiler/TypesUtils.ml20
3 files changed, 44 insertions, 1 deletions
diff --git a/compiler/Interpreter.ml b/compiler/Interpreter.ml
index d0a54750..769e3144 100644
--- a/compiler/Interpreter.ml
+++ b/compiler/Interpreter.ml
@@ -191,6 +191,18 @@ let initialize_symbolic_context_for_fun (ctx : decls_ctx) (fdef : fun_decl) :
* do it, and because it gives a bit of sanity.
* *)
let sg = fdef.signature in
+ (* Sanity check: no nested borrows, borrows in ADTs, etc. *)
+ cassert __FILE__ __LINE__
+ (List.for_all
+ (fun ty -> not (ty_has_nested_borrows ctx.type_ctx.type_infos ty))
+ (sg.output :: sg.inputs))
+ fdef.meta "Nested borrows are not supported yet";
+ cassert __FILE__ __LINE__
+ (List.for_all
+ (fun ty -> not (ty_has_adt_with_borrows ctx.type_ctx.type_infos ty))
+ (sg.output :: sg.inputs))
+ fdef.meta "ADTs containing borrows are not supported yet";
+
(* Create the context *)
let regions_hierarchy =
FunIdMap.find (FRegular fdef.def_id) ctx.fun_ctx.regions_hierarchies
diff --git a/compiler/InterpreterStatements.ml b/compiler/InterpreterStatements.ml
index 1cf1c5ef..de89f316 100644
--- a/compiler/InterpreterStatements.ml
+++ b/compiler/InterpreterStatements.ml
@@ -1365,10 +1365,21 @@ and eval_transparent_function_call_symbolic (config : config) (meta : Meta.meta)
let func, generics, trait_method_generics, def, regions_hierarchy, inst_sg =
eval_transparent_function_call_symbolic_inst meta call ctx
in
- (* Sanity check *)
+ (* Sanity check: same number of inputs *)
sanity_check __FILE__ __LINE__
(List.length call.args = List.length def.signature.inputs)
def.meta;
+ (* Sanity check: no nested borrows, borrows in ADTs, etc. *)
+ cassert __FILE__ __LINE__
+ (List.for_all
+ (fun ty -> not (ty_has_nested_borrows ctx.type_ctx.type_infos ty))
+ (inst_sg.output :: inst_sg.inputs))
+ meta "Nested borrows are not supported yet";
+ cassert __FILE__ __LINE__
+ (List.for_all
+ (fun ty -> not (ty_has_adt_with_borrows ctx.type_ctx.type_infos ty))
+ (inst_sg.output :: inst_sg.inputs))
+ meta "ADTs containing borrows are not supported yet";
(* Evaluate the function call *)
eval_function_call_symbolic_from_inst_sig config def.meta func def.signature
regions_hierarchy inst_sg generics trait_method_generics call.args call.dest
diff --git a/compiler/TypesUtils.ml b/compiler/TypesUtils.ml
index f5dd7df4..b2c60cc6 100644
--- a/compiler/TypesUtils.ml
+++ b/compiler/TypesUtils.ml
@@ -12,6 +12,26 @@ let ty_has_borrows (infos : TypesAnalysis.type_infos) (ty : ty) : bool =
let info = TypesAnalysis.analyze_ty infos ty in
info.TypesAnalysis.contains_borrow
+let ty_has_adt_with_borrows (infos : TypesAnalysis.type_infos) (ty : ty) : bool
+ =
+ let visitor =
+ object
+ inherit [_] iter_ty as super
+
+ method! visit_ty env ty =
+ match ty with
+ | TAdt (type_id, _) when type_id <> TTuple ->
+ let info = TypesAnalysis.analyze_ty infos ty in
+ if info.TypesAnalysis.contains_borrow then raise Found
+ else super#visit_ty env ty
+ | _ -> super#visit_ty env ty
+ end
+ in
+ try
+ visitor#visit_ty () ty;
+ false
+ with Found -> true
+
(** Retuns true if the type contains nested borrows.
Note that we can't simply explore the type and look for regions: sometimes