-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix errors and warnings building swift/shims on Windows using MSVC #6138
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
Conversation
__attribute__((__pure__)) SWIFT_RUNTIME_STDLIB_INTERFACE __swift_size_t | ||
#if defined(__clang__) || defined(__GNUC__) | ||
__attribute__((__pure__)) | ||
#endif |
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.
We usually prefer pulling the attributes themselves into defines, e.g. SWIFT_RUNTIME_ATTRIBUTE_PURE
.
@@ -13,7 +13,12 @@ | |||
#ifndef SWIFT_STDLIB_SHIMS_SWIFT_STDDEF_H | |||
#define SWIFT_STDLIB_SHIMS_SWIFT_STDDEF_H | |||
|
|||
#if !defined(__clang__) | |||
#include <stdint.h> | |||
typedef size_t __swift_size_t; |
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.
The purpose of these headers is to get system-equivalent types without importing any system headers, for ordering reasons. If MSVC doesn't have something like __SIZE_TYPE__
, it's better just to use an appropriate raw type, and maybe we can static_assert somewhere else that it's the same.
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'm not sure that's the point of these headers (or perhaps not the main one). For example, there's a comment in SwiftStdint.h
that says:
// stdint.h is provided by Clang, but it dispatches to libc's stdint.h. As a
// result, using stdint.h here would pull in Darwin module (which includes
// libc). This creates a dependency cycle, so we can't use stdint.h in
I don't think we have this problem with MSVC (confirmed) and perhaps even Clang on Win32(unconfirmed)
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'm not convinced that things will be any better here if MSVC is ever modularized, but okay.
__atomic_fetch_add(&refCount, RC_ONE, __ATOMIC_RELAXED); | ||
#else | ||
std::atomic<uint32_t> stdRefCount = ATOMIC_VAR_INIT(refCount); |
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.
Wait, this doesn't make any sense. You need to increment the real refCount, not a local variable.
@gparker42, @jckarter, is there any problem with just making the real refcount field a std::atomic?
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'm fairly sure there might be some bugs in this, but I wanted to get the thing building. I think the issue you mentioned is correct - perhaps we then need to set refCount
to the value of stdRefCount
here.
Either way, take a look at some of the TODOs I've sprinkled in the file. I'm not sure what the fix is for the issue that there is no such std::atomic_sub_fetch_explicit
even though there is a __atomic_sub_fetch
intrinsic with Clang/GCC
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.
Storing back into refCount just wouldn't be atomic.
@@ -13,6 +13,24 @@ | |||
#ifndef SWIFT_STDLIB_SHIMS_SWIFT_STDINT_H | |||
#define SWIFT_STDLIB_SHIMS_SWIFT_STDINT_H | |||
|
|||
#if !defined(__clang__) | |||
#include <stdint.h> |
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.
Same thing as above, we can't do this because it pulls in system modules.
@@ -18,6 +18,10 @@ | |||
#ifndef SWIFT_STDLIB_SHIMS_VISIBILITY_H | |||
#define SWIFT_STDLIB_SHIMS_VISIBILITY_H | |||
|
|||
#if !defined(__GNUC__) |
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.
You can do this in general using !defined(__has_feature)
, as seen on the very next line. Clang treats it as defined. (And GCC doesn't have __has_feature either AFAIK.)
I'm not sure this does any good—AFAIK, Shims are only built as part of the runtime (which must build with Clang) and are imported by the standard library (which uses swiftc's embedded Clang). |
@jckarter I think you're right - I'll update this PR to remove the non required parts |
Is the runtime actually built with Clang when building for MSVC yet? |
@jrose-apple not yet publically, but once my Windows port is merged, I'll fix it up for Clang. Quick question @jckarter @jrose-apple: I've almost managed to get the entire swift project building using clang-cl and will send a PR to the CMake project once my MSVC/Windows port is merged. I assume that if we can build the runtime with clang, then we can build the runtime with clang-cl? The reason I'm preferring clang-cl right now is because CMake seems to be able to identify the compiler |
I've also updated the PR to avoid a warning if |
I was asking specifically about the runtime. Our CMake already has an option to try to build the runtime library specifically with the just-built Clang, rather than the compiler on the host system (which probably wouldn't have the necessary Swift extensions). I believe @bob-wilson just re-enabled that by default if you do a clean build, but I could be mistaken. |
Ah right I see, my bad for misunderstanding |
Im not sure I see the point of the two separate commits, but LGTM. |
@swift-ci please test and merge |
@swift-ci please smoke test OS X platform |
@hughbe actually the changes required to build the runtime with clang is near zero. The runtime for windows is currently built with clang on Linux and Darwin. |
@compnerd I know! Some small windows specific stuff but very little |
Actually, I think that @jrose-apple's comments have been addressed. The diff currently looks entirely trivial and correct, so Im going to go ahead and merge this. |
No description provided.