Skip to content

Commit

Permalink
add ImmutableMap to prevent BM persist where unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
ehigham committed Oct 8, 2024
1 parent cb6b260 commit 360af7c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LocalBackend(
ExecutionCache.fromFlags(flags, fs, tmpdir)
},
new IrMetadata(),
mutable.Map.empty,
ImmutableMap.empty,
)(f)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class ServiceBackend(
flags,
serviceBackendContext,
new IrMetadata(),
mutable.Map.empty,
ImmutableMap.empty,
)(f)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class SparkBackend(
ExecutionCache.forTesting
},
new IrMetadata(),
null,
ImmutableMap.empty,
)

override def withExecuteContext[T](f: ExecuteContext => T)(implicit E: Enclosing): T =
Expand Down
1 change: 1 addition & 0 deletions hail/src/main/scala/is/hail/expr/ir/BlockMatrixIR.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package is.hail.expr.ir

import is.hail.annotations.NDArray
import is.hail.backend.ExecuteContext
import is.hail.expr.Nat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package is.hail.expr.ir

import is.hail.annotations.Region
import is.hail.asm4s._
import is.hail.backend.ExecuteContext
Expand Down
25 changes: 25 additions & 0 deletions hail/src/main/scala/is/hail/utils/ImmutableMap.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package is.hail.utils

import scala.collection.mutable

case class ImmutableMap[K, V](m: Map[K, V]) extends mutable.AbstractMap[K, V] {
override def +=(kv: (K, V)): ImmutableMap.this.type =
throw new UnsupportedOperationException()

override def -=(key: K): ImmutableMap.this.type =
throw new UnsupportedOperationException()

override def get(key: K): Option[V] =
m.get(key)

override def iterator: Iterator[(K, V)] =
m.iterator

override def toMap[T, U](implicit ev: (K, V) <:< (T, U)): Map[T, U] =
m.toMap
}

object ImmutableMap {
def empty[K, V]: ImmutableMap[K, V] =
ImmutableMap(Map.empty)
}
7 changes: 7 additions & 0 deletions hail/src/main/scala/is/hail/utils/richUtils/RichMap.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package is.hail.utils.richUtils

import is.hail.utils.ImmutableMap

import scala.collection.mutable

class RichMap[K, V](val m: Map[K, V]) extends AnyVal {
def force =
m.map(identity) // needed to make serializable: https://issues.scala-lang.org/browse/SI-7005
Expand All @@ -9,4 +13,7 @@ class RichMap[K, V](val m: Map[K, V]) extends AnyVal {

def isTrivial(implicit eq: K =:= V): Boolean =
m.forall { case (k, v) => k == v }

def immutableMutableMap: mutable.Map[K, V] =
ImmutableMap(m)
}

0 comments on commit 360af7c

Please sign in to comment.