Skip to content

Commit 0488c5a

Browse files
authored
Merge pull request #64943 from nkcsgexi/block-list
2 parents caf6e35 + 3c9ff9a commit 0488c5a

File tree

8 files changed

+122
-0
lines changed

8 files changed

+122
-0
lines changed

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/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>">;

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/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/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11771177

11781178
Opts.DumpTypeWitnessSystems = Args.hasArg(OPT_dump_type_witness_systems);
11791179

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

0 commit comments

Comments
 (0)