mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
19119ad88a
@_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
17 lines
969 B
Swift
17 lines
969 B
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
// The bare @_preInverseGenerics does NOT require the experimental feature.
|
|
@_preInverseGenerics
|
|
func bare<T: ~Copyable>(_ t: borrowing T) {}
|
|
|
|
// The 'except:' form DOES require the experimental feature.
|
|
@_preInverseGenerics(except: ~Copyable) // expected-error {{'@_preInverseGenerics' is an experimental feature; use '-enable-experimental-feature PreInverseGenericsExcept'}}
|
|
func exceptCopyable<T: ~Copyable & ~Escapable>(_ t: borrowing T) {}
|
|
|
|
// An invalid attribute with 'except:' still DOES require the feature.
|
|
@_preInverseGenerics(except: Int) // expected-error {{'@_preInverseGenerics' is an experimental feature; use '-enable-experimental-feature PreInverseGenericsExcept'}}
|
|
// expected-error@-1 {{'except' argument to '@_preInverseGenerics' must consist only of inverse constraints such as '~Copyable' or '~Escapable'}}
|
|
func exceptInt<T: ~Copyable & ~Escapable>(_ t: borrowing T) {}
|
|
|
|
|