Skip to content
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

Strip TypeExpr of its TypeLoc #31253

Merged
merged 5 commits into from
Apr 28, 2020
Merged

Strip TypeExpr of its TypeLoc #31253

merged 5 commits into from
Apr 28, 2020

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Apr 24, 2020

Remove duplication in the modeling of TypeExpr. The type of a TypeExpr
node is always a metatype corresponding to the contextual
type of the type it's referencing. For some reason, the instance type
was also stored in this TypeLoc at random points in semantic analysis.

Under the assumption that this instance type is always going to be the
instance type of the contextual type of the expression, introduce
a number of simplifications:

  1. Explicit TypeExpr nodes must be created with a TypeRepr node
  2. Implicit TypeExpr nodes must be created with a contextual type
  3. The typing rules for implicit TypeExpr simply opens this type

This opens the door for the further removal of TypeLocs from Expr nodes by replacing them with the TypeExprs.

CodaFi added 3 commits April 23, 2020 14:51
Remove duplication in the modeling of TypeExpr. The type of a TypeExpr
node is always a metatype corresponding to the contextual
type of the type it's referencing. For some reason, the instance type
was also stored in this TypeLoc at random points in semantic analysis.

Under the assumption that this instance type is always going to be the
instance type of the contextual type of the expression, introduce
a number of simplifications:

1) Explicit TypeExpr nodes must be created with a TypeRepr node
2) Implicit TypeExpr nodes must be created with a contextual type
3) The typing rules for implicit TypeExpr simply opens this type
Make it slightly easier to enforce the invariant that implicit TypeExpr
nodes have a contextual type set.
@CodaFi CodaFi requested a review from xedin April 24, 2020 00:06
@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 24, 2020

@swift-ci test

@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 24, 2020

@swift-ci test source compatibility

@@ -116,7 +116,7 @@ _ = [Int!]() // expected-error {{'!' is not allowed here; perhaps '?' was intend
let _: [Int!] = [1] // expected-error {{'!' is not allowed here; perhaps '?' was intended?}}{{12-13=?}}
_ = Optional<Int!>(nil) // expected-error {{'!' is not allowed here; perhaps '?' was intended?}}{{17-18=?}}
let _: Optional<Int!> = nil // expected-error {{'!' is not allowed here; perhaps '?' was intended?}}{{20-21=?}}
_ = Int!?(0) // expected-error {{'!' is not allowed here; perhaps '?' was intended?}}{{8-9=?}}
_ = Int!?(0) // expected-error 3 {{'!' is not allowed here; perhaps '?' was intended?}}{{8-9=?}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xedin I don't know how concerned we are about this case, but it's triple-diagnosing because precheck and the solver are resolving the underlying type separately. The only thing stopping it from doing that before was that it was storing the instance type in the TypeLoc and using that to bypass type resolution.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's unfortunate but as far as I understand if we stop trying to lookup members in resolveDeclRefExpr this should no longer be a problem, is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I bet that tackles one of them. The one in precheck was always suspicious because it relied on the order of validation. That leaves the only strictly necessary one: The one in the solver.

// HACK: If there's not enough information in the constraint system,
// create a garbage base type to force it to diagnose
// this as an ambiguous expression.
typeExpr = TypeExpr::createImplicitHack(loc, ErrorType::get(ctx), ctx);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DougGregor This seems... less than ideal. But I'm not sure what else to do about this case.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - a55e6b259baf7c1d8d013b5dfd60e77f2c804917

@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 24, 2020

@swift-ci test

@swiftlang swiftlang deleted a comment from swift-ci Apr 24, 2020
@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 24, 2020

@swift-ci test source compatibility

@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 24, 2020

@swift-ci test source compatibility Debug

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - e853ad5cc5516d48a80efa3c71188c88c7eb2dd5

@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 24, 2020

@swift-ci test Linux

@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 24, 2020

Debug compat died and release is unrelated. Will give it a try when the bots are in better shape

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.

It's great to get rid of TypeLoc in TypeExpr but we need to get the story about getInstanceType straight to avoid future misuses...

@@ -116,7 +116,7 @@ _ = [Int!]() // expected-error {{'!' is not allowed here; perhaps '?' was intend
let _: [Int!] = [1] // expected-error {{'!' is not allowed here; perhaps '?' was intended?}}{{12-13=?}}
_ = Optional<Int!>(nil) // expected-error {{'!' is not allowed here; perhaps '?' was intended?}}{{17-18=?}}
let _: Optional<Int!> = nil // expected-error {{'!' is not allowed here; perhaps '?' was intended?}}{{20-21=?}}
_ = Int!?(0) // expected-error {{'!' is not allowed here; perhaps '?' was intended?}}{{8-9=?}}
_ = Int!?(0) // expected-error 3 {{'!' is not allowed here; perhaps '?' was intended?}}{{8-9=?}}
Copy link
Contributor

Choose a reason for hiding this comment

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

That's unfortunate but as far as I understand if we stop trying to lookup members in resolveDeclRefExpr this should no longer be a problem, is that correct?

@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 24, 2020

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e853ad5cc5516d48a80efa3c71188c88c7eb2dd5

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - d5edee8

@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 25, 2020

@swift-ci test Linux

@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 28, 2020

@swift-ci test

@CodaFi
Copy link
Contributor Author

CodaFi commented Apr 28, 2020

@CodaFi CodaFi merged commit a6fc9b3 into swiftlang:master Apr 28, 2020
@CodaFi CodaFi deleted the casting-call branch April 28, 2020 16:49
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