Skip to content

Fix #3018: use List instead of Map in InlineLocalObjects #3021

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 2 commits into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import core.Symbols._
import core.Flags._
import ast.Trees._
import scala.collection.mutable
import scala.collection.mutable.LinkedHashMap
import transform.SymUtils._
import config.Printers.simplify
import Simplify._
Expand All @@ -33,12 +34,12 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
// ValDefs whose lhs is used with `._1` (or any getter call).
val gettersCalled = mutable.HashSet[Symbol]()

// Map from class to new fields, initialised between visitor and transformer.
var newFieldsMapping: Map[Symbol, Map[Symbol, Symbol]] = null
// | | |
// | | New fields, replacements these getters
// | Usages of getters of these classes
// ValDefs of the classes that are being torn apart; = candidates.intersect(gettersCalled)
// Immutable sorted map from class to new fields, initialized between visitor and transformer.
var newFieldsMapping: Map[Symbol, LinkedHashMap[Symbol, Symbol]] = null
// | | |
// | | New fields, replacements these getters
// | Usages of getters of these classes
// ValDefs of the classes that are being torn apart; = candidates.intersect(gettersCalled)

def clear(): Unit = {
candidates.clear()
Expand All @@ -57,7 +58,7 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
val info: Type = x.asSeenFrom(refVal.info).info.finalResultType.widenDealias
ctx.newSymbol(owner, name, flags, info)
}
(refVal, accessors.zip(newLocals).toMap)
(refVal, LinkedHashMap[Symbol, Symbol](accessors.zip(newLocals): _*))
}.toMap
}

Expand Down Expand Up @@ -99,7 +100,7 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
Thicket(newFieldsDefs :+ recreate)

case t @ Select(rec, _) if isImmutableAccessor(t) =>
newFieldsMapping.getOrElse(rec.symbol, Map.empty).get(t.symbol) match {
newFieldsMapping.getOrElse(rec.symbol, Map.empty[Symbol, Symbol]).get(t.symbol) match {
case None => t
case Some(newSym) => ref(newSym)
}
Expand All @@ -108,3 +109,4 @@ class InlineLocalObjects(val simplifyPhase: Simplify) extends Optimisation {
}
}
}

1 change: 1 addition & 0 deletions tests/run/i3018.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-optimise
Copy link
Member

Choose a reason for hiding this comment

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

flags files are ignored by vulpix, flags have to be put in the code in CompilationTests.scala

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed in #3029

24 changes: 24 additions & 0 deletions tests/run/i3018.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Type
class Symbol

sealed trait Space
case object Empty extends Space
case class Typ(tp: Type, decomposed: Boolean) extends Space
case class Prod(tp: Type, unappTp: Type, unappSym: Symbol, params: List[Space], full: Boolean) extends Space
case class Or(spaces: List[Space]) extends Space

object Test {
def simplify(space: Space, aggressive: Boolean = false): Space = space match {
case Prod(tp, fun, sym, spaces, full) =>
val sp = Prod(tp, fun, sym, spaces.map(simplify(_)), full)
if (sp.params.contains(Empty)) Empty
else sp
case Or(spaces) => space
case Typ(tp, _) => space
case _ => space
}

def main(args: Array[String]): Unit = {
simplify(Prod(new Type, new Type, new Symbol, Nil, false))
}
}