Skip to content

Commit ce86f8e

Browse files
authored
Merge pull request #667 from swiftwasm/maxd/master-merge
The conflict resolution itself was trivial, the main breakage source was the introduction of `_add_target_variant_c_compile_link_flags` in `AddSwiftStdlib.cmake`, which is where `_WASI_EMULATED_MMAN` had to be moved from `_add_host_variant_c_compile_link_flags` in `AddSwift.cmake`.
2 parents eef11bc + 606aacc commit ce86f8e

File tree

74 files changed

+2693
-197
lines changed

Some content is hidden

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

74 files changed

+2693
-197
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
907907
endif()
908908

909909
find_package(Python2 COMPONENTS Interpreter REQUIRED)
910+
find_package(Python3 COMPONENTS Interpreter REQUIRED)
910911

911912
#
912913
# Find optional dependencies.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Please make sure you use Python 2.x. Python 3.x is not supported currently.
9191

9292
#### macOS
9393

94-
To build for macOS, you need [Xcode 11.4](https://developer.apple.com/xcode/downloads/).
94+
To build for macOS, you need [Xcode 11.4](https://developer.apple.com/xcode/resources/).
9595
The required version of Xcode changes frequently, and is often a beta release.
9696
Check this document or the host information on <https://ci.swift.org> for the
9797
current required version.
@@ -158,7 +158,9 @@ First create a directory for all of the Swift sources:
158158
**Note:** This is important since update-checkout (see below) checks out
159159
repositories next to the Swift source directory. This means that if one clones
160160
Swift and has other unrelated repositories, update-checkout may not clone those
161-
repositories and will update them instead.
161+
repositories and will update them instead. Be aware that `update-checkout`
162+
currently does not support paths with non-ASCII characters. If such characters
163+
are present in the path to `swift-source`, `update-checkout` will fail.
162164

163165
**Via HTTPS** For those checking out sources as read-only, HTTPS works best:
164166

cmake/modules/AddSwift.cmake

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function(is_darwin_based_sdk sdk_name out_var)
7272
endfunction()
7373

7474
# Usage:
75-
# _add_variant_c_compile_link_flags(
75+
# _add_host_variant_c_compile_link_flags(
7676
# SDK sdk
7777
# ARCH arch
7878
# BUILD_TYPE build_type
@@ -86,7 +86,7 @@ endfunction()
8686
# DEPLOYMENT_VERSION_WATCHOS version
8787
#
8888
# )
89-
function(_add_variant_c_compile_link_flags)
89+
function(_add_host_variant_c_compile_link_flags)
9090
set(oneValueArgs SDK ARCH BUILD_TYPE RESULT_VAR_NAME ENABLE_LTO ANALYZE_CODE_COVERAGE
9191
DEPLOYMENT_VERSION_OSX DEPLOYMENT_VERSION_MACCATALYST DEPLOYMENT_VERSION_IOS DEPLOYMENT_VERSION_TVOS DEPLOYMENT_VERSION_WATCHOS
9292
MACCATALYST_BUILD_FLAVOR
@@ -189,7 +189,7 @@ function(_add_variant_c_compile_link_flags)
189189
endfunction()
190190

191191

192-
function(_add_variant_c_compile_flags)
192+
function(_add_host_variant_c_compile_flags)
193193
set(oneValueArgs SDK ARCH BUILD_TYPE ENABLE_ASSERTIONS ANALYZE_CODE_COVERAGE
194194
DEPLOYMENT_VERSION_OSX DEPLOYMENT_VERSION_MACCATALYST DEPLOYMENT_VERSION_IOS DEPLOYMENT_VERSION_TVOS DEPLOYMENT_VERSION_WATCHOS
195195
RESULT_VAR_NAME ENABLE_LTO
@@ -202,7 +202,7 @@ function(_add_variant_c_compile_flags)
202202

203203
set(result ${${CFLAGS_RESULT_VAR_NAME}})
204204

205-
_add_variant_c_compile_link_flags(
205+
_add_host_variant_c_compile_link_flags(
206206
SDK "${CFLAGS_SDK}"
207207
ARCH "${CFLAGS_ARCH}"
208208
BUILD_TYPE "${CFLAGS_BUILD_TYPE}"
@@ -351,8 +351,6 @@ function(_add_variant_c_compile_flags)
351351
list(APPEND result "SHELL:${CMAKE_INCLUDE_SYSTEM_FLAG_C}${path}")
352352
endforeach()
353353
list(APPEND result "-D__ANDROID_API__=${SWIFT_ANDROID_API_LEVEL}")
354-
elseif("${CFLAGS_SDK}" STREQUAL "WASI")
355-
list(APPEND result "-D_WASI_EMULATED_MMAN")
356354
endif()
357355

358356
if("${CFLAGS_SDK}" STREQUAL "LINUX")
@@ -365,7 +363,7 @@ function(_add_variant_c_compile_flags)
365363
set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
366364
endfunction()
367365

368-
function(_add_variant_link_flags)
366+
function(_add_host_variant_link_flags)
369367
set(oneValueArgs SDK ARCH BUILD_TYPE ENABLE_ASSERTIONS ANALYZE_CODE_COVERAGE
370368
DEPLOYMENT_VERSION_OSX DEPLOYMENT_VERSION_MACCATALYST DEPLOYMENT_VERSION_IOS DEPLOYMENT_VERSION_TVOS DEPLOYMENT_VERSION_WATCHOS
371369
RESULT_VAR_NAME ENABLE_LTO LTO_OBJECT_NAME LINK_LIBRARIES_VAR_NAME LIBRARY_SEARCH_DIRECTORIES_VAR_NAME
@@ -384,7 +382,7 @@ function(_add_variant_link_flags)
384382
set(link_libraries ${${LFLAGS_LINK_LIBRARIES_VAR_NAME}})
385383
set(library_search_directories ${${LFLAGS_LIBRARY_SEARCH_DIRECTORIES_VAR_NAME}})
386384

387-
_add_variant_c_compile_link_flags(
385+
_add_host_variant_c_compile_link_flags(
388386
SDK "${LFLAGS_SDK}"
389387
ARCH "${LFLAGS_ARCH}"
390388
BUILD_TYPE "${LFLAGS_BUILD_TYPE}"
@@ -658,7 +656,7 @@ function(_add_swift_host_library_single target)
658656

659657
set(library_search_directories)
660658

661-
_add_variant_c_compile_flags(
659+
_add_host_variant_c_compile_flags(
662660
SDK "${SWIFT_HOST_VARIANT_SDK}"
663661
ARCH "${SWIFT_HOST_VARIANT_ARCH}"
664662
BUILD_TYPE ${CMAKE_BUILD_TYPE}
@@ -679,7 +677,7 @@ function(_add_swift_host_library_single target)
679677
message(FATAL_ERROR "WASM does not support shared libraries.")
680678
endif()
681679
endif()
682-
_add_variant_link_flags(
680+
_add_host_variant_link_flags(
683681
SDK "${SWIFT_HOST_VARIANT_SDK}"
684682
ARCH "${SWIFT_HOST_VARIANT_ARCH}"
685683
BUILD_TYPE ${CMAKE_BUILD_TYPE}
@@ -859,15 +857,15 @@ function(_add_swift_host_executable_single name)
859857
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")
860858

861859
# Add variant-specific flags.
862-
_add_variant_c_compile_flags(
860+
_add_host_variant_c_compile_flags(
863861
SDK "${SWIFTEXE_SINGLE_SDK}"
864862
ARCH "${SWIFTEXE_SINGLE_ARCHITECTURE}"
865863
BUILD_TYPE "${CMAKE_BUILD_TYPE}"
866864
ENABLE_ASSERTIONS "${LLVM_ENABLE_ASSERTIONS}"
867865
ENABLE_LTO "${SWIFT_TOOLS_ENABLE_LTO}"
868866
ANALYZE_CODE_COVERAGE "${SWIFT_ANALYZE_CODE_COVERAGE}"
869867
RESULT_VAR_NAME c_compile_flags)
870-
_add_variant_link_flags(
868+
_add_host_variant_link_flags(
871869
SDK "${SWIFTEXE_SINGLE_SDK}"
872870
ARCH "${SWIFTEXE_SINGLE_ARCHITECTURE}"
873871
BUILD_TYPE "${CMAKE_BUILD_TYPE}"

docs/DevelopmentTips.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,25 @@ Given the size of artifacts generated, you might also want to bump the cache siz
4141
You can run some compiles to see if it is actually doing something by running `sccache --show-stats`. Depending on the exact compilation task you're running, you might see very different cache hit rates. For example, `sccache` is particularly effective if you're rebuilding LLVM, which doesn't change so frequently from the Swift compiler's perspective. On the other hand, if you're changing the compiler's AST, the cache hit rate is likely to be much lower.
4242

4343
One known issue with `sccache` is that you might occassionally get an "error: Connection to server timed out", even though you didn't stop the server. Simply re-running the build command usually works.
44+
45+
## Memory usage
46+
47+
When building Swift, peak memory usage happens during the linking phases that produce llvm and swift executables. In case your build fails because a process ran out of RAM, you can use one or more of the following techniques to reduce the peak memory usage.
48+
49+
### Reduce the amount of debug symbols
50+
51+
We can use debug symbols for only the part of the project we intend to work on. For example, when working on the compiler itself, we can build with debug symbols enabled only for the compiler:
52+
53+
```
54+
build-script --release --debug-swift
55+
```
56+
57+
### Reduce the number of parallel link jobs
58+
59+
By default, `build-script` will spawn as many parallel compile / link jobs as there are CPUs in the machine. We can reduce the number of parallel link jobs by setting the `LLVM_PARALLEL_LINK_JOBS` and `SWIFT_PARALLEL_LINK_JOBS` CMake properties. We can set them through the `--llvm-cmake-options` and `--swift-cmake-options` arguments to `build-script`.
60+
61+
For example, to have `build-script` spawn only one link job at a time, we can invoke it as:
62+
63+
```
64+
build-script --llvm-cmake-options==-DLLVM_PARALLEL_LINK_JOBS=1 --swift-cmake-options=-DSWIFT_PARALLEL_LINK_JOBS=1
65+
```

docs/SIL.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -772,14 +772,6 @@ types. Function types are transformed in order to encode additional attributes:
772772
a way as to guarantee that it is polymorphic across all possible
773773
implementors of the protocol.
774774

775-
- The **fully uncurried representation** of the function type, with
776-
all of the curried argument clauses flattened into a single argument
777-
clause. For instance, a curried function ``func foo(_ x:A)(y:B) -> C``
778-
might be emitted as a function of type ``((y:B), (x:A)) -> C``. The
779-
exact representation depends on the function's `calling
780-
convention`_, which determines the exact ordering of currying
781-
clauses. Methods are treated as a form of curried function.
782-
783775
Layout Compatible Types
784776
```````````````````````
785777

include/swift/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,8 @@ class alignas(RequirementRepr) TrailingWhereClause final :
14341434
return SourceRange(WhereLoc,
14351435
getRequirements().back().getSourceRange().End);
14361436
}
1437+
1438+
void print(llvm::raw_ostream &OS, bool printWhereKeyword) const;
14371439
};
14381440

14391441
// A private class for forcing exact field layout.

include/swift/IDE/CompletionInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class CompletionInstance {
5050
/// Returns \c if the callback was called. Returns \c false if the compiler
5151
/// argument has changed, primary file is not the same, the \c Offset is not
5252
/// in function bodies, or the interface hash of the file has changed.
53-
bool performCachedOperaitonIfPossible(
53+
bool performCachedOperationIfPossible(
5454
const swift::CompilerInvocation &Invocation, llvm::hash_code ArgsHash,
5555
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
5656
DiagnosticConsumer *DiagC,

include/swift/IDE/Refactoring.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,17 @@ collectAvailableRefactorings(SourceFile *SF, ResolvedCursorInfo CursorInfo,
141141
std::vector<RefactoringKind> &Scratch,
142142
bool ExcludeRename);
143143

144+
/// Stores information about the reference that rename availability is being
145+
/// queried on.
146+
struct RenameRefInfo {
147+
SourceFile *SF; ///< The source file containing the reference.
148+
SourceLoc Loc; ///< The reference's source location.
149+
bool IsArgLabel; ///< Whether Loc is on an arg label, rather than base name.
150+
};
151+
144152
ArrayRef<RenameAvailabiliyInfo>
145153
collectRenameAvailabilityInfo(const ValueDecl *VD,
154+
Optional<RenameRefInfo> RefInfo,
146155
std::vector<RenameAvailabiliyInfo> &Scratch);
147156

148157
} // namespace ide

include/swift/IDE/Utils.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace swift {
4848
class Type;
4949
class Decl;
5050
class DeclContext;
51+
class CallExpr;
5152
class ClangNode;
5253
class ClangImporter;
5354
class Token;
@@ -226,6 +227,12 @@ struct ResolvedLoc {
226227
bool IsInSelector;
227228
};
228229

230+
/// Used by NameMatcher to track parent CallExprs when walking a checked AST.
231+
struct CallingParent {
232+
Expr *ApplicableTo;
233+
CallExpr *Call;
234+
};
235+
229236

230237
/// Finds the parse-only AST nodes and corresponding name and param/argument
231238
/// label ranges for a given list of input name start locations
@@ -244,6 +251,9 @@ class NameMatcher: public ASTWalker {
244251
unsigned InactiveConfigRegionNestings = 0;
245252
unsigned SelectorNestings = 0;
246253

254+
/// The stack of parent CallExprs and the innermost expression they apply to.
255+
std::vector<CallingParent> ParentCalls;
256+
247257
SourceManager &getSourceMgr() const;
248258

249259
SourceLoc nextLoc() const;
@@ -256,11 +266,11 @@ class NameMatcher: public ASTWalker {
256266
bool shouldSkip(SourceRange Range);
257267
bool shouldSkip(CharSourceRange Range);
258268
bool tryResolve(ASTWalker::ParentTy Node, SourceLoc NameLoc);
259-
bool tryResolve(ASTWalker::ParentTy Node, DeclNameLoc NameLoc, Expr *Arg,
260-
bool checkParentForLabels = false);
269+
bool tryResolve(ASTWalker::ParentTy Node, DeclNameLoc NameLoc, Expr *Arg);
261270
bool tryResolve(ASTWalker::ParentTy Node, SourceLoc NameLoc, LabelRangeType RangeType,
262271
ArrayRef<CharSourceRange> LabelLocs);
263272
bool handleCustomAttrs(Decl *D);
273+
Expr *getApplicableArgFor(Expr* E);
264274

265275
std::pair<bool, Expr*> walkToExprPre(Expr *E) override;
266276
Expr* walkToExprPost(Expr *E) override;
@@ -281,6 +291,7 @@ class NameMatcher: public ASTWalker {
281291
public:
282292
explicit NameMatcher(SourceFile &SrcFile) : SrcFile(SrcFile) { }
283293
std::vector<ResolvedLoc> resolve(ArrayRef<UnresolvedLoc> Locs, ArrayRef<Token> Tokens);
294+
ResolvedLoc resolve(UnresolvedLoc Loc);
284295
};
285296

286297
enum class RangeKind : int8_t {

lib/AST/ASTDumper.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,23 @@ void RequirementRepr::print(ASTPrinter &out) const {
164164
printImpl(out, /*AsWritten=*/true);
165165
}
166166

167+
static void printTrailingRequirements(ASTPrinter &Printer,
168+
ArrayRef<RequirementRepr> Reqs,
169+
bool printWhereKeyword) {
170+
if (Reqs.empty()) return;
171+
172+
if (printWhereKeyword)
173+
Printer << " where ";
174+
interleave(
175+
Reqs,
176+
[&](const RequirementRepr &req) {
177+
Printer.callPrintStructurePre(PrintStructureKind::GenericRequirement);
178+
req.print(Printer);
179+
Printer.printStructurePost(PrintStructureKind::GenericRequirement);
180+
},
181+
[&] { Printer << ", "; });
182+
}
183+
167184
void GenericParamList::print(llvm::raw_ostream &OS) const {
168185
OS << '<';
169186
interleave(*this,
@@ -176,14 +193,9 @@ void GenericParamList::print(llvm::raw_ostream &OS) const {
176193
},
177194
[&] { OS << ", "; });
178195

179-
if (!getRequirements().empty()) {
180-
OS << " where ";
181-
interleave(getRequirements(),
182-
[&](const RequirementRepr &req) {
183-
req.print(OS);
184-
},
185-
[&] { OS << ", "; });
186-
}
196+
StreamPrinter Printer(OS);
197+
printTrailingRequirements(Printer, getRequirements(),
198+
/*printWhereKeyword*/true);
187199
OS << '>';
188200
}
189201

@@ -192,6 +204,13 @@ void GenericParamList::dump() const {
192204
llvm::errs() << '\n';
193205
}
194206

207+
void TrailingWhereClause::print(llvm::raw_ostream &OS,
208+
bool printWhereKeyword) const {
209+
StreamPrinter Printer(OS);
210+
printTrailingRequirements(Printer, getRequirements(),
211+
printWhereKeyword);
212+
}
213+
195214
static void printGenericParameters(raw_ostream &OS, GenericParamList *Params) {
196215
if (!Params)
197216
return;
@@ -664,9 +683,7 @@ namespace {
664683
}
665684
if (auto whereClause = decl->getTrailingWhereClause()) {
666685
OS << " where requirements: ";
667-
interleave(whereClause->getRequirements(),
668-
[&](const RequirementRepr &req) { req.print(OS); },
669-
[&] { OS << ", "; });
686+
whereClause->print(OS, /*printWhereKeyword*/false);
670687
}
671688
if (decl->overriddenDeclsComputed()) {
672689
OS << " overridden=";

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,6 @@ class PrintAST : public ASTVisitor<PrintAST> {
802802
Decl *attachingTo);
803803
void printWhereClauseFromRequirementSignature(ProtocolDecl *proto,
804804
Decl *attachingTo);
805-
void printTrailingWhereClause(TrailingWhereClause *whereClause);
806805

807806
void printGenericSignature(GenericSignature genericSig,
808807
unsigned flags);
@@ -1361,18 +1360,6 @@ void PrintAST::printWhereClauseFromRequirementSignature(ProtocolDecl *proto,
13611360
});
13621361
}
13631362

1364-
void PrintAST::printTrailingWhereClause(TrailingWhereClause *whereClause) {
1365-
Printer << " " << tok::kw_where << " ";
1366-
interleave(
1367-
whereClause->getRequirements(),
1368-
[&](const RequirementRepr &req) {
1369-
Printer.callPrintStructurePre(PrintStructureKind::GenericRequirement);
1370-
req.print(Printer);
1371-
Printer.printStructurePost(PrintStructureKind::GenericRequirement);
1372-
},
1373-
[&] { Printer << ", "; });
1374-
}
1375-
13761363
/// A helper function to return the depth of a requirement.
13771364
static unsigned getDepthOfRequirement(const Requirement &req) {
13781365
switch (req.getKind()) {

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3940,8 +3940,8 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
39403940

39413941
// Retrieve the set of requirements that a given associated type declaration
39423942
// produces, in the form that would be seen in the where clause.
3943-
auto getAssociatedTypeReqs = [&](AssociatedTypeDecl *assocType,
3944-
const char *start) {
3943+
const auto getAssociatedTypeReqs = [&](const AssociatedTypeDecl *assocType,
3944+
const char *start) {
39453945
std::string result;
39463946
{
39473947
llvm::raw_string_ostream out(result);
@@ -3955,6 +3955,13 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
39553955
}, [&] {
39563956
out << ", ";
39573957
});
3958+
3959+
if (const auto whereClause = assocType->getTrailingWhereClause()) {
3960+
if (!assocType->getInherited().empty())
3961+
out << ", ";
3962+
3963+
whereClause->print(out, /*printWhereKeyword*/false);
3964+
}
39583965
}
39593966
return result;
39603967
};

lib/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ add_subdirectory(Markup)
3131
add_subdirectory(Migrator)
3232
add_subdirectory(Option)
3333
add_subdirectory(Parse)
34-
add_subdirectory(ParseSIL)
3534
add_subdirectory(PrintAsObjC)
3635
add_subdirectory(RemoteAST)
3736
add_subdirectory(Sema)

lib/Frontend/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ target_link_libraries(swiftFrontend PRIVATE
2020
swiftSIL
2121
swiftMigrator
2222
swiftOption
23-
swiftParseSIL
2423
swiftSILGen
2524
swiftSILOptimizer
2625
swiftIRGen

0 commit comments

Comments
 (0)