Skip to content

Commit e3c5838

Browse files
committed
[cxx-interop] Recognize CxxStdlib as an alias for std
C++ standard library module is called `std`. To make it more clear to a Swift developer that this module is a C++ stdlib, and not a Swift stdlib, let's rename it to `CxxStdlib`. This is the first step in the module rename. We don't ban `std` in this patch to be able to build SwiftCompilerSources with hosttools until a new Swift compiler is shipped.
1 parent 435af14 commit e3c5838

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

include/swift/AST/KnownIdentifiers.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ IDENTIFIER(CoreFoundation)
6060
IDENTIFIER(count)
6161
IDENTIFIER(CVarArg)
6262
IDENTIFIER(Cxx)
63+
IDENTIFIER(CxxStdlib)
6364
IDENTIFIER(Darwin)
6465
IDENTIFIER(Distributed)
6566
IDENTIFIER(dealloc)

lib/ClangImporter/ClangImporter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,14 @@ ClangImporter::loadModule(SourceLoc importLoc,
20012001
ModuleDecl *ClangImporter::Implementation::loadModule(
20022002
SourceLoc importLoc, ImportPath::Module path) {
20032003
ModuleDecl *MD = nullptr;
2004+
ASTContext &ctx = getNameImporter().getContext();
2005+
2006+
if (path.front().Item == ctx.Id_CxxStdlib) {
2007+
ImportPath::Builder adjustedPath(ctx.getIdentifier("std"), importLoc);
2008+
adjustedPath.append(path.getSubmodulePath());
2009+
path = adjustedPath.get().getModulePath(ImportKind::Module);
2010+
}
2011+
20042012
if (!DisableSourceImport)
20052013
MD = loadModuleClang(importLoc, path);
20062014
if (!MD)

test/Interop/Cxx/stdlib/libcxx-module-interface.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %target-swift-ide-test -print-module -module-to-print=std -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-STD
2-
// RUN: %target-swift-ide-test -print-module -module-to-print=std.iosfwd -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-IOSFWD
3-
// RUN: %target-swift-ide-test -print-module -module-to-print=std.string -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-STRING
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=CxxStdlib -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-STD
2+
// RUN: %target-swift-ide-test -print-module -module-to-print=CxxStdlib.iosfwd -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-IOSFWD
3+
// RUN: %target-swift-ide-test -print-module -module-to-print=CxxStdlib.string -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-STRING
44

55
// This test is specific to libc++ and therefore only runs on Darwin platforms.
66
// REQUIRES: OS=macosx || OS=ios

test/Interop/Cxx/stdlib/libstdcxx-module-interface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-ide-test -print-module -module-to-print=std -source-filename=x -enable-experimental-cxx-interop -module-cache-path %t > %t/interface.swift
2+
// RUN: %target-swift-ide-test -print-module -module-to-print=CxxStdlib -source-filename=x -enable-experimental-cxx-interop -module-cache-path %t > %t/interface.swift
33
// RUN: %FileCheck %s -check-prefix=CHECK-STD < %t/interface.swift
44
// RUN: %FileCheck %s -check-prefix=CHECK-SIZE-T < %t/interface.swift
55
// RUN: %FileCheck %s -check-prefix=CHECK-TO-STRING < %t/interface.swift

test/Interop/Cxx/stdlib/msvcprt-module-interface.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-ide-test -print-module -module-to-print std -source-filename none -enable-experimental-cxx-interop -module-cache-path %t | %FileCheck %s -check-prefix CHECK-STD
3-
// RUN: %target-swift-ide-test -print-module -module-to-print=std.string -source-filename=x -enable-experimental-cxx-interop -module-cache-path %t | %FileCheck %s -check-prefix CHECK-STRING
2+
// RUN: %target-swift-ide-test -print-module -module-to-print CxxStdlib -source-filename none -enable-experimental-cxx-interop -module-cache-path %t | %FileCheck %s -check-prefix CHECK-STD
3+
// RUN: %target-swift-ide-test -print-module -module-to-print=CxxStdlib.string -source-filename=x -enable-experimental-cxx-interop -module-cache-path %t | %FileCheck %s -check-prefix CHECK-STRING
44

55
// This test is specific to msvcprt and therefore only runs on Windows.
66
// REQUIRES: OS=windows-msvc

test/Interop/Cxx/stdlib/use-std-string.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
2+
// RUN: %target-run-simple-swift(-D USE_CXXSTDLIB_SPELLING -I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
23
//
34
// REQUIRES: executable_test
45
//
@@ -8,11 +9,19 @@
89
import StdlibUnittest
910
import StdString
1011
#if os(Linux)
12+
#if USE_CXXSTDLIB_SPELLING
13+
import CxxStdlib
14+
#else
1115
import std
12-
// FIXME: import std.string once libstdc++ is split into submodules.
16+
#endif
17+
// FIXME: import CxxStdlib.string once libstdc++ is split into submodules.
18+
#else
19+
#if USE_CXXSTDLIB_SPELLING
20+
import CxxStdlib.string
1321
#else
1422
import std.string
1523
#endif
24+
#endif
1625

1726
var StdStringTestSuite = TestSuite("StdString")
1827

0 commit comments

Comments
 (0)