Skip to content

V11 & V12 - Fails to set value to nested optional mutable field #7406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DZakh opened this issue Apr 24, 2025 · 3 comments · Fixed by #7421
Closed

V11 & V12 - Fails to set value to nested optional mutable field #7406

DZakh opened this issue Apr 24, 2025 · 3 comments · Fixed by #7421
Labels
Milestone

Comments

@DZakh
Copy link
Member

DZakh commented Apr 24, 2025

@nojaf
Copy link
Collaborator

nojaf commented Apr 24, 2025

Workaround is too add mutable as well to the parent?

@cknitt cknitt added the bug label Apr 28, 2025
@cknitt cknitt added this to the v12 milestone Apr 28, 2025
@cristianoc
Copy link
Collaborator

Here's an example that does not use mutable at all:

type nested = {field?: int}
type pair = (nested, string)

let p: pair = ({}, "")


let x = fst(p)
let y = fst(p)

Gives:

let p = [
  {},
  ""
];

let x = {};

let y = {};

So it seems that the initialisation {} is inlined or something, which loses the alias between x and y (and w.r.t the first component of p).

@cristianoc
Copy link
Collaborator

Here's a tweaked example that does not use optional fields at all:

type record = {field: int}
type pair = (record, string)

let p: pair = ({field:2}, "")


let x = fst(p)
let y = fst(p)

and shows the duplication of the record value:

let p = [
  {
    field: 2
  },
  ""
];

let x = {
  field: 2
};

let y = {
  field: 2
};

cristianoc added a commit that referenced this issue May 5, 2025
…attening

Fixes #7406

fix: avoid creating unnecessary copies of allocating constants in field flattening

The field flattening optimization was creating unnecessary copies of allocating constants
(like Const_block and Const_some), which could lead to memory issues. This change makes
the optimization only flatten fields when the constant doesn't allocate memory.
cristianoc added a commit that referenced this issue May 5, 2025
…attening

Fixes #7406

fix: avoid creating unnecessary copies of allocating constants in field flattening

The field flattening optimization was creating unnecessary copies of allocating constants
(like Const_block and Const_some), which could lead to memory issues. This change makes
the optimization only flatten fields when the constant doesn't allocate memory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants