Skip to content

Commit 3541995

Browse files
committed
some cleanup
1 parent 46b1094 commit 3541995

File tree

2 files changed

+10
-87
lines changed

2 files changed

+10
-87
lines changed

src/common/Base.scala

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,8 @@ trait BaseExp extends Base with Expressions with Blocks with Transforming {
4040
protected def unit[T:Manifest](x: T) = Const(x)
4141
}
4242

43-
trait BlockExp extends BaseExp
43+
trait BlockExp extends BaseExp with Blocks
4444

45-
/*
46-
trait BlockExp extends BaseExp with Blocks {
47-
48-
implicit object CanTransformBlock extends CanTransform[Block] {
49-
def transform[A](x: Block[A], t: Transformer): Block[A] = Block(t(x.res))
50-
}
51-
52-
}
53-
*/
5445

5546
trait EffectExp extends BaseExp with Effects {
5647

@@ -66,17 +57,8 @@ trait EffectExp extends BaseExp with Effects {
6657
}
6758

6859
override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = e match {
69-
/*
70-
case Reflect(x, u, es) =>
71-
reifyEffects {
72-
context = f(es)
73-
mirror(x)
74-
}
75-
76-
*/
77-
// case Reflect(Print(x), u, es) => Reflect(Print(f(x)), es map (e => f(e)))
7860
case Reflect(x, u, es) => reflectMirrored(mirrorDef(e,f).asInstanceOf[Reflect[A]])
79-
case Reify(x, u, es) => Reify(f(x), mapOver(f,u), f(es)) //TODO: u
61+
case Reify(x, u, es) => Reify(f(x), mapOver(f,u), f(es))
8062
case _ => super.mirror(e,f)
8163
}
8264

@@ -85,7 +67,7 @@ trait EffectExp extends BaseExp with Effects {
8567
trait BaseFatExp extends BaseExp with FatExpressions with FatTransforming
8668

8769

88-
// The traits below provide an interface to codegen so that client do
70+
// The traits below provide an interface to codegen so that clients do
8971
// not need to depend on internal._
9072

9173
trait ScalaGenBase extends ScalaCodegen

src/internal/Expressions.scala

Lines changed: 7 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -45,48 +45,6 @@ trait Expressions extends Utils {
4545
cs.map(c => all(c).reverse.map(c => c.fileName.split("/").last + ":" + c.line).mkString("//")).mkString(";")
4646
}
4747

48-
/*
49-
def fresh[T:Manifest] = {
50-
val (name, id, nameId) = nextName("x")
51-
val sym = Sym[T](id)
52-
sym.name = name
53-
sym.nameId = nameId
54-
sym
55-
}
56-
57-
def fresh[T:Manifest](d: Def[T], ctx: Option[SourceContext]) = {
58-
def enclosingNamedContext(sc: SourceContext): Option[SourceContext] = sc.bindings match {
59-
case (null, _) :: _ =>
60-
if (!sc.parent.isEmpty) enclosingNamedContext(sc.parent.get)
61-
else None
62-
case (name, line) :: _ =>
63-
Some(sc)
64-
}
65-
66-
// create base name from source context
67-
val (basename, line, srcCtx) = if (!ctx.isEmpty) {
68-
enclosingNamedContext(ctx.get) match {
69-
case None =>
70-
// no enclosing context has variable assignment
71-
var outermost = ctx.get
72-
while (!outermost.parent.isEmpty) {
73-
outermost = outermost.parent.get
74-
}
75-
("x", 0, Some(outermost))
76-
case Some(sc) => sc.bindings match {
77-
case (n, l) :: _ =>
78-
(n, l, Some(sc))
79-
}
80-
}
81-
} else ("x", 0, None)
82-
val (name, id, nameId) = nextName(basename)
83-
val sym = Sym[T](id)
84-
sym.name = name
85-
sym.nameId = nameId
86-
sym.sourceContext = srcCtx
87-
sym
88-
}
89-
*/
9048

9149
abstract class Def[+T] { // operations (composite)
9250
override final lazy val hashCode = scala.runtime.ScalaRunTime._hashCode(this.asInstanceOf[Product])
@@ -136,7 +94,8 @@ trait Expressions extends Utils {
13694
def reflectSubGraph(ds: List[Stm]): Unit = {
13795
val lhs = ds.flatMap(_.lhs)
13896
assert(lhs.length == lhs.distinct.length, "multiple defs: " + ds)
139-
val existing = lhs flatMap (globalDefsCache get _)//globalDefs filter (_.lhs exists (lhs contains _))
97+
// equivalent to: globalDefs filter (_.lhs exists (lhs contains _))
98+
val existing = lhs flatMap (globalDefsCache get _)
14099
assert(existing.isEmpty, "already defined: " + existing + " for " + ds)
141100
localDefs = localDefs ::: ds
142101
globalDefs = globalDefs ::: ds
@@ -172,7 +131,7 @@ trait Expressions extends Utils {
172131
}
173132

174133
object Def {
175-
def unapply[T](e: Exp[T]): Option[Def[T]] = e match { // really need to test for sym?
134+
def unapply[T](e: Exp[T]): Option[Def[T]] = e match {
176135
case s @ Sym(_) =>
177136
findDefinition(s).flatMap(_.defines(s))
178137
case _ =>
@@ -189,8 +148,9 @@ trait Expressions extends Utils {
189148
case ss: Iterable[Any] => ss.toList.flatMap(syms(_))
190149
// All case classes extend Product!
191150
case p: Product =>
192-
//return p.productIterator.toList.flatMap(syms(_))
193-
/* performance hotspot */
151+
// performance hotspot: this is the same as
152+
// p.productIterator.toList.flatMap(syms(_))
153+
// but faster
194154
val iter = p.productIterator
195155
val out = new ListBuffer[Sym[Any]]
196156
while (iter.hasNext) {
@@ -232,7 +192,7 @@ trait Expressions extends Utils {
232192
case _ => Nil
233193
}
234194

235-
195+
// generic symbol traversal: f is expected to call rsyms again
236196
def rsyms[T](e: Any)(f: Any=>List[T]): List[T] = e match {
237197
case s: Sym[Any] => f(s)
238198
case ss: Iterable[Any] => ss.toList.flatMap(f)
@@ -255,25 +215,6 @@ trait Expressions extends Utils {
255215
def freqCold(e: Any) = symsFreq(e).map(p=>(p._1,p._2*0.5))
256216

257217

258-
259-
/*
260-
def symsFreq(e: Any): List[(Sym[Any], Double)] = e match {
261-
case s: Sym[Any] => List((s,1.0))
262-
case p: Product => p.productIterator.toList.flatMap(symsFreq(_))
263-
case _ => Nil
264-
}
265-
*/
266-
267-
/*
268-
def symsShare(e: Any): List[(Sym[Any], Int)] = {
269-
case s: Sym[Any] => List(s)
270-
case p: Product => p.productIterator.toList.flatMap(symsShare(_))
271-
case _ => Nil
272-
}
273-
*/
274-
275-
276-
277218
// bookkeeping
278219

279220
def reset { // used by delite?

0 commit comments

Comments
 (0)