Skip to content
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

More @abi checking #80383

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Mar 28, 2025

This PR refines the @abi checking added in #79466 in several ways:

  • Fixes a bug where ABI-only VarDecls in the primary file were not fully checked
  • Adds specific behaviors for various uses of CustomAttr:
    • Global actor isolation attributes are permitted in @abi and may vary from the API counterpart
    • Result builder attributes are forbidden in @abi (they have no ABI impact)
    • Property wrapper attributes are forbidden both in @abi and on an API counterpart (more design is needed to control the ABI of the auxiliary declarations)
    • Attached macros are forbidden in @abi (ABI-only decls have no peers or members)
  • Bans freestanding macros in the parser in @abi, matching SwiftParser's behavior
  • Forbids lazy both in @abi and on an API counterpart (like property wrapper attributes, more design is needed to control the ABI of auxiliary declarations)
  • Removes a poorly-designed attribute cloning behavior, making the attributes that used it non-ABI instead:
    • @inlinable and other inlining attributes
    • @_borrowed

These changes bring the implementation into alignment with the revised @abi proposal.

Note that the macro expansion tests in this PR will require a matching SwiftSyntax PR that makes SwiftParser parse @abi attributes even when the experimental feature is turned off; the recovery behavior without that patch is just too catastrophic for macro tests to emit sensible diagnostics. See swiftlang/swift-syntax#3026.

@beccadax beccadax force-pushed the abi-inspected-your-appearance-again branch from 9049600 to 7815b82 Compare March 29, 2025 02:19
beccadax added 7 commits April 1, 2025 11:37
The decl checker was effectively not being run on these because we weren’t typechecking the PBD and typechecking the VarDecl itself is basically a no-op.
Macro expansions are now treated like a part of the source file they belong to, for purposes of the “second declaration is the one that’s diagnosed” rule. This helps stabilize a behavior that was easy to perturb.
CustomAttr backs four different features, each of which requires a different behavior in `@abi`:

• Global actors: Permitted (and permitted to vary) since they can affect mangling
• Result builders: Forbidden inside an `@abi` since they have no ABI impact
• Property wrappers: Forbidden both inside an `@abi` and on a decl with an `@abi` since it’s not clear how we would apply `@abi` to the auxiliary decls
• Attached macros: Forbidden inside an `@abi` since an ABI-only decl has no body, accessors, members, peers, extensions, or (currently) conformances

Implement these behaviors (outside of `ABIDeclChecker` since they can’t be described there).
SwiftSyntaxParser is already doing this, and we already diagnosed it in Sema anyway, so we’re just moving that diagnostic earlier so the ASTGen testing mode is happy. Also adding compiler tests for it.
It’s not clear how `@abi` would apply to the auxiliary decl used for `lazy`.
Inlinability doesn’t affect the mangling except in function specializations, which are applied after the fact and should never mangle in information from an ABI-only decl. That means we can simply ban these from `@abi` instead of inferring them.

Also adds some assertions to help double-check that SIL never tries to directly mangle or retrieve inlinability info from an ABI-only decl.
It has indirect effects on the accessors, so it shouldn’t matter, but we can defensively redirect the query to the API counterpart anyway.

This was the last `InferredInABIAttr` attribute, so we can now remove all of the infrastructure involved in supporting attribute inference.
@beccadax
Copy link
Contributor Author

beccadax commented Apr 1, 2025

With swiftlang/swift-syntax#3026

@swift-ci please test

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.

1 participant