Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/swift/Basic/JSONSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,16 @@ struct ScalarTraits<uint32_t> {
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to change ProcessId to use a stdint typedef.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProcessId in swift defined as typedef llvm::sys::ProcessInfo::ProcessId ProcessId;.
LLVM ProcessInfo coded.

struct ProcessInfo {
#if defined(LLVM_ON_UNIX)
  typedef pid_t ProcessId;
#elif defined(LLVM_ON_WIN32)
  typedef unsigned long ProcessId; // Must match the type of DWORD on Windows.
  .....

Changing ProcessId in swift means changing or ignoring LLVM definition.
I think reusing the LLVM definition is better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right. Understandable that LLVM wouldn't want to include all of windows.h just for DWORD.

template<>
struct ScalarTraits<unsigned long> {
static void output(const unsigned long &, llvm::raw_ostream &);
static bool mustQuote(StringRef) { return false; }
};
#endif

template<>
struct ScalarTraits<uint64_t> {
static void output(const uint64_t &, llvm::raw_ostream &);
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Basic/Malloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
#define SWIFT_BASIC_MALLOC_H

#include <cassert>
#if defined(_MSC_VER)
#include <malloc.h>
#else
#include <cstdlib>
#endif

namespace swift {

Expand Down
1 change: 1 addition & 0 deletions include/swift/IDE/CommentConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "swift/Basic/LLVM.h"
#include <memory>
#include <string>

namespace swift {
class Decl;
Expand Down
13 changes: 11 additions & 2 deletions include/swift/SILOptimizer/Utils/Local.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,23 @@ class CastOptimizer {

public:
CastOptimizer(std::function<void (SILInstruction *I, ValueBase *V)> ReplaceInstUsesAction,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I ask why this change was necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the clang with the ms-extension option (not ms-compatibility option), the line of the constructor having two default value of dummy lambda expression is compiled, but three default value constructor is not compiled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's very strange. Mind leaving a comment before I merge?

std::function<void (SILInstruction *)> EraseAction = [](SILInstruction*){},
std::function<void ()> WillSucceedAction = [](){},
std::function<void (SILInstruction *)> EraseAction,
std::function<void ()> WillSucceedAction,
std::function<void ()> 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<void (SILInstruction *I, ValueBase *V)> ReplaceInstUsesAction,
std::function<void (SILInstruction *)> EraseAction = [](SILInstruction*){})
: CastOptimizer(ReplaceInstUsesAction, EraseAction, [](){}, [](){}) {}

/// Simplify checked_cast_br. It may change the control flow.
SILInstruction *
simplifyCheckedCastBranchInst(CheckedCastBranchInst *Inst);
Expand Down
7 changes: 7 additions & 0 deletions lib/Basic/JSONSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ void ScalarTraits<uint32_t>::output(const uint32_t &Val,
Out << Val;
}

#if defined(_MSC_VER)
void ScalarTraits<unsigned long>::output(const unsigned long &Val,
raw_ostream &Out) {
Out << Val;
}
#endif

void ScalarTraits<uint64_t>::output(const uint64_t &Val,
raw_ostream &Out) {
Out << Val;
Expand Down
10 changes: 9 additions & 1 deletion lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
30 changes: 20 additions & 10 deletions lib/Immediate/Immediate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dlfcn.h>

#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) {
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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;
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,9 @@ namespace {
unsigned level,
ArrayRef<CallArgParam> actualArgs);

void filterList(ArrayRef<CallArgParam> actualArgs);
void filterListArgs(ArrayRef<CallArgParam> actualArgs);
void filterList(Type actualArgsType) {
return filterList(decomposeArgType(actualArgsType));
return filterListArgs(decomposeArgType(actualArgsType));
}
void filterList(ClosenessPredicate predicate);
void filterContextualMemberList(Expr *argExpr);
Expand Down Expand Up @@ -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<CallArgParam> actualArgs) {
void CalleeCandidateInfo::filterListArgs(ArrayRef<CallArgParam> 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 {
Expand Down Expand Up @@ -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.
Expand All @@ -1547,7 +1547,7 @@ void CalleeCandidateInfo::filterContextualMemberList(Expr *argExpr) {
ArgElts.push_back(param);
}

return filterList(ArgElts);
return filterListArgs(ArgElts);
}

CalleeCandidateInfo::CalleeCandidateInfo(Type baseType,
Expand Down