Skip to content

Commit c5fbb42

Browse files
committed
[Obs] Switch to peer instead of arbitrary macros
This adopts `@attached(peer)` for generating an observable type's underscored storage when expanding the `@ObservationTracked` macro, instead of using `arbitrary` with the member macro on the observable type.
1 parent 4f9a35e commit c5fbb42

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

lib/Macros/Sources/ObservationMacros/ObservableMacro.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,6 @@ extension ObservableMacro: MemberMacro {
225225
declaration.addIfNeeded(ObservableMacro.accessFunction(observableType), to: &declarations)
226226
declaration.addIfNeeded(ObservableMacro.withMutationFunction(observableType), to: &declarations)
227227

228-
#if !OBSERVATION_SUPPORTS_PEER_MACROS
229-
let storedInstanceVariables = declaration.definedVariables.filter { $0.isValidForObservation }
230-
for property in storedInstanceVariables {
231-
if property.hasMacroApplication(ObservableMacro.ignoredMacroName) { continue }
232-
let storage = DeclSyntax(property.privatePrefixed("_", addingAttribute: ObservableMacro.ignoredAttribute))
233-
declaration.addIfNeeded(storage, to: &declarations)
234-
}
235-
#endif
236-
237228
return declarations
238229
}
239230
}

stdlib/public/Observation/Sources/Observation/Observable.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ public protocol Observable { }
4040
/// }
4141
/// }
4242
@available(SwiftStdlib 5.9, *)
43-
#if OBSERVATION_SUPPORTS_PEER_MACROS
4443
@attached(member, names: named(_$observationRegistrar), named(access), named(withMutation))
45-
#else
46-
@attached(member, names: named(_$observationRegistrar), named(access), named(withMutation), arbitrary)
47-
#endif
4844
@attached(memberAttribute)
4945
@attached(extension, conformances: Observable)
5046
public macro Observable() =
@@ -56,9 +52,7 @@ public macro Observable() =
5652
/// framework isn't necessary.
5753
@available(SwiftStdlib 5.9, *)
5854
@attached(accessor, names: named(init), named(get), named(set))
59-
#if OBSERVATION_SUPPORTS_PEER_MACROS
6055
@attached(peer, names: prefixed(_))
61-
#endif
6256
public macro ObservationTracked() =
6357
#externalMacro(module: "ObservationMacros", type: "ObservationTrackedMacro")
6458

test/stdlib/Observation/Observable.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// REQUIRES: swift_swift_parser, executable_test
22

3-
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library -enable-experimental-feature InitAccessors -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -Xfrontend -plugin-path -Xfrontend %swift-host-lib-dir/plugins)
3+
// RUN: %target-run-simple-swift( -Xfrontend -dump-macro-expansions -Xfrontend -disable-availability-checking -parse-as-library -enable-experimental-feature InitAccessors -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -Xfrontend -plugin-path -Xfrontend %swift-host-lib-dir/plugins)
44

55
// Run this test via the swift-plugin-server
66
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library -enable-experimental-feature InitAccessors -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -Xfrontend -external-plugin-path -Xfrontend %swift-host-lib-dir/plugins#%swift-plugin-server)
@@ -183,6 +183,10 @@ struct Validator {
183183

184184

185185
let suite = TestSuite("Observable")
186+
187+
suite.test("only instantiate") {
188+
let test = MiddleNamePerson()
189+
}
186190

187191
suite.test("unobserved value changes") {
188192
let test = MiddleNamePerson()

0 commit comments

Comments
 (0)