Skip to content

Commit 90d0306

Browse files
committed
[cxx-interop] Workaround name lookup issues with namespace simd
On Apple platforms, a system module `simd` declares a `namespace simd` under `#if defined(__cplusplus)`. This namespace defines C++ overlays of the simd types, but these types are already refined for Swift separately, so it's not necessary to import this namespace. This is the same issue previously encountered for the `os` module, work around it in the same way. rdar://143007477 (cherry picked from commit c7021ae)
1 parent eedae18 commit 90d0306

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,14 @@ namespace {
11551155
decl->getOwningModule() &&
11561156
decl->getOwningModule()->getTopLevelModuleName() == "os")
11571157
return nullptr;
1158+
// Workaround for simd module declaring `namespace simd` on Darwin,
1159+
// causing name lookup issues. That namespace declares C++ overlays of
1160+
// types that are already refined for Swift, so let's not import the
1161+
// namespace (rdar://143007477).
1162+
if (decl->getIdentifier() && decl->getName() == "simd" &&
1163+
decl->getOwningModule() &&
1164+
decl->getOwningModule()->getTopLevelModuleName() == "simd")
1165+
return nullptr;
11581166
// If this is a top-level namespace, don't put it in the module we're
11591167
// importing, put it in the "__ObjC" module that is implicitly imported.
11601168
if (!decl->getParent()->isNamespace())
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs -cxx-interoperability-mode=default %s
2+
3+
// REQUIRES: objc_interop
4+
// REQUIRES: VENDOR=apple
5+
6+
import simd
7+
8+
var _: simd.simd_quatf! = nil

0 commit comments

Comments
 (0)