Skip to content

[Variadic Generics] Always use PackType as the substitution for type parameter packs. #64166

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 6 commits into from
Mar 7, 2023

Conversation

hborla
Copy link
Member

@hborla hborla commented Mar 7, 2023

Canonicalize the representation of type parameter pack substitutions as PackType, instead of sometimes using PackType and sometimes using PackArchetypeType.

Subsumes #63908

rjmccall and others added 4 commits March 6, 2023 17:08
This simplifies the representation and allows clients to handle fewer
cases.  It also removes an ambiguity in the representation which could
lead us to have two canonical types for the same type.

This is definitely not working yet, but I'm not making progress on
it quickly enough to unblock what we need to unblock; it'll have to
be fixed in parallel.
…d pack

element environments.

This allows the constraint system to ensure that for a given pack expansion locator,
the given shape class is always the same when requesting the element environment.
If the shape class differs, it means there's a same-shape requirement failure, which
will be diagnosed via the ShapeOf constraint simplification.
The rewrite rules are not quite right yet for same-element requirements, so
let's ban them for now.
…etonPackExpansion,

and update variadic generics SILGen tests for the representation change.
@hborla hborla requested review from xedin and slavapestov as code owners March 7, 2023 06:08
if (!gp->isParameterPack())
return archetype;

return PackType::getSingletonPackExpansion(archetype);
Copy link
Member Author

Choose a reason for hiding this comment

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

@slavapestov I tried changing this to:

    return SubstitutionMap::get(
      nominal->getGenericSignatureOfContext(),
      genericEnv->getForwardingSubstitutionMap());

but it still crashed when building the standard library. I didn't spend much time figuring out why because I wanted to finish the PackType representation change, but I can come back to it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Heh, no worries

@hborla
Copy link
Member Author

hborla commented Mar 7, 2023

@swift-ci please smoke test

@hborla hborla requested a review from rjmccall March 7, 2023 06:10
@hborla hborla requested a review from AnthonyLatsis as a code owner March 7, 2023 09:14
@hborla
Copy link
Member Author

hborla commented Mar 7, 2023

@swift-ci please smoke test

@hborla hborla merged commit 75c1b6e into swiftlang:main Mar 7, 2023
@hborla hborla deleted the parameter-pack-substitution branch March 7, 2023 14:39
@@ -920,6 +920,10 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
auto arg = found->rhs;
if (auto *expansionType = arg->getAs<PackExpansionType>())
arg = expansionType->getPatternType();

if (arg->isParameterPack())
Copy link
Contributor

Choose a reason for hiding this comment

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

PackMatcher should be refactored to do this. Right now it unwraps one element packs, and here we re-wrap them

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I'll fix that, thanks!

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