Are Records value types or reference types?

# Boris Zbarsky (11 years ago)

It's not obvious to me from people.mozilla.org/~jorendorff/es6-draft.html#sec-list-and-record-specification-type whether a Record is a value type or reference type.

At least some parts of the spec seem to assume it's a reference type. Specifically, people.mozilla.org/~jorendorff/es6-draft.html#sec-createresolvingfunctions is assuming that after it completes the two functions have [[AlreadyResolved]] slots that are both references to the same exact Record, so mutating the [[value]] in one of them will make the other see the new [[[value]] as well.

If this is how Records work, it would be good to spell that out explicitly.

# Boris Zbarsky (11 years ago)

On 10/26/14, 11:12 PM, Allen Wirfs-Brock wrote:

ES List and Record specification type values have reference semantics

OK. Can we explicitly say so in the spec, please?

# Brendan Eich (11 years ago)

Boris Zbarsky wrote:

If this is how Records work, it would be good to spell that out explicitly.

Mutable records have reference, not value, semantics -- good point.

Some might object to calling any such spec-internal device a "record". This use of spec-internal reference-semantics mutable "record" could be awkward in a future edition:

sebmarkbage/ecmascript-immutable-data-structures

Does the spec anywhere else need reference semantics for its internal list and record types?

# Allen Wirfs-Brock (11 years ago)

On Oct 26, 2014, at 8:38 PM, Brendan Eich wrote:

Boris Zbarsky wrote:

If this is how Records work, it would be good to spell that out explicitly.

Mutable records have reference, not value, semantics -- good point.

Some might object to calling any such spec-internal device a "record". This use of spec-internal reference-semantics mutable "record" could be awkward in a future edition:

sebmarkbage/ecmascript-immutable-data-structures

But that is describing language level types, not spec. devices. they would not directly map to the List/Record specification types.

Does the spec anywhere else need reference semantics for its internal list and record types?

Yes, all over the place. The spec. explicitly makes copies when it doesn't want shared references.

# Brendan Eich (11 years ago)

Allen Wirfs-Brock wrote:

But that is describing language level types, not spec. devices. they would not directly map to the List/Record specification types.

Of course, but the name "record" would be confusingly overloaded. Can we avoid this?

Yes, all over the place. The spec. explicitly makes copies when it doesn't want shared references.

All over the place? I see 12 "copy of" occurrences, not all about internal list and record types. Probably < 10 to consider. More in a bit.

# Allen Wirfs-Brock (11 years ago)

On Oct 27, 2014, at 4:17 PM, Brendan Eich wrote:

All over the place? I see 12 "copy of" occurrences, not all about internal list and record types. Probably < 10 to consider. More in a bit.

Not too many places where copy occurs, because mostly reference semantics are what is needed. Things like Realm records, module records, and environment records (the later are their own thing and not actually "Records". But they probably should be) are mutable and passed around by implicit reference.

Naming and other such editorial conventions can evolve, but in terms of finishing ES6 they are lower priority than resolve remaining bugs and open technical issues.

# Brendan Eich (11 years ago)

Allen Wirfs-Brock wrote:

Naming and other such editorial conventions can evolve, but in terms of finishing ES6 they are lower priority than resolve remaining bugs and open technical issues.

Easiest fix: s/<Record>/Struct/g or better. Just a thought, not putting this on your plate, rather asking for es-discuss discussion.