Skip to content

Commit

Permalink
Resolve code review comments
Browse files Browse the repository at this point in the history
* split off just to get the obvious stuff up in an easily reviewed form.
  • Loading branch information
ekmett authored and kustosz committed Jun 16, 2022
1 parent 4320a04 commit ba952e5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AtomConstructor> variants;
private @CompilerDirectives.CompilationFinal(dimensions = 1) AtomConstructor[] variants;

/**
* Creates a new Atom constructor for a given name. The constructor is not valid until {@link
Expand Down Expand Up @@ -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<AtomConstructor> getVariants() { return variants; }
public AtomConstructor[] getVariants() {
if (variants == null) throw new IllegalStateException("variants not initialized");
return variants.clone();
}

public void setVariants(List<AtomConstructor> 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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit ba952e5

Please sign in to comment.