[clang] [clang/AST] Make it possible to use SwiftAttr in type context (PR #108631)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 26 06:20:38 PDT 2024


erichkeane wrote:

> I think the interesting template cases are like:
> 
> ```
> template<typename T> struct S {
>   T foo();
> };
> 
> S<int> a;
> S<SWIFT_SENDABLE int> b;
> 
> void f() {
>   a.foo();
>   b.foo();
> }
> ```
> 
> The question is, whether we actually have the type attributes where we expect to have them, or do we lose them? Hopefully @erichkeane can correct me if I'm wrong.
> 
> That being said, one question is whether we actually need type attributes to be propagated in this case for Swift's interop.
> 
> For the release notes, you'd want to mention that `swift_attr` can now be applied to types (maybe a small motivation why) in `clang/docs/ReleaseNotes.rst`. It has a section for attribute changes.

You're correct, the problem with attributed type is that it is going to be lost A LOT every time we canonicalize the type, else they need to be different types, and thus those would be different instantiations.  This is SOMETIMES not problematic (and sometimes even wanted, see vector types), but it IS problematic if you want your attribute to not cause problems being used in containers/etc, since `std::is_same<int, MY_INT_ATTRIBUTED_TYPE>` being 'false' is problematic for many use cases.

https://github.com/llvm/llvm-project/pull/108631


More information about the cfe-commits mailing list