@@ -45,48 +45,6 @@ trait Expressions extends Utils {
45
45
cs.map(c => all(c).reverse.map(c => c.fileName.split(" /" ).last + " :" + c.line).mkString(" //" )).mkString(" ;" )
46
46
}
47
47
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
- */
90
48
91
49
abstract class Def [+ T ] { // operations (composite)
92
50
override final lazy val hashCode = scala.runtime.ScalaRunTime ._hashCode(this .asInstanceOf [Product ])
@@ -136,7 +94,8 @@ trait Expressions extends Utils {
136
94
def reflectSubGraph (ds : List [Stm ]): Unit = {
137
95
val lhs = ds.flatMap(_.lhs)
138
96
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 _)
140
99
assert(existing.isEmpty, " already defined: " + existing + " for " + ds)
141
100
localDefs = localDefs ::: ds
142
101
globalDefs = globalDefs ::: ds
@@ -172,7 +131,7 @@ trait Expressions extends Utils {
172
131
}
173
132
174
133
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 {
176
135
case s @ Sym (_) =>
177
136
findDefinition(s).flatMap(_.defines(s))
178
137
case _ =>
@@ -189,8 +148,9 @@ trait Expressions extends Utils {
189
148
case ss : Iterable [Any ] => ss.toList.flatMap(syms(_))
190
149
// All case classes extend Product!
191
150
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
194
154
val iter = p.productIterator
195
155
val out = new ListBuffer [Sym [Any ]]
196
156
while (iter.hasNext) {
@@ -232,7 +192,7 @@ trait Expressions extends Utils {
232
192
case _ => Nil
233
193
}
234
194
235
-
195
+ // generic symbol traversal: f is expected to call rsyms again
236
196
def rsyms [T ](e : Any )(f : Any => List [T ]): List [T ] = e match {
237
197
case s : Sym [Any ] => f(s)
238
198
case ss : Iterable [Any ] => ss.toList.flatMap(f)
@@ -255,25 +215,6 @@ trait Expressions extends Utils {
255
215
def freqCold (e : Any ) = symsFreq(e).map(p=> (p._1,p._2* 0.5 ))
256
216
257
217
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
-
277
218
// bookkeeping
278
219
279
220
def reset { // used by delite?
0 commit comments