diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/AtomConstructor.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/AtomConstructor.java index a2f235901ad6..b6b392a42f87 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/AtomConstructor.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/AtomConstructor.java @@ -45,7 +45,7 @@ public final class AtomConstructor implements TruffleObject { private @CompilerDirectives.CompilationFinal Function constructorFunction; private @CompilerDirectives.CompilationFinal AtomConstructor parentType; - private @CompilerDirectives.CompilationFinal scala.collection.immutable.List variants; + private @CompilerDirectives.CompilationFinal(dimensions = 1) AtomConstructor[] variants; /** * Creates a new Atom constructor for a given name. The constructor is not valid until {@link @@ -257,21 +257,34 @@ public String toString() { * * @return the parent of this atom constructor if it is a variant in a sum type, null otherwise */ - public AtomConstructor getParentType() { return parentType; } + public AtomConstructor getParentType() { + return parentType; + } public void setParentType(AtomConstructor parent) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + if (parentType != null) throw new IllegalStateException("parent type already initialized"); parentType = parent; } /** - * Gets the list of all variants of this constructor if this is a variant in a sum type. + * Gets the array of all variants of this constructor if this is a variant in a sum type. * - * @return + * @return the array of variants */ - public List getVariants() { return variants; } + public AtomConstructor[] getVariants() { + if (variants == null) throw new IllegalStateException("variants not initialized"); + return variants.clone(); + } - public void setVariants(List variantConstructors) { - variants = variantConstructors; + /** + * Sets the array of all variants of this constructor when used as a sum type. + */ + + public void setVariants(AtomConstructor[] variantConstructors) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + if (variants != null) throw new IllegalStateException("variants already initialized"); + variants = variantConstructors.clone(); } /** diff --git a/engine/runtime/src/main/scala/org/enso/compiler/codegen/RuntimeStubsGenerator.scala b/engine/runtime/src/main/scala/org/enso/compiler/codegen/RuntimeStubsGenerator.scala index c249e34d8292..4c023e7695f8 100644 --- a/engine/runtime/src/main/scala/org/enso/compiler/codegen/RuntimeStubsGenerator.scala +++ b/engine/runtime/src/main/scala/org/enso/compiler/codegen/RuntimeStubsGenerator.scala @@ -42,7 +42,7 @@ class RuntimeStubsGenerator(builtins: Builtins) { // link parents to variants and vice versa constructors.foreach { case (tp,tcons) => val variants = tp.variants.map(scope.getConstructor(_).get()).toList; - tcons.setVariants(variants); + tcons.setVariants(variants.toArray); variants.foreach(_.setParentType(tcons)); } } diff --git a/engine/runtime/src/main/scala/org/enso/compiler/phase/StubIrBuilder.scala b/engine/runtime/src/main/scala/org/enso/compiler/phase/StubIrBuilder.scala index 29867026b52e..182a14dfb3de 100644 --- a/engine/runtime/src/main/scala/org/enso/compiler/phase/StubIrBuilder.scala +++ b/engine/runtime/src/main/scala/org/enso/compiler/phase/StubIrBuilder.scala @@ -3,10 +3,10 @@ package org.enso.compiler.phase import org.enso.compiler.core.IR import org.enso.compiler.core.ir.MetadataStorage._ import org.enso.compiler.data.BindingsMap -import org.enso.compiler.data.BindingsMap.{ModuleReference, ResolvedConstructor, ResolvedMethod} import org.enso.compiler.pass.analyse.BindingAnalysis import org.enso.interpreter.runtime.Module +import scala.collection.immutable.ArraySeq import scala.jdk.CollectionConverters._ /** Builds an IR stub. This is useful for source-less modules (such as @@ -31,7 +31,7 @@ object StubIrBuilder { cons.getArity, allFieldsDefaulted = false, builtinType = false, - variants = cons.getVariants.map(_.getName) + variants = ArraySeq.unsafeWrapArray(cons.getVariants).map(_.getName) ); } val moduleMethods = Option(scope.getMethods.get(scope.getAssociatedType)) @@ -47,16 +47,16 @@ object StubIrBuilder { val exportedBindings = definedConstructors.map(c => ( c.name.toLowerCase, - List(ResolvedConstructor(ModuleReference.Concrete(module), c)) + List(BindingsMap.ResolvedConstructor(BindingsMap.ModuleReference.Concrete(module), c)) ) ) ++ moduleMethods.map(m => - (m.name, List(ResolvedMethod(ModuleReference.Concrete(module), m))) + (m.name, List(BindingsMap.ResolvedMethod(BindingsMap.ModuleReference.Concrete(module), m))) ) val meta = BindingsMap( definedConstructors, polyglot, moduleMethods, - ModuleReference.Concrete(module) + BindingsMap.ModuleReference.Concrete(module) ) meta.exportedSymbols = exportedBindings.toMap ir.updateMetadata(BindingAnalysis -->> meta)