@@ -3,7 +3,6 @@ package is.hail.backend
33import is .hail .HailFeatureFlags
44import is .hail .annotations .{Region , RegionPool }
55import is .hail .asm4s .HailClassLoader
6- import is .hail .backend .local .LocalTaskContext
76import is .hail .expr .ir .{BaseIR , CompileCache , Compiled }
87import is .hail .expr .ir .LoweredTableReader .LoweredTableReaderCoercer
98import is .hail .expr .ir .lowering .IrMetadata
@@ -72,7 +71,7 @@ object ExecuteContext {
7271 coercerCache : mutable.Map [Any , LoweredTableReaderCoercer ],
7372 )(
7473 f : ExecuteContext => T
75- ): T = {
74+ ): T =
7675 RegionPool .scoped { pool =>
7776 pool.scopedRegion { region =>
7877 using(new ExecuteContext (
@@ -94,7 +93,6 @@ object ExecuteContext {
9493 ))(f(_))
9594 }
9695 }
97- }
9896
9997 def createTmpPathNoCleanup (tmpdir : String , prefix : String , extension : String = null ): String = {
10098 val random = new SecureRandom ()
@@ -113,7 +111,7 @@ class ExecuteContext(
113111 val backend : Backend ,
114112 val references : Map [String , ReferenceGenome ],
115113 val fs : FS ,
116- val r : Region ,
114+ override val r : Region ,
117115 val timer : ExecutionTimer ,
118116 val tempFileManager : TempFileManager ,
119117 val theHailClassLoader : HailClassLoader ,
@@ -123,7 +121,7 @@ class ExecuteContext(
123121 val CompileCache : CompileCache ,
124122 val PersistedIrCache : mutable.Map [Int , BaseIR ],
125123 val PersistedCoercerCache : mutable.Map [Any , LoweredTableReaderCoercer ],
126- ) extends Closeable {
124+ ) extends HailTaskContext with Closeable {
127125
128126 val rngNonce : Long =
129127 try
@@ -142,10 +140,14 @@ class ExecuteContext(
142140
143141 val memo : mutable.Map [Any , Any ] = new mutable.HashMap [Any , Any ]()
144142
145- val taskContext : HailTaskContext = new LocalTaskContext (0 , 0 )
143+ private [this ] val onCloseTasks = mutable.ArrayBuffer .empty[() => Unit ]
144+ override def onClose (f : () => Unit ): Unit = onCloseTasks += f
145+
146+ def run [A ](f : Compiled [A ])(implicit E : Enclosing ): A =
147+ time(f(theHailClassLoader, fs, this , r))
146148
147149 def scopedExecution [T ](f : Compiled [T ])(implicit E : Enclosing ): T =
148- using( new LocalTaskContext ( 0 , 0 ))(tc => time(f(theHailClassLoader, fs, tc, r )))
150+ r.pool.scopedRegion(r => local(r = r)(_.run(f )))
149151
150152 def createTmpPath (prefix : String , extension : String = null , local : Boolean = false ): String =
151153 tempFileManager.newTmpPath(if (local) localTmpdir else tmpdir, prefix, extension)
@@ -159,8 +161,8 @@ class ExecuteContext(
159161 def shouldLogIR (): Boolean = ! shouldNotLogIR()
160162
161163 override def close (): Unit = {
164+ onCloseTasks.foreach(_())
162165 tempFileManager.close()
163- taskContext.close()
164166 }
165167
166168 def time [A ](block : => A )(implicit E : Enclosing ): A =
@@ -179,7 +181,7 @@ class ExecuteContext(
179181 flags : HailFeatureFlags = this .flags,
180182 irMetadata : IrMetadata = this .irMetadata,
181183 blockMatrixCache : mutable.Map [String , BlockMatrix ] = this .BlockMatrixCache ,
182- codeCache : CompileCache = this .CompileCache ,
184+ compileCache : CompileCache = this .CompileCache ,
183185 persistedIrCache : mutable.Map [Int , BaseIR ] = this .PersistedIrCache ,
184186 persistedCoercerCache : mutable.Map [Any , LoweredTableReaderCoercer ] = this .PersistedCoercerCache ,
185187 )(
@@ -198,7 +200,7 @@ class ExecuteContext(
198200 flags,
199201 irMetadata,
200202 blockMatrixCache,
201- codeCache ,
203+ compileCache ,
202204 persistedIrCache,
203205 persistedCoercerCache,
204206 ))(f)
0 commit comments