mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 07:41:04 +01:00
Add SemIR support for virtual functions (#4272)
I guess this technically would also allow code to pass check that hasn't before, and that isn't covered by tests (since it's masked by other failures in the tests that already test this functionality) - should I add another test/add some code to a valid test case? Also, this'll miscompile in lowering, since there's no support there yet - should I do anything about that to make lowering fail in some way? Or is it acceptable that some things just silently mis-lower? (I could add a currently-miscompiling test case too, to demonstrate this? (not sure if the autogenerated tests leave space for comments that would explain that the currently-tested behavior is incorrect?)) Is the addition to EntityWithParamsBase suitable? of course not all functions can be virtual, so it's a wasted bit at the moment for all those cases (though it's free, since it's bitpacked - but as we want to add more bits in there it might not be a scalable solution)? --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
8ac9c80e87
commit
5806d8385d
@@ -194,9 +194,17 @@ static auto BuildFunctionDecl(Context& context,
|
||||
DiagnoseModifiers(context, introducer, is_definition, parent_scope_inst_id,
|
||||
parent_scope_inst);
|
||||
bool is_extern = introducer.modifier_set.HasAnyOf(KeywordModifierSet::Extern);
|
||||
if (introducer.modifier_set.HasAnyOf(KeywordModifierSet::Method)) {
|
||||
context.TODO(introducer.modifier_node_id(ModifierOrder::Decl),
|
||||
"method modifier");
|
||||
SemIR::FunctionFields::VirtualModifier virtual_modifier =
|
||||
SemIR::FunctionFields::VirtualModifier::None;
|
||||
|
||||
if (introducer.modifier_set.HasAnyOf(KeywordModifierSet::Virtual)) {
|
||||
virtual_modifier = SemIR::FunctionFields::VirtualModifier::Virtual;
|
||||
}
|
||||
if (introducer.modifier_set.HasAnyOf(KeywordModifierSet::Abstract)) {
|
||||
virtual_modifier = SemIR::FunctionFields::VirtualModifier::Abstract;
|
||||
}
|
||||
if (introducer.modifier_set.HasAnyOf(KeywordModifierSet::Impl)) {
|
||||
virtual_modifier = SemIR::FunctionFields::VirtualModifier::Impl;
|
||||
}
|
||||
if (introducer.modifier_set.HasAnyOf(KeywordModifierSet::Interface)) {
|
||||
// TODO: Once we are saving the modifiers for a function, add check that
|
||||
@@ -216,7 +224,8 @@ static auto BuildFunctionDecl(Context& context,
|
||||
auto function_info =
|
||||
SemIR::Function{{name_context.MakeEntityWithParamsBase(
|
||||
name, decl_id, is_extern, introducer.extern_library)},
|
||||
{.return_storage_id = return_storage_id}};
|
||||
{.return_storage_id = return_storage_id,
|
||||
.virtual_modifier = virtual_modifier}};
|
||||
if (is_definition) {
|
||||
function_info.definition_id = decl_id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user