Skip to content

[IRGen] Lowered open_pack_element. #63363

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

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Feb 2, 2023

Initial lowering support for the open_pack_element instruction. While lowering,

open_pack_element 
  %index 
  of <..., U_i..., ...> 
  at <..., Pack_i, ....>, 
  shape $U_k, 
  uuid "01234567-89AB-CDEF-0123-000000000000"

binds (@pack_element(...) U_i) to the type T(i, %index) at %index in Pack_i for all i of the appropriate shape.

Materialize the metadata address for T(i, %index) depending on what's already available. In general, compare the %index to the upper bound of each element's range: if it's in range, emit the metadata at %innerIndex := %index - %innerLowerBound; if it's out of range, jump to the next comparison. From each metadata emission block, jump to a merge point where the result metadata is defined to be the phi of the metadata materialized in each predecessor.

Still to do: handle conformances.

@nate-chandler nate-chandler force-pushed the variadic-generics/irgen/open_pack_element branch from 2451aee to 2141a70 Compare February 2, 2023 01:57
@nate-chandler nate-chandler force-pushed the variadic-generics/irgen/open_pack_element branch from 2141a70 to 4128050 Compare February 2, 2023 03:35
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler force-pushed the variadic-generics/irgen/open_pack_element branch from 4128050 to 3fa849e Compare February 2, 2023 04:54
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

case GenericRequirement::Kind::Metadata: {
CanGenericTypeParamType ty;
if ((ty = dyn_cast<GenericTypeParamType>(requirement.getTypeParameter())) &&
ty->isParameterPack())
Copy link
Contributor

Choose a reason for hiding this comment

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

We might see this kind of requirement for associated types of packs, too, right?

You should have enough information to set the requirement kind as MetadataPack / WitnessTablePack in the first place, and that'll probably make clients of this a lot easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added these new kinds in 6a44de2 . Does the static member function GenericRequirement::isPack added there correctly identify which types are packs?

@nate-chandler nate-chandler force-pushed the variadic-generics/irgen/open_pack_element branch from 3fa849e to e3daab3 Compare February 2, 2023 15:56
The mapping from requirement kind to llvm::Type is repeated several
places.  Pull it into a helper.
Added pack flavors of requirement kinds for metadata and witness tables.

Fixes the function signatures for variadic generic functions which
previously used %swift.type* for variadic generic parameters--those are
lists of metadata and should actually be %swift.type**.
The function emits the metadata for the element of a pack expansion at a
specified index.  It was previously defined inline in the loop--defined
in emitPackExpansionType--which populates a new metadata array with
elements derived from a preexisting array.  It will be used to emit a
single element in the case that only one is needed.
The parameter name to emitPackExpansionElementMetadata matched the
preexisting local variable name.  Change it to something meaningful to
callers.  Use a separate commit to make the original extraction more
obviously just an extraction.
@nate-chandler nate-chandler force-pushed the variadic-generics/irgen/open_pack_element branch from e3daab3 to a442245 Compare February 2, 2023 20:48
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler marked this pull request as ready for review February 2, 2023 20:52
@nate-chandler
Copy link
Contributor Author

@swift-ci please test macOS platform

@nate-chandler nate-chandler merged commit 7b317c0 into swiftlang:main Feb 3, 2023
@nate-chandler nate-chandler deleted the variadic-generics/irgen/open_pack_element branch February 3, 2023 04:26
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.

2 participants