-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Link from tasty #2910
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
Link from tasty #2910
Conversation
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.
This duplicates the already existing ClassSymbol#tree
d544c1c
to
3117430
Compare
@smarter deduplicated |
08618cf
to
adab2a8
Compare
The requested change has been made. |
Thanks, not sure if I'll have time to review this today, this isn't urgent anyway is it? |
It is not urgent. |
Will need rebase on #2958 |
30abe4f
to
1a991ff
Compare
* return the PackageDef tree for this class, otherwise EmptyTree. | ||
* This will force the info of the class. | ||
*/ | ||
def unitTree(implicit ctx: Context): tpd.Tree /* tpd.PackageDef | tpd.TypeDef | tpd.EmptyTree */ = { |
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.
I'm unhappy about having both unitTree
and tree
. I think we should just have unitTree
(but give it a different name like just tree
because it's not the full compilation unit tree, it's only the current class tree wrapped with PackageDefs).
else findTree(tree).get | ||
} | ||
|
||
/** If this is a top-level class, and if `-Yretain-trees` or `-YlinkOptimise` is set, |
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.
Can we please decide if options should be written -like-this
or -likeThis
and stick to it? Having both is really annoying.
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.
Oh, it is actually -Xlink-optimise
and this is a typo.
deb434c
to
caaeceb
Compare
b8f8d36
to
9db592a
Compare
@smarter ping review |
9db592a
to
2b2f22e
Compare
Rebased |
2b2f22e
to
56987cb
Compare
Rebased |
def mkCompilationUnit(clsd: ClassDenotation, unpickled: Tree)(implicit ctx: Context): CompilationUnit = { | ||
val unit1 = new CompilationUnit(new SourceFile(clsd.symbol.sourceFile, Seq())) | ||
unit1.tpdTree = unpickled | ||
force.traverse(unit1.tpdTree) |
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.
Do you actually need to force the tree for the linker?
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.
When we first tried it with @DarkDimius we needed it. But it looks like we do not need it anymore.
@@ -47,6 +47,7 @@ class Compiler { | |||
List(new PostTyper), // Additional checks and cleanups after type checking | |||
List(new sbt.ExtractAPI), // Sends a representation of the API of classes to sbt via callbacks | |||
List(new Pickler), // Generate TASTY info | |||
List(new LinkAll), // Link all |
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.
Not a very detailed description :)
@@ -102,6 +102,7 @@ class ScalaSettings extends Settings.SettingGroup { | |||
val YcheckAllPatmat = BooleanSetting("-Ycheck-all-patmat", "Check exhaustivity and redundancy of all pattern matching (used for testing the algorithm)") | |||
val YretainTrees = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree") | |||
val YshowTreeIds = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.") | |||
val YRunClasspath = PathSetting("-YRunClasspath", "Specify where to find user class files while executing run tests.", defaultClasspath) |
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.
If this only for tests it shouldn't be a compiler option. You can use a property instead like the stuff in compiler/test/dotty/Properties.scala
@@ -113,6 +114,7 @@ class ScalaSettings extends Settings.SettingGroup { | |||
val YoptPhases = PhasesSetting("-Yopt-phases", "Restrict the optimisation phases to execute under -optimise.") | |||
val YoptFuel = IntSetting("-Yopt-fuel", "Maximum number of optimisations performed under -optimise.", -1) | |||
val optimise = BooleanSetting("-optimise", "Generates faster bytecode by applying local optimisations to the .program") withAbbreviation "-optimize" | |||
val XlinkOptimise = BooleanSetting("-Xlink-optimise", "Link class files.").withAbbreviation("-Xlink-optimize") |
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.
Longer description?
* for this class, otherwise EmptyTree. This will force the info of the class. | ||
*/ | ||
def tree(implicit ctx: Context): tpd.Tree /* tpd.TypeDef | tpd.EmptyTree */ = { | ||
/** If this is a top-level class, and if `-Yretain-trees` or `-Xlink-optimise` is set, |
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.
This comment is not 100% true since if this is a top-level class and -Xlink-optimise is set, but the class comes from the sources and not tasty, it will return EmptyTree.
@@ -154,6 +154,9 @@ class FirstTransform extends MiniPhaseTransform with InfoTransformer with Annota | |||
cpy.Template(impl)(self = EmptyValDef) | |||
} | |||
|
|||
override def transformPackageDef(tree: PackageDef)(implicit ctx: Context, info: TransformerInfo): Tree = |
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.
Add a comment explaining why this is needed?
@@ -154,6 +154,9 @@ class FirstTransform extends MiniPhaseTransform with InfoTransformer with Annota | |||
cpy.Template(impl)(self = EmptyValDef) | |||
} | |||
|
|||
override def transformPackageDef(tree: PackageDef)(implicit ctx: Context, info: TransformerInfo): Tree = | |||
if (tree.stats.isEmpty) theEmptyTree else tree |
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.
Why theEmptyTree
and not EmptyTree
?
|
||
override def phaseName = "linkAll" | ||
|
||
override def prepareForUnit(tree: tpd.Tree)(implicit ctx: Context): TreeTransform = NoTransform |
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.
Why?
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.
see comment
else super.runOn(units) | ||
|
||
/** Loads and processes new compilation units, possibly loading more units. */ | ||
private def allUnits(processed: Set[CompilationUnit], unprocessed: Set[CompilationUnit], loadedClasses: Set[ClassDenotation])(implicit ctx: Context): List[CompilationUnit] = { |
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.
I would use an inner method for the recursive calls and not have the parameters processed and loadedClasses on the outer method.
val acc1 = this(acc, constr) | ||
inParents = true | ||
val acc2 = this(acc1, parents) | ||
inParents = false |
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.
Don't think this is correct in general, you assume that inParents will be false before you set it to true, but you can have a Template inside the parents of a Template, e.g:
class A(x: Int)
class B extends A({ class Foo; 1 })
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.
This works, I added a test for it.
ec50c12
to
1ce86d4
Compare
@smarter, all requested changes have been done. |
1ce86d4
to
8a4071a
Compare
8a4071a
to
4f0b070
Compare
No description provided.