Skip to content

fix Builtin.sizeof et al for metatypes #65354

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

Merged
merged 1 commit into from
Apr 22, 2023

Conversation

eeckstein
Copy link
Contributor

Those builtins always need to assume a thick metatype which is a pointer. In other words the builtins need to use the maximally abstracted type.

rdar://108308786

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein requested a review from jckarter April 21, 2023 17:19
@Azoy
Copy link
Contributor

Azoy commented Apr 21, 2023

How does this affect code like:

unsafeBitCast(Int.self, to: UnsafeRawPointer.self)

?

Previously this would assert at runtime because of the size mismatch, but with this change would this actually succeed now?

@eeckstein
Copy link
Contributor Author

would this actually succeed now?

yes

@@ -120,6 +120,12 @@ getLoweredTypeAndTypeInfo(IRGenModule &IGM, Type unloweredType) {
return {lowered, IGM.getTypeInfo(lowered)};
}

static std::pair<SILType, const TypeInfo &>
getMaximallyAbstractedLoweredTypeAndTypeInfo(IRGenModule &IGM, Type unloweredType) {
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 function unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!
And also the test was wrong: I need to disable the target-constant-folding pass. Otherwise the builtins are already constant folded before they reach IRGen.
Fixed.

Those builtins always need to assume a thick metatype which is a pointer.
In other words the builtins need to use the maximally abstracted type.

rdar://108308786
@eeckstein eeckstein force-pushed the fix-sizeof-builtin branch from 7582779 to f5a0519 Compare April 21, 2023 19:09
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein merged commit ac7a478 into swiftlang:main Apr 22, 2023
@eeckstein eeckstein deleted the fix-sizeof-builtin branch April 22, 2023 05:43
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.

3 participants