Skip to content

Commit 10d49aa

Browse files
committed
Typecheck ABI-only VarDecls
The decl checker was effectively not being run on these because we weren’t typechecking the PBD and typechecking the VarDecl itself is basically a no-op.
1 parent 8e30d7f commit 10d49aa

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

lib/AST/NameLookup.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,6 +2310,13 @@ void NominalTypeDecl::recordObjCMethod(AbstractFunctionDecl *method,
23102310
if (!ObjCMethodLookup && !createObjCMethodLookup())
23112311
return;
23122312

2313+
// Only record API decls.
2314+
Decl *abiRoleDecl = method;
2315+
if (auto accessor = dyn_cast<AccessorDecl>(method))
2316+
abiRoleDecl = accessor->getStorage();
2317+
if (!ABIRoleInfo(abiRoleDecl).providesAPI())
2318+
return;
2319+
23132320
// Record the method.
23142321
bool isInstanceMethod = method->isObjCInstanceMethod();
23152322
auto &vec = (*ObjCMethodLookup)[{selector, isInstanceMethod}].Methods;

lib/Sema/TypeCheckAttrABI.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ void checkABIAttrPBD(PatternBindingDecl *APBD, VarDecl *VD) {
11531153
}
11541154

11551155
// Check that each pattern has the same number of variables.
1156+
bool didDiagnose = false;
11561157
for (auto i : range(PBD->getNumPatternEntries())) {
11571158
SmallVector<VarDecl *, 8> VDs;
11581159
SmallVector<VarDecl *, 8> AVDs;
@@ -1162,18 +1163,24 @@ void checkABIAttrPBD(PatternBindingDecl *APBD, VarDecl *VD) {
11621163

11631164
if (VDs.size() < AVDs.size()) {
11641165
for (auto AVD : drop_begin(AVDs, VDs.size())) {
1165-
AVD->diagnose(diag::attr_abi_mismatched_var,
1166-
AVD, /*isABI=*/true);
1166+
AVD->diagnose(diag::attr_abi_mismatched_var, AVD, /*isABI=*/true);
1167+
didDiagnose = true;
11671168
}
11681169
}
11691170
else if (VDs.size() > AVDs.size()) {
11701171
for (auto VD : drop_begin(VDs, AVDs.size())) {
1171-
VD->diagnose(diag::attr_abi_mismatched_var,
1172-
VD, /*isABI=*/false);
1172+
VD->diagnose(diag::attr_abi_mismatched_var, VD, /*isABI=*/false);
1173+
didDiagnose = true;
11731174
}
11741175
}
11751176
}
1177+
if (didDiagnose)
1178+
return;
1179+
1180+
// Check the ABI PBD--this is what checks the underlying vars.
1181+
TypeChecker::typeCheckDecl(APBD);
11761182
}
1183+
11771184
} // end anonymous namespace
11781185

11791186
void TypeChecker::checkDeclABIAttribute(Decl *D, ABIAttr *attr) {

lib/Sema/TypeCheckStorage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,6 +3847,10 @@ void HasStorageRequest::cacheResult(bool hasStorage) const {
38473847
StorageImplInfo
38483848
StorageImplInfoRequest::evaluate(Evaluator &evaluator,
38493849
AbstractStorageDecl *storage) const {
3850+
auto abiRole = ABIRoleInfo(storage);
3851+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
3852+
return abiRole.getCounterpart()->getImplInfo();
3853+
38503854
if (auto *param = dyn_cast<ParamDecl>(storage)) {
38513855
return StorageImplInfo::getSimpleStored(
38523856
param->isImmutableInFunctionBody()

0 commit comments

Comments
 (0)