mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
With the upcoming `MemberImportVisibility` feature enabled, code built with Cxx interop also enabled could be rejected by the compiler with cryptic errors about the `__ObjC` module not being imported. This is the result of a surprising implementation detail of Cxx interop. When importing C++ namespaces and their members, the Clang importer puts these declarations in the Clang header import module (a.k.a. the bridging header module, `__ObjC`). C++ namespaces don't have a logical modular home in the Swift AST because they can span multiple modules, so it's understandable why this implementation was chosen. However, the concrete members of namespaces also get placed in the `__ObjC` module too, and this really confuses things. To work around this idiosyncrasy of Cxx interop, I've introduced `Decl::getModuleContextForNameLookup()` which returns the module that a declaration would ideally belong to if Cxx interop didn't have this behavior. This alternative to `Decl::getModuleContext()` is now used everywhere that `MemberImportVisibility` rules are enforced to provide consistency. Additionally, I found that I also had to further special-case the header import module for Cxx interop because it turns out that there are some additional declarations, beyond imported namespaces, that also live there and need to be implicitly visible in every source file. The `__ObjC` module is not implicitly imported in source files when Cxx interop is enabled, so these declarations are not deemed visible under normal name lookup rules. When I tried to add an implicit import of `__ObjC` when Cxx interop is enabled, it broke a bunch tests. So for now, when a decl really belongs to the `__ObjC` module in Cxx interop mode, we just always allow it to be referenced. This Cxx interop behavior really needs a re-think in my opinion, but that will require larger discussions. Resolves rdar://136600598.
72 lines
1.3 KiB
Plaintext
72 lines
1.3 KiB
Plaintext
module Classes {
|
|
header "classes.h"
|
|
requires cplusplus
|
|
}
|
|
|
|
module ClassesSecondHeader {
|
|
// TODO: we shouldn't have to include both of these, and the decls defined in
|
|
// these headers should be added to the correct module
|
|
// (https://github.com/apple/swift/issues/56592).
|
|
header "classes.h"
|
|
header "classes-second-header.h"
|
|
requires cplusplus
|
|
}
|
|
|
|
module FreeFunctions {
|
|
header "free-functions.h"
|
|
requires cplusplus
|
|
}
|
|
|
|
module FreeFunctionsSecondHeader {
|
|
header "free-functions.h"
|
|
header "free-functions-second-header.h"
|
|
requires cplusplus
|
|
}
|
|
|
|
module Submodules {
|
|
module SubmoduleA {
|
|
header "submodule-a.h"
|
|
requires cplusplus
|
|
}
|
|
module SubmoduleB {
|
|
header "submodule-b.h"
|
|
requires cplusplus
|
|
}
|
|
}
|
|
|
|
module Templates {
|
|
header "templates.h"
|
|
requires cplusplus
|
|
}
|
|
|
|
module TemplatesSecondHeader {
|
|
header "templates.h"
|
|
header "templates-second-header.h"
|
|
requires cplusplus
|
|
}
|
|
|
|
module TemplatesWithForwardDecl {
|
|
header "templates-with-forward-decl.h"
|
|
requires cplusplus
|
|
}
|
|
|
|
module Extensions {
|
|
header "extensions.h"
|
|
requires cplusplus
|
|
}
|
|
|
|
module Enums {
|
|
header "enums.h"
|
|
requires cplusplus
|
|
}
|
|
|
|
module MembersDirect {
|
|
header "members-direct.h"
|
|
requires cplusplus
|
|
}
|
|
|
|
module MembersTransitive {
|
|
header "members-transitive.h"
|
|
requires cplusplus
|
|
}
|