ModuleInterface: Ensure implicit accessors are created before printing.

Previously, implicit accessors would be omitted from `.swiftinterface` files
emitted with lazy typechecking enabled.
This commit is contained in:
Allan Shortlidge
2023-09-08 15:04:45 -07:00
parent 9b641f9ba3
commit 5e76f76255
5 changed files with 62 additions and 10 deletions

View File

@@ -2270,6 +2270,13 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
return;
}
// Force implicit accessors to be created if they haven't been already.
if (shouldTypeCheck(Options)) {
ASD->visitEmittedAccessors([](AccessorDecl *accessor) {
(void)accessor;
});
}
// Collect the accessor declarations that we should print.
SmallVector<AccessorDecl *, 4> accessorsToPrint;
auto AddAccessorToPrint = [&](AccessorKind kind) {

View File

@@ -47,6 +47,29 @@ public func publicFuncWithOpaqueReturnType() -> some PublicProto { // expected-n
}
}
// MARK: - Property wrappers
@propertyWrapper
public struct PublicWrapper<T> {
public var wrappedValue: T {
get {
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
}
set {
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
}
}
public var projectedValue: PublicWrapper { self }
public init(wrappedValue value: T) {
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}
}
}
@propertyWrapper
struct InternalWrapper<T> {} // expected-error {{property wrapper type 'InternalWrapper' does not contain a non-static property named 'wrappedValue'}}
// MARK: - Global vars
public var publicGlobalVar: Int = 0
@@ -80,6 +103,7 @@ protocol InternalProtoConformingToPublicProto: PublicProto {
public struct PublicStruct {
public var publicProperty: Int
public var publicPropertyInferredType = ""
@PublicWrapper public var publicWrappedProperty = 3.14
public init(x: Int) {
_ = DoesNotExist() // expected-error {{cannot find 'DoesNotExist' in scope}}

View File

@@ -31,6 +31,8 @@ func testPublicStruct() {
let _: Int = s.publicMethod()
let _: Int = s.publicProperty
let _: String = s.publicPropertyInferredType
let _: Double = s.publicWrappedProperty
let _: Double = s.$publicWrappedProperty.wrappedValue
PublicStruct.publicStaticMethod()
}

View File

@@ -42,6 +42,14 @@
// CHECK: public struct PublicStruct {
// CHECK: public var publicProperty: Swift.Int
// CHECK: public var publicPropertyInferredType: Swift.String
// CHECK: @lazy_typecheck.PublicWrapper @_projectedValueProperty($publicWrappedProperty) public var publicWrappedProperty: Swift.Double {
// CHECK-NEXT: get
// CHECK-NEXT: set
// CHECK-NEXT: _modify
// CHECK-NEXT: }
// CHECK: public var $publicWrappedProperty: lazy_typecheck.PublicWrapper<Swift.Double> {
// CHECK-NEXT: get
// CHECK-NEXT: }
// CHECK: public init(x: Swift.Int)
// CHECK: public func publicMethod() -> Swift.Int
// CHECK: public static func publicStaticMethod()

View File

@@ -87,20 +87,31 @@ exports:
'_$s14lazy_typecheck12PublicStructV14publicPropertySivpMV',
'_$s14lazy_typecheck12PublicStructV14publicPropertySivs',
'_$s14lazy_typecheck12PublicStructV18publicStaticMethodyyFZ',
'_$s14lazy_typecheck12PublicStructV1xACSi_tcfC', '_$s14lazy_typecheck12PublicStructV26publicPropertyInferredTypeSSvM',
'_$s14lazy_typecheck12PublicStructV1xACSi_tcfC', '_$s14lazy_typecheck12PublicStructV21publicWrappedPropertySdvM',
'_$s14lazy_typecheck12PublicStructV21publicWrappedPropertySdvg',
'_$s14lazy_typecheck12PublicStructV21publicWrappedPropertySdvpMV',
'_$s14lazy_typecheck12PublicStructV21publicWrappedPropertySdvs',
'_$s14lazy_typecheck12PublicStructV22$publicWrappedPropertyAA0C7WrapperVySdGvg',
'_$s14lazy_typecheck12PublicStructV22$publicWrappedPropertyAA0C7WrapperVySdGvpMV',
'_$s14lazy_typecheck12PublicStructV26publicPropertyInferredTypeSSvM',
'_$s14lazy_typecheck12PublicStructV26publicPropertyInferredTypeSSvg',
'_$s14lazy_typecheck12PublicStructV26publicPropertyInferredTypeSSvpMV',
'_$s14lazy_typecheck12PublicStructV26publicPropertyInferredTypeSSvs',
'_$s14lazy_typecheck12PublicStructVMa', '_$s14lazy_typecheck12PublicStructVMn',
'_$s14lazy_typecheck12PublicStructVN', '_$s14lazy_typecheck13inlinableFuncSiyF',
'_$s14lazy_typecheck15publicGlobalVarSivM', '_$s14lazy_typecheck15publicGlobalVarSivg',
'_$s14lazy_typecheck15publicGlobalVarSivs', '_$s14lazy_typecheck16EmptyPublicProtoMp',
'_$s14lazy_typecheck16EmptyPublicProtoTL', '_$s14lazy_typecheck18PublicDerivedClassC1xACSi_tcfC',
'_$s14lazy_typecheck18PublicDerivedClassC1xACSi_tcfc', '_$s14lazy_typecheck18PublicDerivedClassCMa',
'_$s14lazy_typecheck18PublicDerivedClassCMm', '_$s14lazy_typecheck18PublicDerivedClassCMn',
'_$s14lazy_typecheck18PublicDerivedClassCMo', '_$s14lazy_typecheck18PublicDerivedClassCN',
'_$s14lazy_typecheck18PublicDerivedClassCfD', '_$s14lazy_typecheck18PublicDerivedClassCfd',
'_$s14lazy_typecheck19PublicGenericStructV12publicMethodxyF',
'_$s14lazy_typecheck12PublicStructVN', '_$s14lazy_typecheck13PublicWrapperV12wrappedValueACyxGx_tcfC',
'_$s14lazy_typecheck13PublicWrapperV12wrappedValuexvM', '_$s14lazy_typecheck13PublicWrapperV12wrappedValuexvg',
'_$s14lazy_typecheck13PublicWrapperV12wrappedValuexvpMV',
'_$s14lazy_typecheck13PublicWrapperV12wrappedValuexvs', '_$s14lazy_typecheck13PublicWrapperV14projectedValueACyxGvg',
'_$s14lazy_typecheck13PublicWrapperV14projectedValueACyxGvpMV',
'_$s14lazy_typecheck13PublicWrapperVMa', '_$s14lazy_typecheck13PublicWrapperVMn',
'_$s14lazy_typecheck13inlinableFuncSiyF', '_$s14lazy_typecheck15publicGlobalVarSivM',
'_$s14lazy_typecheck15publicGlobalVarSivg', '_$s14lazy_typecheck15publicGlobalVarSivs',
'_$s14lazy_typecheck16EmptyPublicProtoMp', '_$s14lazy_typecheck16EmptyPublicProtoTL',
'_$s14lazy_typecheck18PublicDerivedClassC1xACSi_tcfC', '_$s14lazy_typecheck18PublicDerivedClassC1xACSi_tcfc',
'_$s14lazy_typecheck18PublicDerivedClassCMa', '_$s14lazy_typecheck18PublicDerivedClassCMm',
'_$s14lazy_typecheck18PublicDerivedClassCMn', '_$s14lazy_typecheck18PublicDerivedClassCMo',
'_$s14lazy_typecheck18PublicDerivedClassCN', '_$s14lazy_typecheck18PublicDerivedClassCfD',
'_$s14lazy_typecheck18PublicDerivedClassCfd', '_$s14lazy_typecheck19PublicGenericStructV12publicMethodxyF',
'_$s14lazy_typecheck19PublicGenericStructVMa', '_$s14lazy_typecheck19PublicGenericStructVMn',
'_$s14lazy_typecheck19PublicGenericStructVyxGAA05EmptyC5ProtoA2A08InternalE13ForConstraintVRszlMc',
'_$s14lazy_typecheck19PublicGenericStructVyxGAA05EmptyC5ProtoA2A08InternalE13ForConstraintVRszlWP',