-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Solve some of the fallout of new refcount representation on Windows build #7762
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
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've switched over to the Swift calling convention, so you're going to need to build the runtime with clang. Not sure this has any benefit.
I should clarify - this isn't about building the runtime with clang, this is about building the compiler with MSVC. The irgen module imports certain parts of the runtime such as refCount.h and Metadata.h so these files have to be msvc - compatible |
@swift-ci Please benchmark |
stdlib/public/SwiftShims/RefCount.h
Outdated
@@ -432,7 +431,14 @@ class RefCountBitsT { | |||
} | |||
|
|||
LLVM_ATTRIBUTE_ALWAYS_INLINE | |||
RefCountBitsT(RefCountBitsT<RefCountIsInline> newbits) { | |||
RefCountBitsT(int dummy, RefCountBitsT<RefCountIsInline> newbits) { |
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.
Does this work if you do something more clever like:
RefCOuntBitsT(RefCountBitsT<RefCountIsInline> newBits, int dummy = 0);
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 tried this at first, and unfortunately it does not: MSVC get's confused, and starts complaining about ambiguous initializer lists - this happens anywhere where the dummy is the second parameter
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.
This is actually a Clang bug - GCC and MSVC correctly reject this code! The problem here is that we are actually declaring a copy constructor, at least for the situation where refcountIsInline==true
.
We should definitely fix this, but in a nicer way.
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.
template <bool refcountIsInline>
class RefCountBitsT {
RefCountBitsT(RefCountBitsT<true> newbits) { }
};
class SideTableRefCountBits : public RefCountBitsT<false> {
SideTableRefCountBits(RefCountBitsT<true> newbits)
: RefCountBitsT<false>(newbits) {}
};
If anyone's got some suggestions that don't involve a dummy, let me know.
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 could write the inline to out-of-line conversion as a static function and remove this initializer / copy constructor. It might be used infrequently enough to be reasonable.
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 found it hard to convert this into a static function as it is called by a constructor in a sub class (that doesn't have access to private state)
I went for passing a pointer instead of the actual value. Let me know what you all think
stdlib/public/SwiftShims/RefCount.h
Outdated
@@ -725,7 +731,13 @@ class RefCounts { | |||
#if !__LP64__ | |||
// FIXME: hack - something somewhere is assuming a 3-word header on 32-bit | |||
// See also other fixmes marked "small header for 32-bit" | |||
uintptr_t unused __attribute__((unavailable)); | |||
#if __has_attribute(unavailable) |
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.
Can this be hoisted out to the header with all the other macros for the shims?
@swift-ci please smoke test |
Can I get a quick review :) This fix is cleaner than using a dummy and works with all compilers |
stdlib/public/SwiftShims/RefCount.h
Outdated
@@ -433,10 +433,13 @@ class RefCountBitsT { | |||
} | |||
|
|||
LLVM_ATTRIBUTE_ALWAYS_INLINE | |||
RefCountBitsT(RefCountBitsT<RefCountIsInline> newbits) { | |||
RefCountBitsT(RefCountBitsT<RefCountIsInline> *newbitsPtr) { |
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.
Can it be a const RefCountBitsT<RefCountIsInline> *
?
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 seems to work, let's see what Clang says
@swift-ci please smoke test and merge |
1 similar comment
@swift-ci please smoke test and merge |
The main meat of this PR:
The implementation of
atomic<T>
on Windows ,MSVC (with both visual c++ and clang compiler), requires the followingI'm currently getting a failure here on Windows, possibly due to this line here (RefCount.h, L434):
I'm fairly sure the Visual C++ compiler thinks this is a copy constructor, so fails the check.
@gparker42