Skip to content

[6.4] introduce @_preInverseGenerics(except:)#89171

Open
kavon wants to merge 4 commits into
swiftlang:release/6.4.xfrom
kavon:cherry-pick-kavon-preinverse-generics-except-176395527
Open

[6.4] introduce @_preInverseGenerics(except:)#89171
kavon wants to merge 4 commits into
swiftlang:release/6.4.xfrom
kavon:cherry-pick-kavon-preinverse-generics-except-176395527

Conversation

@kavon
Copy link
Copy Markdown
Member

@kavon kavon commented May 15, 2026

Explanation: Introduces additional flexibility for avoiding mangling changes by expanding the @_preInverseGenerics attribute with support for filtering-out inverses except some subset. Needed to support Span<~Escapable> without ABI break.

Scope: Upgrades a bool AllowInverses in the mangler into a InvertibleProtocolSet of allowed inverses. Includes parsing and serialization to populate that set.

Issues: rdar://176395527

Risk: Low. The only risk is that this messes up mangling for ordinary @_preInverseGenerics (or just symbols containing inverses in general), since this generalizes its implementation. But the changes that are risky are pretty limited in scope so they're easier to inspect.

Testing: regression tests included

Cherry-pick of: #88976 & #89264 & #89269

kavon added 2 commits May 15, 2026 08:19
I'd like `InvertibleProtocolSet::allKnown()` to be evaluated
at compile-time.

(cherry picked from commit ceb302c)
@_preInverseGenerics(except: <inverses>) is an extension of the existing
@_preInverseGenerics attribute that provides selective control over which
inverse requirements are mangled into a declaration's symbol name.

While the bare @_preInverseGenerics strips all inverse constraints
(~Copyable and ~Escapable) from mangling, the 'except:' form allows specific
inverses to be retained. This is needed when a type like Span already had
~Copyable mangled into its ABI-stable symbols and now needs to retroactively
adopt ~Escapable without changing those existing symbols. You can now express
that with `@_preInverseGenerics(except: ~Copyable)` to strip-out every inverse
except ~Copyable to preserve the pre-existing ~Copyable-containing symbols.

It requires the new experimental feature `PreInverseGenericsExcept`.

rdar://176395527
(cherry picked from commit 19119ad)
@kavon
Copy link
Copy Markdown
Member Author

kavon commented May 15, 2026

@swift-ci test

@kavon kavon marked this pull request as ready for review May 15, 2026 16:29
@kavon kavon requested a review from a team as a code owner May 15, 2026 16:29
@kavon kavon enabled auto-merge May 16, 2026 00:48
@kavon kavon disabled auto-merge May 18, 2026 16:37
I added the warning based on an observation that it has no effect
on members of the extension, but didn't validate whether it has some
subtle effect on other symbols, such as those for conformances declared
with that extension. To reduce confusion, it's better to not warn until
it's safe enough to remove uses of it on extensions in the stdlib.

Related to swiftlang#88976

(cherry picked from commit bcaa5b6)
@kavon
Copy link
Copy Markdown
Member Author

kavon commented May 19, 2026

@swift-ci test

@kavon kavon requested a review from natecook1000 May 19, 2026 20:35
…ttribute

We need an alias since `@_preInverseGenerics(except: ...)` has custom parsing that older
compilers aren't designed to handle. Only simple decl attributes are parsed correctly by
older compilers, so this alias allows you to write this:

```
@_preInverseGenericsExceptCopyable
var x = 0
var x = 0
```

Which all helps with the introduction of Span<~Escapable>.

related to rdar://176395527

(cherry picked from commit 14c2574)
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