Skip to content

Commit 5a433f1

Browse files
committed
Explicitly call parseTypeOrValue for type value instructions
1 parent 86050e2 commit 5a433f1

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,42 @@ bool SILParser::parseASTType(CanType &result,
10581058
return false;
10591059
}
10601060

1061+
bool SILParser::parseASTTypeOrValue(CanType &result,
1062+
GenericSignature genericSig,
1063+
GenericParamList *genericParams,
1064+
bool forceContextualType) {
1065+
auto parsedType = P.parseTypeOrValue();
1066+
if (parsedType.isNull()) return true;
1067+
1068+
// If we weren't given a specific generic context to resolve the type
1069+
// within, use the contextual generic parameters and always produce
1070+
// a contextual type. Otherwise, produce a contextual type only if
1071+
// we were asked for one.
1072+
bool wantContextualType = forceContextualType;
1073+
if (!genericSig) {
1074+
genericSig = ContextGenericSig;
1075+
wantContextualType = true;
1076+
}
1077+
if (genericParams == nullptr)
1078+
genericParams = ContextGenericParams;
1079+
1080+
bindSILGenericParams(parsedType.get());
1081+
1082+
auto resolvedType = performTypeResolution(
1083+
parsedType.get(), /*isSILType=*/false, genericSig, genericParams);
1084+
if (wantContextualType && genericSig) {
1085+
resolvedType = genericSig.getGenericEnvironment()
1086+
->mapTypeIntoContext(resolvedType);
1087+
}
1088+
1089+
if (resolvedType->hasError())
1090+
return true;
1091+
1092+
result = resolvedType->getCanonicalType();
1093+
1094+
return false;
1095+
}
1096+
10611097
void SILParser::bindSILGenericParams(TypeRepr *TyR) {
10621098
// Resolve the generic environments for parsed generic function and box types.
10631099
class HandleSILGenericParamsWalker : public ASTWalker {
@@ -3098,7 +3134,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
30983134
CanType paramType;
30993135
if (parseSILType(Ty) ||
31003136
parseVerbatim("for") ||
3101-
parseASTType(paramType))
3137+
parseASTTypeOrValue(paramType))
31023138
return true;
31033139

31043140
ResultVal = B.createTypeValue(InstLoc, Ty, paramType);

lib/SIL/Parser/SILParser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ class SILParser {
235235
return false;
236236
}
237237

238+
bool parseASTTypeOrValue(CanType &result,
239+
GenericSignature genericSig = GenericSignature(),
240+
GenericParamList *genericParams = nullptr,
241+
bool forceContextualType = false);
242+
238243
std::optional<StringRef>
239244
parseOptionalAttribute(ArrayRef<StringRef> expected) {
240245
// We parse here @ <identifier>.

0 commit comments

Comments
 (0)