Skip to content

[5.9] Observable protocol non-marker, @Observable class only #67196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 11, 2023

Conversation

natecook1000
Copy link
Member

@natecook1000 natecook1000 commented Jul 10, 2023

  • Explanation: Three top-level changes:
    • Converts Observable to be a non-marker protocol, which in turns requires a change in the @Observable macro to emit a conformance extension only when the target type doesn't already provide conformance
    • Makes the @Observable macro only applicable to classes (adding structs to the already-prohibited enums and actors)
    • Adds trivial Sendable/Hashable/Codable conformances for the ObservationRegistrar type
  • Scope: Impacts adopters of the @Observable macro.
  • Risk: Adopters that have applied @Observable to structs will receive a new compile-time error.
  • Testing: Modified test cases to work with the new protocol.
  • Reviewer: @stephentyrone
  • Main branch PRs: [Observation] Switch Observable to be a non-marker protocol #66993 and Make the @Observable macro class only #67033

* Make ObservationRegistrar Codable/Hashable

These conformances enable automatic Codable synthesis for Observable
types, and smooth the runway for structs being supported by the
Observable macro in the future.

* Limit Observable macro to classes

This removes the ability for the Observable macro to apply to structs,
and adds diagnostic tests for the three disallowed declaration kinds.
…ang#66993)

With support for redundant conformance declarations via macros,
the `Observable` protocol can be a non-marker protocol, which
provides more flexibility for evolution in the future.

rdar://111463883

This change also switches to the new ExtensionMacro protocol,
the requirement for which includes information about whether the
conformance to the Observable protocol has already been added, either
in the declaration or in a superclass to the macro-attributed type.
This allows the @observable macro to be applied to subclasses of
observable types without redundant-conformance errors.
@natecook1000 natecook1000 requested a review from a team as a code owner July 10, 2023 06:09
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit 0d63fbc into swiftlang:release/5.9 Jul 11, 2023
@natecook1000 natecook1000 deleted the observable_5_9 branch July 12, 2023 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants