Skip to content

Commit b11ccb6

Browse files
authored
Merge pull request #83964 from tshortli/module-interface-parameter-property-wrappers
ModuleInterface: Only print API-level property wrappers in swiftinterfaces
2 parents 0eae70c + 4411324 commit b11ccb6

File tree

2 files changed

+58
-15
lines changed

2 files changed

+58
-15
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,20 @@ void PrintAST::printAttributes(const Decl *D) {
14171417
scope.Options.ExcludeAttrList.push_back(DeclAttrKind::Consuming);
14181418
scope.Options.ExcludeAttrList.push_back(DeclAttrKind::Borrowing);
14191419
}
1420-
1420+
1421+
// If we're printing a swiftinterface and the attached property wrappers don't
1422+
// have an external effect, skip them.
1423+
if (Options.IsForSwiftInterface) {
1424+
if (auto *PD = dyn_cast<ParamDecl>(D)) {
1425+
if (!PD->hasExternalPropertyWrapper() &&
1426+
PD->getDeclContext()->getResilienceExpansion() !=
1427+
ResilienceExpansion::Minimal) {
1428+
for (auto *attr : PD->getAttachedPropertyWrappers())
1429+
scope.Options.ExcludeCustomAttrList.push_back(attr);
1430+
}
1431+
}
1432+
}
1433+
14211434
attrs.print(Printer, Options, D);
14221435
}
14231436

test/ModuleInterface/property_wrappers.swift

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,46 @@
99

1010
@propertyWrapper
1111
public struct Wrapper<T> {
12-
public var value: T
12+
public var wrappedValue: T
1313

14-
public var wrappedValue: T {
15-
get { value }
16-
set { value = newValue }
14+
public init(wrappedValue: T) {
15+
self.wrappedValue = wrappedValue
1716
}
1817
}
1918

2019
@propertyWrapper
2120
public struct WrapperWithInitialValue<T> {
22-
private var value: T
23-
24-
public var wrappedValue: T {
25-
get { value }
26-
set { value = newValue }
27-
}
21+
public var wrappedValue: T
2822

2923
public init(initialValue: T) {
30-
self.value = initialValue
24+
self.wrappedValue = initialValue
3125
}
3226

3327
public init(alternate value: T) {
34-
self.value = value
28+
self.wrappedValue = value
3529
}
3630

3731
public var projectedValue: Wrapper<T> {
38-
get { Wrapper(value: value) }
39-
set { value = newValue.value }
32+
get { Wrapper(wrappedValue: wrappedValue) }
33+
set { wrappedValue = newValue.wrappedValue }
34+
}
35+
}
36+
37+
@propertyWrapper
38+
public struct ProjectedValueWrapper<T> {
39+
public var wrappedValue: T
40+
41+
public init(wrappedValue: T) {
42+
self.wrappedValue = wrappedValue
43+
}
44+
45+
public init(projectedValue: Wrapper<T>) {
46+
self.wrappedValue = projectedValue.wrappedValue
47+
}
48+
49+
public var projectedValue: Wrapper<T> {
50+
get { Wrapper(wrappedValue: wrappedValue) }
51+
set { wrappedValue = newValue.wrappedValue }
4052
}
4153
}
4254

@@ -64,4 +76,22 @@ public struct HasWrappers {
6476
// CHECK-NEXT: _modify
6577
// CHECK-NEXT: }
6678
@WrapperWithInitialValue(alternate: false) public var z
79+
80+
// CHECK: public func hasParameterWithImplementationWrapper(x: Swift.Int)
81+
public func hasParameterWithImplementationWrapper(@Wrapper x: Int) { }
82+
83+
// CHECK: public func hasParameterWithImplementationWrapperComposed(x: Swift.Int)
84+
public func hasParameterWithImplementationWrapperComposed(@Wrapper @ProjectedValueWrapper x: Int) { }
85+
86+
// CHECK: @inlinable public func hasParameterWithImplementationWrapperInlinable(@TestResilient.Wrapper x: Swift.Int)
87+
@inlinable public func hasParameterWithImplementationWrapperInlinable(@Wrapper x: Int) { }
88+
89+
// CHECK: @_alwaysEmitIntoClient public func hasParameterWithImplementationWrapperAEIC(@TestResilient.Wrapper x: Swift.Int)
90+
@_alwaysEmitIntoClient public func hasParameterWithImplementationWrapperAEIC(@Wrapper x: Int) { }
91+
92+
// CHECK: public func hasParameterWithAPIWrapper(@TestResilient.ProjectedValueWrapper x: Swift.Int)
93+
public func hasParameterWithAPIWrapper(@ProjectedValueWrapper x: Int) { }
94+
95+
// CHECK: public func hasParameterWithAPIWrapperComposed(@TestResilient.ProjectedValueWrapper @TestResilient.Wrapper x: Swift.Int)
96+
public func hasParameterWithAPIWrapperComposed(@ProjectedValueWrapper @Wrapper x: Int) { }
6797
}

0 commit comments

Comments
 (0)