@@ -174,7 +174,7 @@ namespace {
174
174
// / A callback to be invoked every time a type was deserialized.
175
175
std::function<void (Type)> ParsedTypeCallback;
176
176
177
- bool performTypeLocChecking (TypeLoc &T , bool IsSILType,
177
+ Type performTypeLocChecking (TypeRepr *TyR , bool IsSILType,
178
178
GenericEnvironment *GenericEnv = nullptr );
179
179
180
180
void convertRequirements (SILFunction *F, ArrayRef<RequirementRepr> From,
@@ -868,34 +868,32 @@ void SILParser::convertRequirements(SILFunction *F,
868
868
IdentTypeReprLookup PerformLookup (P);
869
869
// Use parser lexical scopes to resolve references
870
870
// to the generic parameters.
871
- auto ResolveToInterfaceType = [&](TypeLoc Ty) -> Type {
872
- Ty.getTypeRepr ()->walk (PerformLookup);
873
- performTypeLocChecking (Ty, /* IsSIL */ false );
874
- assert (Ty.getType ());
875
- return Ty.getType ()->mapTypeOutOfContext ();
871
+ auto ResolveToInterfaceType = [&](TypeRepr *Ty) -> Type {
872
+ Ty->walk (PerformLookup);
873
+ return performTypeLocChecking (Ty, /* IsSIL */ false )->mapTypeOutOfContext ();
876
874
};
877
875
878
876
for (auto &Req : From) {
879
877
if (Req.getKind () == RequirementReprKind::SameType) {
880
- auto FirstType = ResolveToInterfaceType (Req.getFirstTypeLoc ());
881
- auto SecondType = ResolveToInterfaceType (Req.getSecondTypeLoc ());
878
+ auto FirstType = ResolveToInterfaceType (Req.getFirstTypeRepr ());
879
+ auto SecondType = ResolveToInterfaceType (Req.getSecondTypeRepr ());
882
880
Requirement ConvertedRequirement (RequirementKind::SameType, FirstType,
883
881
SecondType);
884
882
To.push_back (ConvertedRequirement);
885
883
continue ;
886
884
}
887
885
888
886
if (Req.getKind () == RequirementReprKind::TypeConstraint) {
889
- auto Subject = ResolveToInterfaceType (Req.getSubjectLoc ());
890
- auto Constraint = ResolveToInterfaceType (Req.getConstraintLoc ());
887
+ auto Subject = ResolveToInterfaceType (Req.getSubjectRepr ());
888
+ auto Constraint = ResolveToInterfaceType (Req.getConstraintRepr ());
891
889
Requirement ConvertedRequirement (RequirementKind::Conformance, Subject,
892
890
Constraint);
893
891
To.push_back (ConvertedRequirement);
894
892
continue ;
895
893
}
896
894
897
895
if (Req.getKind () == RequirementReprKind::LayoutConstraint) {
898
- auto Subject = ResolveToInterfaceType (Req.getSubjectLoc ());
896
+ auto Subject = ResolveToInterfaceType (Req.getSubjectRepr ());
899
897
Requirement ConvertedRequirement (RequirementKind::Layout, Subject,
900
898
Req.getLayoutConstraint ());
901
899
To.push_back (ConvertedRequirement);
@@ -1094,14 +1092,16 @@ static bool parseDeclSILOptional(bool *isTransparent,
1094
1092
return false ;
1095
1093
}
1096
1094
1097
- bool SILParser::performTypeLocChecking (TypeLoc & T, bool IsSILType,
1095
+ Type SILParser::performTypeLocChecking (TypeRepr * T, bool IsSILType,
1098
1096
GenericEnvironment *GenericEnv) {
1099
1097
if (GenericEnv == nullptr )
1100
1098
GenericEnv = ContextGenericEnv;
1101
1099
1102
- return swift::performTypeLocChecking (P.Context , T,
1100
+ TypeLoc loc (T);
1101
+ (void ) swift::performTypeLocChecking (P.Context , loc,
1103
1102
/* isSILMode=*/ true , IsSILType,
1104
1103
GenericEnv, &P.SF );
1104
+ return loc.getType ();
1105
1105
}
1106
1106
1107
1107
// / Find the top-level ValueDecl or Module given a name.
@@ -1155,17 +1155,17 @@ static ValueDecl *lookupMember(Parser &P, Type Ty, DeclBaseName Name,
1155
1155
bool SILParser::parseASTType (CanType &result, GenericEnvironment *env) {
1156
1156
ParserResult<TypeRepr> parsedType = P.parseType ();
1157
1157
if (parsedType.isNull ()) return true ;
1158
- TypeLoc loc = parsedType.get ();
1159
- if (performTypeLocChecking (loc, /* IsSILType= */ false , env ))
1158
+ auto resolvedType = performTypeLocChecking ( parsedType.get (), /* IsSILType= */ false , env );
1159
+ if (resolvedType-> hasError ( ))
1160
1160
return true ;
1161
1161
1162
1162
if (env)
1163
- result = loc. getType () ->mapTypeOutOfContext ()->getCanonicalType ();
1163
+ result = resolvedType ->mapTypeOutOfContext ()->getCanonicalType ();
1164
1164
else
1165
- result = loc. getType () ->getCanonicalType ();
1165
+ result = resolvedType ->getCanonicalType ();
1166
1166
1167
1167
// Invoke the callback on the parsed type.
1168
- ParsedTypeCallback (loc. getType () );
1168
+ ParsedTypeCallback (resolvedType );
1169
1169
return false ;
1170
1170
}
1171
1171
@@ -1244,16 +1244,16 @@ bool SILParser::parseSILType(SILType &Result,
1244
1244
ParsedGenericEnv = env;
1245
1245
1246
1246
// Apply attributes to the type.
1247
- TypeLoc Ty = P.applyAttributeToType (TyR.get (), attrs, specifier, specifierLoc);
1248
-
1249
- if (performTypeLocChecking (Ty, /* IsSILType= */ true , OuterGenericEnv ))
1247
+ auto *attrRepr = P.applyAttributeToType (TyR.get (), attrs, specifier, specifierLoc);
1248
+ auto Ty = performTypeLocChecking (attrRepr, /* IsSILType= */ true , OuterGenericEnv);
1249
+ if (Ty-> hasError ( ))
1250
1250
return true ;
1251
1251
1252
- Result = SILType::getPrimitiveType (Ty. getType () ->getCanonicalType (),
1252
+ Result = SILType::getPrimitiveType (Ty->getCanonicalType (),
1253
1253
category);
1254
1254
1255
1255
// Invoke the callback on the parsed type.
1256
- ParsedTypeCallback (Ty. getType () );
1256
+ ParsedTypeCallback (Ty);
1257
1257
1258
1258
return false ;
1259
1259
}
@@ -1644,34 +1644,34 @@ bool SILParser::parseSILBBArgsAtBranch(SmallVector<SILValue, 6> &Args,
1644
1644
// /
1645
1645
// / FIXME: This is a hack to work around the lack of a DeclContext for
1646
1646
// / witness tables.
1647
- static void bindProtocolSelfInTypeRepr (TypeLoc &TL, ProtocolDecl *proto) {
1648
- if (auto typeRepr = TL.getTypeRepr ()) {
1649
- // AST walker to update 'Self' references.
1650
- class BindProtocolSelf : public ASTWalker {
1651
- ProtocolDecl *proto;
1652
- GenericTypeParamDecl *selfParam;
1653
- Identifier selfId;
1654
-
1655
- public:
1656
- BindProtocolSelf (ProtocolDecl *proto)
1657
- : proto(proto),
1658
- selfParam (proto->getProtocolSelfType ()->getDecl()),
1659
- selfId(proto->getASTContext ().Id_Self) {
1660
- }
1647
+ static void bindProtocolSelfInTypeRepr (TypeRepr *typeRepr, ProtocolDecl *proto) {
1648
+ assert (typeRepr);
1661
1649
1662
- virtual bool walkToTypeReprPre (TypeRepr *T) override {
1663
- if (auto ident = dyn_cast<IdentTypeRepr>(T)) {
1664
- auto firstComponent = ident->getComponentRange ().front ();
1665
- if (firstComponent->getNameRef ().isSimpleName (selfId))
1666
- firstComponent->setValue (selfParam, proto);
1667
- }
1650
+ // AST walker to update 'Self' references.
1651
+ class BindProtocolSelf : public ASTWalker {
1652
+ ProtocolDecl *proto;
1653
+ GenericTypeParamDecl *selfParam;
1654
+ Identifier selfId;
1668
1655
1669
- return true ;
1656
+ public:
1657
+ BindProtocolSelf (ProtocolDecl *proto)
1658
+ : proto(proto),
1659
+ selfParam (proto->getProtocolSelfType ()->getDecl()),
1660
+ selfId(proto->getASTContext ().Id_Self) {
1661
+ }
1662
+
1663
+ virtual bool walkToTypeReprPre (TypeRepr *T) override {
1664
+ if (auto ident = dyn_cast<IdentTypeRepr>(T)) {
1665
+ auto firstComponent = ident->getComponentRange ().front ();
1666
+ if (firstComponent->getNameRef ().isSimpleName (selfId))
1667
+ firstComponent->setValue (selfParam, proto);
1670
1668
}
1671
- };
1672
1669
1673
- typeRepr->walk (BindProtocolSelf(proto));
1674
- }
1670
+ return true ;
1671
+ }
1672
+ };
1673
+
1674
+ typeRepr->walk (BindProtocolSelf(proto));
1675
1675
}
1676
1676
1677
1677
// / Parse the substitution list for an apply instruction or
@@ -1693,12 +1693,13 @@ bool SILParser::parseSubstitutions(SmallVectorImpl<ParsedSubstitution> &parsed,
1693
1693
ParserResult<TypeRepr> TyR = P.parseType ();
1694
1694
if (TyR.isNull ())
1695
1695
return true ;
1696
- TypeLoc Ty = TyR.get ();
1697
1696
if (defaultForProto)
1698
- bindProtocolSelfInTypeRepr (Ty, defaultForProto);
1699
- if (performTypeLocChecking (Ty, /* IsSILType=*/ false , GenericEnv))
1697
+ bindProtocolSelfInTypeRepr (TyR.get (), defaultForProto);
1698
+
1699
+ auto Ty = performTypeLocChecking (TyR.get (), /* IsSILType=*/ false , GenericEnv);
1700
+ if (Ty->hasError ())
1700
1701
return true ;
1701
- parsed.push_back ({Loc, Ty. getType () });
1702
+ parsed.push_back ({Loc, Ty});
1702
1703
} while (P.consumeIf (tok::comma));
1703
1704
1704
1705
// Consume the closing '>'.
@@ -2090,31 +2091,27 @@ bool SILParser::parseSILDeclRef(SILDeclRef &Member, bool FnTypeRequired) {
2090
2091
GenericsScope.reset ();
2091
2092
if (TyR.isNull ())
2092
2093
return true ;
2093
- TypeLoc Ty = TyR.get ();
2094
2094
2095
2095
// The type can be polymorphic.
2096
2096
GenericEnvironment *genericEnv = nullptr ;
2097
2097
if (auto fnType = dyn_cast<FunctionTypeRepr>(TyR.get ())) {
2098
2098
if (auto generics = fnType->getGenericParams ()) {
2099
- assert (!Ty.wasValidated () && Ty.getType ().isNull ());
2100
-
2101
2099
genericEnv = handleSILGenericParams (generics, &P.SF );
2102
2100
fnType->setGenericEnvironment (genericEnv);
2103
2101
}
2104
2102
if (auto generics = fnType->getPatternGenericParams ()) {
2105
- assert (!Ty.wasValidated () && Ty.getType ().isNull ());
2106
-
2107
2103
genericEnv = handleSILGenericParams (generics, &P.SF );
2108
2104
fnType->setPatternGenericEnvironment (genericEnv);
2109
2105
}
2110
2106
}
2111
2107
2112
- if (performTypeLocChecking (Ty, /* IsSILType=*/ false , genericEnv))
2108
+ auto Ty = performTypeLocChecking (TyR.get (), /* IsSILType=*/ false , genericEnv);
2109
+ if (Ty->hasError ())
2113
2110
return true ;
2114
2111
2115
2112
// Pick the ValueDecl that has the right type.
2116
2113
ValueDecl *TheDecl = nullptr ;
2117
- auto declTy = Ty. getType () ->getCanonicalType ();
2114
+ auto declTy = Ty->getCanonicalType ();
2118
2115
for (unsigned I = 0 , E = values.size (); I < E; ++I) {
2119
2116
auto *decl = values[I];
2120
2117
@@ -6306,14 +6303,13 @@ ProtocolConformanceRef SILParser::parseProtocolConformanceHelper(
6306
6303
ParserResult<TypeRepr> TyR = P.parseType ();
6307
6304
if (TyR.isNull ())
6308
6305
return ProtocolConformanceRef ();
6309
- TypeLoc Ty = TyR.get ();
6310
6306
if (defaultForProto) {
6311
- bindProtocolSelfInTypeRepr (Ty , defaultForProto);
6307
+ bindProtocolSelfInTypeRepr (TyR. get () , defaultForProto);
6312
6308
}
6313
6309
6314
- if (performTypeLocChecking (Ty, /* IsSILType=*/ false , witnessEnv))
6310
+ auto ConformingTy = performTypeLocChecking (TyR.get (), /* IsSILType=*/ false , witnessEnv);
6311
+ if (ConformingTy->hasError ())
6315
6312
return ProtocolConformanceRef ();
6316
- auto ConformingTy = Ty.getType ();
6317
6313
6318
6314
if (P.parseToken (tok::colon, diag::expected_sil_witness_colon))
6319
6315
return ProtocolConformanceRef ();
@@ -6429,7 +6425,7 @@ static bool parseSILVTableEntry(
6429
6425
return true ;
6430
6426
TypeLoc Ty = TyR.get ();
6431
6427
if (isDefaultWitnessTable)
6432
- bindProtocolSelfInTypeRepr (Ty , proto);
6428
+ bindProtocolSelfInTypeRepr (TyR. get () , proto);
6433
6429
if (swift::performTypeLocChecking (P.Context , Ty,
6434
6430
/* isSILMode=*/ false ,
6435
6431
/* isSILType=*/ false ,
@@ -6490,7 +6486,7 @@ static bool parseSILVTableEntry(
6490
6486
return true ;
6491
6487
TypeLoc Ty = TyR.get ();
6492
6488
if (isDefaultWitnessTable)
6493
- bindProtocolSelfInTypeRepr (Ty , proto);
6489
+ bindProtocolSelfInTypeRepr (TyR. get () , proto);
6494
6490
if (swift::performTypeLocChecking (P.Context , Ty,
6495
6491
/* isSILMode=*/ false ,
6496
6492
/* isSILType=*/ false ,
0 commit comments