Skip to content

Commit 5e76f76

Browse files
committed
ModuleInterface: Ensure implicit accessors are created before printing.
Previously, implicit accessors would be omitted from `.swiftinterface` files emitted with lazy typechecking enabled.
1 parent 9b641f9 commit 5e76f76

File tree

5 files changed

+62
-10
lines changed

5 files changed

+62
-10
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,13 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
22702270
return;
22712271
}
22722272

2273+
// Force implicit accessors to be created if they haven't been already.
2274+
if (shouldTypeCheck(Options)) {
2275+
ASD->visitEmittedAccessors([](AccessorDecl *accessor) {
2276+
(void)accessor;
2277+
});
2278+
}
2279+
22732280
// Collect the accessor declarations that we should print.
22742281
SmallVector<AccessorDecl *, 4> accessorsToPrint;
22752282
auto AddAccessorToPrint = [&](AccessorKind kind) {

test/Inputs/lazy_typecheck.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,29 @@ public func publicFuncWithOpaqueReturnType() -> some PublicProto { // expected-n
4747
}
4848
}
4949

50+
// MARK: - Property wrappers
51+
52+
@propertyWrapper
53+
public struct PublicWrapper<T> {
54+
public var wrappedValue: T {
55+
get {
56+
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
57+
}
58+
set {
59+
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
60+
}
61+
}
62+
63+
public var projectedValue: PublicWrapper { self }
64+
65+
public init(wrappedValue value: T) {
66+
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
67+
}
68+
}
69+
70+
@propertyWrapper
71+
struct InternalWrapper<T> {} // expected-error {{property wrapper type 'InternalWrapper' does not contain a non-static property named 'wrappedValue'}}
72+
5073
// MARK: - Global vars
5174

5275
public var publicGlobalVar: Int = 0
@@ -80,6 +103,7 @@ protocol InternalProtoConformingToPublicProto: PublicProto {
80103
public struct PublicStruct {
81104
public var publicProperty: Int
82105
public var publicPropertyInferredType = ""
106+
@PublicWrapper public var publicWrappedProperty = 3.14
83107

84108
public init(x: Int) {
85109
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}

test/Inputs/lazy_typecheck_client.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func testPublicStruct() {
3131
let _: Int = s.publicMethod()
3232
let _: Int = s.publicProperty
3333
let _: String = s.publicPropertyInferredType
34+
let _: Double = s.publicWrappedProperty
35+
let _: Double = s.$publicWrappedProperty.wrappedValue
3436
PublicStruct.publicStaticMethod()
3537
}
3638

test/ModuleInterface/lazy-typecheck.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
// CHECK: public struct PublicStruct {
4343
// CHECK: public var publicProperty: Swift.Int
4444
// CHECK: public var publicPropertyInferredType: Swift.String
45+
// CHECK: @lazy_typecheck.PublicWrapper @_projectedValueProperty($publicWrappedProperty) public var publicWrappedProperty: Swift.Double {
46+
// CHECK-NEXT: get
47+
// CHECK-NEXT: set
48+
// CHECK-NEXT: _modify
49+
// CHECK-NEXT: }
50+
// CHECK: public var $publicWrappedProperty: lazy_typecheck.PublicWrapper<Swift.Double> {
51+
// CHECK-NEXT: get
52+
// CHECK-NEXT: }
4553
// CHECK: public init(x: Swift.Int)
4654
// CHECK: public func publicMethod() -> Swift.Int
4755
// CHECK: public static func publicStaticMethod()

test/TBD/lazy-typecheck.swift

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,31 @@ exports:
8787
'_$s14lazy_typecheck12PublicStructV14publicPropertySivpMV',
8888
'_$s14lazy_typecheck12PublicStructV14publicPropertySivs',
8989
'_$s14lazy_typecheck12PublicStructV18publicStaticMethodyyFZ',
90-
'_$s14lazy_typecheck12PublicStructV1xACSi_tcfC', '_$s14lazy_typecheck12PublicStructV26publicPropertyInferredTypeSSvM',
90+
'_$s14lazy_typecheck12PublicStructV1xACSi_tcfC', '_$s14lazy_typecheck12PublicStructV21publicWrappedPropertySdvM',
91+
'_$s14lazy_typecheck12PublicStructV21publicWrappedPropertySdvg',
92+
'_$s14lazy_typecheck12PublicStructV21publicWrappedPropertySdvpMV',
93+
'_$s14lazy_typecheck12PublicStructV21publicWrappedPropertySdvs',
94+
'_$s14lazy_typecheck12PublicStructV22$publicWrappedPropertyAA0C7WrapperVySdGvg',
95+
'_$s14lazy_typecheck12PublicStructV22$publicWrappedPropertyAA0C7WrapperVySdGvpMV',
96+
'_$s14lazy_typecheck12PublicStructV26publicPropertyInferredTypeSSvM',
9197
'_$s14lazy_typecheck12PublicStructV26publicPropertyInferredTypeSSvg',
9298
'_$s14lazy_typecheck12PublicStructV26publicPropertyInferredTypeSSvpMV',
9399
'_$s14lazy_typecheck12PublicStructV26publicPropertyInferredTypeSSvs',
94100
'_$s14lazy_typecheck12PublicStructVMa', '_$s14lazy_typecheck12PublicStructVMn',
95-
'_$s14lazy_typecheck12PublicStructVN', '_$s14lazy_typecheck13inlinableFuncSiyF',
96-
'_$s14lazy_typecheck15publicGlobalVarSivM', '_$s14lazy_typecheck15publicGlobalVarSivg',
97-
'_$s14lazy_typecheck15publicGlobalVarSivs', '_$s14lazy_typecheck16EmptyPublicProtoMp',
98-
'_$s14lazy_typecheck16EmptyPublicProtoTL', '_$s14lazy_typecheck18PublicDerivedClassC1xACSi_tcfC',
99-
'_$s14lazy_typecheck18PublicDerivedClassC1xACSi_tcfc', '_$s14lazy_typecheck18PublicDerivedClassCMa',
100-
'_$s14lazy_typecheck18PublicDerivedClassCMm', '_$s14lazy_typecheck18PublicDerivedClassCMn',
101-
'_$s14lazy_typecheck18PublicDerivedClassCMo', '_$s14lazy_typecheck18PublicDerivedClassCN',
102-
'_$s14lazy_typecheck18PublicDerivedClassCfD', '_$s14lazy_typecheck18PublicDerivedClassCfd',
103-
'_$s14lazy_typecheck19PublicGenericStructV12publicMethodxyF',
101+
'_$s14lazy_typecheck12PublicStructVN', '_$s14lazy_typecheck13PublicWrapperV12wrappedValueACyxGx_tcfC',
102+
'_$s14lazy_typecheck13PublicWrapperV12wrappedValuexvM', '_$s14lazy_typecheck13PublicWrapperV12wrappedValuexvg',
103+
'_$s14lazy_typecheck13PublicWrapperV12wrappedValuexvpMV',
104+
'_$s14lazy_typecheck13PublicWrapperV12wrappedValuexvs', '_$s14lazy_typecheck13PublicWrapperV14projectedValueACyxGvg',
105+
'_$s14lazy_typecheck13PublicWrapperV14projectedValueACyxGvpMV',
106+
'_$s14lazy_typecheck13PublicWrapperVMa', '_$s14lazy_typecheck13PublicWrapperVMn',
107+
'_$s14lazy_typecheck13inlinableFuncSiyF', '_$s14lazy_typecheck15publicGlobalVarSivM',
108+
'_$s14lazy_typecheck15publicGlobalVarSivg', '_$s14lazy_typecheck15publicGlobalVarSivs',
109+
'_$s14lazy_typecheck16EmptyPublicProtoMp', '_$s14lazy_typecheck16EmptyPublicProtoTL',
110+
'_$s14lazy_typecheck18PublicDerivedClassC1xACSi_tcfC', '_$s14lazy_typecheck18PublicDerivedClassC1xACSi_tcfc',
111+
'_$s14lazy_typecheck18PublicDerivedClassCMa', '_$s14lazy_typecheck18PublicDerivedClassCMm',
112+
'_$s14lazy_typecheck18PublicDerivedClassCMn', '_$s14lazy_typecheck18PublicDerivedClassCMo',
113+
'_$s14lazy_typecheck18PublicDerivedClassCN', '_$s14lazy_typecheck18PublicDerivedClassCfD',
114+
'_$s14lazy_typecheck18PublicDerivedClassCfd', '_$s14lazy_typecheck19PublicGenericStructV12publicMethodxyF',
104115
'_$s14lazy_typecheck19PublicGenericStructVMa', '_$s14lazy_typecheck19PublicGenericStructVMn',
105116
'_$s14lazy_typecheck19PublicGenericStructVyxGAA05EmptyC5ProtoA2A08InternalE13ForConstraintVRszlMc',
106117
'_$s14lazy_typecheck19PublicGenericStructVyxGAA05EmptyC5ProtoA2A08InternalE13ForConstraintVRszlWP',

0 commit comments

Comments
 (0)