@@ -3,6 +3,7 @@ package is.hail.expr.ir
33import is .hail .annotations .Region
44import is .hail .asm4s ._
55import is .hail .backend .ExecuteContext
6+ import is .hail .expr .ir .LoweredTableReader .LoweredTableReaderCoercer
67import is .hail .expr .ir .defs .{Literal , PartitionReader , ReadPartition , ToStream }
78import is .hail .expr .ir .functions .UtilFunctions
89import is .hail .expr .ir .lowering .{TableStage , TableStageDependency }
@@ -144,16 +145,6 @@ class PartitionIteratorLongReader(
144145 )
145146}
146147
147- abstract class LoweredTableReaderCoercer {
148- def coerce (
149- ctx : ExecuteContext ,
150- globals : IR ,
151- contextType : Type ,
152- contexts : IndexedSeq [Any ],
153- body : IR => IR ,
154- ): TableStage
155- }
156-
157148class GenericTableValue (
158149 val fullTableType : TableType ,
159150 val uidFieldName : String ,
@@ -169,12 +160,11 @@ class GenericTableValue(
169160 assert(contextType.hasField(" partitionIndex" ))
170161 assert(contextType.fieldType(" partitionIndex" ) == TInt32 )
171162
172- private var ltrCoercer : LoweredTableReaderCoercer = _
173-
174163 private def getLTVCoercer (ctx : ExecuteContext , context : String , cacheKey : Any )
175- : LoweredTableReaderCoercer = {
176- if (ltrCoercer == null ) {
177- ltrCoercer = LoweredTableReader .makeCoercer(
164+ : LoweredTableReaderCoercer =
165+ ctx.CoercerCache .getOrElseUpdate(
166+ (1 , contextType, fullTableType.key, cacheKey),
167+ LoweredTableReader .makeCoercer(
178168 ctx,
179169 fullTableType.key,
180170 1 ,
@@ -185,11 +175,8 @@ class GenericTableValue(
185175 bodyPType,
186176 body,
187177 context,
188- cacheKey,
189- )
190- }
191- ltrCoercer
192- }
178+ ),
179+ )
193180
194181 def toTableStage (ctx : ExecuteContext , requestedType : TableType , context : String , cacheKey : Any )
195182 : TableStage = {
@@ -218,11 +205,13 @@ class GenericTableValue(
218205 val contextsIR = ToStream (Literal (TArray (contextType), contexts))
219206 TableStage (globalsIR, p, TableStageDependency .none, contextsIR, requestedBody)
220207 } else {
221- getLTVCoercer(ctx, context, cacheKey).coerce (
208+ getLTVCoercer(ctx, context, cacheKey)(
222209 ctx,
223210 globalsIR,
224- contextType, contexts,
225- requestedBody)
211+ contextType,
212+ contexts,
213+ requestedBody,
214+ )
226215 }
227216 }
228217}
0 commit comments