diff --git a/hail/src/main/scala/is/hail/HailContext.scala b/hail/src/main/scala/is/hail/HailContext.scala index f52efe60ee7..b7028fe2b01 100644 --- a/hail/src/main/scala/is/hail/HailContext.scala +++ b/hail/src/main/scala/is/hail/HailContext.scala @@ -19,7 +19,6 @@ import org.apache.spark.executor.InputMetrics import org.apache.spark.rdd.RDD import org.json4s.Extraction import org.json4s.jackson.JsonMethods -import sourcecode.Enclosing case class FilePartition(index: Int, file: String) extends Partition @@ -42,7 +41,7 @@ object HailContext { def backend: Backend = get.backend - def sparkBackend(implicit E: Enclosing): SparkBackend = get.backend.asSpark + def sparkBackend(implicit E: SourcePos): SparkBackend = get.backend.asSpark def configureLogging(logFile: String, quiet: Boolean, append: Boolean): Unit = { org.apache.log4j.helpers.LogLog.setInternalDebugging(true) diff --git a/hail/src/main/scala/is/hail/backend/Backend.scala b/hail/src/main/scala/is/hail/backend/Backend.scala index 4ca7147e25d..62d1e8ad096 100644 --- a/hail/src/main/scala/is/hail/backend/Backend.scala +++ b/hail/src/main/scala/is/hail/backend/Backend.scala @@ -9,14 +9,13 @@ import is.hail.io.fs.FS import is.hail.types.RTable import is.hail.types.encoded.EType import is.hail.types.physical.PTuple -import is.hail.utils.fatal +import is.hail.utils.{fatal, SourcePos} import scala.reflect.ClassTag import java.io.{Closeable, OutputStream} import com.fasterxml.jackson.core.StreamReadConstraints -import sourcecode.Enclosing object Backend { @@ -85,7 +84,7 @@ abstract class Backend extends Closeable { def close(): Unit - def asSpark(implicit E: Enclosing): SparkBackend = + def asSpark(implicit E: SourcePos): SparkBackend = fatal(s"${getClass.getSimpleName}: ${E.value} requires SparkBackend") def lowerDistributedSort( diff --git a/hail/src/main/scala/is/hail/backend/ExecuteContext.scala b/hail/src/main/scala/is/hail/backend/ExecuteContext.scala index ff8cb0d9d87..2c1d2aa722a 100644 --- a/hail/src/main/scala/is/hail/backend/ExecuteContext.scala +++ b/hail/src/main/scala/is/hail/backend/ExecuteContext.scala @@ -17,8 +17,6 @@ import scala.collection.mutable import java.io._ import java.security.SecureRandom -import sourcecode.Enclosing - trait TempFileManager extends AutoCloseable { def newTmpPath(tmpdir: String, prefix: String, extension: String = null): String } @@ -150,7 +148,7 @@ class ExecuteContext( def scopedExecution[T]( f: (HailClassLoader, FS, HailTaskContext, Region) => T - )(implicit E: Enclosing + )(implicit E: SourcePos ): T = using(new LocalTaskContext(0, 0)) { tc => time { @@ -176,7 +174,7 @@ class ExecuteContext( taskContext.close() } - def time[A](block: => A)(implicit E: Enclosing): A = + def time[A](block: => A)(implicit E: SourcePos): A = timer.time(E.value)(block) def local[A]( diff --git a/hail/src/main/scala/is/hail/backend/api/Py4JBackendApi.scala b/hail/src/main/scala/is/hail/backend/api/Py4JBackendApi.scala index cfbe7112cc1..4d106bc89ed 100644 --- a/hail/src/main/scala/is/hail/backend/api/Py4JBackendApi.scala +++ b/hail/src/main/scala/is/hail/backend/api/Py4JBackendApi.scala @@ -42,7 +42,6 @@ import org.apache.spark.sql.DataFrame import org.json4s import org.json4s._ import org.json4s.jackson.{JsonMethods, Serialization} -import sourcecode.Enclosing final class Py4JBackendApi(backend: Backend) extends Closeable with ErrorHandling { @@ -298,7 +297,7 @@ final class Py4JBackendApi(backend: Backend) extends Closeable with ErrorHandlin selfContainedExecution: Boolean = true )( f: ExecuteContext => T - )(implicit E: Enclosing + )(implicit E: SourcePos ): (T, Timings) = ExecutionTimer.time { timer => ExecuteContext.scoped( diff --git a/hail/src/main/scala/is/hail/backend/spark/SparkBackend.scala b/hail/src/main/scala/is/hail/backend/spark/SparkBackend.scala index da36fcee670..671c1f07d17 100644 --- a/hail/src/main/scala/is/hail/backend/spark/SparkBackend.scala +++ b/hail/src/main/scala/is/hail/backend/spark/SparkBackend.scala @@ -30,7 +30,6 @@ import org.apache.spark._ import org.apache.spark.broadcast.Broadcast import org.apache.spark.rdd.RDD import org.apache.spark.sql.SparkSession -import sourcecode.Enclosing class SparkBroadcastValue[T](bc: Broadcast[T]) extends BroadcastValue[T] with Serializable { def value: T = bc.value @@ -71,7 +70,7 @@ object SparkBackend { private var theSparkBackend: SparkBackend = _ - def sparkContext(implicit E: Enclosing): SparkContext = HailContext.sparkBackend.sc + def sparkContext(implicit E: SourcePos): SparkContext = HailContext.sparkBackend.sc def checkSparkCompatibility(jarVersion: String, sparkVersion: String): Unit = { def majorMinor(version: String): String = version.split("\\.", 3).take(2).mkString(".") @@ -352,7 +351,7 @@ class SparkBackend(val sc: SparkContext) extends Backend { def defaultParallelism: Int = sc.defaultParallelism - override def asSpark(implicit E: Enclosing): SparkBackend = this + override def asSpark(implicit E: SourcePos): SparkBackend = this def close(): Unit = SparkBackend.stop() diff --git a/hail/src/main/scala/is/hail/expr/ir/Compile.scala b/hail/src/main/scala/is/hail/expr/ir/Compile.scala index ecb4e0d06d7..fec4b42741c 100644 --- a/hail/src/main/scala/is/hail/expr/ir/Compile.scala +++ b/hail/src/main/scala/is/hail/expr/ir/Compile.scala @@ -17,8 +17,6 @@ import is.hail.utils._ import java.io.PrintWriter -import sourcecode.Enclosing - case class CodeCacheKey( aggSigs: IndexedSeq[AggStateSig], args: Seq[(Name, EmitParamType)], @@ -89,7 +87,7 @@ object compile { optimize: Boolean, print: Option[PrintWriter], )(implicit - E: Enclosing, + E: SourcePos, N: sourcecode.Name, ): (Option[SingleCodeType], (HailClassLoader, FS, HailTaskContext, Region) => F with Mixin) = ctx.time { @@ -131,7 +129,7 @@ object compile { CompiledFunction(rt, fb.resultWithIndex(print)) }, ).asInstanceOf[CompiledFunction[F with Mixin]].tuple - } + }(E) } object CompileIterator { diff --git a/hail/src/main/scala/is/hail/expr/ir/lowering/IRState.scala b/hail/src/main/scala/is/hail/expr/ir/lowering/IRState.scala index 3d4dcfbd264..752c358a749 100644 --- a/hail/src/main/scala/is/hail/expr/ir/lowering/IRState.scala +++ b/hail/src/main/scala/is/hail/expr/ir/lowering/IRState.scala @@ -5,8 +5,9 @@ import is.hail.expr.ir.{ BaseIR, IRTraversal, RelationalLet, RelationalRef, TableKeyBy, TableKeyByAndAggregate, TableOrderBy, } +import is.hail.utils.SourcePos -abstract class IRState(implicit E: sourcecode.Enclosing) { +abstract class IRState(implicit E: SourcePos) { protected val rules: Array[Rule] final def verify(ctx: ExecuteContext, ir: BaseIR): Unit = @@ -19,7 +20,7 @@ abstract class IRState(implicit E: sourcecode.Enclosing) { } } - def +(other: IRState)(implicit E: sourcecode.Enclosing): IRState = { + def +(other: IRState)(implicit E: SourcePos): IRState = { val newRules = rules ++ other.rules new IRState()(E) { val rules: Array[Rule] = newRules diff --git a/hail/src/main/scala/is/hail/expr/ir/lowering/LoweringPass.scala b/hail/src/main/scala/is/hail/expr/ir/lowering/LoweringPass.scala index dd8975ad263..bd1a028d5c7 100644 --- a/hail/src/main/scala/is/hail/expr/ir/lowering/LoweringPass.scala +++ b/hail/src/main/scala/is/hail/expr/ir/lowering/LoweringPass.scala @@ -23,7 +23,7 @@ final class IrMetadata() { } } -abstract class LoweringPass(implicit E: sourcecode.Enclosing) { +abstract class LoweringPass(implicit E: SourcePos) { val before: IRState val after: IRState val context: String diff --git a/hail/src/main/scala/is/hail/utils/ExecutionTimer.scala b/hail/src/main/scala/is/hail/utils/ExecutionTimer.scala index c7be2c63f7d..4fa6f69ee05 100644 --- a/hail/src/main/scala/is/hail/utils/ExecutionTimer.scala +++ b/hail/src/main/scala/is/hail/utils/ExecutionTimer.scala @@ -6,11 +6,10 @@ import scala.collection.mutable import org.json4s.{JArray, JString, JValue} import org.json4s.JsonAST.JLong -import sourcecode.Enclosing object ExecutionTimer { - def time[T](f: ExecutionTimer => T)(implicit E: Enclosing): (T, Timings) = { + def time[T](f: ExecutionTimer => T)(implicit E: SourcePos): (T, Timings) = { val timer = new ExecutionTimer(E.value) val result = f(timer) timer.finish() @@ -18,7 +17,7 @@ object ExecutionTimer { (result, timer.result) } - def logTime[T](f: ExecutionTimer => T)(implicit E: Enclosing): T = { + def logTime[T](f: ExecutionTimer => T)(implicit E: SourcePos): T = { val (result, _) = time[T](f) result } diff --git a/hail/src/main/scala/is/hail/utils/package.scala b/hail/src/main/scala/is/hail/utils/package.scala index 36fc0b91c70..ba607f4fc5c 100644 --- a/hail/src/main/scala/is/hail/utils/package.scala +++ b/hail/src/main/scala/is/hail/utils/package.scala @@ -1075,6 +1075,8 @@ package object utils implicit def evalLazy[A](f: Lazy[A]): A = f() + + type SourcePos = sourcecode.FullName } class CancellingExecutorService(delegate: ExecutorService) extends AbstractExecutorService {