Skip to content

ABI: Only store bitwise take-able values inline #16759

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

aschwaighofer
Copy link
Contributor

SR-343
rdar://31414907

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 2980674

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 2980674

@jckarter
Copy link
Contributor

Thanks!

@@ -1288,6 +1291,10 @@ FixedPacking TypeInfo::getFixedPacking(IRGenModule &IGM) const {
if (!fixedTI)
return FixedPacking::Dynamic;

// By convention we don't store bitwise takable values inline.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment wrong? We don't store non-bitwise takable values inline right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. The comment is inverted.

@slavapestov
Copy link
Contributor

What about resilience, where a value might be bitwise takable in one resilience domain but not in another?

@slavapestov
Copy link
Contributor

I'm assuming you can now optimize value witness functions for existentials to memcpy the inline buffer. Is that correct?

Also more tests would be nice. In particular I'm worried about resilience here. If two different modules have a different idea of whether a struct is bitwise takable, will we generate invalid code if one module stores a struct into an existential and another one loads from it?

@jckarter
Copy link
Contributor

Determining whether a resilient type can be stored inline in an existential buffer is already a dynamic judgment, since you don't know the size, so we should ask the type metadata the question dynamically. I agree it's worth adding tests for.

@aschwaighofer
Copy link
Contributor Author

@slavapestov

What about resilience, where a value might be bitwise takable in one resilience domain but not in another?

If we access a value resiliently than we also have to accesss bitwise takability/isInline resiliently.
There is an existing test case that verifies that the isInline flag has changed.

I will add some more tests.

@aschwaighofer
Copy link
Contributor Author

@slavapestov

I'm assuming you can now optimize value witness functions for existentials to memcpy the inline buffer.

Correct. I can now remove the existential value witness: initializeBufferWithTakeOfBuffer (i.e a move of an existential) and replace it with calls to memcpy.
Either, the value in the existential buffer is inline and bitwise takable in which case a memcpy is safe, or the value in the existential buffer is a reference to the heap object holding the value in which case a memcpy is also safe.

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 6da374e

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 6da374e

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - c7d4bd9

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - c7d4bd9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants