diff --git a/engine/common/src/main/java/org/enso/common/Asserts.java b/engine/common/src/main/java/org/enso/common/Asserts.java new file mode 100644 index 000000000000..8d3001f636a4 --- /dev/null +++ b/engine/common/src/main/java/org/enso/common/Asserts.java @@ -0,0 +1,14 @@ +package org.enso.common; + +public final class Asserts { + private Asserts() { + } + + public static void assertInJvm(boolean check) { + assert check; + } + + public static void assertInJvm(boolean check, String msg) { + assert check : msg; + } +} diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/context/LocalScope.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/context/LocalScope.scala index 4054d26b5ead..bb6c7eb2ed6c 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/context/LocalScope.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/context/LocalScope.scala @@ -107,7 +107,7 @@ class LocalScope( symbolsProvider: () => FrameVariableNames = null ): LocalScope = { val sp = if (flattenToParent) { - assert(symbolsProvider == null) + org.enso.common.Asserts.assertInJvm(symbolsProvider == null) this.symbolsProvider } else { symbolsProvider diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/data/BindingsMap.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/data/BindingsMap.scala index dea0795eeeb1..cea6cc861314 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/data/BindingsMap.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/data/BindingsMap.scala @@ -428,12 +428,12 @@ object BindingsMap { exportedAs: Option[String], symbols: List[String] ) { - assert( + org.enso.common.Asserts.assertInJvm( symbols.forall(!_.contains(".")), "Not expected fully qualified names as symbols" ) if (exportedAs.isDefined) { - assert( + org.enso.common.Asserts.assertInJvm( !exportedAs.get.contains("."), "Not expected fully qualified name as `exportedAs`" ) @@ -492,8 +492,8 @@ object BindingsMap { exports: List[ir.module.scope.Export.Module], targets: List[ImportTarget] ) { - assert(targets.nonEmpty) - assert( + org.enso.common.Asserts.assertInJvm(targets.nonEmpty) + org.enso.common.Asserts.assertInJvm( areTargetsConsistent(), "All targets must be either static methods or conversion methods" ) diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala index 5d477d4efaaa..a524f70ebff6 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala @@ -336,11 +336,11 @@ case object FramePointerAnalysis extends IRPass { scope: Graph.Scope, defOcc: GraphOccurrence.Def ): Int = { - assert( + org.enso.common.Asserts.assertInJvm( graph.scopeFor(defOcc.id).contains(scope), "Def occurrence must be in the given scope" ) - assert( + org.enso.common.Asserts.assertInJvm( scope.allDefinitions.contains(defOcc), "The given scope must contain the given Def occurrence" ) diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/alias/graph/Graph.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/alias/graph/Graph.scala index edf167ef724f..21abf4d890ca 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/alias/graph/Graph.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/alias/graph/Graph.scala @@ -55,7 +55,7 @@ sealed class Graph( * @param sym the symbol occurrence */ def addGlobalSymbol(sym: GraphOccurrence.Global): Unit = { - assert(!frozen) + org.enso.common.Asserts.assertInJvm(!frozen) if (!globalSymbols.contains(sym.symbol)) { globalSymbols = globalSymbols + (sym.symbol -> sym) } @@ -116,7 +116,8 @@ sealed class Graph( } private def addSourceTargetLink(link: Graph.Link): Unit = { - assert(!frozen) + // commented out: used from DebugEvalNode + // org.enso.common.Asserts.assertInJvm(!frozen) sourceLinks = sourceLinks.updatedWith(link.source)(v => v.map(s => s + link).orElse(Some(Set(link))) ) @@ -382,7 +383,7 @@ object Graph { * @return this scope with parent scope set */ def withParent(parentScope: Scope): this.type = { - assert(parent.isEmpty) + org.enso.common.Asserts.assertInJvm(parent.isEmpty) this.parent = Some(parentScope) this } @@ -697,7 +698,7 @@ object Graph { /** Disassociates this Scope from its parent. */ def removeScopeFromParent(): Unit = { - assert(this.parent.nonEmpty) + org.enso.common.Asserts.assertInJvm(this.parent.nonEmpty) this.parent.foreach(_.removeScopeFromParent(this)) } } diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/FunctionBinding.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/FunctionBinding.scala index b17fb09632f1..1b5efd6a0aa1 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/FunctionBinding.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/FunctionBinding.scala @@ -180,7 +180,8 @@ case object FunctionBinding extends IRPass { errors.Conversion.MissingSourceType(args.head.name.name) ) } else { - assert(!isPrivate, "Should be handled by previous match") + org.enso.common.Asserts + .assertInJvm(!isPrivate, "Should be handled by previous match") val firstArg :: restArgs = args val firstArgumentType = firstArg.ascribedType.get val firstArgumentName = firstArg.name diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/MethodDefinitions.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/MethodDefinitions.scala index 03072c3e1dec..4bb76a610202 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/MethodDefinitions.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/MethodDefinitions.scala @@ -103,7 +103,8 @@ case object MethodDefinitions extends IRPass { ) match { case Some(Resolution(ResolvedType(_, tp))) if canGenerateStaticWrappers(tp) => - assert(method.body.isInstanceOf[Function.Lambda]) + org.enso.common.Asserts + .assertInJvm(method.body.isInstanceOf[Function.Lambda]) val dup = method.duplicate() // This is the self argument that will receive the `SelfType.type` value upon dispatch, it is added to avoid modifying the dispatch mechanism. val syntheticModuleSelfArg = DefinitionArgument.Specified( @@ -197,7 +198,10 @@ case object MethodDefinitions extends IRPass { errors.Resolution.ResolverError(err) ) case Right(resolvedItems) => - assert(resolvedItems.size == 1, "Expected a single resolution") + org.enso.common.Asserts.assertInJvm( + resolvedItems.size == 1, + "Expected a single resolution" + ) resolvedItems.head match { case _: BindingsMap.ResolvedConstructor => errors.Resolution( diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/Patterns.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/Patterns.scala index 36033c97358f..e2914b67881a 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/Patterns.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/Patterns.scala @@ -88,7 +88,8 @@ object Patterns extends IRPass { bindingsMap.resolveQualifiedName(parts) match { case Left(err) => Left(err) case Right(resolvedNames) => - assert(resolvedNames.size == 1, "Expected a single resolution") + org.enso.common.Asserts + .assertInJvm(resolvedNames.size == 1, "Expected a single resolution") Right(resolvedNames.head) } } @@ -104,7 +105,8 @@ object Patterns extends IRPass { bindingsMap.resolveQualifiedNameIn(scope, submoduleNames, finalItem) match { case Left(err) => Left(err) case Right(resolvedNames) => - assert(resolvedNames.size == 1, "Expected a single resolution") + org.enso.common.Asserts + .assertInJvm(resolvedNames.size == 1, "Expected a single resolution") Right(resolvedNames.head) } } @@ -118,7 +120,8 @@ object Patterns extends IRPass { bindingsMap.resolveName(name) match { case Left(err) => Left(err) case Right(resolvedNames) => - assert(resolvedNames.size == 1, "Expected a single resolution") + org.enso.common.Asserts + .assertInJvm(resolvedNames.size == 1, "Expected a single resolution") Right(resolvedNames.head) } } diff --git a/engine/runtime/src/main/scala/org/enso/interpreter/runtime/DefaultPackageRepository.scala b/engine/runtime/src/main/scala/org/enso/interpreter/runtime/DefaultPackageRepository.scala index 976fa8ddfd14..6abdb97a8767 100644 --- a/engine/runtime/src/main/scala/org/enso/interpreter/runtime/DefaultPackageRepository.scala +++ b/engine/runtime/src/main/scala/org/enso/interpreter/runtime/DefaultPackageRepository.scala @@ -489,7 +489,7 @@ private class DefaultPackageRepository( syntheticModule: Module, refs: List[QualifiedName] ): Unit = { - assert(syntheticModule.isSynthetic) + org.enso.common.Asserts.assertInJvm(syntheticModule.isSynthetic) if (!loadedModules.contains(syntheticModule.getName.toString)) { loadedModules.put( syntheticModule.getName.toString, @@ -497,7 +497,7 @@ private class DefaultPackageRepository( ) } else { val loaded = loadedModules(syntheticModule.getName.toString) - assert(!loaded.isSynthetic) + org.enso.common.Asserts.assertInJvm(!loaded.isSynthetic) loaded .asInstanceOf[TruffleCompilerContext.Module] .unsafeModule() diff --git a/engine/runtime/src/main/scala/org/enso/interpreter/runtime/IrToTruffle.scala b/engine/runtime/src/main/scala/org/enso/interpreter/runtime/IrToTruffle.scala index fa2a01f0f469..c7b47140b4a1 100644 --- a/engine/runtime/src/main/scala/org/enso/interpreter/runtime/IrToTruffle.scala +++ b/engine/runtime/src/main/scala/org/enso/interpreter/runtime/IrToTruffle.scala @@ -1088,7 +1088,7 @@ class IrToTruffle( asAssociatedType(actualModule), method.name ) - assert( + org.enso.common.Asserts.assertInJvm( fun != null, s"exported symbol `${method.name}` needs to be registered first in the module " ) @@ -1106,7 +1106,7 @@ class IrToTruffle( case Right(List(BindingsMap.ResolvedType(modWithTp, _))) => val tpScope = asScope(modWithTp.unsafeAsModule()) val tp = tpScope.getType(staticMethod.tpName, true) - assert( + org.enso.common.Asserts.assertInJvm( tp != null, s"Type should be defined in module ${modWithTp.getName}" ) @@ -1118,7 +1118,7 @@ class IrToTruffle( eigenTp, staticMethod.methodName ) - assert( + org.enso.common.Asserts.assertInJvm( fun != null, s"exported symbol (static method) `${staticMethod.name}` needs to be registered first in the module " ) @@ -1147,7 +1147,7 @@ class IrToTruffle( val targetTpScope = asScope(modWithTargetTp.unsafeAsModule()) val targetTp = targetTpScope.getType(conversionMethod.targetTpName, true) - assert( + org.enso.common.Asserts.assertInJvm( targetTp != null, s"Target type should be defined in module ${module.getName}" ) @@ -1163,7 +1163,7 @@ class IrToTruffle( conversionMethod.sourceTpName, true ) - assert( + org.enso.common.Asserts.assertInJvm( sourceTp != null, s"Source type should be defined in module ${module.getName}" ) @@ -1172,7 +1172,7 @@ class IrToTruffle( sourceTp, targetTp ) - assert( + org.enso.common.Asserts.assertInJvm( conversionFun != null, s"Conversion method `$conversionMethod` should be defined in module ${module.getName}" ) @@ -2570,7 +2570,7 @@ class IrToTruffle( // Note [Handling Suspended Defaults] val defaultedValue = if (arg.suspended && defaultExpression != null) { - assert(arg.defaultValue.isDefined) + org.enso.common.Asserts.assertInJvm(arg.defaultValue.isDefined) val defaultRootNode = ClosureRootNode.build( language, scope,