mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Use non-canonical instructions in default values. (#7737)
Per feedback on #7665, this PR switches the default value table storage from canonical constant inst_ids to non-canonical. Furthermore, this PR simplifies the default value support in check by requiring that the first owned declaration of a function completely specify all of its default values. Updates the diagnostic code and tests to reflect this new stricter requirement.
This commit is contained in:
@@ -373,6 +373,25 @@ static auto DiagnosePositionalParams(Context& context,
|
||||
function_info.param_patterns_id = SemIR::InstBlockId::Empty;
|
||||
}
|
||||
|
||||
// Diagnoses that the default values for function parameters have been
|
||||
// completely specified, which is a requirement on the first owning declaration
|
||||
// of a function.
|
||||
static auto CheckDefaultValuesCompletelySpecified(
|
||||
Context& context, SemIR::Function& function_info) -> void {
|
||||
auto unspecified_value_ids = llvm::make_filter_range(
|
||||
context.inst_blocks().GetOrEmpty(
|
||||
function_info.call_param_default_values_id),
|
||||
[&context](auto inst_id) {
|
||||
return context.insts().Is<SemIR::UnspecifiedValue>(inst_id);
|
||||
});
|
||||
for (auto inst_id : unspecified_value_ids) {
|
||||
CARBON_DIAGNOSTIC(PatternDefaultValueNotSpecified, Error,
|
||||
"found unspecified default parameter value in the "
|
||||
"function's first owning declaration");
|
||||
context.emitter().Emit(inst_id, PatternDefaultValueNotSpecified);
|
||||
}
|
||||
}
|
||||
|
||||
// Build a FunctionDecl describing the signature of a function. This
|
||||
// handles the common logic shared by function declaration syntax and function
|
||||
// definition syntax.
|
||||
@@ -457,6 +476,10 @@ static auto BuildFunctionDecl(Context& context,
|
||||
}
|
||||
|
||||
DiagnosePositionalParams(context, function_info);
|
||||
if (name_context.state != DeclNameStack::NameContext::State::Poisoned &&
|
||||
!name_context.prev_inst_id().has_value()) {
|
||||
CheckDefaultValuesCompletelySpecified(context, function_info);
|
||||
}
|
||||
|
||||
TryMergeRedecl(
|
||||
context, name_context, std::nullopt,
|
||||
|
||||
Reference in New Issue
Block a user