diff --git a/src/ownershipInference.ml b/src/ownershipInference.ml index 41e5c72d..16f5efea 100644 --- a/src/ownershipInference.ml +++ b/src/ownershipInference.ml @@ -794,7 +794,9 @@ let rec process_expr ~output ((e_id,_),expr) ~o_arity = split_loop r (o1 :: ol1) (o2 :: ol2) in let%bind (ol1, ol2) = split_loop ol [] [] in - return (IntList ol1, Ref(IntList((List.tl ol2) @ [(List.hd @@ List.rev ol2)]), List.hd ol2)) + let%bind o_copied = alloc_ovar (MGen e_id) (P.var v) in + add_constraint (Eq (o_copied, List.hd @@ List.rev ol2)) >> + return (IntList ol1, Ref(IntList((List.tl ol2) @ [o_copied]), List.hd ol2)) | _ -> failwith "The value pattern matched must be IntList" in process_pattern_matching ~e_id ~output v type_of_v e2 h r type_of_r e3 ~o_arity diff --git a/src/test/list/reverse2-debug.imp b/src/test/list/reverse2-debug.imp new file mode 100644 index 00000000..99ca23f0 --- /dev/null +++ b/src/test/list/reverse2-debug.imp @@ -0,0 +1,32 @@ +_reverse(l, l_next) { + match l_next with + Nil -> { + // alias(*(l.Cons.2) = l_next); + return l + } + | Cons(h, t) -> { + let t_deref = *t in { + t := l; + alias(l_next.Cons.2 = t); + let reversed = _reverse(l_next, t_deref) in + reversed + } + } +} + +reverse(l) { + match l with + Nil -> l + | Cons(h, r) -> { + let reversed = _reverse(Nil, l) in + reversed + } +} + +{ + let n = mkref Nil in + let m = mkref Cons(1, n) in + let l = Cons(2, m) in + let rev_l = reverse(l) in + () +} \ No newline at end of file diff --git a/src/test/list/reverse2.imp b/src/test/list/reverse2.imp index 09d99c3b..d15e56db 100644 --- a/src/test/list/reverse2.imp +++ b/src/test/list/reverse2.imp @@ -10,7 +10,7 @@ mklist(n) { _reverse(l, l_next) { match l_next with Nil -> { - alias(*(l.Cons.2) = l_next); + // alias(*(l.Cons.2) = l_next); return l } | Cons(h, t) -> {