Skip to content

[IRGen] Re-introduce TypeLayout strings #62059

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 17 commits into from
Nov 30, 2022
Merged

Conversation

drexin
Copy link
Contributor

@drexin drexin commented Nov 11, 2022

Layout strings encode the structure of a type into a byte string that can be
interpreted by a runtime function to achieve a destroy or copy. Rather than
generating ir for a destroy/assignWithCopy/etc, we instead generate a layout
string which encodes enough information for a called runtime function to
perform the operation for us. Value witness functions tend to be quite large,
so this allows us to replace them with a single call instead. This gives us the
option of making a codesize/runtime cost trade off.

Gwen Mittertreiner and others added 12 commits November 11, 2022 08:37
Layout strings encode the structure of a type into a byte string that can be
interpreted by a runtime function to achieve a destroy or copy. Rather than
generating ir for a destroy/assignWithCopy/etc, we instead generate a layout
string which encodes enough information for a called runtime function to
perform the operation for us. Value witness functions tend to be quite large,
so this allows us to replace them with a single call instead. This gives us the
option of making a codesize/runtime cost trade off.
This marks a type definition that should use generic bytecode based
value witnesses rather than generating the standard suite of
value witness functions. This should reduce the codesize of the binary
for a runtime interpretation of the bytecode cost.
Summary:
This creates a library to store the runtime functions in to deploy to
runtimes that do not implement bytecode layouts. Right now, that is
everything. Once these are added to the runtime itself, it can be used
to deploy to old runtimes.
If GenerateLayoutBytecode is enabled, Create a layout string and use it
to call swift_generic_destroy
Add Resilient type and Archetype Support to Bytecode Layouts
Implements swift_generic_initialize and swift_generic_assign to allow copying
types using bytecode based witnesses.
Added a test to ensure layouts are correct and getting generated
MultiEnums currently have some correctness issues with non fixed multienum
types. Disabling them for now then going to attempt a correct implementation in
a follow up patch
@drexin
Copy link
Contributor Author

drexin commented Nov 11, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test

@drexin drexin force-pushed the wip-struct-layouts branch from 7a467f2 to 60a2a39 Compare November 11, 2022 17:59
@drexin
Copy link
Contributor Author

drexin commented Nov 11, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test

@drexin drexin force-pushed the wip-struct-layouts branch from 60a2a39 to 3a81f72 Compare November 11, 2022 21:45
@drexin
Copy link
Contributor Author

drexin commented Nov 11, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Nov 14, 2022

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Nov 15, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Nov 15, 2022

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Nov 15, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test

@drexin drexin force-pushed the wip-struct-layouts branch from ff34261 to 57a675e Compare November 15, 2022 21:33
@drexin
Copy link
Contributor Author

drexin commented Nov 15, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Nov 15, 2022

@swift-ci smoke test macos

@drexin
Copy link
Contributor Author

drexin commented Nov 15, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test macos

1 similar comment
@drexin
Copy link
Contributor Author

drexin commented Nov 16, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test macos

@drexin
Copy link
Contributor Author

drexin commented Nov 16, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test macos

3 similar comments
@drexin
Copy link
Contributor Author

drexin commented Nov 16, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test macos

@drexin
Copy link
Contributor Author

drexin commented Nov 16, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test macos

@drexin
Copy link
Contributor Author

drexin commented Nov 16, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test macos

@drexin drexin requested a review from aschwaighofer November 16, 2022 23:13
@drexin drexin marked this pull request as ready for review November 16, 2022 23:15
Copy link
Contributor

@aschwaighofer aschwaighofer left a comment

Choose a reason for hiding this comment

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

LGTM (mostly, besides on MUSTFIX comment)

if (!IGM.getOptions().ForceStructTypeLayouts) {
return IGM.typeLayoutCache.getOrCreateTypeInfoBasedEntry(*this, T);
}
return IGM.typeLayoutCache.getOrCreateScalarEntry(
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect we will want to communicate the number of witness tables here in the future. The protocol witness table pointers are part of the layout of an existential type.
Maybe by building an aligned entry group that starts with a scalar entry of an existential reference (modeling the storage only) and then trailing pod scalar entries for the witnesses. (Hmm does that correctly capture the extra inhabitants/spare spits -- would need investigation)

case ScalarKind::POD: {
assert(typeInfo.isFixedSize());
Size size = cast<FixedTypeInfo>(typeInfo).getFixedSize();
switch (size.getValueInBits()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not handle i1 (bool).

//
// enum class LayoutType: char {
// // Scalars
// I8 = 'c',
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing (at least) i1.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the scalar encoding as is is sufficient. LLVM builtin types are available -- eventually, we need to be able to match/encode the results of getSpareBitsForType.

@drexin drexin force-pushed the wip-struct-layouts branch from 57a675e to 93eadca Compare November 28, 2022 17:36
@drexin
Copy link
Contributor Author

drexin commented Nov 28, 2022

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Nov 28, 2022

swiftlang/swift-syntax#1073

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Nov 29, 2022

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Nov 29, 2022

@swift-ci smoke test

@drexin drexin merged commit 3cf40ea into swiftlang:main Nov 30, 2022
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