Skip to content

First steps to support dependent matches #4997

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

Closed
wants to merge 173 commits into from

Conversation

gsps
Copy link
Contributor

@gsps gsps commented Aug 24, 2018

This PR is based on our ongoing work to add dependent types via the TypeOf encoding and extends #4806.

At the moment this branch only affects the precision of types given to bindings inside of match patterns. For instance, given

dependent def headOfCons1 =
  Cons(1, Cons(2, Nil)) match {
    case Cons(x, _) => x
  }

we can now reason about the extracted x in relation to the scrutinee Cons(1, Cons(2, Nil)), so that

headOfCons1: 1

can be proven by the type checker.

Note that this PR currently does not do any reduction of matches on the type level, so a match with multiple cases will not behave any differently yet.

gsps and others added 30 commits June 13, 2018 16:51
Disable stability check on SingletonTypeTree for now.
Introduce TypeOf only to suspend type checking of top-level TypeApply, Apply, If and Match AST nodes.
The reason why we need to ba a proper subtype of AnnotatedType and not
simply instanciate it is because we a custom equality.

For instance we want to disregard the differance between Ident and
TypedTrees since the later replaces the former during typing.
The commented parts are copy pasted from the AppliedTermRef PR
AnnotatedType uses precise equivalance of Trees, whereas TypeOf is only
concerned with certain top level trees.
Also, restore the invariant that the type of the TypeOf tree is the
TypeOf type itself. Here is an example showing what would go wrong
if we didn't do that. Suppose we have
  def f(x: Int) = x
  def g(x: Int) = 2 * x
  def h(f: Int => Int) = f(1)
  h(g): { 2 * 1 }
Given a type map substituting f for g in f(1), the underlying
type should be substituted to the result type of g(1), that is,
2 * 1.
We now effectively -Xprint-types for trees within TypeOf. Instead, we show the underlying type for the top-level tree.
Also added toString in TypeOf.
In the new scheme, we never touch a TypeOf tree's type and ensure this by assigning that tree NoType. This currently induces additional tree copies which could be removed at a later point.

In the process we also fixed bugs in TreeCopier, which would sometimes not go through TypeAssigner when it should have.
@OlivierBlanvillain OlivierBlanvillain self-assigned this Oct 2, 2018
@odersky
Copy link
Contributor

odersky commented Jan 12, 2019

@gsps @OlivierBlanvillain Inactive for 3 months with lots of accumulated conflicts. Should we close this now?

@OlivierBlanvillain
Copy link
Contributor

We still indent to work on this PR. It's currently work in progress on is builds on top of #4806 and #4671 which where both indented as intermediate reviewable/mergable milestones. I guess we can close #4806 as resolving conflicts on an intermediate state would not be a very good use of time...

@odersky
Copy link
Contributor

odersky commented Jan 12, 2019

@OlivierBlanvillain OK, please go ahead and close #4806.

This commits resolves all the merge conflicts to make the branch
compile, but tests are still failing. Here is what breaks in
dotty.tools.dotc.CompilationTests:

    tests/neg/erased-singleton.scala failed
    tests/neg/i5521.scala failed
    tests/pos/dependent-patterns.scala failed
    tests/pos/dependent3.scala failed
    tests/pos/dependent6.scala failed
    tests/run/implicitMatch.scala failed
    tests/run/tuple-for-comprehension.scala failed
    tests/run/tuple-patmat.scala failed
By adding a few widenUnapplyPath...
Apparently Dotty and scalac do not handle this private in the say way...
@b-studios
Copy link
Contributor

@OlivierBlanvillain do you still intend to merge this / work on this?

@anatoliykmetyuk
Copy link
Contributor

There was no activity on this one for a long while, so let's close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants