Separate pattern types from expression types (#5360)

This is a step toward treating patterns as compile-time constants, so
that we can import them more easily.
This commit is contained in:
Geoff Romer
2025-04-28 16:54:37 +00:00
committed by GitHub
parent 84384cf126
commit fafb655d39
565 changed files with 11956 additions and 8095 deletions
+7 -4
View File
@@ -337,7 +337,8 @@ static auto MakeParamPatternsBlockId(Context& context, SemIR::LocId loc_id,
params.reserve(clang_decl.parameters().size());
for (const clang::ParmVarDecl* param : clang_decl.parameters()) {
clang::QualType param_type = param->getType().getCanonicalType();
SemIR::TypeId type_id = MapType(context, param_type).type_id;
SemIR::TypeId type_id =
GetPatternType(context, MapType(context, param_type).type_id);
if (type_id == SemIR::ErrorInst::TypeId) {
context.TODO(loc_id, llvm::formatv("Unsupported: parameter type: {0}",
param_type.getAsString()));
@@ -386,14 +387,16 @@ static auto GetReturnType(Context& context, SemIR::LocId loc_id,
ret_type.getAsString()));
return SemIR::ErrorInst::InstId;
}
auto pattern_type_id = GetPatternType(context, type_id);
SemIR::InstId return_slot_pattern_id = AddInstInNoBlock(
// TODO: Fill in a location for the return type once available.
context, SemIR::LocIdAndInst::NoLoc(SemIR::ReturnSlotPattern(
{.type_id = type_id, .type_inst_id = type_inst_id})));
context,
SemIR::LocIdAndInst::NoLoc(SemIR::ReturnSlotPattern(
{.type_id = pattern_type_id, .type_inst_id = type_inst_id})));
SemIR::InstId param_pattern_id = AddInstInNoBlock(
// TODO: Fill in a location for the return type once available.
context, SemIR::LocIdAndInst::NoLoc(SemIR::OutParamPattern(
{.type_id = type_id,
{.type_id = pattern_type_id,
.subpattern_id = return_slot_pattern_id,
.index = SemIR::CallParamIndex::None})));
return param_pattern_id;