Skip to content

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

Merged
merged 14 commits into from
Sep 15, 2017
Merged

Link from tasty #2910

merged 14 commits into from
Sep 15, 2017

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

Copy link
Member

@smarter smarter left a 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

@nicolasstucki
Copy link
Contributor Author

@smarter deduplicated ClassSymbol#tree

@nicolasstucki
Copy link
Contributor Author

The requested change has been made.

@smarter
Copy link
Member

smarter commented Jul 28, 2017

Thanks, not sure if I'll have time to review this today, this isn't urgent anyway is it?

@nicolasstucki
Copy link
Contributor Author

It is not urgent.
It will help me expose some bug later on and make sure that the current state does not break.

@nicolasstucki
Copy link
Contributor Author

Will need rebase on #2958

* 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 */ = {
Copy link
Member

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,
Copy link
Member

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.

Copy link
Contributor Author

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.

@nicolasstucki
Copy link
Contributor Author

@smarter ping review

@nicolasstucki
Copy link
Contributor Author

Rebased

@nicolasstucki
Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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)
Copy link
Member

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")
Copy link
Member

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,
Copy link
Member

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 =
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

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] = {
Copy link
Member

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
Copy link
Member

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 })

Copy link
Contributor Author

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.

@nicolasstucki nicolasstucki force-pushed the link-from-tasty branch 3 times, most recently from ec50c12 to 1ce86d4 Compare September 5, 2017 08:03
@nicolasstucki
Copy link
Contributor Author

@smarter, all requested changes have been done.

@nicolasstucki nicolasstucki merged commit d46d7a3 into scala:master Sep 15, 2017
@allanrenucci allanrenucci deleted the link-from-tasty branch December 14, 2017 19:23
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.

2 participants