diff --git a/include/swift/Basic/JSONSerialization.h b/include/swift/Basic/JSONSerialization.h index dc5fcc676be92..253b0ace859c6 100644 --- a/include/swift/Basic/JSONSerialization.h +++ b/include/swift/Basic/JSONSerialization.h @@ -481,6 +481,16 @@ struct ScalarTraits { static bool mustQuote(StringRef) { return false; } }; +#if defined(_MSC_VER) +// In MSVC, 'unsigned long' is 32bit size and different from uint32_t, +// and it is used to define swift::sys::ProcessId. +template<> +struct ScalarTraits { + static void output(const unsigned long &, llvm::raw_ostream &); + static bool mustQuote(StringRef) { return false; } +}; +#endif + template<> struct ScalarTraits { static void output(const uint64_t &, llvm::raw_ostream &); diff --git a/include/swift/Basic/Malloc.h b/include/swift/Basic/Malloc.h index be2f6c52fa2f0..1964828cd8423 100644 --- a/include/swift/Basic/Malloc.h +++ b/include/swift/Basic/Malloc.h @@ -19,7 +19,11 @@ #define SWIFT_BASIC_MALLOC_H #include +#if defined(_MSC_VER) +#include +#else #include +#endif namespace swift { diff --git a/include/swift/IDE/CommentConversion.h b/include/swift/IDE/CommentConversion.h index af87e4aa8844a..5f778c452a1fb 100644 --- a/include/swift/IDE/CommentConversion.h +++ b/include/swift/IDE/CommentConversion.h @@ -15,6 +15,7 @@ #include "swift/Basic/LLVM.h" #include +#include namespace swift { class Decl; diff --git a/include/swift/SILOptimizer/Utils/Local.h b/include/swift/SILOptimizer/Utils/Local.h index dba8e8f7a7137..36939d41475e5 100644 --- a/include/swift/SILOptimizer/Utils/Local.h +++ b/include/swift/SILOptimizer/Utils/Local.h @@ -485,14 +485,23 @@ class CastOptimizer { public: CastOptimizer(std::function ReplaceInstUsesAction, - std::function EraseAction = [](SILInstruction*){}, - std::function WillSucceedAction = [](){}, + std::function EraseAction, + std::function WillSucceedAction, std::function WillFailAction = [](){}) : ReplaceInstUsesAction(ReplaceInstUsesAction), EraseInstAction(EraseAction), WillSucceedAction(WillSucceedAction), WillFailAction(WillFailAction) {} + // This constructor is used in + // 'SILOptimizer/Mandatory/ConstantPropagation.cpp'. MSVC2015 compiler + // couldn't use the single constructor version which has three default + // arguments. It seems the number of the default argument with lambda is + // limited. + CastOptimizer(std::function ReplaceInstUsesAction, + std::function EraseAction = [](SILInstruction*){}) + : CastOptimizer(ReplaceInstUsesAction, EraseAction, [](){}, [](){}) {} + /// Simplify checked_cast_br. It may change the control flow. SILInstruction * simplifyCheckedCastBranchInst(CheckedCastBranchInst *Inst); diff --git a/lib/Basic/JSONSerialization.cpp b/lib/Basic/JSONSerialization.cpp index ed17af9d6507c..4921ea78b5cf4 100644 --- a/lib/Basic/JSONSerialization.cpp +++ b/lib/Basic/JSONSerialization.cpp @@ -261,6 +261,13 @@ void ScalarTraits::output(const uint32_t &Val, Out << Val; } +#if defined(_MSC_VER) +void ScalarTraits::output(const unsigned long &Val, + raw_ostream &Out) { + Out << Val; +} +#endif + void ScalarTraits::output(const uint64_t &Val, raw_ostream &Out) { Out << Val; diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index f73fca77057da..bec468217b3bc 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -631,8 +631,16 @@ int Compilation::performSingleCommand(const Job *Cmd) { const char *ExecPath = Cmd->getExecutable(); const char **argv = Argv.data(); - for (auto &envPair : Cmd->getExtraEnvironment()) + for (auto &envPair : Cmd->getExtraEnvironment()) { +#if defined(_MSC_VER) + llvm::SmallString<256> envStr = StringRef(envPair.first); + envStr.append(StringRef("=")); + envStr.append(StringRef(envPair.second)); + _putenv(envStr.c_str()); +#else setenv(envPair.first, envPair.second, /*replacing=*/true); +#endif + } return ExecuteInPlace(ExecPath, argv); } diff --git a/lib/Immediate/Immediate.cpp b/lib/Immediate/Immediate.cpp index 5233c5a39b74c..e2832712d5a26 100644 --- a/lib/Immediate/Immediate.cpp +++ b/lib/Immediate/Immediate.cpp @@ -37,17 +37,27 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Support/Path.h" - +#if defined(_MSC_VER) +#include "Windows.h" +#else #include - +#endif using namespace swift; using namespace swift::immediate; +static bool loadRuntimeLib(StringRef runtimeLibPathWithName) { +#if defined(_MSC_VER) + return LoadLibrary(runtimeLibPathWithName.str().c_str()); +#else + return dlopen(runtimeLibPathWithName.str().c_str(), RTLD_LAZY | RTLD_GLOBAL); +#endif +} + static bool loadRuntimeLib(StringRef sharedLibName, StringRef runtimeLibPath) { // FIXME: Need error-checking. llvm::SmallString<128> Path = runtimeLibPath; llvm::sys::path::append(Path, sharedLibName); - return dlopen(Path.c_str(), RTLD_LAZY | RTLD_GLOBAL); + return loadRuntimeLib(Path); } bool swift::immediate::loadSwiftRuntime(StringRef runtimeLibPath) { @@ -60,7 +70,7 @@ static bool tryLoadLibrary(LinkLibrary linkLib, // If we have an absolute or relative path, just try to load it now. if (llvm::sys::path::has_parent_path(path.str())) { - return dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL); + return loadRuntimeLib(path); } bool success = false; @@ -80,14 +90,14 @@ static bool tryLoadLibrary(LinkLibrary linkLib, for (auto &libDir : searchPathOpts.LibrarySearchPaths) { path = libDir; llvm::sys::path::append(path, stem.str()); - success = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL); + success = loadRuntimeLib(path); if (success) break; } - // Let dlopen determine the best search paths. + // Let loadRuntimeLib determine the best search paths. if (!success) - success = dlopen(stem.c_str(), RTLD_LAZY | RTLD_GLOBAL); + success = loadRuntimeLib(stem); // If that fails, try our runtime library path. if (!success) @@ -106,14 +116,14 @@ static bool tryLoadLibrary(LinkLibrary linkLib, for (auto &frameworkDir : searchPathOpts.FrameworkSearchPaths) { path = frameworkDir; llvm::sys::path::append(path, frameworkPart.str()); - success = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL); + success = loadRuntimeLib(path); if (success) break; } - // If that fails, let dlopen search for system frameworks. + // If that fails, let loadRuntimeLib search for system frameworks. if (!success) - success = dlopen(frameworkPart.c_str(), RTLD_LAZY | RTLD_GLOBAL); + success = loadRuntimeLib(frameworkPart); break; } } diff --git a/lib/Sema/CSDiag.cpp b/lib/Sema/CSDiag.cpp index 4366c45354c71..c7f10e8451eb9 100644 --- a/lib/Sema/CSDiag.cpp +++ b/lib/Sema/CSDiag.cpp @@ -879,9 +879,9 @@ namespace { unsigned level, ArrayRef actualArgs); - void filterList(ArrayRef actualArgs); + void filterListArgs(ArrayRef actualArgs); void filterList(Type actualArgsType) { - return filterList(decomposeArgType(actualArgsType)); + return filterListArgs(decomposeArgType(actualArgsType)); } void filterList(ClosenessPredicate predicate); void filterContextualMemberList(Expr *argExpr); @@ -1483,7 +1483,7 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn) { /// After the candidate list is formed, it can be filtered down to discard /// obviously mismatching candidates and compute a "closeness" for the /// resultant set. -void CalleeCandidateInfo::filterList(ArrayRef actualArgs) { +void CalleeCandidateInfo::filterListArgs(ArrayRef actualArgs) { // Now that we have the candidate list, figure out what the best matches from // the candidate list are, and remove all the ones that aren't at that level. filterList([&](UncurriedCandidate candidate) -> ClosenessResultTy { @@ -1530,7 +1530,7 @@ void CalleeCandidateInfo::filterContextualMemberList(Expr *argExpr) { CallArgParam param; param.Ty = argType; - return filterList(param); + return filterListArgs(param); } // If we have a tuple expression, form a tuple type. @@ -1547,7 +1547,7 @@ void CalleeCandidateInfo::filterContextualMemberList(Expr *argExpr) { ArgElts.push_back(param); } - return filterList(ArgElts); + return filterListArgs(ArgElts); } CalleeCandidateInfo::CalleeCandidateInfo(Type baseType,