mirror of
https://github.com/apple/swift.git
synced 2026-11-18 04:54:16 +01:00
ClangImporter imports C 'Class' as AnyClass, but declaring a C-interop function that takes/returns it via @c or @_extern(c) was rejected. Support it across three layers: Sema: make AnyClass (an ExistentialMetatypeType of AnyObject) representable in ForeignLanguage::C, gated on ObjC interop since 'Class' is an ObjC runtime type. Reuse getObjCObjectRepresentable so C and ObjC agree on the kind. SILGen: a @c/@_extern(c) function is emitted directly as its C entry point (no separate native thunk), so bridge the metatype at that boundary in place: objc_to_thick_metatype on a 'Class' parameter in the prolog, and thick_to_objc_metatype on an AnyClass result in the epilog. Both are no-ops unless the native and foreign SIL types differ. PrintAsClang: keep the @c declaration in the plain-C section and emit '#include <objc/objc.h>' there when a @c decl uses 'Class', so the generated header stays usable from plain C.