-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c43ae4a
Add patching functionality for migration
odersky c1e263b
Avoid setupMethod in Driver
odersky 12d8955
Better encapsulation
odersky ad483d8
Add functionality to navigate ASTs
odersky 2ff667a
Test language features always in phase typer.
odersky ec90a19
Untangle withAnnotation naming.
odersky 54f6399
Fix desugaring of lazy patterns.
odersky 420878d
Copy full modifiers to companions
odersky 294d21f
Better error message when an outer path is not found.
odersky d822b1e
Add @volatile when rewriting lazy vals from Scala2.
odersky e61cd1b
Test case for #1149
odersky 8881a98
More neg tests
odersky dbc06d9
Remove println
odersky a378a46
Disable volatile interpretation of lazy vals under -language:Scala2
odersky c1814a0
Maintain source position in Getters
odersky 4db804b
More detailed diagnostic in NavigateAST
odersky 919f268
Patch redundant `_' suffixes.
odersky 87b30c9
Rewrite test
odersky d24e10c
Polish rewrite test
odersky c0927cf
Fix setChildPositions
odersky 6ddc911
Fix assert in Rewrites
odersky bde5e4d
Add patch for variance errors
odersky 13a376c
Fix patch for constructors with procedure syntax
odersky 13e3d59
Fix two rewrite patches.
odersky 6c18e37
Address reviewer comments.
odersky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package dotty.tools.dotc | ||
package ast | ||
|
||
import core.Contexts.Context | ||
import core.Decorators._ | ||
import util.Positions._ | ||
import Trees.{MemberDef, DefTree} | ||
|
||
/** Utility functions to go from typed to untyped ASTs */ | ||
object NavigateAST { | ||
|
||
/** The untyped tree corresponding to typed tree `tree` in the compilation | ||
* unit specified by `ctx` | ||
*/ | ||
def toUntyped(tree: tpd.Tree)(implicit ctx: Context): untpd.Tree = | ||
untypedPath(tree, exactMatch = true) match { | ||
case (utree: untpd.Tree) :: _ => | ||
utree | ||
case _ => | ||
val loosePath = untypedPath(tree, exactMatch = false) | ||
throw new | ||
Error(i"""no untyped tree for $tree, pos = ${tree.pos}, envelope = ${tree.envelope} | ||
|best matching path =\n$loosePath%\n====\n% | ||
|path positions = ${loosePath.map(_.pos)} | ||
|path envelopes = ${loosePath.map(_.envelope)}""".stripMargin) | ||
} | ||
|
||
/** The reverse path of untyped trees starting with a tree that closest matches | ||
* `tree` and ending in the untyped tree at the root of the compilation unit | ||
* specified by `ctx`. | ||
* @param exactMatch If `true`, the path must start with a node that exactly | ||
* matches `tree`, or `Nil` is returned. | ||
* If `false` the path might start with a node enclosing | ||
* the logical position of `tree`. | ||
* Note: A complication concerns member definitions. ValDefs and DefDefs | ||
* have after desugaring a position that spans just the name of the symbol being | ||
* defined and nothing else. So we look instead for an untyped tree approximating the | ||
* envelope of the definition, and declare success if we find another DefTree. | ||
*/ | ||
def untypedPath(tree: tpd.Tree, exactMatch: Boolean = false)(implicit ctx: Context): List[Positioned] = | ||
tree match { | ||
case tree: MemberDef[_] => | ||
untypedPath(tree.envelope) match { | ||
case path @ (last: DefTree[_]) :: _ => path | ||
case path if !exactMatch => path | ||
case _ => Nil | ||
} | ||
case _ => | ||
untypedPath(tree.pos) match { | ||
case (path @ last :: _) if last.pos == tree.pos || !exactMatch => path | ||
case _ => Nil | ||
} | ||
} | ||
|
||
/** The reverse part of the untyped root of the compilation unit of `ctx` to | ||
* position `pos`. | ||
*/ | ||
def untypedPath(pos: Position)(implicit ctx: Context): List[Positioned] = | ||
pathTo(pos, ctx.compilationUnit.untpdTree) | ||
|
||
|
||
/** The reverse path from node `from` to the node that closest encloses position `pos`, | ||
* or `Nil` if no such path exists. If a non-empty path is returned it starts with | ||
* the node closest enclosing `pos` and ends with `from`. | ||
*/ | ||
def pathTo(pos: Position, from: Positioned)(implicit ctx: Context): List[Positioned] = { | ||
def childPath(it: Iterator[Any], path: List[Positioned]): List[Positioned] = { | ||
while (it.hasNext) { | ||
val path1 = it.next match { | ||
case p: Positioned => singlePath(p, path) | ||
case xs: List[_] => childPath(xs.iterator, path) | ||
case _ => path | ||
} | ||
if (path1 ne path) return path1 | ||
} | ||
path | ||
} | ||
def singlePath(p: Positioned, path: List[Positioned]): List[Positioned] = | ||
if (p.envelope contains pos) childPath(p.productIterator, p :: path) | ||
else path | ||
singlePath(from, Nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what was wrong with the previous version of this method? And was it impossible to write the new version using recursive calls? I think it'd be helpful to add some comments explaining how this algorithm work and what are the invariants for all the mutable variables.