Skip to content

Commit

Permalink
Fix preallocation for some ctor patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
tjammer committed Nov 4, 2023
1 parent 9da1541 commit f31cb15
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/monomorph_tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,12 @@ and prep_let p id uniq e pass toplvl =
(* username *)
let un = reconstr_module_username ~mname:p.mname ~mainmod:p.mainmodule id in

(* For owned values, increase alloc level so they get preallocated correctly.
It's important we don't do this for borrowed values, because a borrowed
value might be (partly) owned later, for instance in a ctor pattern. There,
the level must not be increased, otherwise this borrowed value will be
preallocated at its creation. *)
let p = match pass with Dmove -> enter_level p | Dset | Dmut | Dnorm -> p in
let p, e1, func = morph_expr { p with ret = false } e in
let ms, malloc, mallocs =
match pass with
Expand Down Expand Up @@ -1485,10 +1491,12 @@ and prep_let p id uniq e pass toplvl =
let vars = Vars.add uniq (Global (uniq, func, used)) vars in
({ p with vars }, Some uniq)
| _ ->
let kind = let_kind pass in
(match kind with Lborrow -> () | Lowned -> set_alloca p func.alloc);
(match pass with
| Dmove -> set_alloca p func.alloc
| Dset | Dmut | Dnorm -> ());
({ p with vars = Vars.add un (Normal func) p.vars }, None)
in
let p = match pass with Dmove -> leave_level p | Dset | Dmut | Dnorm -> p in
(un, p, e1, gn, ms)

and morph_record mk p labels typ =
Expand Down

0 comments on commit f31cb15

Please sign in to comment.