@@ -93,17 +93,13 @@ static CodableConformanceType typeConformsToCodable(DeclContext *context,
93
93
// / Returns whether the given variable conforms to the given {En,De}codable
94
94
// / protocol.
95
95
// /
96
- // / \param tc The typechecker to use in validating {En,De}codable conformance.
97
- // /
98
- // / \param context The \c DeclContext in which to check conformance.
96
+ // / \param DC The \c DeclContext in which to check conformance.
99
97
// /
100
98
// / \param varDecl The \c VarDecl to validate.
101
99
// /
102
100
// / \param proto The \c ProtocolDecl to check conformance to.
103
- static CodableConformanceType varConformsToCodable (TypeChecker &tc,
104
- DeclContext *context,
105
- VarDecl *varDecl,
106
- ProtocolDecl *proto) {
101
+ static CodableConformanceType
102
+ varConformsToCodable (DeclContext *DC, VarDecl *varDecl, ProtocolDecl *proto) {
107
103
// If the decl doesn't yet have a type, we may be seeing it before the type
108
104
// checker has gotten around to evaluating its type. For example:
109
105
//
@@ -117,8 +113,8 @@ static CodableConformanceType varConformsToCodable(TypeChecker &tc,
117
113
// // hasn't yet been evaluated
118
114
// }
119
115
bool isIUO = varDecl->isImplicitlyUnwrappedOptional ();
120
- return typeConformsToCodable (context , varDecl->getValueInterfaceType (),
121
- isIUO, proto);
116
+ return typeConformsToCodable (DC , varDecl->getValueInterfaceType (), isIUO ,
117
+ proto);
122
118
}
123
119
124
120
// / Retrieve the variable name for the purposes of encoding/decoding.
@@ -135,7 +131,6 @@ static Identifier getVarNameForCoding(VarDecl *var) {
135
131
// / \param codingKeysDecl The \c CodingKeys enum decl to validate.
136
132
static bool validateCodingKeysEnum (DerivedConformance &derived,
137
133
EnumDecl *codingKeysDecl) {
138
- auto &tc = derived.TC ;
139
134
auto conformanceDC = derived.getConformanceContext ();
140
135
141
136
// Look through all var decls in the given type.
@@ -161,8 +156,8 @@ static bool validateCodingKeysEnum(DerivedConformance &derived,
161
156
for (auto elt : codingKeysDecl->getAllElements ()) {
162
157
auto it = properties.find (elt->getName ());
163
158
if (it == properties.end ()) {
164
- tc. diagnose ( elt->getLoc (), diag::codable_extraneous_codingkey_case_here,
165
- elt->getName ());
159
+ elt->diagnose ( diag::codable_extraneous_codingkey_case_here,
160
+ elt->getName ());
166
161
// TODO: Investigate typo-correction here; perhaps the case name was
167
162
// misspelled and we can provide a fix-it.
168
163
propertiesAreValid = false ;
@@ -171,17 +166,16 @@ static bool validateCodingKeysEnum(DerivedConformance &derived,
171
166
172
167
// We have a property to map to. Ensure it's {En,De}codable.
173
168
auto conformance =
174
- varConformsToCodable (tc, conformanceDC, it->second , derived.Protocol );
169
+ varConformsToCodable (conformanceDC, it->second , derived.Protocol );
175
170
switch (conformance) {
176
171
case Conforms:
177
172
// The property was valid. Remove it from the list.
178
173
properties.erase (it);
179
174
break ;
180
175
181
176
case DoesNotConform:
182
- tc.diagnose (it->second ->getLoc (),
183
- diag::codable_non_conforming_property_here,
184
- derived.getProtocolType (), it->second ->getType ());
177
+ it->second ->diagnose (diag::codable_non_conforming_property_here,
178
+ derived.getProtocolType (), it->second ->getType ());
185
179
LLVM_FALLTHROUGH;
186
180
187
181
case TypeNotValidated:
@@ -215,8 +209,8 @@ static bool validateCodingKeysEnum(DerivedConformance &derived,
215
209
// The var was not default initializable, and did not have an explicit
216
210
// initial value.
217
211
propertiesAreValid = false ;
218
- tc. diagnose ( it->second ->getLoc (), diag::codable_non_decoded_property_here,
219
- derived.getProtocolType (), it->first );
212
+ it->second ->diagnose ( diag::codable_non_decoded_property_here,
213
+ derived.getProtocolType (), it->first );
220
214
}
221
215
}
222
216
@@ -241,8 +235,7 @@ struct CodingKeysValidity {
241
235
// /
242
236
// / \returns A \c CodingKeysValidity value representing the result of the check.
243
237
static CodingKeysValidity hasValidCodingKeysEnum (DerivedConformance &derived) {
244
- auto &tc = derived.TC ;
245
- auto &C = tc.Context ;
238
+ auto &C = derived.Context ;
246
239
auto codingKeysDecls =
247
240
derived.Nominal ->lookupDirect (DeclName (C.Id_CodingKeys ));
248
241
if (codingKeysDecls.empty ())
@@ -255,9 +248,8 @@ static CodingKeysValidity hasValidCodingKeysEnum(DerivedConformance &derived) {
255
248
256
249
auto *codingKeysTypeDecl = dyn_cast<TypeDecl>(result);
257
250
if (!codingKeysTypeDecl) {
258
- tc.diagnose (result->getLoc (),
259
- diag::codable_codingkeys_type_is_not_an_enum_here,
260
- derived.getProtocolType ());
251
+ result->diagnose (diag::codable_codingkeys_type_is_not_an_enum_here,
252
+ derived.getProtocolType ());
261
253
return CodingKeysValidity (/* hasType=*/ true , /* isValid=*/ false );
262
254
}
263
255
@@ -279,18 +271,18 @@ static CodingKeysValidity hasValidCodingKeysEnum(DerivedConformance &derived) {
279
271
codingKeysTypeDecl->getLoc () :
280
272
cast<TypeDecl>(result)->getLoc ();
281
273
282
- tc .diagnose (loc, diag::codable_codingkeys_type_does_not_conform_here,
283
- derived.getProtocolType ());
274
+ C. Diags .diagnose (loc, diag::codable_codingkeys_type_does_not_conform_here,
275
+ derived.getProtocolType ());
284
276
285
277
return CodingKeysValidity (/* hasType=*/ true , /* isValid=*/ false );
286
278
}
287
279
288
280
// CodingKeys must be an enum for synthesized conformance.
289
281
auto *codingKeysEnum = dyn_cast<EnumDecl>(codingKeysTypeDecl);
290
282
if (!codingKeysEnum) {
291
- tc. diagnose ( codingKeysTypeDecl->getLoc (),
292
- diag::codable_codingkeys_type_is_not_an_enum_here,
293
- derived.getProtocolType ());
283
+ codingKeysTypeDecl->diagnose (
284
+ diag::codable_codingkeys_type_is_not_an_enum_here,
285
+ derived.getProtocolType ());
294
286
return CodingKeysValidity (/* hasType=*/ true , /* isValid=*/ false );
295
287
}
296
288
@@ -303,8 +295,7 @@ static CodingKeysValidity hasValidCodingKeysEnum(DerivedConformance &derived) {
303
295
// /
304
296
// / If able to synthesize the enum, adds it directly to \c derived.Nominal.
305
297
static EnumDecl *synthesizeCodingKeysEnum (DerivedConformance &derived) {
306
- auto &tc = derived.TC ;
307
- auto &C = tc.Context ;
298
+ auto &C = derived.Context ;
308
299
// Create CodingKeys in the parent type always, because both
309
300
// Encodable and Decodable might want to use it, and they may have
310
301
// different conditional bounds. CodingKeys is simple and can't
@@ -348,7 +339,7 @@ static EnumDecl *synthesizeCodingKeysEnum(DerivedConformance &derived) {
348
339
// concurrently checking the variables for the current protocol
349
340
// conformance being synthesized, for which we use the conformance
350
341
// context, not the type.
351
- auto conformance = varConformsToCodable (tc, derived.getConformanceContext (),
342
+ auto conformance = varConformsToCodable (derived.getConformanceContext (),
352
343
varDecl, derived.Protocol );
353
344
switch (conformance) {
354
345
case Conforms:
@@ -363,9 +354,8 @@ static EnumDecl *synthesizeCodingKeysEnum(DerivedConformance &derived) {
363
354
}
364
355
365
356
case DoesNotConform:
366
- tc.diagnose (varDecl->getLoc (),
367
- diag::codable_non_conforming_property_here,
368
- derived.getProtocolType (), varDecl->getType ());
357
+ varDecl->diagnose (diag::codable_non_conforming_property_here,
358
+ derived.getProtocolType (), varDecl->getType ());
369
359
LLVM_FALLTHROUGH;
370
360
371
361
case TypeNotValidated:
@@ -380,7 +370,10 @@ static EnumDecl *synthesizeCodingKeysEnum(DerivedConformance &derived) {
380
370
return nullptr ;
381
371
382
372
// Forcibly derive conformance to CodingKey.
383
- tc.checkConformancesInContext (enumDecl, enumDecl);
373
+ //
374
+ // FIXME: Drop the dependency on the type checker.
375
+ auto *tc = static_cast <TypeChecker *>(C.getLazyResolver ());
376
+ tc->checkConformancesInContext (enumDecl, enumDecl);
384
377
385
378
// Add to the type.
386
379
target->addMember (enumDecl);
@@ -706,7 +699,7 @@ deriveBodyEncodable_encode(AbstractFunctionDecl *encodeDecl, void *) {
706
699
// /
707
700
// / Adds the function declaration to the given type before returning it.
708
701
static FuncDecl *deriveEncodable_encode (DerivedConformance &derived) {
709
- auto &C = derived.TC . Context ;
702
+ auto &C = derived.Context ;
710
703
auto conformanceDC = derived.getConformanceContext ();
711
704
712
705
// Expected type: (Self) -> (Encoder) throws -> ()
@@ -985,7 +978,7 @@ deriveBodyDecodable_init(AbstractFunctionDecl *initDecl, void *) {
985
978
// /
986
979
// / Adds the function declaration to the given type before returning it.
987
980
static ValueDecl *deriveDecodable_init (DerivedConformance &derived) {
988
- auto &C = derived.TC . Context ;
981
+ auto &C = derived.Context ;
989
982
990
983
auto classDecl = dyn_cast<ClassDecl>(derived.Nominal );
991
984
auto conformanceDC = derived.getConformanceContext ();
@@ -1056,8 +1049,6 @@ static bool canSynthesize(DerivedConformance &derived, ValueDecl *requirement) {
1056
1049
//
1057
1050
// If the required initializer is not available, we shouldn't attempt to
1058
1051
// synthesize CodingKeys.
1059
- auto &tc = derived.TC ;
1060
- ASTContext &C = tc.Context ;
1061
1052
auto proto = derived.Protocol ;
1062
1053
auto *classDecl = dyn_cast<ClassDecl>(derived.Nominal );
1063
1054
if (proto->isSpecificProtocol (KnownProtocolKind::Decodable) && classDecl) {
@@ -1072,8 +1063,9 @@ static bool canSynthesize(DerivedConformance &derived, ValueDecl *requirement) {
1072
1063
// super.init() must be accessible.
1073
1064
// Passing an empty params array constructs a compound name with no
1074
1065
// arguments (as opposed to a simple name when omitted).
1075
- memberName = DeclName (C, DeclBaseName::createConstructor (),
1076
- ArrayRef<Identifier>());
1066
+ memberName =
1067
+ DeclName (derived.Context , DeclBaseName::createConstructor (),
1068
+ ArrayRef<Identifier>());
1077
1069
}
1078
1070
1079
1071
auto result =
@@ -1139,9 +1131,9 @@ ValueDecl *DerivedConformance::deriveEncodable(ValueDecl *requirement) {
1139
1131
if (!isa<StructDecl>(Nominal) && !isa<ClassDecl>(Nominal))
1140
1132
return nullptr ;
1141
1133
1142
- if (requirement->getBaseName () != TC. Context .Id_encode ) {
1134
+ if (requirement->getBaseName () != Context.Id_encode ) {
1143
1135
// Unknown requirement.
1144
- TC. diagnose ( requirement->getLoc (), diag::broken_encodable_requirement);
1136
+ requirement->diagnose ( diag::broken_encodable_requirement);
1145
1137
return nullptr ;
1146
1138
}
1147
1139
@@ -1163,12 +1155,12 @@ ValueDecl *DerivedConformance::deriveEncodable(ValueDecl *requirement) {
1163
1155
// diagnostics, then potentially collect notes. If we succeed in
1164
1156
// synthesizing Encodable, we can cancel the transaction and get rid of the
1165
1157
// fake failures.
1166
- DiagnosticTransaction diagnosticTransaction (TC. Context .Diags );
1167
- TC. diagnose (ConformanceDecl, diag::type_does_not_conform,
1168
- Nominal->getDeclaredType (), getProtocolType ());
1169
- TC. diagnose (requirement, diag::no_witnesses, diag::RequirementKind::Func,
1170
- requirement->getFullName (), getProtocolType (),
1171
- /* AddFixIt=*/ false );
1158
+ DiagnosticTransaction diagnosticTransaction (Context.Diags );
1159
+ ConformanceDecl-> diagnose (diag::type_does_not_conform,
1160
+ Nominal->getDeclaredType (), getProtocolType ());
1161
+ requirement-> diagnose (diag::no_witnesses, diag::RequirementKind::Func,
1162
+ requirement->getFullName (), getProtocolType (),
1163
+ /* AddFixIt=*/ false );
1172
1164
1173
1165
// Check other preconditions for synthesized conformance.
1174
1166
// This synthesizes a CodingKeys enum if possible.
@@ -1187,7 +1179,7 @@ ValueDecl *DerivedConformance::deriveDecodable(ValueDecl *requirement) {
1187
1179
1188
1180
if (requirement->getBaseName () != DeclBaseName::createConstructor ()) {
1189
1181
// Unknown requirement.
1190
- TC. diagnose ( requirement->getLoc (), diag::broken_decodable_requirement);
1182
+ requirement->diagnose ( diag::broken_decodable_requirement);
1191
1183
return nullptr ;
1192
1184
}
1193
1185
@@ -1199,12 +1191,12 @@ ValueDecl *DerivedConformance::deriveDecodable(ValueDecl *requirement) {
1199
1191
// diagnostics produced by canSynthesize and deriveDecodable_init to produce
1200
1192
// them in the right order -- see the comment in deriveEncodable for
1201
1193
// background on this transaction.
1202
- DiagnosticTransaction diagnosticTransaction (TC. Context .Diags );
1203
- TC. diagnose ( ConformanceDecl->getLoc (), diag::type_does_not_conform,
1204
- Nominal->getDeclaredType (), getProtocolType ());
1205
- TC. diagnose (requirement , diag::no_witnesses ,
1206
- diag::RequirementKind::Constructor, requirement->getFullName (),
1207
- getProtocolType (), /* AddFixIt=*/ false );
1194
+ DiagnosticTransaction diagnosticTransaction (Context.Diags );
1195
+ ConformanceDecl->diagnose ( diag::type_does_not_conform,
1196
+ Nominal->getDeclaredType (), getProtocolType ());
1197
+ requirement-> diagnose (diag::no_witnesses , diag::RequirementKind::Constructor ,
1198
+ requirement->getFullName (), getProtocolType (),
1199
+ /* AddFixIt=*/ false );
1208
1200
1209
1201
// Check other preconditions for synthesized conformance.
1210
1202
// This synthesizes a CodingKeys enum if possible.
0 commit comments