Skip to content

AST: Inherit access level of an opaque type decl from its naming decl #66515

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

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Jun 9, 2023

When an OpaqueTypeDecl is constructed, the access level attributes of the decl that names the opaque type are copied on to it. However, the @usableFromInline attribute is not permitted on every decl, so it does not get copied. This in turn causes effective access level computations for opaque types to fail to take @usableFromInline into account and that results in the emitted symbol getting the wrong linkage during IRGen. The fix is to make the effective access computation take this quirk of opaque types into account directly, instead of relying on copying of attributes.

Resolves rdar://110544170

@tshortli tshortli requested a review from jckarter June 9, 2023 21:57
@tshortli
Copy link
Contributor Author

tshortli commented Jun 9, 2023

@swift-ci please test

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Can you remove the access level copying too, then?

@tshortli
Copy link
Contributor Author

Can you remove the access level copying too, then?

Good idea, I think it makes sense to do that. However, I'd like to make that part of the change on main only as I think it increases the chances of regression slightly (I don't know whether any other part of the compiler queries for the modifiers/attributes and might be affected).

@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli tshortli force-pushed the usable-from-inline-opaque-type-decl-linkage branch from 01bec1d to 9367f16 Compare June 12, 2023 19:03
When an `OpaqueTypeDecl` is constructed, the access level attributes of the
decl that names the opaque type were copied on to it. However, the
`@usableFromInline` attribute is not permitted on every decl, so it does not
get copied. This in turn causes access level computations for opaque types to
fail to take `@usableFromInline` into account and that results in the emitted
symbol getting the wrong linkage during IRGen. The fix is to make access level
computations take this quirk of opaque types into account directly (like they
already to for several other kinds of decls), instead of relying on copying of
attributes.

Resolves rdar://110544170
@tshortli tshortli force-pushed the usable-from-inline-opaque-type-decl-linkage branch from 9367f16 to 775b4a4 Compare June 12, 2023 19:05
@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli
Copy link
Contributor Author

Removing the attribute copying revealed that my previous approach to the fix was incomplete. I've updated the PR to better match how access level exceptions for other kinds of decls are handled, specifically by updating both AccessLevelRequest and ValueDecl::isUsableFromInline.

@slavapestov
Copy link
Contributor

Removing the attribute copying revealed that my previous approach to the fix was incomplete.

That's why I enjoy these kinds of cleanups. Thank you for seeing this through!

@tshortli tshortli merged commit 9bb035f into swiftlang:main Jun 13, 2023
@tshortli tshortli deleted the usable-from-inline-opaque-type-decl-linkage branch June 13, 2023 01:02
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