[cxx-interop] Re-implement namespaces using enums + extensions.

C++ namespaces are module-independent, but enums are owned by their module's in Swift. So, to prevent declaring two enums with the same name, this patch implements a new approach to namespaces: enums with extensions.

Here's an example:
```
// Module A
namespace N { void test1(); }
// Module B
namespace N { void test2(); }
// __ObjC module
enum N { }
// Swift module A
extension N { func test1() }
// Swift module B
extension N { func test1() }
```

Thanks to @gribozavr for the great idea.
This commit is contained in:
zoecarver
2020-12-08 09:56:06 -08:00
parent 22acb2fc9f
commit bd96959d14
28 changed files with 794 additions and 13 deletions

View File

@@ -0,0 +1,7 @@
// RUN: %target-swift-ide-test -print-module -module-to-print=FreeFunctionsSecondHeader -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s
// TODO: This file doesn't really test anything because functions need not be defined.
// CHECK: extension FunctionsNS1 {
// CHECK-NOT: extension
// CHECK: static func definedInDefs() -> UnsafePointer<CChar>!
// CHECK: }