Commit Graph

12 Commits

Author SHA1 Message Date
Gabor Horvath
616de41526 [cxx-interop] Fix nested structs for non-opaque types
The test for nested constructs used library evolution forcing all types
to be opaque. As a result some code paths for non-opaque types were not
updated to support nested types. This patch updates the rest of the code
making sure we use fully qualified names (so they also work in the
context of the nested classes), and generate correct names for the C
compatibility structs that cannot contain "::".

Fixes #80291

rdar://147882976
2025-04-03 15:30:01 +01:00
Becca Royal-Gordon
da07ff577c [PrintAsClang] Warn about unstable decl order
PrintAsClang is supposed to emit declarations in the same order regardless of the compiler’s internal state, but we have repeatedly found that our current criteria are inadequate, resulting in non-functionality-affecting changes to generated header content. Add a diagnostic that’s emitted when this happens soliciting a bug report.

Since there *should* be no cases where the compiler fails to order declarations, this diagnostic is never actually emitted. Instead, we test this change by enabling `-verify` on nearly all PrintAsClang tests to make sure they are unaffected.

This did demonstrate a missing criterion that only mattered in C++ mode: extensions that varied only in their generic signature were not sorted stably. Add a sort criterion for this.
2025-02-14 21:41:36 -08:00
Gabor Horvath
94b466656e [cxx-interop] Support nested structs
It is really involved to change how methods and classes are emitted into
the header so this patch introduces the impression of nested structs
through using statements and still emits the structs themselves as top
level structs. It emits them in their own namespace to avoid name
collisions. This patch also had to change some names to be fully
qualified to avoid some name lookup errors in case of nested structs.
Moreover, nesting level of 3 and above requires C++17 because it relies
on nested namespaces. Only nested structs are supported, not nested
classes.

Since this patch is already started to grow quite big, I decided to put
it out for reviews and plan to address some of the shortcomings in a
follow-up PR.

rdar://118793469
2024-09-10 13:22:17 +01:00
Gabor Horvath
c3a02cd80d [cxx-interop] Emit Swift StdLib dependencies when all public decls emitted
The generated header would not compile without these dependencies. Moreover
users probably expect all-public option to be the most permissive filter
including the maximal amount of declarations.
2024-07-03 18:07:41 +01:00
Egor Zhdan
a0e1588417 [cxx-interop] Fix reverse interop test for virtual method dispatch on arm64e
rdar://105396625
2024-06-21 16:26:23 +01:00
Becca Royal-Gordon
80f38be3b8 [PrintAsClang] Fix thunks for Never funcs
Swift-to-C++ thunk printing for functions didn’t really take into account Swift’s `Never` type. This type maps to `SWIFT_NORETURN`, but it also requires other tweaks to code generation, such as omitting the `return` keyword. (Removing that requires minor changes to many tests.)

Fixes rdar://124137073.
2024-03-29 22:12:19 -07:00
Mike Ash
20ae0ad34e [Test] Disable some failing tests on ARM64e.
Disabling these tests:
    IRGen/ptrauth-foreign.sil
    IRGen/ptrauth_field_fptr_import.swift
    Interop/SwiftToCxx/class/swift-class-virtual-method-dispatch-arm64e.swift
    Interop/SwiftToCxx/class/swift-class-virtual-method-dispatch.swift
    Interop/SwiftToCxx/class/swift-subclass-of-resilient-class-virtual-method-dispatch.swift
2023-02-14 11:39:44 -05:00
Alex Lorenz
c9f9d9025b [interop][SwiftToCxx] fix offset computation for 32 bit platforms for vtable dispatch 2023-02-13 10:30:38 -08:00
Alex Lorenz
981e828b2a [interop][SwiftToCxx] dispatch swift class methods using signed isa and signed method pointer on arm64e 2023-02-11 14:05:59 -08:00
Alex Lorenz
b63577d89e [interop][SwiftToCxx] use vtable/thunk to dispatch class subscript getters 2023-02-11 05:55:54 -08:00
Alex Lorenz
71e4462508 [interop][SwiftToCxx] use vtable offset/thunk to dispatch class property accessors 2023-02-11 05:55:47 -08:00
Alex Lorenz
b7007cb748 [interop][SwiftToCxx] dispatch Swift class methods correctly using the vtable 2023-02-09 20:20:53 -08:00