@@ -2,6 +2,7 @@ package is.hail.expr.ir
22
33import is .hail .collection .FastSeq
44import is .hail .collection .compat .immutable .ArraySeq
5+ import is .hail .expr .ir .Scope .AGG
56import is .hail .expr .ir .defs ._
67import is .hail .types .tcoerce
78import is .hail .types .virtual ._
@@ -224,38 +225,40 @@ object Bindings {
224225 private def childEnvValue (ir : IR , i : Int ): Bindings [Type ] =
225226 ir match {
226227 case Block (bindings, _) =>
227- val bindingsTypes = bindings.view.take(i).map(b => b.name -> b.value.typ).to(ArraySeq )
228+ val types = ArraySeq .newBuilder[(Name , Type )]
229+ types.sizeHint(i)
230+
228231 val eval = ArraySeq .newBuilder[Int ]
232+ eval.sizeHint(i) // most likely binding in eval
233+
229234 val agg = ArraySeq .newBuilder[Int ]
230235 val scan = ArraySeq .newBuilder[Int ]
231- for (k <- 0 until i) bindings(k) match {
232- case Binding (_, _, Scope .EVAL ) =>
233- eval += k
234- case Binding (_, _, Scope .AGG ) =>
235- agg += k
236- case Binding (_, _, Scope .SCAN ) =>
237- scan += k
238- }
239- if (i < bindings.length) bindings(i).scope match {
240- case Scope .EVAL =>
241- Bindings (
242- bindingsTypes,
243- eval.result(),
244- AggEnv .bindOrNoOp(agg.result()),
245- AggEnv .bindOrNoOp(scan.result()),
246- )
247- case Scope .AGG =>
248- Bindings (bindingsTypes, agg.result(), AggEnv .Promote , AggEnv .bindOrNoOp(scan.result()))
249- case Scope .SCAN =>
250- Bindings (bindingsTypes, scan.result(), AggEnv .bindOrNoOp(agg.result()), AggEnv .Promote )
236+
237+ for (k <- 0 until i) {
238+ val Binding (name, value, scope) = bindings(k)
239+ types += name -> value.typ
240+ scope match {
241+ case Scope .EVAL =>
242+ eval += k
243+ case Scope .AGG =>
244+ agg += k
245+ case Scope .SCAN =>
246+ scan += k
247+ }
251248 }
252- else
249+
250+ if (i == bindings.length || bindings(i).scope == Scope .EVAL )
253251 Bindings (
254- bindingsTypes ,
252+ types.result() ,
255253 eval.result(),
256254 AggEnv .bindOrNoOp(agg.result()),
257255 AggEnv .bindOrNoOp(scan.result()),
258256 )
257+ else if (bindings(i).scope == AGG )
258+ Bindings (types.result(), agg.result(), AggEnv .Promote , AggEnv .bindOrNoOp(scan.result()))
259+ else // SCAN
260+ Bindings (types.result(), scan.result(), AggEnv .bindOrNoOp(agg.result()), AggEnv .Promote )
261+
259262 case TailLoop (name, args, resultType, _) if i == args.length =>
260263 Bindings (
261264 args.map { case (name, ir) => name -> ir.typ } :+
0 commit comments