From 54c48b00f70343a46575890c262f28c09e00e043 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Tue, 7 Dec 2021 16:53:45 +0100 Subject: Rewrite lookup_loan_opt with visitors --- src/Interpreter.ml | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/Interpreter.ml b/src/Interpreter.ml index 9787af65..d97ab5a8 100644 --- a/src/Interpreter.ml +++ b/src/Interpreter.ml @@ -118,12 +118,15 @@ let loans_in_value (v : V.typed_value) : bool = false with Found -> true -(** Lookup a loan content in a value *) -let lookup_loan_in_value (ek : exploration_kind) (l : V.BorrowId.id) - (v : V.typed_value) : V.loan_content option = +(** Lookup a loan content. + + The loan is referred to by a borrow id. + *) +let lookup_loan_opt (ek : exploration_kind) (l : V.BorrowId.id) (env : C.env) : + V.loan_content option = let obj = object - inherit [_] V.iter_typed_value as super + inherit [_] C.iter_env_concrete as super method! visit_MutBorrow env bid mv = if ek.enter_mut_borrows then super#visit_MutBorrow env bid mv else () @@ -147,24 +150,10 @@ let lookup_loan_in_value (ek : exploration_kind) (l : V.BorrowId.id) in (* We use exceptions *) try - obj#visit_typed_value () v; + obj#visit_env () env; None with FoundLoanContent lc -> Some lc -(** Lookup a loan content. - - The loan is referred to by a borrow id. - *) -let lookup_loan_opt (ek : exploration_kind) (l : V.BorrowId.id) (env : C.env) : - V.loan_content option = - let lookup_loan_in_env_value (ev : C.env_value) : V.loan_content option = - match ev with - | C.Var (_, v) -> lookup_loan_in_value ek l v - | C.Abs _ -> raise Unimplemented (* TODO *) - | C.Frame -> None - in - List.find_map lookup_loan_in_env_value env - (** Lookup a loan content. The loan is referred to by a borrow id. -- cgit v1.2.3