Read a record copy's mutable fields before overrides that can assign them
Why
A record spread {...base, a: e} of a record with fewer than 20 fields and no optional field, or of an array record, reads the fields of base one by one. The values were evaluated in the order the type declares the fields, so a mutable field declared after a was read after e had run, and an assignment in e, or while it awaited, showed up in the copy. A JSX spread of such props did the same. A mutable field that follows an override with side effects is now bound before all the overrides. Immutable fields, mutable fields declared before every such override, and copies whose overrides have no side effects compile as before. no_side_effects moves unchanged from Lam_analysis to Lambda_effects in compiler/typing, where the translation to Lambda can use it.
modifiedJS record spread copied field by field
type s = {a1: int, mutable b1: int}let f = (base: s) => {...base, a1: {base.b1 = 100; 5}}
js
modifiedJS JSX spread of props copied field by field
@@config({flags: ["-bs-jsx", "4"]})@inline(never) let id = x => xtype props = {className: string, mutable title: string}module C = { @react.componentWithProps let make = (props: props) => React.string(props.title)}let jsxProps = (base: props) => <C {...base} className={base.title = "changed"; id("c")} />
js
Review
- Why bind only some fields? A field read before the overrides in the literal already has the right value, and an immutable field can't be assigned through its own type, so binding them would only add variables to the output. A base coerced from a type where the field is mutable can still change under an immutable field; such reads stay in place.
- Which checked-in outputs change? mario_game.mjs, where
vptis overridden by a call and four mutable fields follow it.