Skip to content

Improve handling of types in constraint system. #6583

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 1 commit into from
Jan 5, 2017
Merged

Improve handling of types in constraint system. #6583

merged 1 commit into from
Jan 5, 2017

Conversation

rudkx
Copy link
Contributor

@rudkx rudkx commented Jan 5, 2017

Several fixes in order to make handling of types more consistent.

In particular:

  • Expression types used within the constraint system itself always use
    the type map.
  • Prior to calling out to any TypeChecker functions, the types are
    written back into the expression tree. After the call, the types are
    read back into the constraint system type map and cleared from the
    expression tree.
  • Some calls to directly set types on the expressions are reintroduced
    in places they make sense (e.g. when building up new expressions that
    are then passed to typeCheckExpressionShallow).

ConstraintSystem::setType() is still setting the type on the expression
nodes at the moment, because there is still some incorrect handling of
types that I need to track down (in particular some issues related to
closures do not appear to be handled correctly).

Also, the diagnostics have not been updated at all to use the types from
the constraint system where appropriate.

@rudkx rudkx self-assigned this Jan 5, 2017
@rudkx
Copy link
Contributor Author

rudkx commented Jan 5, 2017

@swift-ci Please test

1 similar comment
@rudkx
Copy link
Contributor Author

rudkx commented Jan 5, 2017

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jan 5, 2017

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - fefae4979f12253c55097891d50be0e81d0422ab
Test requested by - @rudkx

@swift-ci
Copy link
Contributor

swift-ci commented Jan 5, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - fefae4979f12253c55097891d50be0e81d0422ab
Test requested by - @rudkx

@rudkx rudkx changed the title [WIP] Improve handling of types in constraint system. Improve handling of types in constraint system. Jan 5, 2017
@rudkx
Copy link
Contributor Author

rudkx commented Jan 5, 2017

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jan 5, 2017

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 98fc1ab3211e23fee80b2d7ec4b08455fccc9b03
Test requested by - @rudkx

@swift-ci
Copy link
Contributor

swift-ci commented Jan 5, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 98fc1ab3211e23fee80b2d7ec4b08455fccc9b03
Test requested by - @rudkx

@rudkx
Copy link
Contributor Author

rudkx commented Jan 5, 2017

@swift-ci Please smoke test

@DougGregor
Copy link
Member

These places where we're calling back into the TypeChecker... should they be folded into the ConstraintSystem so that we don't have to do the write-back-into-expressions step? Is this mainly callWitness?

@rudkx
Copy link
Contributor Author

rudkx commented Jan 5, 2017

Yes it's possible a few of these should be moved into the constraint system. I did that with one or two functions in a previous commit. I looked at callWitness and it appeared to be used from other places outside of CSApply so I didn't look at moving it in.

There are a few other places where we are currently writing types back, but I did that somewhat defensively at the moment to get closer to something that works. I intend on going back and removing ones that I suspect aren't actually needed (e.g. typeCheckExpressionShallow generally only looks at the untyped top-level node so perhaps it's not needed).

It's difficult to do that as we're still writing the types in ConstraintSystem::setType(). I may be able to determine that today before actually merging any of this in.

@DougGregor
Copy link
Member

For something like callWitness, we could still provide a TypeChecker version that constructs a constraint system, records the types of the subexpressions in the constraint system, and then hops over to the implementation that doesn't ever use Expr::getType().

Not that we have to do the above before merging this excellent PR; I'm thinking about the trajectory here.

@rudkx
Copy link
Contributor Author

rudkx commented Jan 5, 2017

Okay I found a pile of new work I had missed originally where we pass Expr* into functions in Expr.cpp that read and write types, so I'm going to use this as a checkpoint and then address those issues. It looks like at least some of that functionality is only used from the constraint system and should just be moved there, and other pieces can probably be addressed in other ways.

I think I'm going to try to encapsulate as much of the cruft here (by cruft I mean reading/writing types back and forth) into some entry points in ConstraintSystem that do the calls into the type checker so that there is one place it's happening rather than N.

Several fixes in order to make handling of types more consistent.

In particular:

- Expression types used within the constraint system itself always use
  the type map.

- Prior to calling out to any TypeChecker functions, the types are
  written back into the expression tree. After the call, the types are
  read back into the constraint system type map.

- Some calls to directly set types on the expressions are reintroduced
  in places they make sense (e.g. when building up new expressions that
  are then passed to typeCheckExpressionShallow).

ConstraintSystem::setType() is still setting the type on the expression
nodes at the moment, because there is still some incorrect handling of
types that I need to track down (in particular some issues related to
closures do not appear to be handled correctly). Similarly, when we
cache the types in the constraint system map, we are not clearing them
from the expression tree yet.

The diagnostics have not been updated at all to use the types from
the constraint system where appropriate, and that will need to happen as
well before we can remove the write from ConstraintSystem::setType()
into the expression and enable the clearing of the expression tree type
when we cache it in the constraint system.
@rudkx
Copy link
Contributor Author

rudkx commented Jan 5, 2017

@swift-ci Please smoke test and merge

@rudkx
Copy link
Contributor Author

rudkx commented Jan 5, 2017

@swift-ci Please smoke test

@rudkx rudkx merged commit 62e825a into swiftlang:master Jan 5, 2017
@rudkx rudkx deleted the cs-typemap branch January 5, 2017 22:33
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