-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Port swift/remote to Windows and MSVC #6025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===--- Unreachable.h - Implements swift_unrachable ------------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines swift_unreachable, an LLVM-independent implementation of | ||
// llvm_unreachable. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_BASIC_UNREACHABLE_H | ||
#define SWIFT_BASIC_UNREACHABLE_H | ||
|
||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
#ifdef __GNUC__ | ||
#define SWIFT_ATTRIBUTE_NORETURN __attribute__((noreturn)) | ||
#elif defined(_MSC_VER) | ||
#define SWIFT_ATTRIBUTE_NORETURN __declspec(noreturn) | ||
#else | ||
#define SWIFT_ATTRIBUTE_NORETURN | ||
#endif | ||
|
||
SWIFT_ATTRIBUTE_NORETURN | ||
inline static void swift_unreachable(const char* msg) { | ||
assert(false && msg); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you get an unused variable warning when building release? (_NDEBUG). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so, haven't done a release build - I've fixed this |
||
(void)msg; | ||
abort(); | ||
} | ||
|
||
#endif // SWIFT_BASIC_UNREACHABLE_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_swift_library(swiftRemoteAST STATIC | ||
RemoteAST.cpp | ||
InProcessMemoryReader.cpp | ||
LINK_LIBRARIES | ||
swiftSema swiftIRGen) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===--- InProcessMemoryReader.cpp - Reads local memory ---------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See http://swift.org/LICENSE.txt for license information | ||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements the abstract interface for working with remote memory. | ||
// This method cannot be implemented in the header, as we must avoid importing | ||
// <windows.h> in a header, which causes conflicts with Swift definitions. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "swift/Remote/InProcessMemoryReader.h" | ||
|
||
#if defined(_WIN32) | ||
#define WIN32_LEAN_AND_MEAN | ||
#define NOMINMAX | ||
#include <windows.h> | ||
#else | ||
#include <dlfcn.h> | ||
#endif | ||
|
||
using namespace swift; | ||
using namespace swift::remote; | ||
|
||
RemoteAddress InProcessMemoryReader::getSymbolAddress(const std::string &name) { | ||
#if defined(_WIN32) | ||
auto pointer = GetProcAddress(GetModuleHandle(NULL), name.c_str()); | ||
#else | ||
auto pointer = dlsym(RTLD_DEFAULT, name.c_str()); | ||
#endif | ||
return RemoteAddress(pointer); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "swift/Basic/Unreachable.h" | ||
#include "swift/Reflection/ReflectionContext.h" | ||
#include "swift/Reflection/TypeLowering.h" | ||
#include "swift/Remote/CMemoryReader.h" | ||
|
@@ -20,7 +21,7 @@ using namespace swift::reflection; | |
using namespace swift::remote; | ||
|
||
using NativeReflectionContext | ||
= ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>; | ||
= swift::reflection::ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
uint16_t | ||
swift_reflection_getSupportedMetadataVersion() { | ||
|
@@ -45,12 +46,12 @@ swift_reflection_createReflectionContext(void *ReaderContext, | |
|
||
auto Reader = std::make_shared<CMemoryReader>(ReaderImpl); | ||
auto Context | ||
= new ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>(Reader); | ||
= new swift::reflection::ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>(Reader); | ||
return reinterpret_cast<SwiftReflectionContextRef>(Context); | ||
} | ||
|
||
void swift_reflection_destroyReflectionContext(SwiftReflectionContextRef ContextRef) { | ||
auto Context = reinterpret_cast<ReflectionContext<InProcess> *>(ContextRef); | ||
auto Context = reinterpret_cast<swift::reflection::ReflectionContext<InProcess> *>(ContextRef); | ||
delete Context; | ||
} | ||
|
||
|
@@ -175,6 +176,8 @@ swift_layout_kind_t getTypeInfoKind(const TypeInfo &TI) { | |
} | ||
} | ||
} | ||
|
||
swift_unreachable("Unhandled TypeInfoKind in switch"); | ||
} | ||
|
||
static swift_typeinfo_t convertTypeInfo(const TypeInfo *TI) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, please don't name this
swift_unreachable
—we still want people to preferllvm_unreachable
when possible. How aboutswift_runtime_unreachable
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…if there isn't already such a thing somewhere in the real runtime, in which case we should use that.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just use
llvm_unreachable
with a runtime-local implementation ofllvm_unreachable_internal
for debug builds? Unreachable branches should be optimized as really unreachable in release builds of the runtime.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could be even better. I'm honestly fairly unhappy about us having runtime things in include/swift/Basic/, but maybe I should be unhappy about having runtime libraries in lib/.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking we'd just reimplement
llvm_unreachable_internal
locally inside the runtime. We already have to provide a reimplementation of some LLVM hashing stuff to be able to useDenseMap
inside the runtime.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't realize we'd actually bitten the bullet and put DenseMap in. Should we just link llvmSupport and let the linker figure it out? ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrose-apple, while you propose that (probably) in jest, that would help with another issue that recently came up. The ABI breaking validation for LLVM uses a value in llvmSuppprt. We ended up having to add another build option to disable it and force disable for swift.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth a shot. If linking llvmSupport into the runtime doesn't affect the binary size too much, it'd certainly be preferable to cherry-picking certain definitions we need.