Skip to content

Commit 6a8d321

Browse files
committed
[Type checker] Move ad-hoc isObjC/isDynamic checking to finalization.
Whenever we visit a declaration via the DeclChecker, add it to the list of declarations to finalize. This makes sure that we can centralize the notion of “finalize for SILGen” and that it will be called for everything in the source file being processed.
1 parent cde94f6 commit 6a8d321

File tree

8 files changed

+22
-40
lines changed

8 files changed

+22
-40
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,8 +2332,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
23322332
if (auto VD = dyn_cast<ValueDecl>(decl)) {
23332333
checkRedeclaration(TC, VD);
23342334

2335-
(void)VD->isObjC();
2336-
(void)VD->isDynamic();
2335+
// Make sure we finalize this declaration.
2336+
TC.DeclsToFinalize.insert(VD);
23372337

23382338
// If this is a member of a nominal type, don't allow it to have a name of
23392339
// "Type" or "Protocol" since we reserve the X.Type and X.Protocol
@@ -4683,6 +4683,17 @@ static void finalizeType(TypeChecker &TC, NominalTypeDecl *nominal) {
46834683
continue;
46844684

46854685
TC.DeclsToFinalize.insert(VD);
4686+
4687+
// The only thing left to do is synthesize storage for lazy variables.
4688+
auto *prop = dyn_cast<VarDecl>(D);
4689+
if (!prop)
4690+
continue;
4691+
4692+
if (prop->getAttrs().hasAttribute<LazyAttr>() && !prop->isStatic() &&
4693+
(!prop->getGetter() || !prop->getGetter()->hasBody())) {
4694+
finalizeAbstractStorageDecl(TC, prop);
4695+
TC.completeLazyVarImplementation(prop);
4696+
}
46864697
}
46874698

46884699
if (auto *CD = dyn_cast<ClassDecl>(nominal)) {
@@ -4726,19 +4737,8 @@ void TypeChecker::finalizeDecl(ValueDecl *decl) {
47264737
finalizeType(*this, nominal);
47274738
} else if (auto storage = dyn_cast<AbstractStorageDecl>(decl)) {
47284739
finalizeAbstractStorageDecl(*this, storage);
4729-
4730-
// Synthesize storage for lazy variables, if still needed.
4731-
if (auto var = dyn_cast<VarDecl>(decl)) {
4732-
if (var->getAttrs().hasAttribute<LazyAttr>() && !var->isStatic() &&
4733-
var->getGetter() && !var->getGetter()->hasBody()) {
4734-
completeLazyVarImplementation(var);
4735-
}
4736-
}
47374740
}
47384741

4739-
// Ensure that we've computed access.
4740-
(void)decl->getFormalAccess();
4741-
47424742
// Compute overrides.
47434743
(void)decl->getOverriddenDecls();
47444744

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
569569
// FIXME: If we're not planning to run SILGen, this is wasted effort.
570570
while (TC.NextDeclToFinalize < TC.DeclsToFinalize.size()) {
571571
auto decl = TC.DeclsToFinalize[TC.NextDeclToFinalize++];
572-
if (decl->isInvalid() || TC.Context.hadError())
572+
if (decl->isInvalid())
573573
continue;
574574

575575
TC.finalizeDecl(decl);

test/FixCode/fixits-apply-objc.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ import ObjectiveC
44

55
// REQUIRES: objc_interop
66

7-
@objc class Selectors {
8-
func takeSel(_: Selector) {}
9-
func mySel() {}
10-
func test() {
11-
takeSel("mySel")
12-
takeSel(Selector("mySel"))
13-
}
14-
}
15-
167
func foo(an : Any) {
178
let a1 : AnyObject
189
a1 = an

test/FixCode/fixits-apply-objc.swift.result

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ import ObjectiveC
44

55
// REQUIRES: objc_interop
66

7-
@objc class Selectors {
8-
func takeSel(_: Selector) {}
9-
func mySel() {}
10-
func test() {
11-
takeSel(#selector(Selectors.mySel))
12-
takeSel(#selector(Selectors.mySel))
13-
}
14-
}
15-
167
func foo(an : Any) {
178
let a1 : AnyObject
189
a1 = an as AnyObject

test/IDE/complete_pound_keypath.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,5 @@ func completeInKeyPath2() {
4141
// CHECK-IN_KEYPATH: Decl[InstanceVar]/CurrNominal: prop1[#String#]; name=prop1
4242
// CHECK-IN_KEYPATH: Decl[InstanceVar]/CurrNominal: prop2[#ObjCClass?#]; name=prop2
4343
// CHECK-IN_KEYPATH: Decl[InstanceVar]/Super: hashValue[#Int#]; name=hashValue
44-
// CHECK-IN_KEYPATH: Decl[InstanceVar]/Super: hash[#Int#]; name=hash
4544

4645

test/Sema/Inputs/availability_multi_other.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,18 @@ class OtherIntroduced10_51 {
3232
return OtherIntroduced10_52()
3333
}
3434

35-
func takes10_52(o: OtherIntroduced10_52) {
35+
func takes10_52(o: OtherIntroduced10_52) {
3636
}
37-
37+
// expected-error@-2{{'OtherIntroduced10_52' is only available on OS X 10.52 or newer}}
38+
// expected-note@-3{{add @available attribute to enclosing instance method}}
39+
3840
@available(OSX, introduced: 10.52)
3941
func takes10_52Introduced10_52(o: OtherIntroduced10_52) {
4042
}
4143

44+
// expected-error@+1{{'OtherIntroduced10_52' is only available on OS X 10.52 or newer}}
4245
var propOf10_52: OtherIntroduced10_52 =
43-
44-
45-
OtherIntroduced10_52() // We don't expect an error here because the initializer is not type checked (by design).
46+
OtherIntroduced10_52()
4647

4748
@available(OSX, introduced: 10.52)
4849
var propOf10_52Introduced10_52: OtherIntroduced10_52 = OtherIntroduced10_52()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
struct External {
2-
var member: Something
2+
var member: Something // expected-error{{use of undeclared type 'Something'}}
33
}
44

55
struct OtherExternal {}

test/decl/protocol/conforms/near_miss_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class C1a : P1 {
1111
@objc func doSomething(a: Int, c: Double) { }
1212
// expected-warning@-1{{instance method 'doSomething(a:c:)' nearly matches optional requirement 'doSomething(a:b:)' of protocol 'P1'}}
13-
// expected-note@-2{{rename to 'doSomething(a:b:)' to satisfy this requirement}}{{34-34=b }}{{none}}
13+
// expected-note@-2{{rename to 'doSomething(a:b:)' to satisfy this requirement}}{{34-34=b }}{{8-8=(doSomethingWithA:b:)}} {{34-34=b }}
1414
// expected-note@-3{{move 'doSomething(a:c:)' to an extension to silence this warning}}
1515
// expected-note@-4{{make 'doSomething(a:c:)' private to silence this warning}}{{9-9=private }}
1616
}

0 commit comments

Comments
 (0)