Skip to content

Commit

Permalink
Apply #193 to 2.10 bridge
Browse files Browse the repository at this point in the history
Ref #193
  • Loading branch information
eed3si9n committed Nov 23, 2016
1 parent 01345b5 commit 09a32f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ lazy val publishBridgesAndTest = Command.args("publishBridgesAndTest", "<version
val version = args mkString ""
s"${compilerInterface.id}/publishLocal" ::
(compilerBridgeScalaVersions map (v => s"plz $v ${zincApiInfo.id}/publishLocal")) :::
// (compilerBridgeScalaVersions map (v => s"plz $v ${compilerBridge.id}/test")) :::
(compilerBridgeScalaVersions map (v => s"plz $v ${compilerBridge.id}/test")) :::
(compilerBridgeScalaVersions map (v => s"plz $v ${compilerBridge.id}/publishLocal")) :::
s"plz $version zincRoot/test" ::
s"plz $version zincRoot/scripted" ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class ExtractUsedNames[GlobalType <: CallbackGlobal](val global: GlobalType) ext
* https://github.com/sbt/sbt/issues/1544
*/
private val inspectedOriginalTrees = collection.mutable.Set.empty[Tree]
private val inspectedTypeTrees = collection.mutable.Set.empty[Tree]

override def traverse(tree: Tree): Unit = tree match {
case MacroExpansionOf(original) if inspectedOriginalTrees.add(original) =>
Expand All @@ -106,9 +107,11 @@ class ExtractUsedNames[GlobalType <: CallbackGlobal](val global: GlobalType) ext
val nameAsString = name.decode.trim
if (enclosingNonLocalClass == NoSymbol || enclosingNonLocalClass.isPackage) {
namesUsedAtTopLevel += nameAsString
()
} else {
val className = ExtractUsedNames.this.className(enclosingNonLocalClass)
namesUsedInClasses(className) += nameAsString
()
}
}

Expand Down Expand Up @@ -136,7 +139,9 @@ class ExtractUsedNames[GlobalType <: CallbackGlobal](val global: GlobalType) ext
// to types but that might be a bad thing because it might expand aliases eagerly which
// not what we need
case t: TypeTree if t.original != null =>
t.original.foreach(traverse)
if (inspectedTypeTrees.add(t.original)) {
t.original.foreach(traverse)
}
case t if t.hasSymbol =>
addSymbol(t.symbol)
if (t.tpe != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ExtractUsedNamesPerformanceSpecification extends UnitSpec {
}

val TestResource = "/ExtractUsedNamesPerformance.scala.source"
val scala210diff = Set("Any", "Nothing", "_root_", "StringAdd")

it should "be executed in reasonable time" in {
var zipfs: Option[FileSystem] = None
Expand All @@ -46,13 +47,13 @@ class ExtractUsedNamesPerformanceSpecification extends UnitSpec {
val expectedNamesForDepFn1 = Set("DepFn1", "Out", "T", "AnyRef", "scala")
val expectedNamesForHNil = Set("x", "package", "HNil", "ScalaRunTime", "T", "Iterator", "Boolean", "$" + "isInstanceOf", "::", "Nothing", "x$1", "acme", "typedProductIterator", "Int", "<init>", "apply", "Object", "IndexOutOfBoundsException", "scala", "HList", "toString", "H", "Serializable", "h", "Product", "Any", "runtime", "matchEnd3", "String")
val expectedNamesForHList = Set("Tupler", "acme", "scala", "Serializable", "Product")
assert(usedNames("acme.Tupler") === expectedNamesForTupler)
assert(usedNames("acme.TuplerInstances") === expectedNamesForTuplerInstances)
assert(usedNames("acme.TuplerInstances.<refinement>") === expectedNamesForRefinement)
assert(usedNames("acme.$colon$colon") === `expectedNamesFor::`)
assert(usedNames("acme.DepFn1") === expectedNamesForDepFn1)
assert(usedNames("acme.HNil") === expectedNamesForHNil)
assert(usedNames("acme.HList") === expectedNamesForHList)
assert(usedNames("acme.Tupler") -- scala210diff === expectedNamesForTupler -- scala210diff)
assert(usedNames("acme.TuplerInstances") -- scala210diff === expectedNamesForTuplerInstances -- scala210diff)
assert(usedNames("acme.TuplerInstances.<refinement>") -- scala210diff === expectedNamesForRefinement -- scala210diff)
assert(usedNames("acme.$colon$colon") -- scala210diff === `expectedNamesFor::` -- scala210diff)
assert(usedNames("acme.DepFn1") -- scala210diff === expectedNamesForDepFn1 -- scala210diff)
assert(usedNames("acme.HNil") -- scala210diff === expectedNamesForHNil -- scala210diff)
assert(usedNames("acme.HList") -- scala210diff === expectedNamesForHList -- scala210diff)
}

it should "correctly find Out0 (not stored in inspected trees) both in TuplerInstances and TuplerInstances.<refinement>" in {
Expand All @@ -69,11 +70,12 @@ class ExtractUsedNamesPerformanceSpecification extends UnitSpec {
val usedNames = compilerForTesting.extractUsedNamesFromSrc(src)
val expectedNamesForTuplerInstances = Set("Tupler", "AnyRef", "L", "Out0", "scala", "HList")
val expectedNamesForTuplerInstancesRefinement = Set("Out0")
assert(usedNames("TuplerInstances") === expectedNamesForTuplerInstances)
assert(usedNames("TuplerInstances.<refinement>") === expectedNamesForTuplerInstancesRefinement)
assert(usedNames("TuplerInstances") -- scala210diff === expectedNamesForTuplerInstances -- scala210diff)
assert(usedNames("TuplerInstances.<refinement>") -- scala210diff === expectedNamesForTuplerInstancesRefinement -- scala210diff)
}

it should "correctly collect used names from macro extension" in {
pending
val ext = """|package acme
|import scala.reflect.macros.blackbox.Context
|
Expand Down

0 comments on commit 09a32f4

Please sign in to comment.