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

Skip vptr when performing object initialization #4490

Merged
merged 4 commits into from
Nov 6, 2024

Conversation

dwblaikie
Copy link
Contributor

The cehck for vptr could be done differently (is this class dynamic and
its base class non-dynamic), and if we change the layout (to put the
vptr after any base) then this code will break (could add an assertion
that the vptr isn't present apart from at the start of the field list if
that'd seem worthwhile).

There's still later issues with lowering (if this patch causes crashes
in lowering, do they result in fuzz failures/need to be avoided before
this change is submitted?)

The cehck for vptr could be done differently (is this class dynamic and
its base class non-dynamic), and if we change the layout (to put the
vptr after any base) then this code will break (could add an assertion
that the vptr isn't present apart from at the start of the field list if
that'd seem worthwhile).

There's still later issues with lowering (if this patch causes crashes
in lowering, do they result in fuzz failures/need to be avoided before
this change is submitted?)
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 good, thanks!

for (auto [i, dest_field_id] : llvm::enumerate(dest_elem_fields)) {
auto dest_field =
sem_ir.insts().GetAs<SemIR::StructTypeField>(dest_field_id);
if (dest_field.name_id == SemIR::NameId::Vptr) {
new_block.Set(i, SemIR::InstId::BuiltinError);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a TODO comment here to put a real vtable pointer in the vptr slot.

Comment on lines +395 to +399
bool dest_has_vptr =
!dest_elem_fields.empty() &&
sem_ir.insts()
.GetAs<SemIR::StructTypeField>(dest_elem_fields.front())
.name_id == SemIR::NameId::Vptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be worth factoring out into a helper function. Let's keep an eye on this and see if we want to do it in more places.

@dwblaikie dwblaikie added this pull request to the merge queue Nov 6, 2024
Merged via the queue into carbon-language:trunk with commit d79a374 Nov 6, 2024
8 checks passed
@dwblaikie dwblaikie deleted the no_source_init_vptr branch November 6, 2024 18:39
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