Skip to content

Commit d1d5243

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 3aa1ed1 commit d1d5243

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
@@ -2317,6 +2317,13 @@ void NominalTypeDecl::recordObjCMethod(AbstractFunctionDecl *method,
23172317
if (!ObjCMethodLookup && !createObjCMethodLookup())
23182318
return;
23192319

2320+
// Only record API decls.
2321+
Decl *abiRoleDecl = method;
2322+
if (auto accessor = dyn_cast<AccessorDecl>(method))
2323+
abiRoleDecl = accessor->getStorage();
2324+
if (!ABIRoleInfo(abiRoleDecl).providesAPI())
2325+
return;
2326+
23202327
// Record the method.
23212328
bool isInstanceMethod = method->isObjCInstanceMethod();
23222329
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
@@ -3844,6 +3844,10 @@ void HasStorageRequest::cacheResult(bool hasStorage) const {
38443844
StorageImplInfo
38453845
StorageImplInfoRequest::evaluate(Evaluator &evaluator,
38463846
AbstractStorageDecl *storage) const {
3847+
auto abiRole = ABIRoleInfo(storage);
3848+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
3849+
return abiRole.getCounterpart()->getImplInfo();
3850+
38473851
if (auto *param = dyn_cast<ParamDecl>(storage)) {
38483852
return StorageImplInfo::getSimpleStored(
38493853
param->isImmutableInFunctionBody()

0 commit comments

Comments
 (0)