Skip to content

Commit

Permalink
Use a stable ordering for renamed symbols
Browse files Browse the repository at this point in the history
We should generate the exact same bytecode regardless of the order in which
files are loaded. Relying on Symbol.id for ordering reflects the order in which
symbols were accessed, and that depends on what files are compiled. Instead,
we should use source positions wherever possible, since all the renamable symbols
originate from the currently compiled unit.
  • Loading branch information
dragos committed Jan 10, 2018
1 parent 4a03b99 commit 7c0f351
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/compiler/scala/tools/nsc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,21 @@ abstract class LambdaLift extends InfoTransform {
/** Symbols that are called from an inner class. */
private val calledFromInner = new LinkedHashSet[Symbol]

private val ord = Ordering.fromLessThan[Symbol](_ isLess _)
private def newSymSet = TreeSet.empty[Symbol](ord)
private val posord = Ordering.fromLessThan[Symbol] { (sym1: Symbol, sym2: Symbol) =>
if (sym1.pos.isDefined && sym2.pos.isDefined
&& sym1.pos.source == sym2.pos.source
&& sym1.pos.point != sym2.pos.point)
sym1.pos.point < sym2.pos.point
else
sym1 isLess sym2
}
private def newSymSet(ord: Ordering[Symbol]) = TreeSet.empty[Symbol](ord)

private def symSet(f: LinkedHashMap[Symbol, SymSet], sym: Symbol): SymSet =
f.getOrElseUpdate(sym, newSymSet)
f.getOrElseUpdate(sym, newSymSet(Ordering.fromLessThan(_ isLess _)))

/** The set of symbols that need to be renamed. */
private val renamable = newSymSet
private val renamable = newSymSet(posord)

/**
* The new names for free variables proxies. If we simply renamed the
Expand Down

0 comments on commit 7c0f351

Please sign in to comment.