Skip to content

Commit d790477

Browse files
authored
Merge branch 'main' into name-lookup-filtering-expanded-top-level
2 parents 8e63bf1 + e355fd8 commit d790477

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+310
-112
lines changed

docs/CppInteroperability/GettingStartedWithC++Interop.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module CxxTest {
3232
Add the C++ module to the include path and enable C++ interop:
3333
- Navigate to your project directory
3434
- In `Project` navigate to `Build Settings` -> `Swift Compiler`
35-
- Under `Custom Flags` -> `Other Swift Flags` add `-cxx-interoperability-mode=swift-5.9`
35+
- Under `Custom Flags` -> `Other Swift Flags` add `-cxx-interoperability-mode=default`
3636
- Under `Search Paths` -> `Import Paths` add your search path to the C++ module (i.e, `./ProjectName/CxxTest`).
3737

3838
- This should now allow your to import your C++ Module into any `.swift` file.
@@ -81,7 +81,7 @@ After creating your Swift package project, follow the steps [Creating a Module t
8181
- Swift code will be in `Sources/CxxInterop` called `main.swift`
8282
- C++ source code follows the example shown in [Creating a Module to contain your C++ source code](#creating-a-module-to-contain-your-c-source-code)
8383
- Under targets, add the name of your C++ module and the directory containing the Swift code as a target.
84-
- In the target defining your Swift target, add a`dependencies` to the C++ Module, the `path`, `source`, and `swiftSettings` with `unsafeFlags` with the source to the C++ Module, and enable `-cxx-interoperability-mode=swift-5.9`
84+
- In the target defining your Swift target, add a`dependencies` to the C++ Module, the `path`, `source`, and `swiftSettings` with `unsafeFlags` with the source to the C++ Module, and enable `-cxx-interoperability-mode=default`
8585

8686
```
8787
//In Package Manifest
@@ -111,7 +111,7 @@ let package = Package(
111111
sources: [ "main.swift" ],
112112
swiftSettings: [.unsafeFlags([
113113
"-I", "Sources/CxxTest",
114-
"-cxx-interoperability-mode=swift-5.9",
114+
"-cxx-interoperability-mode=default",
115115
])]
116116
),
117117
]
@@ -144,7 +144,7 @@ After creating your project follow the steps [Creating a Module to contain your
144144
- Create a `CMakeLists.txt` file and configure for your project
145145
- In`add_library` invoke `cxx-support` with the path to the C++ implementation file
146146
- Add the `target_include_directories` with `cxx-support` and path to the C++ Module `${CMAKE_SOURCE_DIR}/Sources/CxxTest`
147-
- Add the `add_executable` to the specific files/directory you would like to generate source, with`SHELL:-cxx-interoperability-mode=swift-5.9`.
147+
- Add the `add_executable` to the specific files/directory you would like to generate source, with`SHELL:-cxx-interoperability-mode=default`.
148148
- In the example below we will be following the file structure used in [Creating a Swift Package](#Creating-a-Swift-Package)
149149

150150
```
@@ -167,7 +167,7 @@ target_include_directories(cxx-support PUBLIC
167167
168168
add_executable(CxxInterop ./Sources/CxxInterop/main.swift)
169169
target_compile_options(CxxInterop PRIVATE
170-
"SHELL:-cxx-interoperability-mode=swift-5.9"
170+
"SHELL:-cxx-interoperability-mode=default"
171171
target_link_libraries(CxxInterop PRIVATE cxx-support)
172172
173173
```

include/swift/AST/ASTContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "swift/Basic/LangOptions.h"
3131
#include "swift/Basic/Located.h"
3232
#include "swift/Basic/Malloc.h"
33+
#include "swift/Basic/BlockList.h"
3334
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
3435
#include "clang/AST/DeclTemplate.h"
3536
#include "llvm/ADT/ArrayRef.h"
@@ -365,6 +366,8 @@ class ASTContext final {
365366
/// The Swift module currently being compiled.
366367
ModuleDecl *MainModule = nullptr;
367368

369+
/// The block list where we can find special actions based on module name;
370+
BlockListStore blockListConfig;
368371
private:
369372
/// The current generation number, which reflects the number of
370373
/// times that external modules have been loaded.

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,9 @@ WARNING(compiler_plugin_not_loaded,none,
524524
ERROR(dont_enable_interop_and_compat,none,
525525
"do not pass both -enable-experimental-cxx-interop and "
526526
"-cxx-interoperability-mode. Remove -enable-experimental-cxx-interop.", ())
527-
528-
ERROR(invalid_interop_compat_mode,none,
529-
"invalid option passed to -cxx-interoperability-mode. Please select either "
530-
"'off' or 'swift-5.9'.", ())
527+
528+
NOTE(valid_cxx_interop_modes,none,
529+
"valid arguments to '-cxx-interoperability-mode=' are %0", (StringRef))
531530
NOTE(swift_will_maintain_compat,none,
532531
"Swift will maintain source compatibility for imported APIs based on the "
533532
"selected compatibility mode, so updating the Swift compiler will not "

include/swift/Basic/BlockList.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//===--- BlockList.h ---------------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines some miscellaneous overloads of hash_value() and
14+
// simple_display().
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_BASIC_BLOCKLIST_H
19+
#define SWIFT_BASIC_BLOCKLIST_H
20+
21+
#include "swift/Basic/LLVM.h"
22+
#include "llvm/ADT/StringRef.h"
23+
24+
namespace swift {
25+
26+
enum class BlockListAction: uint8_t {
27+
ShouldUseBinaryModule = 0,
28+
ShouldUseTextualModule,
29+
};
30+
31+
enum class BlockListKeyKind: uint8_t {
32+
ModuleName,
33+
ProjectName
34+
};
35+
36+
class BlockListStore {
37+
public:
38+
struct Implementation;
39+
bool hasBlockListAction(StringRef key, BlockListKeyKind keyKind,
40+
BlockListAction action);
41+
BlockListStore();
42+
~BlockListStore();
43+
private:
44+
friend class ASTContext;
45+
void addConfigureFilePath(StringRef path);
46+
Implementation &Impl;
47+
};
48+
49+
} // namespace swift
50+
51+
#endif // SWIFT_BASIC_BLOCKLIST_H

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ namespace swift {
556556
/// The model of concurrency to be used.
557557
ConcurrencyModel ActiveConcurrencyModel = ConcurrencyModel::Standard;
558558

559+
/// All block list configuration files to be honored in this compilation.
560+
std::vector<std::string> BlocklistConfigFilePath;
561+
559562
bool isConcurrencyModelTaskToThread() const {
560563
return ActiveConcurrencyModel == ConcurrencyModel::TaskToThread;
561564
}

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ def Raccess_note : Separate<["-"], "Raccess-note">,
240240
def Raccess_note_EQ : Joined<["-"], "Raccess-note=">,
241241
Alias<Raccess_note>;
242242

243+
def block_list_file
244+
: Separate<["-"], "blocklist-file">, MetaVarName<"<path>">,
245+
HelpText<"The path to a blocklist configuration file">;
243246
} // end let Flags = [FrontendOption, NoDriverOption]
244247

245248
def debug_crash_Group : OptionGroup<"<automatic crashing options>">;

include/swift/SIL/TypeLowering.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,14 +1260,16 @@ class TypeConverter {
12601260
/// Check the result of
12611261
/// getTypeLowering(AbstractionPattern,Type,TypeExpansionContext).
12621262
void verifyLowering(const TypeLowering &, AbstractionPattern origType,
1263-
Type origSubstType, TypeExpansionContext forExpansion);
1263+
CanType origSubstType,
1264+
TypeExpansionContext forExpansion);
12641265
bool
1265-
visitAggregateLeaves(Lowering::AbstractionPattern origType, Type substType,
1266+
visitAggregateLeaves(Lowering::AbstractionPattern origType,
1267+
CanType substType,
12661268
TypeExpansionContext context,
1267-
std::function<bool(Type, Lowering::AbstractionPattern,
1269+
std::function<bool(CanType, Lowering::AbstractionPattern,
12681270
ValueDecl *, Optional<unsigned>)>
12691271
isLeafAggregate,
1270-
std::function<bool(Type, Lowering::AbstractionPattern,
1272+
std::function<bool(CanType, Lowering::AbstractionPattern,
12711273
ValueDecl *, Optional<unsigned>)>
12721274
visit);
12731275
#endif

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,9 +713,14 @@ ASTContext::ASTContext(
713713
registerNameLookupRequestFunctions(evaluator);
714714

715715
createModuleToExecutablePluginMap();
716+
716717
// Provide a default OnDiskOutputBackend if user didn't supply one.
717718
if (!OutputBackend)
718719
OutputBackend = llvm::makeIntrusiveRefCnt<llvm::vfs::OnDiskOutputBackend>();
720+
// Insert all block list config paths.
721+
for (auto path: langOpts.BlocklistConfigFilePath) {
722+
blockListConfig.addConfigureFilePath(path);
723+
}
719724
}
720725

721726
ASTContext::~ASTContext() {

lib/ASTGen/Sources/ASTGen/Decls.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,10 @@ extension ASTGenVisitor {
8989

9090
let firstName: UnsafeMutableRawPointer?
9191
let secondName: UnsafeMutableRawPointer?
92-
let type: UnsafeMutableRawPointer?
93-
94-
if let nodeFirstName = node.firstName,
95-
// Swift AST represnts "_" as nil.
96-
nodeFirstName.text != "_" {
92+
93+
let nodeFirstName = node.firstName
94+
if nodeFirstName.text != "_" {
95+
// Swift AST represents "_" as nil.
9796
var text = nodeFirstName.text
9897
firstName = text.withUTF8 { buf in
9998
SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count)
@@ -111,11 +110,7 @@ extension ASTGenVisitor {
111110
secondName = nil
112111
}
113112

114-
if let typeSyntax = node.type {
115-
type = visit(typeSyntax).rawValue
116-
} else {
117-
type = nil
118-
}
113+
let type = visit(node.type).rawValue
119114

120115
return .decl(ParamDecl_create(ctx, loc, loc, firstName, loc, secondName, type, declContext))
121116
}

lib/ASTGen/Sources/ASTGen/Diagnostics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func emitDiagnostic(
110110
message: fixIt.message.message,
111111
severity: .note,
112112
position: diagnostic.position,
113-
fixItChanges: fixIt.changes.changes
113+
fixItChanges: fixIt.changes
114114
)
115115
}
116116

@@ -231,7 +231,7 @@ extension SourceManager {
231231
severity: .note,
232232
node: diagnostic.node,
233233
position: diagnostic.position,
234-
fixItChanges: fixIt.changes.changes
234+
fixItChanges: fixIt.changes
235235
)
236236
}
237237

lib/Basic/BlockList.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//===--- BlockList.cpp - BlockList utilities ------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "llvm/ADT/STLExtras.h"
14+
#include "llvm/ADT/StringSwitch.h"
15+
#include "llvm/Support/YAMLParser.h"
16+
#include "llvm/Support/YAMLTraits.h"
17+
#include "swift/Basic/BlockList.h"
18+
#include "swift/Basic/SourceManager.h"
19+
20+
struct swift::BlockListStore::Implementation {
21+
llvm::StringMap<std::vector<BlockListAction>> ModuleActionDict;
22+
llvm::StringMap<std::vector<BlockListAction>> ProjectActionDict;
23+
void addConfigureFilePath(StringRef path);
24+
bool hasBlockListAction(StringRef key, BlockListKeyKind keyKind,
25+
BlockListAction action);
26+
};
27+
28+
swift::BlockListStore::BlockListStore(): Impl(*new Implementation()) {}
29+
30+
swift::BlockListStore::~BlockListStore() { delete &Impl; }
31+
32+
bool swift::BlockListStore::hasBlockListAction(StringRef key,
33+
BlockListKeyKind keyKind, BlockListAction action) {
34+
return Impl.hasBlockListAction(key, keyKind, action);
35+
}
36+
37+
void swift::BlockListStore::addConfigureFilePath(StringRef path) {
38+
Impl.addConfigureFilePath(path);
39+
}
40+
41+
bool swift::BlockListStore::Implementation::hasBlockListAction(StringRef key,
42+
BlockListKeyKind keyKind, BlockListAction action) {
43+
auto *dict = keyKind == BlockListKeyKind::ModuleName ? &ModuleActionDict :
44+
&ProjectActionDict;
45+
auto it = dict->find(key);
46+
if (it == dict->end())
47+
return false;
48+
return llvm::is_contained(it->second, action);
49+
}
50+
51+
void swift::BlockListStore::Implementation::addConfigureFilePath(StringRef path) {
52+
53+
}

lib/Basic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ add_swift_host_library(swiftBasic STATIC
7878
Unicode.cpp
7979
UUID.cpp
8080
Version.cpp
81+
BlockList.cpp
8182

8283
${llvm_revision_inc}
8384
${clang_revision_inc}

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,8 @@ static void addSearchPathInvocationArguments(
7575
static std::vector<std::string> getClangDepScanningInvocationArguments(
7676
ASTContext &ctx,
7777
Optional<StringRef> sourceFileName = None) {
78-
std::vector<std::string> commandLineArgs;
79-
80-
// Form the basic command line.
81-
commandLineArgs.push_back("clang");
82-
importer::getNormalInvocationArguments(commandLineArgs, ctx);
83-
importer::addCommonInvocationArguments(commandLineArgs, ctx);
78+
std::vector<std::string> commandLineArgs =
79+
ClangImporter::getClangArguments(ctx);
8480
addSearchPathInvocationArguments(commandLineArgs, ctx);
8581

8682
auto sourceFilePos = std::find(
@@ -114,6 +110,10 @@ static std::vector<std::string> getClangDepScanningInvocationArguments(
114110
*syntaxOnlyPos = "-c";
115111
}
116112

113+
// The Clang modules produced by ClangImporter are always embedded in an
114+
// ObjectFilePCHContainer and contain -gmodules debug info.
115+
commandLineArgs.push_back("-gmodules");
116+
117117
return commandLineArgs;
118118
}
119119

lib/Frontend/CompilerInvocation.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,26 @@ enum class CxxCompatMode {
438438
static CxxCompatMode validateCxxInteropCompatibilityMode(StringRef mode) {
439439
if (mode == "off")
440440
return CxxCompatMode::off;
441+
if (mode == "default")
442+
return CxxCompatMode::enabled;
443+
// FIXME: Drop swift-5.9.
441444
if (mode == "swift-5.9")
442445
return CxxCompatMode::enabled;
443446
return CxxCompatMode::invalid;
444447
}
445448

449+
static void diagnoseCxxInteropCompatMode(Arg *verArg, ArgList &Args,
450+
DiagnosticEngine &diags) {
451+
// General invalid argument error
452+
diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
453+
verArg->getAsString(Args), verArg->getValue());
454+
455+
// Note valid C++ interoperability modes.
456+
auto validVers = {llvm::StringRef("off"), llvm::StringRef("default")};
457+
auto versStr = "'" + llvm::join(validVers, "', '") + "'";
458+
diags.diagnose(SourceLoc(), diag::valid_cxx_interop_modes, versStr);
459+
}
460+
446461
static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
447462
DiagnosticEngine &Diags,
448463
const FrontendOptions &FrontendOpts) {
@@ -940,10 +955,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
940955
auto interopCompatMode = validateCxxInteropCompatibilityMode(A->getValue());
941956
Opts.EnableCXXInterop |= (interopCompatMode == CxxCompatMode::enabled);
942957

943-
if (interopCompatMode == CxxCompatMode::invalid) {
944-
Diags.diagnose(SourceLoc(), diag::invalid_interop_compat_mode);
945-
Diags.diagnose(SourceLoc(), diag::swift_will_maintain_compat);
946-
}
958+
if (interopCompatMode == CxxCompatMode::invalid)
959+
diagnoseCxxInteropCompatMode(A, Args, Diags);
947960
}
948961

949962
if (Args.hasArg(OPT_enable_experimental_cxx_interop)) {
@@ -1164,6 +1177,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11641177

11651178
Opts.DumpTypeWitnessSystems = Args.hasArg(OPT_dump_type_witness_systems);
11661179

1180+
for (auto A : Args.getAllArgValues(options::OPT_block_list_file)) {
1181+
Opts.BlocklistConfigFilePath.push_back(A);
1182+
}
11671183
if (const Arg *A = Args.getLastArg(options::OPT_concurrency_model)) {
11681184
Opts.ActiveConcurrencyModel =
11691185
llvm::StringSwitch<ConcurrencyModel>(A->getValue())

0 commit comments

Comments
 (0)