Skip to content

Commit

Permalink
Laying groundwork for a followup ticket.
Browse files Browse the repository at this point in the history
To solve SI-5304, we should change `isQualifierSafeToElide`.
  • Loading branch information
retronym committed Jan 26, 2013
1 parent 412ad57 commit 2580a51
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -835,16 +835,16 @@ abstract class GenICode extends SubComponent {
generatedType = toTypeKind(sym.info)
val hostClass = findHostClass(qualifier.tpe, sym)
log(s"Host class of $sym with qual $qualifier (${qualifier.tpe}) is $hostClass")
val qualSafeToInline = treeInfo isExprSafeToInline qualifier
val qualSafeToElide = treeInfo isQualifierSafeToElide qualifier

def genLoadQualUnlessInlinable: Context =
if (qualSafeToInline) ctx else genLoadQualifier(tree, ctx)
def genLoadQualUnlessElidable: Context =
if (qualSafeToElide) ctx else genLoadQualifier(tree, ctx)

if (sym.isModule) {
genLoadModule(genLoadQualUnlessInlinable, tree)
genLoadModule(genLoadQualUnlessElidable, tree)
}
else if (sym.isStaticMember) {
val ctx1 = genLoadQualUnlessInlinable
val ctx1 = genLoadQualUnlessElidable
ctx1.bb.emit(LOAD_FIELD(sym, true) setHostClass hostClass, tree.pos)
ctx1
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/scala/tools/nsc/transform/Flatten.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.collection.mutable.ListBuffer

abstract class Flatten extends InfoTransform {
import global._
import treeInfo.isExprSafeToInline
import treeInfo.isQualifierSafeToElide

/** the following two members override abstract members in Transform */
val phaseName: String = "flatten"
Expand Down Expand Up @@ -121,7 +121,7 @@ abstract class Flatten extends InfoTransform {
exitingFlatten {
atPos(tree.pos) {
val ref = gen.mkAttributedRef(sym)
if (isExprSafeToInline(qual)) ref
if (isQualifierSafeToElide(qual)) ref
else Block(List(qual), ref).setType(tree.tpe) // need to execute the qualifier but refer directly to the lifted module.
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
case Select(module, apply) =>
( // SI-4859 `CaseClass1().InnerCaseClass2()` must not be rewritten to `new InnerCaseClass2()`;
// {expr; Outer}.Inner() must not be rewritten to `new Outer.Inner()`.
treeInfo.isExprSafeToInline(module) &&
treeInfo.isQualifierSafeToElide(module) &&
// SI-5626 Classes in refinement types cannot be constructed with `new`. In this case,
// the companion class is actually not a ClassSymbol, but a reference to an abstract type.
module.symbol.companionClass.isClass
Expand Down
3 changes: 3 additions & 0 deletions src/reflect/scala/reflect/internal/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ abstract class TreeInfo {
false
}

// TODO SI-5304 tighten this up so we don't elide side effect in module loads
def isQualifierSafeToElide(tree: Tree): Boolean = isExprSafeToInline(tree)

/** Is tree an expression which can be inlined without affecting program semantics?
*
* Note that this is not called "isExprPure" since purity (lack of side-effects)
Expand Down

0 comments on commit 2580a51

Please sign in to comment.