Skip to content

Try/cycle detection #161

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 8 commits into from
Oct 11, 2014
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Aug 13, 2014

Some initial steps to take over former RefChecks functionality. Includes some cleanups in transforms.
The biggest change has to do F-bounded polymorphism. We now do cycle detection early and break
all legal cycles with a LazyRef type. Without this precaution lots of code would blow up with a stack overflow - checkbounds being one example.

odersky added 8 commits August 3, 2014 20:43
Added decorators for symbols that can query specific
annotations and annotation arguments (for now, -deprecated
and -migration are added)
Added method to traverse all parts of a type.
Two improvements to TreeTransform:

1) Added transformOther functionality which handles trees not handled by other parts
2) Passes down Mode.Pattern in the context when in a pattern.

TreeTransform no longer normalizes unknown trees but passes them to transformOther.
The former Companions phase has been renamed to FirstTransform. It now performs the
following optimizations:
 - adds companion objects (this was done before)
 - other normalizations that were formally done in TreeTransform,
 - rewrite native methods to stubs (this was formally done in RefChecks)
Cycles are now detected early, when an info is first completed.
Legal, f-bounded cycles are broken by a LazyRef, which will construct
its type lazily. This makes checkBounds validation of AppliedTypeTrees work
(in FirstTransform). Formerly, this stackoverflowed despite the laziness
precautions in findMember.

Todo: Do the same for class files coming from Java and Scala 2.x.
Insert LazyRefs to break cycles for F-bounded types that
are unpickled or read from Java signatures.
Now that F-bunded types are treated more robustly, we can check bounds for
non-emptyness during Typer.

This unvealed one wrong test (wonder how that passed scalac?), which got
moved to neg.
@odersky
Copy link
Contributor Author

odersky commented Aug 13, 2014

@review by @DarkDimius and whoever else wants to have a look at it.

This was referenced Aug 13, 2014
@samuelgruetter
Copy link
Contributor

This PR seems to fix the StackOverflowError we got in #91, but here's another example which does not yet work:

object infpaths3 {

  object a {
    trait T { t =>
      type M <: t.g.N
      type T <: a.T
      val f: t.T

      trait U { u =>
        type N <: t.f.M
        type U <: a.x.g.U
        val f: u.U
      }
      val g: t.U
    }
    val x: a.T = ???
  }

}

On branch try/cycle-detection (#161) (and also on branch change/treecopying (#164)):

$ sbt "run examples/infpaths3.scala"
[error] examples/infpaths3.scala:5: error: illegal cyclic reference: upper bound T.this.g.N of type M refers back to the type itself
[error]       type M <: t.g.N
[error]              ^

but after outputting this, dotty runs into an infinite loop.

With scalac, the cycles are detected, and there's no infinite loop:

<console>:16: error: cyclic aliasing or subtyping involving type M
               type N <: t.f.M
                    ^
<console>:17: error: cyclic aliasing or subtyping involving type U
               type U <: a.x.g.U
                    ^

@DarkDimius DarkDimius merged commit 19b6a04 into scala:master Oct 11, 2014
@allanrenucci allanrenucci deleted the try/cycle-detection branch December 14, 2017 19:25
WojciechMazur pushed a commit to WojciechMazur/dotty that referenced this pull request Mar 19, 2025
Backport "Update asm to patched 9.7.1" to 3.3 LTS
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