Skip to content

Serialization: Encode custom availability domains #80616

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
Apr 9, 2025

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Apr 7, 2025

When serializing @available attributes, if the attribute applies to a custom domain include enough information to deserialize the reference to that domain.

Additionally, remove the now unnecessary ClangImporter Swift lookup table support for availability domains. Clang now handles looking up serialized availability domain declarations in precompiled modules itself.

Finally, when printing .swiftinterfaces guard declarations that use the CustomAvailability feature.

Resolves rdar://138441265.

@tshortli
Copy link
Contributor Author

tshortli commented Apr 7, 2025

swiftlang/llvm-project#10438

@swift-ci please test

tshortli added 3 commits April 8, 2025 08:53
Partially revert swiftlang#80035 now that Clang
has its own APIs for querying serialized modules for the decl representing the
availability domain with a given name.
When serializing `@available` attributes, if the attribute applies to a custom
domain include enough information to deserialize the reference to that domain.

Resolves rdar://138441265.
@tshortli tshortli force-pushed the availability-domain-serialization branch from cd827e7 to 10c910e Compare April 8, 2025 15:53
@tshortli
Copy link
Contributor Author

tshortli commented Apr 8, 2025

@swift-ci please smoke test

return AvailabilityDomain::forPlatform(platformKind);
case AvailabilityDomainKind::Custom:
return AvailabilityDomain::forCustom(decl, ctx);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand correctly that there's no default: here because deserialization issues are already protected by decodeDomainKind, so the failure case would only be from the calls to the constructors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, a covered switch should be safe here since we handle out of range enum values elsewhere.

@@ -236,6 +242,10 @@ class AvailabilityDomain final {
/// Returns the string to use when printing an `@available` attribute.
llvm::StringRef getNameForAttributePrinting() const;

/// Returns the decl that represents the domain, or `nullptr` if the domain
/// does not have a decl.
Decl *getDecl() const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the moment, does this always points to a clang VarDecl? And when would a domain not have a decl?

Copy link
Contributor Author

@tshortli tshortli Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, right now it can only reference and imported VarDecl. However, I anticipate it pointing to additional types of declarations once we have a Swift syntax for custom availability domains.

Copy link
Contributor

@xymus xymus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tshortli tshortli enabled auto-merge April 8, 2025 17:04
@tshortli
Copy link
Contributor Author

tshortli commented Apr 8, 2025

@swift-ci please smoke test macOS

@tshortli tshortli merged commit 94a8526 into swiftlang:main Apr 9, 2025
3 checks passed
@tshortli tshortli deleted the availability-domain-serialization branch April 9, 2025 13:32
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.

3 participants