Skip to content

Commit be1a665

Browse files
Merge pull request #4561 from swiftwasm/main
[pull] swiftwasm from main
2 parents b74a4df + 415c5c1 commit be1a665

File tree

66 files changed

+1259
-385
lines changed

Some content is hidden

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

66 files changed

+1259
-385
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ set(SWIFT_ANALYZE_CODE_COVERAGE FALSE CACHE STRING
179179
# SWIFT_VERSION is deliberately /not/ cached so that an existing build directory
180180
# can be reused when a new version of Swift comes out (assuming the user hasn't
181181
# manually set it as part of their own CMake configuration).
182-
set(SWIFT_VERSION "5.7")
182+
set(SWIFT_VERSION "5.8")
183183

184184
set(SWIFT_VENDOR "" CACHE STRING
185185
"The vendor name of the Swift compiler")

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,9 @@ WARNING(framework_search_path_includes_framework_extension,none,
338338
ERROR(error_optimization_remark_pattern, none, "%0 in '%1'",
339339
(StringRef, StringRef))
340340

341-
ERROR(error_invalid_debug_prefix_map, none,
342-
"values for '-debug-prefix-map' must be in the format 'original=remapped'"
343-
", but '%0' was provided", (StringRef))
344-
ERROR(error_invalid_coverage_prefix_map, none,
345-
"values for '-coverage-prefix-map' must be in the format "
346-
"'original=remapped', but '%0' was provided", (StringRef))
341+
ERROR(error_opt_invalid_mapping, none,
342+
"values for '%0' must be in the format 'original=remapped', but '%1' was "
343+
"provided", (StringRef, StringRef))
347344

348345
ERROR(invalid_vfs_overlay_file,none,
349346
"invalid virtual overlay file '%0'", (StringRef))

include/swift/AST/IRGenOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ class IRGenOptions {
254254
/// Path prefixes that should be rewritten in coverage info.
255255
PathRemapper CoveragePrefixMap;
256256

257+
/// Path prefixes that should be rewritten in info besides debug and coverage
258+
/// (use DebugPrefixMap and CoveragePrefixMap for those) - currently just
259+
/// indexing info.
260+
PathRemapper FilePrefixMap;
261+
257262
/// What level of debug info to generate.
258263
IRGenDebugInfoLevel DebugInfoLevel : 2;
259264

include/swift/Basic/PathRemapper.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define SWIFT_BASIC_PATHREMAPPER_H
2626

2727
#include "swift/Basic/LLVM.h"
28+
#include "clang/Basic/PathRemapper.h"
2829
#include "llvm/ADT/SmallVector.h"
2930
#include "llvm/ADT/Twine.h"
3031

@@ -57,6 +58,15 @@ class PathRemapper {
5758
Path.substr(Mapping.first.size())).str();
5859
return Path.str();
5960
}
61+
62+
/// Returns the Clang PathRemapper equivalent, suitable for use with Clang
63+
/// APIs.
64+
clang::PathRemapper asClangPathRemapper() const {
65+
clang::PathRemapper Remapper;
66+
for (const auto &Mapping : PathMappings)
67+
Remapper.addMapping(Mapping.first, Mapping.second);
68+
return Remapper;
69+
}
6070
};
6171

6272
class PathObfuscator {

include/swift/ClangImporter/CXXMethodBridging.h

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ struct CXXMethodBridging {
1818
if (nameIsBlacklist())
1919
return Kind::unknown;
2020

21-
// this should be handled as snake case. See: rdar://89453010
21+
// This should be handled as snake case. See: rdar://89453010
2222
// case. In the future we could
2323
// import these too, though.
2424
auto nameKind = classifyNameKind();
2525
if (nameKind != NameKind::title && nameKind != NameKind::camel &&
26-
nameKind != NameKind::lower)
26+
nameKind != NameKind::lower && nameKind != NameKind::snake)
2727
return Kind::unknown;
2828

2929
if (getClangName().startswith_insensitive("set")) {
@@ -62,16 +62,18 @@ struct CXXMethodBridging {
6262
}
6363

6464
NameKind classifyNameKind() {
65-
bool allLower = llvm::all_of(getClangName(), islower);
65+
bool hasUpper = llvm::any_of(
66+
getClangName(), [](unsigned char ch) { return std::isupper(ch); });
6667

67-
if (getClangName().empty())
68+
if (getClangName().empty()) {
6869
return NameKind::unknown;
70+
}
6971

70-
if (getClangName().contains('_'))
71-
return allLower ? NameKind::snake : NameKind::unknown;
72-
73-
if (allLower)
72+
if (getClangName().contains('_')) {
73+
return hasUpper ? NameKind::unknown : NameKind::snake;
74+
} else if (!hasUpper) {
7475
return NameKind::lower;
76+
}
7577

7678
return islower(getClangName().front()) ? NameKind::camel : NameKind::title;
7779
}
@@ -83,7 +85,7 @@ struct CXXMethodBridging {
8385
return method->getName();
8486
}
8587

86-
// this should be handled as snake case. See: rdar://89453010
88+
// This should be handled as snake case. See: rdar://89453010
8789
std::string importNameAsCamelCaseName() {
8890
std::string output;
8991
auto kind = classify();
@@ -103,6 +105,24 @@ struct CXXMethodBridging {
103105
// The first character is always lowercase.
104106
output.front() = std::tolower(output.front());
105107

108+
if (classifyNameKind() == NameKind::snake) {
109+
for (std::size_t i = 0; i < output.size(); i++) {
110+
size_t next = i + 1;
111+
if (output[i] == '_') {
112+
// If the first or last element is an underscore, remove it.
113+
if (i == 0 || next == output.size()) {
114+
output.erase(i, 1);
115+
} else if (next < output.size()) {
116+
// If the current element is an underscore, capitalize the element
117+
// next to it, and remove the extra element.
118+
output[i] = std::toupper(output[next]);
119+
output.erase(next, 1);
120+
}
121+
}
122+
}
123+
return output;
124+
}
125+
106126
// We already lowercased the first element, so start at one. Look at the
107127
// current element and the next one. To handle cases like UTF8String, start
108128
// making all the uppercase characters lower, until we see an upper case

include/swift/Demangling/Demangler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class NodeFactory {
8080
#endif
8181

8282
public:
83+
#ifndef NDEBUG
84+
/// Enabled only by the unit tests to test the failure paths.
85+
bool disableAssertionsForUnitTest = false;
86+
#endif
8387

8488
NodeFactory() {
8589
#ifdef NODE_FACTORY_DEBUGGING

include/swift/IDE/Utils.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ struct ResolvedCursorInfo {
167167
Type ContainerType;
168168
Stmt *TrailingStmt = nullptr;
169169
Expr *TrailingExpr = nullptr;
170-
/// If this is a call, whether it is "dynamic", see ide::isDynamicCall.
170+
/// It this is a ref, whether it is "dynamic". See \c ide::isDynamicRef.
171171
bool IsDynamic = false;
172-
/// If this is a call, the types of the base (multiple in the case of
172+
/// If this is a dynamic ref, the types of the base (multiple in the case of
173173
/// protocol composition).
174174
SmallVector<NominalTypeDecl *, 1> ReceiverTypes;
175175

@@ -616,11 +616,22 @@ bool isBeingCalled(ArrayRef<Expr*> ExprStack);
616616
/// stack in eg. the case of a `DotSyntaxCallExpr`).
617617
Expr *getBase(ArrayRef<Expr *> ExprStack);
618618

619-
/// Assuming that we have a call, returns whether or not it is "dynamic" based
620-
/// on its base expression and decl of the callee. Note that this is not
621-
/// Swift's "dynamic" modifier (`ValueDecl::isDynamic`), but rathar "can call a
622-
/// function in a conformance/subclass".
623-
bool isDynamicCall(Expr *Base, ValueDecl *D);
619+
/// Returns whether or not \p D could be overridden, eg. it's a member of a
620+
/// protocol, a non-final method in a class, etc.
621+
bool isDeclOverridable(ValueDecl *D);
622+
623+
/// Given a reference to a member \p D and its \p Base expression, return
624+
/// whether that declaration could be dynamic, ie. may resolve to some other
625+
/// declaration. Note that while the decl itself itself may be overridable, a
626+
/// reference to it is not necessarily "dynamic". Furthermore, is *not* the
627+
/// `dynamic` keyword.
628+
///
629+
/// A simple example is `SomeType.classMethod()`. `classMethod`
630+
/// is itself overridable, but that particular reference to it *has* to be the
631+
/// one in `SomeType`. Contrast that to `type(of: foo).classMethod()` where
632+
/// `classMethod` could be any `classMethod` up or down the hierarchy from the
633+
/// type of the \p Base expression.
634+
bool isDynamicRef(Expr *Base, ValueDecl *D);
624635

625636
/// Adds the resolved nominal types of \p Base to \p Types.
626637
void getReceiverType(Expr *Base,

include/swift/Index/IndexRecord.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_INDEX_INDEXRECORD_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "swift/Basic/PathRemapper.h"
1718
#include "llvm/ADT/ArrayRef.h"
1819
#include "llvm/ADT/StringRef.h"
1920

@@ -44,11 +45,14 @@ namespace index {
4445
/// \param targetTriple The target for this compilation.
4546
///
4647
/// \param dependencyTracker The set of dependencies seen while building.
48+
///
49+
/// \param pathRemapper Remapper to use for paths in index data.
4750
bool indexAndRecord(SourceFile *primarySourceFile, StringRef indexUnitToken,
4851
StringRef indexStorePath, bool indexSystemModules,
4952
bool skipStdlib, bool isDebugCompilation,
5053
StringRef targetTriple,
51-
const DependencyTracker &dependencyTracker);
54+
const DependencyTracker &dependencyTracker,
55+
const PathRemapper &pathRemapper);
5256

5357
/// Index the given module and store the results to \p indexStorePath.
5458
///
@@ -76,11 +80,14 @@ bool indexAndRecord(SourceFile *primarySourceFile, StringRef indexUnitToken,
7680
/// \param targetTriple The target for this compilation.
7781
///
7882
/// \param dependencyTracker The set of dependencies seen while building.
83+
///
84+
/// \param pathRemapper Remapper to use for paths in index data.
7985
bool indexAndRecord(ModuleDecl *module, ArrayRef<std::string> indexUnitTokens,
8086
StringRef moduleUnitToken, StringRef indexStorePath,
8187
bool indexSystemModules, bool skipStdlib,
8288
bool isDebugCompilation, StringRef targetTriple,
83-
const DependencyTracker &dependencyTracker);
89+
const DependencyTracker &dependencyTracker,
90+
const PathRemapper &pathRemapper);
8491
// FIXME: indexUnitTokens could be StringRef, but that creates an impedance
8592
// mismatch in the caller.
8693

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ def enable_experimental_concurrency :
278278
Flag<["-"], "enable-experimental-concurrency">,
279279
HelpText<"Enable experimental concurrency model">;
280280

281+
def enable_experimental_cxx_interop :
282+
Flag<["-"], "enable-experimental-cxx-interop">,
283+
HelpText<"Enable C++ interop code generation and config directives">;
284+
281285
def enable_lexical_borrow_scopes :
282286
Joined<["-"], "enable-lexical-borrow-scopes=">,
283287
HelpText<"Whether to emit lexical borrow scopes (default: true)">,
@@ -825,11 +829,6 @@ def emit_sorted_sil : Flag<["-"], "emit-sorted-sil">,
825829
def emit_syntax : Flag<["-"], "emit-syntax">,
826830
HelpText<"Parse input file(s) and emit the Syntax tree(s) as JSON">, ModeOpt;
827831

828-
def enable_experimental_cxx_interop :
829-
Flag<["-"], "enable-experimental-cxx-interop">,
830-
HelpText<"Enable C++ interop code generation and config directives">,
831-
Flags<[FrontendOption, HelpHidden]>;
832-
833832
def enable_cxx_interop :
834833
Flag<["-"], "enable-cxx-interop">,
835834
HelpText<"Alias for -enable-experimental-cxx-interop">,

include/swift/Option/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,9 @@ def debug_prefix_map : Separate<["-"], "debug-prefix-map">,
845845
def coverage_prefix_map : Separate<["-"], "coverage-prefix-map">,
846846
Flags<[FrontendOption]>,
847847
HelpText<"Remap source paths in coverage info">, MetaVarName<"<prefix=replacement>">;
848+
def file_prefix_map : Separate<["-"], "file-prefix-map">,
849+
Flags<[FrontendOption]>,
850+
HelpText<"Remap source paths in debug, coverage, and index info">, MetaVarName<"<prefix=replacement>">;
848851

849852
def file_compilation_dir : Separate<["-"], "file-compilation-dir">,
850853
Flags<[FrontendOption]>, MetaVarName<"<path>">,

0 commit comments

Comments
 (0)