Skip to content

[AST] Remove ParenType #59141

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 3 commits into from
Nov 1, 2024
Merged

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented May 28, 2022

Today ParenType is used:

  1. As the type of ParenExpr
  2. As the payload type of an unlabeled single associated value enum case (and the type of ParenPattern).
  3. As the type for an (X) TypeRepr

For 1, this leads to some odd behavior, e.g the type of (5.0 * 5).squareRoot() is (Double). For 2, we should be checking the arity of the enum case constructor parameters and the presence of ParenPattern respectively. Eventually we ought to consider replacing Paren/TuplePattern with a PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's some utility in preserving the sugar of the type that the user wrote. However it's really not clear to me that this is particularly desirable since a bunch of diagnostic logic is already stripping ParenTypes. In cases where we care about how the type was written in source, we really ought to be consulting the TypeRepr.

Comment on lines +5891 to +5950
// Note we don't look through parens.
ExistentialMetatypeType *existentialTy = nullptr;
if (!constraintRepr->isParenType())
existentialTy = dyn_cast<ExistentialMetatypeType>(ty.get().getPointer());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kavon Is it intentional that this doesn't look through parens, e.g we accept any ~Copyable.Type, but not any ~(Copyable.Type)? For now I've just maintained the current behavior

@hamishknight
Copy link
Contributor Author

Split out a couple of PRs to hopefully make this a bit easier to land:

@hamishknight hamishknight force-pushed the wrapping-paper branch 2 times, most recently from cfc3f53 to 8a5654b Compare October 29, 2024 11:59
Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Can't wait to see this land!

@@ -1470,16 +1470,6 @@ class TypeDecoder {

return Builder.createDictionaryType(key.getType(), value.getType());
}
case NodeKind::SugaredParen: {
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 want to keep some minimal demangler support just in case it's needed for backwards compatibility with existing debug info; just have this return base.getType() on line 1481

Copy link
Contributor Author

@hamishknight hamishknight Oct 29, 2024

Choose a reason for hiding this comment

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

Ah okay, I guess that means we also need to keep the logic in Demangler.cpp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated with the restored demangling code

@hamishknight
Copy link
Contributor Author

swiftlang/llvm-project#4769

@swift-ci please test source compatibility

…arens

Check for `isParenType` on the TypeRepr to avoid
relying on getting that behavior by casting the
type pointer.
I missed this in my other Sema ParenType PR, avoid
relying on ParenType here.
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
@hamishknight
Copy link
Contributor Author

swiftlang/llvm-project#4769

@swift-ci please test

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

LGTM! It's slightly unfortunate that we loose the sugar sometimes in the diagnostics but I don't think it's critical.

@hamishknight
Copy link
Contributor Author

swiftlang/llvm-project#4769

@swift-ci please test macOS

@hamishknight
Copy link
Contributor Author

🚢

@hamishknight hamishknight merged commit df7cac3 into swiftlang:main Nov 1, 2024
5 checks passed
@hamishknight hamishknight deleted the wrapping-paper branch November 1, 2024 16:52
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