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

Implement "fieldset" optimization for record types #2474

Closed
pcwalton opened this Issue Jun 1, 2012 · 5 comments

Comments

Projects
None yet
4 participants
@pcwalton
Contributor

pcwalton commented Jun 1, 2012

Currently, record field names are stored as strings in the structural types. This is inefficient; every time we want to define a record in the type table we must perform a string comparison against every field name. Instead we can simply intern an entire "fieldset" -- a list of interned field strings, compared by pointer value only -- as we come across it. Then ty_rec would be something like fieldset, [mt].

@pcdinh

This comment has been minimized.

Show comment
Hide comment
@pcdinh

pcdinh Jan 14, 2013

I learn from Rust 0.5 documentation that record type is gone. Now you call it struct type. Is that correct?

pcdinh commented Jan 14, 2013

I learn from Rust 0.5 documentation that record type is gone. Now you call it struct type. Is that correct?

@catamorphism

This comment has been minimized.

Show comment
Hide comment
@catamorphism

catamorphism Jan 14, 2013

Contributor

@pcdinh Not exactly. Record types and struct types are different. Two record types can be considered the same if the names and types of all their fields are identical and in the same order (that is: they're structurally the same). A struct type has a name that's part of its identity in addition to its fields and types, and two struct types are only considered the same if they refer to the struct type with the same name.

For example, if you write type Point = {x: int, y: int}; type Dot = {x: int, y: int};, you can use values of type Point and Dot interchangeably. But if you write struct Point {x: int, y: int} struct Dot {x: int, y: int}, the compiler will complain if you use a Dot where a Point is expected, or vice versa.

Contributor

catamorphism commented Jan 14, 2013

@pcdinh Not exactly. Record types and struct types are different. Two record types can be considered the same if the names and types of all their fields are identical and in the same order (that is: they're structurally the same). A struct type has a name that's part of its identity in addition to its fields and types, and two struct types are only considered the same if they refer to the struct type with the same name.

For example, if you write type Point = {x: int, y: int}; type Dot = {x: int, y: int};, you can use values of type Point and Dot interchangeably. But if you write struct Point {x: int, y: int} struct Dot {x: int, y: int}, the compiler will complain if you use a Dot where a Point is expected, or vice versa.

@pcdinh

This comment has been minimized.

Show comment
Hide comment
@pcdinh

pcdinh Jan 14, 2013

Thanks for your clarification. What I read from Rust docs is that I am recommended to use structural type instead of record type because record expression and record types will be removed in a future version.

http://static.rust-lang.org/doc/rust.html#record-expressions
"Note: In future versions of Rust, record expressions and record types will be removed."
http://static.rust-lang.org/doc/rust.html#record-types
"Records are therefore deprecated and will be removed in future versions of Rust. Structure types should be used instead."

Therefore I think that they are identical and can be used interchangeably. It turns out that they are different.

pcdinh commented Jan 14, 2013

Thanks for your clarification. What I read from Rust docs is that I am recommended to use structural type instead of record type because record expression and record types will be removed in a future version.

http://static.rust-lang.org/doc/rust.html#record-expressions
"Note: In future versions of Rust, record expressions and record types will be removed."
http://static.rust-lang.org/doc/rust.html#record-types
"Records are therefore deprecated and will be removed in future versions of Rust. Structure types should be used instead."

Therefore I think that they are identical and can be used interchangeably. It turns out that they are different.

@catamorphism

This comment has been minimized.

Show comment
Hide comment
@catamorphism

catamorphism Jan 14, 2013

Contributor

I think most people won't see much difference between struct types and record types in practice. There's just the one caveat that I thought I'd mention.

Contributor

catamorphism commented Jan 14, 2013

I think most people won't see much difference between struct types and record types in practice. There's just the one caveat that I thought I'd mention.

@nikomatsakis

This comment has been minimized.

Show comment
Hide comment
@nikomatsakis

nikomatsakis May 7, 2013

Contributor

Now that structural records have been removed and strings are interned, I
don't think that this issue is particularly relevant anymore. There are probably
still improvements to be had here, but I'm going to close the issue. @pcwalton
feel free to re-open if you disagree.

Contributor

nikomatsakis commented May 7, 2013

Now that structural records have been removed and strings are interned, I
don't think that this issue is particularly relevant anymore. There are probably
still improvements to be had here, but I'm going to close the issue. @pcwalton
feel free to re-open if you disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment