mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:41:27 +01:00
lazy field index (#4514)
We considered a couple of other options for this: * https://github.com/carbon-language/carbon-lang/pull/4515 Keep the `ElementIndex` numbering vptr-ignorant, and do +1 offsets as needed - seems subtle/easy to miss * https://github.com/carbon-language/carbon-lang/pull/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 #4515 does not have/does address) but does address normal `obj.member` access correctly. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
9c71151e34
commit
f921923b4b
@@ -199,6 +199,15 @@ auto Context::ReplaceInstBeforeConstantUse(SemIR::InstId inst_id,
|
||||
FinishInst(inst_id, inst);
|
||||
}
|
||||
|
||||
auto Context::ReplaceInstPreservingConstantValue(SemIR::InstId inst_id,
|
||||
SemIR::Inst inst) -> void {
|
||||
auto old_const_id = sem_ir().constant_values().Get(inst_id);
|
||||
sem_ir().insts().Set(inst_id, inst);
|
||||
CARBON_VLOG("ReplaceInst: {0} -> {1}\n", inst_id, inst);
|
||||
auto new_const_id = TryEvalInst(*this, inst_id, inst);
|
||||
CARBON_CHECK(old_const_id == new_const_id);
|
||||
}
|
||||
|
||||
auto Context::DiagnoseDuplicateName(SemIRLoc dup_def, SemIRLoc prev_def)
|
||||
-> void {
|
||||
CARBON_DIAGNOSTIC(NameDeclDuplicate, Error,
|
||||
|
||||
Reference in New Issue
Block a user