Skip to content
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

lazy field index #4514

Merged
merged 18 commits into from
Nov 26, 2024
Merged

lazy field index #4514

merged 18 commits into from
Nov 26, 2024

Conversation

dwblaikie
Copy link
Contributor

@dwblaikie dwblaikie commented Nov 12, 2024

We considered a couple of other options for this:

But currently moving forward with this direction - of initializing field indexes with an invalid value until the end of the class definition, then assigning field indexes during construction of the class's object representation struct type. This direction might reinforce/help avoid premature access to the object representation before the class is complete, and give a single place where class layout is done (at class completion) if we want to add more options there, such as class layout optimizations, etc.

This patch still has problems with object initialization (that #4515 does not have/does address) but does address normal obj.member access correctly.

@dwblaikie dwblaikie marked this pull request as ready for review November 12, 2024 21:43
@dwblaikie
Copy link
Contributor Author

Ended up deciding maybe we could use this review as the central point for the design discussion - since the other two patches are a bit more drafty, so I'll leave them in draft mode, but linked from here for context - but maybe keeping the design discussion here in this PR.

Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direction here looks good, thanks!

Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

dwblaikie and others added 17 commits November 26, 2024 17:25
This way if the type_id of the FieldDecl is anything other than Error or
UnboundElementType, this should check-fail at the
`GetAs<UnboundElementType>`. We could add a more explicit check, but I
tend to err towards relying on implicit checks to avoid making the code
too noisy
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
@dwblaikie dwblaikie enabled auto-merge November 26, 2024 18:05
@dwblaikie dwblaikie added this pull request to the merge queue Nov 26, 2024
Merged via the queue into carbon-language:trunk with commit f921923 Nov 26, 2024
8 checks passed
@dwblaikie dwblaikie deleted the lazy_field_index branch November 26, 2024 18:29
bricknerb pushed a commit to bricknerb/carbon-lang that referenced this pull request Nov 28, 2024
We considered a couple of other options for this:
* carbon-language#4515 Keep the
`ElementIndex` numbering vptr-ignorant, and do +1 offsets as needed -
seems subtle/easy to miss
* carbon-language#4517 Always have a
zeroth element in the object representation, make it zero-size in the
case of no-vptr - @zygoloid was concerned this would add overhead
especially to stateless objects used in type-trait-like things.

But currently moving forward with this direction - of initializing field
indexes with an invalid value until the end of the class definition,
then assigning field indexes during construction of the class's object
representation struct type. This direction might reinforce/help avoid
premature access to the object representation before the class is
complete, and give a single place where class layout is done (at class
completion) if we want to add more options there, such as class layout
optimizations, etc.

This patch still has problems with object initialization (that carbon-language#4515
does not have/does address) but does address normal `obj.member` access
correctly.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants