Skip to content

Commit

Permalink
Merge pull request #667 from swiftwasm/maxd/master-merge
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
MaxDesiatov authored Apr 14, 2020
2 parents eef11bc + 606aacc commit ce86f8e
Show file tree
Hide file tree
Showing 74 changed files with 2,693 additions and 197 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
endif()

find_package(Python2 COMPONENTS Interpreter REQUIRED)
find_package(Python3 COMPONENTS Interpreter REQUIRED)

#
# Find optional dependencies.
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Please make sure you use Python 2.x. Python 3.x is not supported currently.

#### macOS

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

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

Expand Down
22 changes: 10 additions & 12 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function(is_darwin_based_sdk sdk_name out_var)
endfunction()

# Usage:
# _add_variant_c_compile_link_flags(
# _add_host_variant_c_compile_link_flags(
# SDK sdk
# ARCH arch
# BUILD_TYPE build_type
Expand All @@ -86,7 +86,7 @@ endfunction()
# DEPLOYMENT_VERSION_WATCHOS version
#
# )
function(_add_variant_c_compile_link_flags)
function(_add_host_variant_c_compile_link_flags)
set(oneValueArgs SDK ARCH BUILD_TYPE RESULT_VAR_NAME ENABLE_LTO ANALYZE_CODE_COVERAGE
DEPLOYMENT_VERSION_OSX DEPLOYMENT_VERSION_MACCATALYST DEPLOYMENT_VERSION_IOS DEPLOYMENT_VERSION_TVOS DEPLOYMENT_VERSION_WATCHOS
MACCATALYST_BUILD_FLAVOR
Expand Down Expand Up @@ -189,7 +189,7 @@ function(_add_variant_c_compile_link_flags)
endfunction()


function(_add_variant_c_compile_flags)
function(_add_host_variant_c_compile_flags)
set(oneValueArgs SDK ARCH BUILD_TYPE ENABLE_ASSERTIONS ANALYZE_CODE_COVERAGE
DEPLOYMENT_VERSION_OSX DEPLOYMENT_VERSION_MACCATALYST DEPLOYMENT_VERSION_IOS DEPLOYMENT_VERSION_TVOS DEPLOYMENT_VERSION_WATCHOS
RESULT_VAR_NAME ENABLE_LTO
Expand All @@ -202,7 +202,7 @@ function(_add_variant_c_compile_flags)

set(result ${${CFLAGS_RESULT_VAR_NAME}})

_add_variant_c_compile_link_flags(
_add_host_variant_c_compile_link_flags(
SDK "${CFLAGS_SDK}"
ARCH "${CFLAGS_ARCH}"
BUILD_TYPE "${CFLAGS_BUILD_TYPE}"
Expand Down Expand Up @@ -351,8 +351,6 @@ function(_add_variant_c_compile_flags)
list(APPEND result "SHELL:${CMAKE_INCLUDE_SYSTEM_FLAG_C}${path}")
endforeach()
list(APPEND result "-D__ANDROID_API__=${SWIFT_ANDROID_API_LEVEL}")
elseif("${CFLAGS_SDK}" STREQUAL "WASI")
list(APPEND result "-D_WASI_EMULATED_MMAN")
endif()

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

function(_add_variant_link_flags)
function(_add_host_variant_link_flags)
set(oneValueArgs SDK ARCH BUILD_TYPE ENABLE_ASSERTIONS ANALYZE_CODE_COVERAGE
DEPLOYMENT_VERSION_OSX DEPLOYMENT_VERSION_MACCATALYST DEPLOYMENT_VERSION_IOS DEPLOYMENT_VERSION_TVOS DEPLOYMENT_VERSION_WATCHOS
RESULT_VAR_NAME ENABLE_LTO LTO_OBJECT_NAME LINK_LIBRARIES_VAR_NAME LIBRARY_SEARCH_DIRECTORIES_VAR_NAME
Expand All @@ -384,7 +382,7 @@ function(_add_variant_link_flags)
set(link_libraries ${${LFLAGS_LINK_LIBRARIES_VAR_NAME}})
set(library_search_directories ${${LFLAGS_LIBRARY_SEARCH_DIRECTORIES_VAR_NAME}})

_add_variant_c_compile_link_flags(
_add_host_variant_c_compile_link_flags(
SDK "${LFLAGS_SDK}"
ARCH "${LFLAGS_ARCH}"
BUILD_TYPE "${LFLAGS_BUILD_TYPE}"
Expand Down Expand Up @@ -658,7 +656,7 @@ function(_add_swift_host_library_single target)

set(library_search_directories)

_add_variant_c_compile_flags(
_add_host_variant_c_compile_flags(
SDK "${SWIFT_HOST_VARIANT_SDK}"
ARCH "${SWIFT_HOST_VARIANT_ARCH}"
BUILD_TYPE ${CMAKE_BUILD_TYPE}
Expand All @@ -679,7 +677,7 @@ function(_add_swift_host_library_single target)
message(FATAL_ERROR "WASM does not support shared libraries.")
endif()
endif()
_add_variant_link_flags(
_add_host_variant_link_flags(
SDK "${SWIFT_HOST_VARIANT_SDK}"
ARCH "${SWIFT_HOST_VARIANT_ARCH}"
BUILD_TYPE ${CMAKE_BUILD_TYPE}
Expand Down Expand Up @@ -859,15 +857,15 @@ function(_add_swift_host_executable_single name)
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")

# Add variant-specific flags.
_add_variant_c_compile_flags(
_add_host_variant_c_compile_flags(
SDK "${SWIFTEXE_SINGLE_SDK}"
ARCH "${SWIFTEXE_SINGLE_ARCHITECTURE}"
BUILD_TYPE "${CMAKE_BUILD_TYPE}"
ENABLE_ASSERTIONS "${LLVM_ENABLE_ASSERTIONS}"
ENABLE_LTO "${SWIFT_TOOLS_ENABLE_LTO}"
ANALYZE_CODE_COVERAGE "${SWIFT_ANALYZE_CODE_COVERAGE}"
RESULT_VAR_NAME c_compile_flags)
_add_variant_link_flags(
_add_host_variant_link_flags(
SDK "${SWIFTEXE_SINGLE_SDK}"
ARCH "${SWIFTEXE_SINGLE_ARCHITECTURE}"
BUILD_TYPE "${CMAKE_BUILD_TYPE}"
Expand Down
22 changes: 22 additions & 0 deletions docs/DevelopmentTips.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,25 @@ Given the size of artifacts generated, you might also want to bump the cache siz
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.

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.

## Memory usage

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.

### Reduce the amount of debug symbols

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:

```
build-script --release --debug-swift
```

### Reduce the number of parallel link jobs

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`.

For example, to have `build-script` spawn only one link job at a time, we can invoke it as:

```
build-script --llvm-cmake-options==-DLLVM_PARALLEL_LINK_JOBS=1 --swift-cmake-options=-DSWIFT_PARALLEL_LINK_JOBS=1
```
8 changes: 0 additions & 8 deletions docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -772,14 +772,6 @@ types. Function types are transformed in order to encode additional attributes:
a way as to guarantee that it is polymorphic across all possible
implementors of the protocol.

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

Layout Compatible Types
```````````````````````

Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,8 @@ class alignas(RequirementRepr) TrailingWhereClause final :
return SourceRange(WhereLoc,
getRequirements().back().getSourceRange().End);
}

void print(llvm::raw_ostream &OS, bool printWhereKeyword) const;
};

// A private class for forcing exact field layout.
Expand Down
2 changes: 1 addition & 1 deletion include/swift/IDE/CompletionInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CompletionInstance {
/// Returns \c if the callback was called. Returns \c false if the compiler
/// argument has changed, primary file is not the same, the \c Offset is not
/// in function bodies, or the interface hash of the file has changed.
bool performCachedOperaitonIfPossible(
bool performCachedOperationIfPossible(
const swift::CompilerInvocation &Invocation, llvm::hash_code ArgsHash,
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
DiagnosticConsumer *DiagC,
Expand Down
9 changes: 9 additions & 0 deletions include/swift/IDE/Refactoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,17 @@ collectAvailableRefactorings(SourceFile *SF, ResolvedCursorInfo CursorInfo,
std::vector<RefactoringKind> &Scratch,
bool ExcludeRename);

/// Stores information about the reference that rename availability is being
/// queried on.
struct RenameRefInfo {
SourceFile *SF; ///< The source file containing the reference.
SourceLoc Loc; ///< The reference's source location.
bool IsArgLabel; ///< Whether Loc is on an arg label, rather than base name.
};

ArrayRef<RenameAvailabiliyInfo>
collectRenameAvailabilityInfo(const ValueDecl *VD,
Optional<RenameRefInfo> RefInfo,
std::vector<RenameAvailabiliyInfo> &Scratch);

} // namespace ide
Expand Down
15 changes: 13 additions & 2 deletions include/swift/IDE/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace swift {
class Type;
class Decl;
class DeclContext;
class CallExpr;
class ClangNode;
class ClangImporter;
class Token;
Expand Down Expand Up @@ -226,6 +227,12 @@ struct ResolvedLoc {
bool IsInSelector;
};

/// Used by NameMatcher to track parent CallExprs when walking a checked AST.
struct CallingParent {
Expr *ApplicableTo;
CallExpr *Call;
};


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

/// The stack of parent CallExprs and the innermost expression they apply to.
std::vector<CallingParent> ParentCalls;

SourceManager &getSourceMgr() const;

SourceLoc nextLoc() const;
Expand All @@ -256,11 +266,11 @@ class NameMatcher: public ASTWalker {
bool shouldSkip(SourceRange Range);
bool shouldSkip(CharSourceRange Range);
bool tryResolve(ASTWalker::ParentTy Node, SourceLoc NameLoc);
bool tryResolve(ASTWalker::ParentTy Node, DeclNameLoc NameLoc, Expr *Arg,
bool checkParentForLabels = false);
bool tryResolve(ASTWalker::ParentTy Node, DeclNameLoc NameLoc, Expr *Arg);
bool tryResolve(ASTWalker::ParentTy Node, SourceLoc NameLoc, LabelRangeType RangeType,
ArrayRef<CharSourceRange> LabelLocs);
bool handleCustomAttrs(Decl *D);
Expr *getApplicableArgFor(Expr* E);

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

enum class RangeKind : int8_t {
Expand Down
39 changes: 28 additions & 11 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,23 @@ void RequirementRepr::print(ASTPrinter &out) const {
printImpl(out, /*AsWritten=*/true);
}

static void printTrailingRequirements(ASTPrinter &Printer,
ArrayRef<RequirementRepr> Reqs,
bool printWhereKeyword) {
if (Reqs.empty()) return;

if (printWhereKeyword)
Printer << " where ";
interleave(
Reqs,
[&](const RequirementRepr &req) {
Printer.callPrintStructurePre(PrintStructureKind::GenericRequirement);
req.print(Printer);
Printer.printStructurePost(PrintStructureKind::GenericRequirement);
},
[&] { Printer << ", "; });
}

void GenericParamList::print(llvm::raw_ostream &OS) const {
OS << '<';
interleave(*this,
Expand All @@ -176,14 +193,9 @@ void GenericParamList::print(llvm::raw_ostream &OS) const {
},
[&] { OS << ", "; });

if (!getRequirements().empty()) {
OS << " where ";
interleave(getRequirements(),
[&](const RequirementRepr &req) {
req.print(OS);
},
[&] { OS << ", "; });
}
StreamPrinter Printer(OS);
printTrailingRequirements(Printer, getRequirements(),
/*printWhereKeyword*/true);
OS << '>';
}

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

void TrailingWhereClause::print(llvm::raw_ostream &OS,
bool printWhereKeyword) const {
StreamPrinter Printer(OS);
printTrailingRequirements(Printer, getRequirements(),
printWhereKeyword);
}

static void printGenericParameters(raw_ostream &OS, GenericParamList *Params) {
if (!Params)
return;
Expand Down Expand Up @@ -664,9 +683,7 @@ namespace {
}
if (auto whereClause = decl->getTrailingWhereClause()) {
OS << " where requirements: ";
interleave(whereClause->getRequirements(),
[&](const RequirementRepr &req) { req.print(OS); },
[&] { OS << ", "; });
whereClause->print(OS, /*printWhereKeyword*/false);
}
if (decl->overriddenDeclsComputed()) {
OS << " overridden=";
Expand Down
13 changes: 0 additions & 13 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,6 @@ class PrintAST : public ASTVisitor<PrintAST> {
Decl *attachingTo);
void printWhereClauseFromRequirementSignature(ProtocolDecl *proto,
Decl *attachingTo);
void printTrailingWhereClause(TrailingWhereClause *whereClause);

void printGenericSignature(GenericSignature genericSig,
unsigned flags);
Expand Down Expand Up @@ -1361,18 +1360,6 @@ void PrintAST::printWhereClauseFromRequirementSignature(ProtocolDecl *proto,
});
}

void PrintAST::printTrailingWhereClause(TrailingWhereClause *whereClause) {
Printer << " " << tok::kw_where << " ";
interleave(
whereClause->getRequirements(),
[&](const RequirementRepr &req) {
Printer.callPrintStructurePre(PrintStructureKind::GenericRequirement);
req.print(Printer);
Printer.printStructurePost(PrintStructureKind::GenericRequirement);
},
[&] { Printer << ", "; });
}

/// A helper function to return the depth of a requirement.
static unsigned getDepthOfRequirement(const Requirement &req) {
switch (req.getKind()) {
Expand Down
11 changes: 9 additions & 2 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3940,8 +3940,8 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(

// Retrieve the set of requirements that a given associated type declaration
// produces, in the form that would be seen in the where clause.
auto getAssociatedTypeReqs = [&](AssociatedTypeDecl *assocType,
const char *start) {
const auto getAssociatedTypeReqs = [&](const AssociatedTypeDecl *assocType,
const char *start) {
std::string result;
{
llvm::raw_string_ostream out(result);
Expand All @@ -3955,6 +3955,13 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
}, [&] {
out << ", ";
});

if (const auto whereClause = assocType->getTrailingWhereClause()) {
if (!assocType->getInherited().empty())
out << ", ";

whereClause->print(out, /*printWhereKeyword*/false);
}
}
return result;
};
Expand Down
1 change: 0 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ add_subdirectory(Markup)
add_subdirectory(Migrator)
add_subdirectory(Option)
add_subdirectory(Parse)
add_subdirectory(ParseSIL)
add_subdirectory(PrintAsObjC)
add_subdirectory(RemoteAST)
add_subdirectory(Sema)
Expand Down
1 change: 0 additions & 1 deletion lib/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ target_link_libraries(swiftFrontend PRIVATE
swiftSIL
swiftMigrator
swiftOption
swiftParseSIL
swiftSILGen
swiftSILOptimizer
swiftIRGen
Expand Down
Loading

0 comments on commit ce86f8e

Please sign in to comment.