-
Notifications
You must be signed in to change notification settings - Fork 10.5k
IRGen: Set a "not bitwise borrowable" bit in value witnesses for @_rawLayout
types.
#76688
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
@swift-ci Please test |
…awLayout` types. For types like `Atomic` and `Mutex`, we want to know that even though they are technically bitwise-takable, they differ from other bitwise-takable types until this point because they are not also "bitwise-borrowable"; while borrowed, they are pinned in memory, so they cannot be passed by value as a borrowed parameter, unlike copyable bitwise-takable types. Add a bit to the value witness table flags to record this. Note that this patch does not include any accompanying runtime support for propagating the flag into runtime-instantiated type metadata. There isn't yet any runtime functionality that varies based on this flag, so that can be implemented separately. rdar://136396806
f4ff132
to
57a56e5
Compare
@swift-ci Please test |
@@ -3927,8 +3927,8 @@ namespace { | |||
} else if (allSingleRefcount | |||
&& ElementsWithNoPayload.size() <= 1) { | |||
CopyDestroyKind = TaggedRefcounted; | |||
} else if (this->EnumImplStrategy::BitwiseTakable == IsBitwiseTakable && | |||
Copyable == IsCopyable) { | |||
} else if (this->EnumImplStrategy::BitwiseTakable == IsBitwiseTakableAndBorrowable |
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.
At first glance, I 'm not sure why CopyDestroyKind
would be affected by BitwiseBorrowable.
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 that it isn't possible for a type to be Copyable
and BitwiseTakable
without being BitwiseBorrowable
, so it didn't really matter which value I compared against here.
@@ -87,7 +87,8 @@ StructLayout::StructLayout(IRGenModule &IGM, std::optional<CanType> type, | |||
if (rawLayout && type) { | |||
auto sd = cast<StructDecl>(decl); | |||
IsKnownTriviallyDestroyable = triviallyDestroyable; | |||
IsKnownBitwiseTakable = bitwiseTakable; | |||
// Raw layout types are never bitwise-borrowable. | |||
IsKnownBitwiseTakable = bitwiseTakable & IsBitwiseTakableOnly; |
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.
Would this be more logically written
IsKnownBitwiseTakable = bitwiseTakable >= IsBitwiseTakableOnly
?
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 trying to keep the patch size down, but now that IsBitwiseTakable_t
is a tristate, I want to rip the Is
off of these Is*BitwiseTakable
names. The code here is masking out the IsBitwiseTakableAndBorrowable
possibility since a raw layout type can be at most bitwise-takable without -borrowable.
IsKnownBitwiseTakable = likeFixedType->isBitwiseTakable(ResilienceExpansion::Maximal); | ||
// Raw layout types are still never bitwise-borrowable. | ||
IsKnownBitwiseTakable = likeFixedType->getBitwiseTakable(ResilienceExpansion::Maximal) | ||
& IsBitwiseTakableOnly; |
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.
Would this be more logically written
>= IsBitwiseTakableOnly
?
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 as above.
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.
Many thanks!
For types like
Atomic
andMutex
, we want to know that even though they are technically bitwise-takable, they differ from other bitwise-takable types until this point because they are not also "bitwise-borrowable"; while borrowed, they are pinned in memory, so they cannot be passed by value as a borrowed parameter, unlike copyable bitwise-takable types. Add a bit to the value witness table flags to record this.Note that this patch does not include any accompanying runtime support for propagating the flag into runtime-instantiated type metadata. There isn't yet any runtime functionality that varies based on this flag, so that can be implemented separately.
rdar://136396806