mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 15:51:07 +01:00
Clean up handling of Call params (#5061)
- Explicitly document that `*Param` and `*ParamPattern` insts represent `Call` parameters. - Stop wrapping compile-time parameter patterns in `ValueParamPattern` insts (because they aren't `Call` parameters). - Document how `MatchContext::results_` relates to the `Call` parameters, and be more consistent about when it's written to. - Remove `RuntimeParamIndex::Unknown`: we no longer need to distinguish "this `Param`'s runtime index is unknown" from "this `Param` isn't a runtime param", because we no longer use `Param`s at all in the latter case. - Rename `RuntimeParamIndex` to `CallParamIndex`. As a side effect of removing the `ValueParamPattern` insts, this fixes a minor diagnostic bug where `NoteInitializingParam` didn't identify the specific parameter that led to a deduction failure, because it expects generic parameters to only be represented by `SymbolicBindingPattern`s, but before this change they could be wrapped in `ValueParamPattern`s.
This commit is contained in:
@@ -62,7 +62,7 @@ auto GetCalleeFunction(const File& sem_ir, InstId callee_id,
|
||||
|
||||
auto Function::GetParamPatternInfoFromPatternId(const File& sem_ir,
|
||||
InstId pattern_id)
|
||||
-> ParamPatternInfo {
|
||||
-> std::optional<ParamPatternInfo> {
|
||||
auto inst_id = pattern_id;
|
||||
auto inst = sem_ir.insts().Get(inst_id);
|
||||
|
||||
@@ -71,16 +71,19 @@ auto Function::GetParamPatternInfoFromPatternId(const File& sem_ir,
|
||||
inst = sem_ir.insts().Get(inst_id);
|
||||
}
|
||||
|
||||
auto param_pattern_inst = inst.TryAs<SemIR::AnyParamPattern>();
|
||||
if (!param_pattern_inst) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto param_pattern_id = inst_id;
|
||||
auto param_pattern_inst = inst.As<SemIR::AnyParamPattern>();
|
||||
|
||||
inst_id = param_pattern_inst.subpattern_id;
|
||||
inst_id = param_pattern_inst->subpattern_id;
|
||||
inst = sem_ir.insts().Get(inst_id);
|
||||
|
||||
auto binding_pattern = inst.As<AnyBindingPattern>();
|
||||
return {.inst_id = param_pattern_id,
|
||||
.inst = param_pattern_inst,
|
||||
.entity_name_id = binding_pattern.entity_name_id};
|
||||
return {{.inst_id = param_pattern_id,
|
||||
.inst = *param_pattern_inst,
|
||||
.entity_name_id = binding_pattern.entity_name_id}};
|
||||
}
|
||||
|
||||
auto Function::GetNameFromPatternId(const File& sem_ir, InstId pattern_id)
|
||||
@@ -97,10 +100,10 @@ auto Function::GetNameFromPatternId(const File& sem_ir, InstId pattern_id)
|
||||
return SemIR::NameId::None;
|
||||
}
|
||||
|
||||
auto param_pattern_inst = inst.As<SemIR::AnyParamPattern>();
|
||||
|
||||
inst_id = param_pattern_inst.subpattern_id;
|
||||
inst = sem_ir.insts().Get(inst_id);
|
||||
if (auto param_pattern_inst = inst.TryAs<SemIR::AnyParamPattern>()) {
|
||||
inst_id = param_pattern_inst->subpattern_id;
|
||||
inst = sem_ir.insts().Get(inst_id);
|
||||
}
|
||||
|
||||
if (inst.Is<ReturnSlotPattern>()) {
|
||||
return SemIR::NameId::ReturnSlot;
|
||||
|
||||
Reference in New Issue
Block a user