@@ -9,6 +9,7 @@ import is.hail.expr.ir.analyses.{
99}
1010import is .hail .expr .ir .compile .Compile
1111import is .hail .expr .ir .defs ._
12+ import is .hail .expr .ir .functions .{MissingnessAwareJVMFunction , MissingnessObliviousJVMFunction }
1213import is .hail .expr .ir .lowering .TableStageDependency
1314import is .hail .expr .ir .ndarrays .EmitNDArray
1415import is .hail .expr .ir .streams .{EmitStream , StreamProducer , StreamUtils }
@@ -2771,14 +2772,53 @@ class Emit[C](val ctx: EmitContext, val cb: EmitClassBuilder[C]) {
27712772 val rvAgg = agg.Extract .getAgg(sig)
27722773 rvAgg.result(cb, sc.states(idx), region)
27732774
2775+ case ir @ Apply (fn, typeArgs, args, rt, errorID) =>
2776+ ir.implementation match {
2777+ case impl : MissingnessObliviousJVMFunction =>
2778+ val unified = impl.unify(typeArgs, args.map(_.typ), rt)
2779+ assert(unified)
2780+
2781+ IEmitCode .multiMap(
2782+ cb,
2783+ args.map(arg => (cb : EmitCodeBuilder ) => emitInNewBuilder(cb, arg)),
2784+ ) { codeArgs =>
2785+ val argSTypes = codeArgs.map(_.st)
2786+ val retType = impl.computeStrictReturnEmitType(ir.typ, argSTypes)
2787+ val k = (fn, typeArgs, argSTypes, retType)
2788+ val meth =
2789+ methods.get(k) match {
2790+ case Some (funcMB) =>
2791+ funcMB
2792+ case None =>
2793+ val funcMB = impl.getAsMethod(mb.ecb, retType, typeArgs, argSTypes : _* )
2794+ methods.update(k, funcMB)
2795+ funcMB
2796+ }
2797+ cb.invokeSCode(
2798+ meth,
2799+ FastSeq [Param ](cb.this_, CodeParam (region), CodeParam (errorID)) ++ codeArgs.map(
2800+ pc =>
2801+ pc : Param
2802+ ): _*
2803+ )
2804+ }
2805+
2806+ case impl : MissingnessAwareJVMFunction =>
2807+ val codeArgs = args.map(a => EmitCode .fromI(cb.emb)(emitInNewBuilder(_, a)))
2808+ val unified = impl.unify(typeArgs, args.map(_.typ), rt)
2809+ assert(unified)
2810+ val retType = impl.computeReturnEmitType(ir.typ, codeArgs.map(_.emitType))
2811+ impl.apply(cb, region, retType.st, typeArgs, errorID, codeArgs : _* )
2812+ }
2813+
27742814 case x @ ApplySeeded (_, args, rngState, staticUID, rt) =>
27752815 val codeArgs = args.map(a => EmitCode .fromI(cb.emb)(emitInNewBuilder(_, a)))
27762816 val codeArgsMem = codeArgs.map(_.memoize(cb, " ApplySeeded_arg" ))
27772817 val state = emitI(rngState).getOrAssert(cb)
27782818 val impl = x.implementation
27792819 assert(impl.unify(Array .empty[Type ], x.argTypes, rt))
27802820 val newState = EmitCode .present(mb, state.asRNGState.splitStatic(cb, staticUID))
2781- impl.applyI(
2821+ impl.asInstanceOf [ MissingnessObliviousJVMFunction ]. applyI(
27822822 region,
27832823 cb,
27842824 impl.computeReturnEmitType(x.typ, newState.emitType +: codeArgs.map(_.emitType)).st,
@@ -3497,45 +3537,6 @@ class Emit[C](val ctx: EmitContext, val cb: EmitClassBuilder[C]) {
34973537 )
34983538 ev.load
34993539
3500- case ir @ Apply (fn, typeArgs, args, rt, errorID) =>
3501- val impl = ir.implementation
3502- val unified = impl.unify(typeArgs, args.map(_.typ), rt)
3503- assert(unified)
3504-
3505- val emitArgs = args.map(a => EmitCode .fromI(mb)(emitI(a, _))).toFastSeq
3506-
3507- val argSTypes = emitArgs.map(_.st)
3508- val retType = impl.computeStrictReturnEmitType(ir.typ, argSTypes)
3509- val k = (fn, typeArgs, argSTypes, retType)
3510- val meth =
3511- methods.get(k) match {
3512- case Some (funcMB) =>
3513- funcMB
3514- case None =>
3515- val funcMB = impl.getAsMethod(mb.ecb, retType, typeArgs, argSTypes : _* )
3516- methods.update(k, funcMB)
3517- funcMB
3518- }
3519- EmitCode .fromI(mb) { cb =>
3520- val emitArgs = args.map(a => EmitCode .fromI(cb.emb)(emitI(a, _))).toFastSeq
3521- IEmitCode .multiMapEmitCodes(cb, emitArgs) { codeArgs =>
3522- cb.invokeSCode(
3523- meth,
3524- FastSeq [Param ](cb.this_, CodeParam (region), CodeParam (errorID)) ++ codeArgs.map(pc =>
3525- pc : Param
3526- ): _*
3527- )
3528- }
3529- }
3530-
3531- case x @ ApplySpecial (_, typeArgs, args, rt, errorID) =>
3532- val codeArgs = args.map(a => emit(a))
3533- val impl = x.implementation
3534- val unified = impl.unify(typeArgs, args.map(_.typ), rt)
3535- assert(unified)
3536- val retType = impl.computeReturnEmitType(x.typ, codeArgs.map(_.emitType))
3537- impl.apply(mb, region, retType.st, typeArgs, errorID, codeArgs : _* )
3538-
35393540 case WritePartition (stream, pctx, writer) =>
35403541 val ctxCode = emit(pctx)
35413542 val streamCode = emitStream(stream, region)
0 commit comments