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

First steps towards rewriting from Scala2 in dotty #1154

Merged
merged 25 commits into from
Mar 18, 2016

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 7, 2016

This is an attempt to do the rewriting right in the dotty compiler. The logic is, if dotty can detect
Scala2 incompatibilities it should be able to apply fixes at the same time. That way there is no error-prone syncing between different tools.

This PR

  • adds rewrite logic
  • adds logic to navigate from typed to untyped trees
  • performs specific rewritings:
    • rewrite procedure syntax,
    • add @volatile for lazy vals
    • drop redundant trailing `_'.
    • mask variance errors with @uncheckedVariance

There is also a change the way annotations are propagated to derived symbols.

With this PR, stdlib can be patched and recompiled without -language:Scala2 (pending fix of
@volatile implicit issues).

vdef1
}

/** Add a @volitile to lazy vals when rewriting from Scala2 */
Copy link
Member

Choose a reason for hiding this comment

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

Typo

Firs version of patching that can be invoked by dotty compiler
itself.
Driver should not know that patch functionality exists. Instead, introduce settings
that can introduce their own stateful values.
No more leaking ofMove PatchedFiles in a settings option. Move all
patch classes into a `Rewrites` object.
Map typed to corresponding untyped trees.
Imports are missing afterwards.
Selectors should be defs, not lazy vals.
Some random neg tests from previous experiments.
Scala2 allows `x _` even if `x` is not a method.
Dotty disallows them. The patch removes the ` _`
in these cases.
Test rewritings that were implemented so far.
Remove println; add docs
Gave overlapping positions in the case of longer lists of children.
`Iterator.sliding(2, 1)` returns a one-element result if the original iterator
contains only one element, which makes it unpleasant to use for our task. Replaced
by a fold.
A constructor

     def this() { ... }

needs to be rewritten to

     def this() = { ... }

not to

     def this(): Unit = { ... }
1. trailing `_`:

    `x _` is rewritten to `(() => x)` not to `x`

2. lazy vals:

Rewrites are done in Typer, not LazyVals. Later on we are too much at risk to
hit synthetically generated lazy vals.
@odersky
Copy link
Contributor Author

odersky commented Mar 12, 2016

Any objections to merge this one?

@smarter
Copy link
Member

smarter commented Mar 12, 2016

I'll review it today.

if (ctx.scala2Mode && sym.owner.isConstructor)
ctx.migrationWarning(s"According to new variance rules, this is no longer accepted; need to annotate with @uncheckedVariance:\n$msg", sym.pos)
if (ctx.scala2Mode && sym.owner.isConstructor) {
ctx.migrationWarning(s"According to new variance rules, this is no longer accepted; need to annotate with @uncheckedVariance:\n$msg, pos = ${sym.pos}", sym.pos)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need pos = ${sym.pos} in the migration warning

*
* Otherwise, in case there is exactly one variable x_1 in pattern
* val/var p = e ==> val/var x_1 = (e: @unchecked) match (case p => (x_1))
* val/var/lazy val p = e ==> val/var x_1 = (e: @unchecked) match (case p => (x_1))
Copy link
Member

Choose a reason for hiding this comment

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

val/var x_1 should be val/var/lazy val x_1 I think

@smarter
Copy link
Member

smarter commented Mar 12, 2016

Probably not worth fixing if it's complicated to deal with but note that:

object Foo {
  lazy val x, y = 1
}

gets rewritten to:

object Foo {
  @volatile @volatile lazy val x, y = 1
}

odersky added a commit that referenced this pull request Mar 18, 2016
First steps towards rewriting from Scala2 in dotty
@odersky odersky merged commit cdbc163 into scala:master Mar 18, 2016
@allanrenucci allanrenucci deleted the add-rewrite branch December 14, 2017 16:57
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.

None yet

3 participants