Evaluate the source of a record spread whose fields are all overridden
Why
When a record literal with a spread writes every field, the type checker reports warning 23 and also dropped the spread's source from the typed tree, so a source with side effects, such as a call, never ran. The same held for JSX props spreads. The source now stays in the typed tree; the record is built from the written fields alone, after the source is evaluated. A source that is a variable is left out of the Lambda term, so the size of a function and the output stay as they were; the Lambda passes drop any other source without side effects. A module with side effects that a source is read from stays imported.
modifiedTypedtree Texp_record
type t = {a: int, b: int}@val external f: unit => t = "f"let make = () => {...f(), a: 1, b: 2}
typed
modifiedJS record spread with every field overridden
type t = {a: int, b: int}@val external f: unit => t = "f"let make = () => {...f(), a: 1, b: 2}
js
modifiedJS source read from a module with side effects
let make = () => {...Effects.base, a: 1, b: 2}js
modifiedTyping let rec check of an overridden source
type callback = {run: unit => int}@val external wrap: callback => callback = "wrap"let rec callback = {...wrap(callback), run: () => 1}
text
Rec_checkRec_checkReview
- Does a copy of the source remain when the record has optional fields or 20 fields or more? No:
record_copies_fieldsholds when every field is written, so the source is never spread into the result. - Does the source affect generalization or
let rec? As the first expression of a sequence would: its value is discarded, so the record stays polymorphic andlet rec r = {...r, a: 1, b: 2}stays accepted, but a source that uses the recursive value early is now rejected, as is a source with a field left to take from it, as before. - Which existing checked-in outputs change? None.