Skip to content

[PreCheckExpr] Allow pack references when resolving types during TypeExpr folding. #64105

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

Conversation

hborla
Copy link
Member

@hborla hborla commented Mar 4, 2023

Pre-check should always allow pack references during TypeExpr folding. CSGen will diagnose cases that appear outside of pack expansion expressions.

@hborla hborla requested review from xedin and slavapestov as code owners March 4, 2023 20:39
@hborla
Copy link
Member Author

hborla commented Mar 4, 2023

@swift-ci please smoke test

…ull type

if the constraint system has not recorded a type for an expanded pack element
type repr.
@hborla
Copy link
Member Author

hborla commented Mar 4, 2023

@swift-ci please smoke test

@hborla
Copy link
Member Author

hborla commented Mar 4, 2023

@swift-ci please smoke test macOS

1 similar comment
@hborla
Copy link
Member Author

hborla commented Mar 5, 2023

@swift-ci please smoke test macOS

// expressions. Some invalid code won't make it there, and
// the constraint system won't have recorded a type.
if (!CS.hasType(elementType->getPackType()))
return Type();
Copy link
Contributor

Choose a reason for hiding this comment

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

Github doesn’t like when comments appear directly on commit apparently…

Aborting here is not ideal for closure contexts because it fails the closure without diagnostic, we should record invalid reference or similar fix and produce a placeholder type just like we do for ErrorExprs…

Copy link
Member Author

@hborla hborla Mar 5, 2023

Choose a reason for hiding this comment

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

This happens when type resolution fails earlier than getting to each T type reprs when they're nested, so a diagnostic has already been produced. I've fixed the other cases where pre-check was failing.

Copy link
Member Author

@hborla hborla Mar 5, 2023

Choose a reason for hiding this comment

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

I can address your suggestion later, but it'll need a little more work than allowing the type variable to bind to a hole, because this type needs to bind to a pack. This means we'll also need to teach ShapeOf constraints to gracefully handle hole types without propagating errors, etc. But for right now, this change fixes a crash-on-invalid, and the type resolution error + unable to infer closure type is a big improvement already.

How about we file a GitHub issue to track that change so we don't forget about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

a diagnostic has already been produced

This is a big problem in closure contexts currently because the diagnostic is produced mid-solving and unbeknownst to the solver so it’s really hard to reason about, we have this invalid reference fix which effectively lies that it produced a diagnostic (another point is that code completion depends on solver not failing early more and more now). We should try and avoid adding more cases like that if possible, fixing it separately sounds good to me!

Copy link
Member Author

Choose a reason for hiding this comment

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

Filed #64109!

@hborla hborla merged commit 2d20644 into swiftlang:main Mar 5, 2023
@hborla hborla deleted the pack-element-type-expr-folding branch March 5, 2023 02:42
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