Skip to content

Commit

Permalink
fix uniqueness_analysis for unboxed tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
riaqn committed Aug 16, 2024
1 parent ad85854 commit bf4f79b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
30 changes: 28 additions & 2 deletions ocaml/testsuite/tests/typing-unique/unique_analysis.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* TEST
flags += "-extension unique";
(* TEST
flags += "-extension unique -extension layouts_beta";
expect;
*)

Expand Down Expand Up @@ -782,3 +782,29 @@ Line 3, characters 20-21:
^

|}]

let foo () =
let t = #("hello", "world") in
let unique_use_tuple : ('a : value & value). unique_ 'a -> unit = fun _ -> () in
unique_use_tuple t;
let #(_, _) = t in
()
[%%expect{|
val foo : unit -> unit = <fun>
|}]

let foo () =
let t = ("hello", "world") in
ignore (unique_id t);
let (_, _) = t in
()
[%%expect{|
Line 4, characters 6-12:
4 | let (_, _) = t in
^^^^^^
Error: This value is read from here, but it has already been used as unique:
Line 3, characters 20-21:
3 | ignore (unique_id t);
^

|}]
4 changes: 1 addition & 3 deletions ocaml/typing/uniqueness_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,6 @@ and pattern_match_single pat paths : Ienv.Extension.t * UF.t =
in
ext, UF.par uf_read uf_args
| Tpat_unboxed_tuple args ->
(* XXX modes *)
let uf_read = Paths.mark_implicit_borrow_memory_address Read occ paths in
let ext, uf_args =
List.mapi
(fun i (_, arg, _) ->
Expand All @@ -1111,7 +1109,7 @@ and pattern_match_single pat paths : Ienv.Extension.t * UF.t =
args
|> conjuncts_pattern_match
in
ext, UF.par uf_read uf_args
ext, uf_args

let pattern_match pat = function
| Match_tuple values -> pattern_match_tuple pat values
Expand Down

0 comments on commit bf4f79b

Please sign in to comment.