From 02e77fc10703dd845420ece649cc579936a14891 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 12 Nov 2024 13:24:43 +0100 Subject: [PATCH 01/18] EnsoObject is an abstract class, not an interface. - Also, EnsoObject exports hasLanguage and getLanguage interop messages. - BranchRecord converted to class --- .../FunctionCallInstrumentationNode.java | 2 +- .../controlflow/caseexpr/BranchResult.java | 10 +++++- .../builtin/meta/AtomWithAHoleNode.java | 5 +-- .../expression/builtin/meta/Instrumentor.java | 2 +- .../org/enso/interpreter/runtime/Module.java | 2 +- .../callable/UnresolvedConstructor.java | 5 +-- .../callable/UnresolvedConversion.java | 5 +-- .../runtime/callable/UnresolvedSymbol.java | 5 +-- .../runtime/callable/function/Function.java | 5 +-- .../interpreter/runtime/data/EnsoDate.java | 2 +- .../runtime/data/EnsoDateTime.java | 2 +- .../runtime/data/EnsoDuration.java | 2 +- .../interpreter/runtime/data/EnsoFile.java | 6 ++-- .../runtime/data/EnsoMultiValue.java | 5 +-- .../interpreter/runtime/data/EnsoObject.java | 23 ++++++++++++- .../interpreter/runtime/data/EnsoSource.java | 2 +- .../runtime/data/EnsoSourceSection.java | 2 +- .../runtime/data/EnsoTimeOfDay.java | 2 +- .../runtime/data/EnsoTimeZone.java | 5 +-- .../runtime/data/ManagedResource.java | 2 +- .../enso/interpreter/runtime/data/Ref.java | 2 +- .../enso/interpreter/runtime/data/Type.java | 5 +-- .../interpreter/runtime/data/atom/Atom.java | 13 +------ .../runtime/data/atom/AtomConstructor.java | 5 +-- .../runtime/data/hash/EnsoHashMap.java | 5 +-- .../runtime/data/hash/HashEntriesVector.java | 7 ++-- .../interpreter/runtime/data/text/Text.java | 2 +- .../runtime/data/vector/Array.java | 5 +-- .../runtime/data/vector/ArrayBuilder.java | 5 +-- .../runtime/data/vector/ArrayOverBuffer.java | 5 +-- .../runtime/data/vector/ArrayProxy.java | 5 +-- .../runtime/data/vector/ArraySlice.java | 2 +- .../runtime/data/vector/Vector.java | 5 +-- .../runtime/error/DataflowError.java | 3 +- .../runtime/error/EnsoException.java | 34 +++++++++++++++++++ .../runtime/error/PanicException.java | 3 +- .../runtime/error/PanicSentinel.java | 3 +- .../runtime/number/EnsoBigInteger.java | 5 +-- .../runtime/scope/DebugLocalScope.java | 19 +++-------- .../runtime/scope/ImportExportScope.java | 2 +- .../runtime/scope/ModuleScope.java | 2 +- .../runtime/scope/TopLevelScope.java | 26 ++------------ .../interpreter/runtime/warning/Warning.java | 2 +- .../runtime/warning/WithWarnings.java | 2 +- 44 files changed, 148 insertions(+), 113 deletions(-) create mode 100644 engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/FunctionCallInstrumentationNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/FunctionCallInstrumentationNode.java index 499279dd78a0..93d38b08ee32 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/FunctionCallInstrumentationNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/FunctionCallInstrumentationNode.java @@ -56,7 +56,7 @@ public boolean isInstrumentable() { /** A simple value class for function call information. */ @ExportLibrary(InteropLibrary.class) - public static final class FunctionCall implements EnsoObject { + public static final class FunctionCall extends EnsoObject { private final Function function; private final State state; private final @CompilerDirectives.CompilationFinal(dimensions = 1) Object[] arguments; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/BranchResult.java b/engine/runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/BranchResult.java index f9c348072845..9e45c94719af 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/BranchResult.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/BranchResult.java @@ -4,7 +4,15 @@ import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.data.EnsoObject; -record BranchResult(boolean isMatched, Object result) implements EnsoObject { +final class BranchResult extends EnsoObject { + private final boolean isMatched; + private final Object result; + + BranchResult(boolean isMatched, Object result) { + this.isMatched = isMatched; + this.result = result; + } + static BranchResult failure(Node node) { return new BranchResult(false, EnsoContext.get(node).getBuiltins().nothing()); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/AtomWithAHoleNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/AtomWithAHoleNode.java index d462f44d42c7..58f75a25b85b 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/AtomWithAHoleNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/AtomWithAHoleNode.java @@ -73,7 +73,7 @@ Object doExecute( } @ExportLibrary(InteropLibrary.class) - static final class HoleInAtom implements EnsoObject { + static final class HoleInAtom extends EnsoObject { Atom result; int index; Function function; @@ -140,7 +140,8 @@ Object invokeMember( } @ExportMessage - String toDisplayString(boolean pure) { + @Override + public String toDisplayString(boolean pure) { return "Meta.atom_with_hole"; } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/Instrumentor.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/Instrumentor.java index c9a5c44f482f..2a20f732a916 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/Instrumentor.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/Instrumentor.java @@ -14,7 +14,7 @@ import org.enso.interpreter.runtime.instrument.Timer; import org.enso.polyglot.debugger.IdExecutionService; -final class Instrumentor implements EnsoObject, IdExecutionService.Callbacks { +final class Instrumentor extends EnsoObject implements IdExecutionService.Callbacks { private final IdExecutionService service; private final RootCallTarget target; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java index e7b0cbded6df..d227b22c5e4d 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java @@ -53,7 +53,7 @@ /** Represents a source module with a known location. */ @ExportLibrary(InteropLibrary.class) -public final class Module implements EnsoObject { +public final class Module extends EnsoObject { private ModuleSources sources; private QualifiedName name; private ModuleScope.Builder scopeBuilder; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java index 1933cb9e2725..3bdb889f7b28 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java @@ -48,7 +48,7 @@ */ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) -public final class UnresolvedConstructor implements EnsoObject { +public final class UnresolvedConstructor extends EnsoObject { private static final CallArgumentInfo[] NONE = new CallArgumentInfo[0]; private final String name; private final Node where; @@ -81,7 +81,8 @@ public String toString() { } @ExportMessage - String toDisplayString(boolean allowSideEffects) { + @Override + public String toDisplayString(boolean allowSideEffects) { return toString(); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConversion.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConversion.java index ddc74e20574a..96d833f64fb5 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConversion.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConversion.java @@ -22,7 +22,7 @@ /** Simple runtime value representing a yet-unresolved by-name symbol. */ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) -public final class UnresolvedConversion implements EnsoObject { +public final class UnresolvedConversion extends EnsoObject { private final ModuleScope scope; /** @@ -71,7 +71,8 @@ public String toString() { } @ExportMessage - String toDisplayString(boolean allowSideEffects) { + @Override + public String toDisplayString(boolean allowSideEffects) { return this.toString(); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedSymbol.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedSymbol.java index 37a071256f65..1f823c6c2463 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedSymbol.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedSymbol.java @@ -24,7 +24,7 @@ /** Simple runtime value representing a yet-unresolved by-name symbol. */ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) -public final class UnresolvedSymbol implements EnsoObject { +public final class UnresolvedSymbol extends EnsoObject { private final String name; private final ModuleScope scope; @@ -85,7 +85,8 @@ public String toString() { @ExportMessage @TruffleBoundary - String toDisplayString(boolean allowSideEffects) { + @Override + public String toDisplayString(boolean allowSideEffects) { return this.toString(); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/function/Function.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/function/Function.java index 527c6e614844..a0c249164262 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/function/Function.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/function/Function.java @@ -39,7 +39,7 @@ /** A runtime representation of a function object in Enso. */ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) -public final class Function implements EnsoObject { +public final class Function extends EnsoObject { private final RootCallTarget callTarget; private final MaterializedFrame scope; private final FunctionSchema schema; @@ -428,7 +428,8 @@ public boolean isFullyApplied() { } @ExportMessage - String toDisplayString(boolean sideEffects) { + @Override + public String toDisplayString(boolean sideEffects) { return toString(); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java index 2517ad1f5a2e..e0a06f9a7193 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java @@ -18,7 +18,7 @@ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) @Builtin(pkg = "date", name = "Date", stdlibName = "Standard.Base.Data.Time.Date.Date") -public final class EnsoDate implements EnsoObject { +public final class EnsoDate extends EnsoObject { private final LocalDate date; public EnsoDate(LocalDate date) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java index 8e4875a72683..d7b9b8abd851 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java @@ -25,7 +25,7 @@ pkg = "date", name = "DateTime", stdlibName = "Standard.Base.Data.Time.Date_Time.Date_Time") -public final class EnsoDateTime implements EnsoObject { +public final class EnsoDateTime extends EnsoObject { private final ZonedDateTime dateTime; public EnsoDateTime(ZonedDateTime dateTime) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDuration.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDuration.java index b8c69738f74a..ca388cd2950b 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDuration.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDuration.java @@ -22,7 +22,7 @@ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) @Builtin(pkg = "date", name = "Duration", stdlibName = "Standard.Base.Data.Time.Duration.Duration") -public final class EnsoDuration implements EnsoObject { +public final class EnsoDuration extends EnsoObject { private final Duration duration; public EnsoDuration(Duration duration) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java index 43a16cd0a667..5431225df155 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java @@ -53,7 +53,7 @@ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) @Builtin(pkg = "io", name = "File", stdlibName = "Standard.Base.System.File.File") -public final class EnsoFile implements EnsoObject { +public final class EnsoFile extends EnsoObject { private final TruffleFile truffleFile; public EnsoFile(TruffleFile truffleFile) { @@ -79,7 +79,7 @@ public EnsoObject outputStream( } @ExportLibrary(InteropLibrary.class) - static final class EnsoOutputStream implements EnsoObject { + static final class EnsoOutputStream extends EnsoObject { private static final String[] MEMBERS = new String[] {"write", "flush", "close"}; private final OutputStream os; @@ -200,7 +200,7 @@ public EnsoObject inputStream( } @ExportLibrary(InteropLibrary.class) - static final class EnsoInputStream implements EnsoObject { + static final class EnsoInputStream extends EnsoObject { private static final String[] MEMBERS = new String[] { "read", "readAllBytes", "readNBytes", "skipNBytes", "markSupported", "available", "close" diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoMultiValue.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoMultiValue.java index 1be55e9a92a6..775ae0620e98 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoMultiValue.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoMultiValue.java @@ -35,7 +35,7 @@ @ExportLibrary(TypesLibrary.class) @ExportLibrary(InteropLibrary.class) -public final class EnsoMultiValue implements EnsoObject { +public final class EnsoMultiValue extends EnsoObject { @CompilationFinal(dimensions = 1) private final Type[] types; @@ -73,7 +73,8 @@ public final Type[] allTypes() { } @ExportMessage - String toDisplayString(boolean ignore) { + @Override + public String toDisplayString(boolean ignore) { return toString(); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java index ce601581161b..19566189a367 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java @@ -1,6 +1,27 @@ package org.enso.interpreter.runtime.data; +import com.oracle.truffle.api.TruffleLanguage; +import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.library.ExportLibrary; +import com.oracle.truffle.api.library.ExportMessage; +import org.enso.interpreter.EnsoLanguage; /** All non-primitive Enso types extends from {@code EnsoObject}. */ -public interface EnsoObject extends TruffleObject {} +@ExportLibrary(InteropLibrary.class) +public abstract class EnsoObject implements TruffleObject { + @ExportMessage + public boolean hasLanguage() { + return true; + } + + @ExportMessage + public Class> getLanguage() { + return EnsoLanguage.class; + } + + @ExportMessage + public Object toDisplayString(boolean allowSideEffects) { + throw new UnsupportedOperationException("unimplemented"); + } +} diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoSource.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoSource.java index fae77b1e7697..601288dfe862 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoSource.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoSource.java @@ -12,7 +12,7 @@ /** Wrapper for exposing sources to Enso. Delegates to original methods with no behavior changes. */ @ExportLibrary(InteropLibrary.class) -public final class EnsoSource implements EnsoObject { +public final class EnsoSource extends EnsoObject { private static final String[] MEMBERS = { "getLanguage", // "getName", // diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoSourceSection.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoSourceSection.java index a15ab53416a7..248bca570735 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoSourceSection.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoSourceSection.java @@ -15,7 +15,7 @@ * changes. */ @ExportLibrary(InteropLibrary.class) -public final class EnsoSourceSection implements EnsoObject { +public final class EnsoSourceSection extends EnsoObject { private static final String[] MEMBERS = { "getStartLine", // "getEndLine", // diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeOfDay.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeOfDay.java index eddfdd798711..f021d8444b0c 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeOfDay.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeOfDay.java @@ -23,7 +23,7 @@ pkg = "date", name = "TimeOfDay", stdlibName = "Standard.Base.Data.Time.Time_Of_Day.Time_Of_Day") -public final class EnsoTimeOfDay implements EnsoObject { +public final class EnsoTimeOfDay extends EnsoObject { private final LocalTime localTime; public EnsoTimeOfDay(LocalTime localTime) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeZone.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeZone.java index c572e98d0d1c..c36fc5229e56 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeZone.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeZone.java @@ -23,7 +23,7 @@ pkg = "date", name = "TimeZone", stdlibName = "Standard.Base.Data.Time.Time_Zone.Time_Zone") -public final class EnsoTimeZone implements EnsoObject { +public final class EnsoTimeZone extends EnsoObject { private final ZoneId zone; public EnsoTimeZone(ZoneId zone) { @@ -84,7 +84,8 @@ public static EnsoTimeZone system() { } @ExportMessage - String toDisplayString(boolean ignoreSideEffects) { + @Override + public String toDisplayString(boolean ignoreSideEffects) { return zone.toString(); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ManagedResource.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ManagedResource.java index d23537aea36a..946cf7861f2c 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ManagedResource.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ManagedResource.java @@ -15,7 +15,7 @@ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) @Builtin(pkg = "resource", stdlibName = "Standard.Base.Runtime.Managed_Resource.Managed_Resource") -public final class ManagedResource implements EnsoObject { +public final class ManagedResource extends EnsoObject { private final Object resource; private final PhantomReference phantomReference; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Ref.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Ref.java index 8bf74270d09f..861945f900b0 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Ref.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Ref.java @@ -13,7 +13,7 @@ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) @Builtin(pkg = "mutable", stdlibName = "Standard.Base.Runtime.Ref.Ref") -public final class Ref implements EnsoObject { +public final class Ref extends EnsoObject { private volatile Object value; /** diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Type.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Type.java index 53d1cf8a6e31..dedd9e4e55f9 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Type.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Type.java @@ -30,7 +30,7 @@ @ExportLibrary(TypesLibrary.class) @ExportLibrary(InteropLibrary.class) -public final class Type implements EnsoObject { +public final class Type extends EnsoObject { private final String name; private @CompilerDirectives.CompilationFinal ModuleScope.Builder definitionScope; @@ -279,7 +279,8 @@ boolean hasMetaParents(@CachedLibrary("this") InteropLibrary lib) { } @ExportMessage - String toDisplayString(boolean allowSideEffects) { + @Override + public String toDisplayString(boolean allowSideEffects) { return name; } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/Atom.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/Atom.java index 3ace353dc5b6..fc17a8b8bf1c 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/Atom.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/Atom.java @@ -19,7 +19,6 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; -import org.enso.interpreter.EnsoLanguage; import org.enso.interpreter.runtime.callable.UnresolvedSymbol; import org.enso.interpreter.runtime.callable.argument.ArgumentDefinition; import org.enso.interpreter.runtime.callable.function.Function; @@ -51,7 +50,7 @@ */ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) -public abstract class Atom implements EnsoObject { +public abstract class Atom extends EnsoObject { final AtomConstructor constructor; private Integer hashCode; @@ -419,16 +418,6 @@ Text toDisplayString( return Text.create(msg); } - @ExportMessage - Class getLanguage() { - return EnsoLanguage.class; - } - - @ExportMessage - boolean hasLanguage() { - return true; - } - @ExportMessage boolean hasType() { return true; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/AtomConstructor.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/AtomConstructor.java index 9a94a4880ce7..e0bf41cb6d80 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/AtomConstructor.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/AtomConstructor.java @@ -41,7 +41,7 @@ */ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) -public final class AtomConstructor implements EnsoObject { +public final class AtomConstructor extends EnsoObject { private final String name; private final Module definitionModule; @@ -414,7 +414,8 @@ Atom instantiate(Object... arguments) throws ArityException { @ExportMessage @TruffleBoundary - String toDisplayString(boolean allowSideEffects) { + @Override + public String toDisplayString(boolean allowSideEffects) { var sb = new StringBuilder(); sb.append("Constructor<").append(getDisplayName()).append(">"); for (var f : getFields()) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/hash/EnsoHashMap.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/hash/EnsoHashMap.java index 2c761b1e214a..65261cebf96e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/hash/EnsoHashMap.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/hash/EnsoHashMap.java @@ -36,7 +36,7 @@ @ExportLibrary(TypesLibrary.class) @ExportLibrary(InteropLibrary.class) @Builtin(stdlibName = "Standard.Base.Data.Dictionary.Dictionary", name = "Dictionary") -public final class EnsoHashMap implements EnsoObject { +public final class EnsoHashMap extends EnsoObject { private final EnsoHashMapBuilder mapBuilder; private final int generation; private final int size; @@ -166,7 +166,8 @@ Type getMetaObject(@Bind("$node") Node node) { @ExportMessage @TruffleBoundary - Object toDisplayString(boolean allowSideEffects) { + @Override + public Object toDisplayString(boolean allowSideEffects) { return toString(true); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/hash/HashEntriesVector.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/hash/HashEntriesVector.java index 3977dbcb8d70..a478e4aaa2e2 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/hash/HashEntriesVector.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/hash/HashEntriesVector.java @@ -15,7 +15,7 @@ * (array), and for Enso {@code Map.to_vector} method. May be empty. */ @ExportLibrary(InteropLibrary.class) -final class HashEntriesVector implements EnsoObject { +final class HashEntriesVector extends EnsoObject { private final EnsoObject[] entryPairs; private HashEntriesVector(Object[] keys, Object[] values) { @@ -74,7 +74,7 @@ void writeArrayElement(long index, Object value) throws UnsupportedMessageExcept } @ExportLibrary(InteropLibrary.class) - static final class EntryPair implements EnsoObject { + static final class EntryPair extends EnsoObject { private final Object key; private final Object value; @@ -126,7 +126,8 @@ void writeArrayElement(long index, Object value) throws UnsupportedMessageExcept @TruffleBoundary @ExportMessage - Object toDisplayString(boolean sideEffectsAllowed) { + @Override + public Object toDisplayString(boolean sideEffectsAllowed) { return "(" + key + ", " + value + ")"; } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/text/Text.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/text/Text.java index 5a882bf17e02..cc4fd708fb5f 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/text/Text.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/text/Text.java @@ -25,7 +25,7 @@ /** The main runtime type for Enso's Text. */ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) -public final class Text implements EnsoObject { +public final class Text extends EnsoObject { private static final Lock LOCK = new ReentrantLock(); private static final Text EMPTY = new Text(""); private volatile Object contents; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/Array.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/Array.java index abebac6de618..3b2a99dedc10 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/Array.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/Array.java @@ -32,7 +32,7 @@ @ExportLibrary(TypesLibrary.class) @ExportLibrary(WarningsLibrary.class) @Builtin(pkg = "mutable", stdlibName = "Standard.Base.Data.Array.Array") -final class Array implements EnsoObject { +final class Array extends EnsoObject { private final Object[] items; /** If true, some elements contain warning, and thus, this Array contains warning. */ @@ -152,7 +152,8 @@ boolean isArrayElementReadable(long index) { } @ExportMessage - String toDisplayString(boolean b) { + @Override + public String toDisplayString(boolean b) { return toString(); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayBuilder.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayBuilder.java index c15ab12d5567..5da2ece85bdf 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayBuilder.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayBuilder.java @@ -15,7 +15,7 @@ import org.enso.interpreter.runtime.warning.WarningsLibrary; @ExportLibrary(InteropLibrary.class) -final class ArrayBuilder implements EnsoObject { +final class ArrayBuilder extends EnsoObject { private static final String[] MEMBERS = new String[] {"isEmpty", "add", "appendTo", "get", "getSize", "toArray"}; private final int initialCapacity; @@ -238,7 +238,8 @@ EnsoObject getMembers(boolean includeInternal) { } @ExportMessage - String toDisplayString(boolean ignore) { + @Override + public String toDisplayString(boolean ignore) { return "Array_Builder"; } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayOverBuffer.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayOverBuffer.java index 6e613ece6084..5abd6f6e6f34 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayOverBuffer.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayOverBuffer.java @@ -14,7 +14,7 @@ @ExportLibrary(TypesLibrary.class) @ExportLibrary(InteropLibrary.class) -final class ArrayOverBuffer implements EnsoObject { +final class ArrayOverBuffer extends EnsoObject { private final ByteBuffer buffer; private ArrayOverBuffer(ByteBuffer buffer) { @@ -61,7 +61,8 @@ static ArrayOverBuffer wrapBuffer(ByteBuffer buffer) { } @ExportMessage - String toDisplayString(boolean allowSideEffects) { + @Override + public String toDisplayString(boolean allowSideEffects) { final InteropLibrary iop = InteropLibrary.getUncached(); return DisplayArrayUtils.toDisplayString(this, allowSideEffects, iop); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayProxy.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayProxy.java index 802c20949f2b..7c08fcd0b4db 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayProxy.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayProxy.java @@ -28,7 +28,7 @@ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) @ImportStatic(BranchProfile.class) -final class ArrayProxy implements EnsoObject { +final class ArrayProxy extends EnsoObject { private final long length; private final Object at; @@ -76,7 +76,8 @@ public Object readArrayElement( } @ExportMessage - String toDisplayString(boolean b) { + @Override + public String toDisplayString(boolean b) { return toString(); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArraySlice.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArraySlice.java index 03d0c2018c70..8d71567aab0e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArraySlice.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArraySlice.java @@ -23,7 +23,7 @@ @ExportLibrary(TypesLibrary.class) @ExportLibrary(InteropLibrary.class) @ExportLibrary(WarningsLibrary.class) -final class ArraySlice implements EnsoObject { +final class ArraySlice extends EnsoObject { private final Object storage; private final long start; private final long end; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/Vector.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/Vector.java index ee80dd21fb1f..4cc5057e3831 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/Vector.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/Vector.java @@ -23,7 +23,7 @@ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) @Builtin(pkg = "immutable", stdlibName = "Standard.Base.Data.Vector.Vector") -abstract class Vector implements EnsoObject { +abstract class Vector extends EnsoObject { private static final Vector EMPTY_LONG = new Long(new long[0]); private static final Vector EMPTY_DOUBLE = new Double(new double[0]); private static final Vector EMPTY_VECTOR = new EnsoOnly(new Object[0]); @@ -72,7 +72,8 @@ final void removeArrayElement(long index) throws UnsupportedMessageException { @ExportMessage @CompilerDirectives.TruffleBoundary - String toDisplayString(boolean allowSideEffects) { + @Override + public String toDisplayString(boolean allowSideEffects) { final InteropLibrary iop = InteropLibrary.getUncached(); return DisplayArrayUtils.toDisplayString(this, allowSideEffects, iop); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java index 46489bb3dbb3..1216a7c958f2 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java @@ -20,7 +20,6 @@ import org.enso.interpreter.node.expression.builtin.text.util.TypeToDisplayTextNode; import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.callable.UnresolvedSymbol; -import org.enso.interpreter.runtime.data.EnsoObject; import org.enso.interpreter.runtime.data.Type; import org.enso.interpreter.runtime.data.vector.ArrayLikeHelpers; import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; @@ -36,7 +35,7 @@ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) @ImportStatic(PanicException.class) -public final class DataflowError extends AbstractTruffleException implements EnsoObject { +public final class DataflowError extends AbstractTruffleException { /** Signals (local) values that haven't yet been initialized */ public static final DataflowError UNINITIALIZED = new DataflowError(null, (Node) null); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java new file mode 100644 index 000000000000..fdd47e67d8ee --- /dev/null +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java @@ -0,0 +1,34 @@ +package org.enso.interpreter.runtime.error; + +import com.oracle.truffle.api.exception.AbstractTruffleException; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.library.ExportLibrary; +import com.oracle.truffle.api.nodes.Node; +import java.util.Objects; +import org.enso.interpreter.runtime.data.EnsoObject; +import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; + +/** + * Base class for all exceptions (dataflow errors and panics) thrown within Enso. Just delegates all + * the interop messages to the delegate field. + */ +@ExportLibrary(value = InteropLibrary.class, delegateTo = "delegate") +@ExportLibrary(value = TypesLibrary.class, delegateTo = "delegate") +class EnsoException extends AbstractTruffleException { + final Object delegate; + + private EnsoException(Object delegate, Node location) { + super(location); + this.delegate = delegate; + } + + static EnsoException fromEnsoObject(EnsoObject ensoObject, Node location) { + Objects.requireNonNull(ensoObject); + return new EnsoException(ensoObject, location); + } + + static EnsoException fromPanicSentinel(PanicSentinel panicSentinel, Node location) { + Objects.requireNonNull(panicSentinel); + return new EnsoException(panicSentinel, location); + } +} diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java index c85698eef44b..a21f0ad9b0bf 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java @@ -21,7 +21,6 @@ import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.callable.UnresolvedSymbol; import org.enso.interpreter.runtime.callable.argument.CallArgumentInfo; -import org.enso.interpreter.runtime.data.EnsoObject; import org.enso.interpreter.runtime.data.Type; import org.enso.interpreter.runtime.data.atom.Atom; import org.enso.interpreter.runtime.data.text.Text; @@ -33,7 +32,7 @@ /** An exception type for user thrown panic exceptions. */ @ExportLibrary(value = InteropLibrary.class, delegateTo = "payload") @ExportLibrary(TypesLibrary.class) -public final class PanicException extends AbstractTruffleException implements EnsoObject { +public final class PanicException extends AbstractTruffleException { final Object payload; private String cacheMessage; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicSentinel.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicSentinel.java index 643c527f8ff9..2d64b1f5d21c 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicSentinel.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicSentinel.java @@ -4,7 +4,6 @@ import com.oracle.truffle.api.library.ExportLibrary; import com.oracle.truffle.api.library.ExportMessage; import com.oracle.truffle.api.nodes.Node; -import org.enso.interpreter.runtime.data.EnsoObject; import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; /** @@ -14,7 +13,7 @@ * not function in textual mode. */ @ExportLibrary(TypesLibrary.class) -public final class PanicSentinel extends AbstractTruffleException implements EnsoObject { +public final class PanicSentinel extends AbstractTruffleException { final PanicException panic; /** diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/number/EnsoBigInteger.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/number/EnsoBigInteger.java index 00dc63ae935e..961d31e88027 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/number/EnsoBigInteger.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/number/EnsoBigInteger.java @@ -17,7 +17,7 @@ /** Internal wrapper for a {@link BigInteger}. */ @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) -public final class EnsoBigInteger implements EnsoObject { +public final class EnsoBigInteger extends EnsoObject { private final BigInteger value; /** @@ -45,7 +45,8 @@ public String toString() { @CompilerDirectives.TruffleBoundary @ExportMessage - String toDisplayString(boolean allowSideEffects) { + @Override + public String toDisplayString(boolean allowSideEffects) { return value.toString(); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/DebugLocalScope.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/DebugLocalScope.java index dcec2f91e0a8..df67f24ea531 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/DebugLocalScope.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/DebugLocalScope.java @@ -1,7 +1,6 @@ package org.enso.interpreter.runtime.scope; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.frame.MaterializedFrame; import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.interop.UnknownIdentifierException; @@ -17,7 +16,6 @@ import java.util.Map.Entry; import java.util.stream.Collectors; import org.enso.compiler.pass.analyse.FramePointer; -import org.enso.interpreter.EnsoLanguage; import org.enso.interpreter.node.EnsoRootNode; import org.enso.interpreter.runtime.callable.function.Function; import org.enso.interpreter.runtime.data.EnsoObject; @@ -35,7 +33,7 @@ * */ @ExportLibrary(InteropLibrary.class) -public class DebugLocalScope implements EnsoObject { +public class DebugLocalScope extends EnsoObject { private final EnsoRootNode rootNode; /** All the bindings, including the parent scopes. */ @@ -119,16 +117,6 @@ private static List> gatherBindingsByLevels(Map> getLanguage() { - return EnsoLanguage.class; - } - @ExportMessage boolean isScope() { return true; @@ -245,7 +233,8 @@ SourceSection getSourceLocation() { @ExportMessage @TruffleBoundary - String toDisplayString(boolean allowSideEffects) { + @Override + public String toDisplayString(boolean allowSideEffects) { return rootNode.toString(); } @@ -277,7 +266,7 @@ private MaterializedFrame getProperFrame(MaterializedFrame frame, FramePointer p /** Simple interop wrapper for a list of strings. */ @ExportLibrary(InteropLibrary.class) - static final class ScopeMembers implements EnsoObject { + static final class ScopeMembers extends EnsoObject { private final List memberNames; ScopeMembers(List memberNames) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ImportExportScope.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ImportExportScope.java index 1b8637fd7e96..76d14e103d1f 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ImportExportScope.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ImportExportScope.java @@ -11,7 +11,7 @@ * A proxy scope delegating to the underlying module's scope. Additionally, `ImportExportScope` may * limit the number of types that are imported/exported. */ -public class ImportExportScope implements EnsoObject { +public class ImportExportScope extends EnsoObject { private final Module module; private final List typesOnlyNames; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ModuleScope.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ModuleScope.java index 8cfeb1837a2d..7394561acdda 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ModuleScope.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ModuleScope.java @@ -20,7 +20,7 @@ /** A representation of Enso's per-file top-level scope. */ @ExportLibrary(TypesLibrary.class) -public final class ModuleScope implements EnsoObject { +public final class ModuleScope extends EnsoObject { private final Type associatedType; private final Module module; private final Map> polyglotSymbols; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/TopLevelScope.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/TopLevelScope.java index c71f2c6315a6..444cf84032bf 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/TopLevelScope.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/TopLevelScope.java @@ -17,7 +17,6 @@ import org.enso.common.MethodNames; import org.enso.compiler.PackageRepository; import org.enso.editions.LibraryName; -import org.enso.interpreter.EnsoLanguage; import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.Module; import org.enso.interpreter.runtime.builtin.Builtins; @@ -30,7 +29,7 @@ /** Represents the top scope of Enso execution, containing all the importable modules. */ @ExportLibrary(InteropLibrary.class) -public final class TopLevelScope implements EnsoObject { +public final class TopLevelScope extends EnsoObject { private final Builtins builtins; private final PackageRepository packageRepository; @@ -263,26 +262,6 @@ Object getScopeParent() throws UnsupportedMessageException { throw UnsupportedMessageException.create(); } - /** - * Checks if this value is associated with a language. - * - * @return {@code true} - */ - @ExportMessage - final boolean hasLanguage() { - return true; - } - - /** - * Returns the language associated with this scope value. - * - * @return the language with which this value is associated - */ - @ExportMessage - final Class getLanguage() { - return EnsoLanguage.class; - } - /** * Converts this scope to a human readable string. * @@ -290,7 +269,8 @@ final Class getLanguage() { * @return a string representation of this scope */ @ExportMessage - final Object toDisplayString(boolean allowSideEffects) { + @Override + public Object toDisplayString(boolean allowSideEffects) { return "Enso.Top_Scope"; } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java index 84c2aa729ad3..572cad30e5ba 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java @@ -20,7 +20,7 @@ @Builtin(pkg = "error", stdlibName = "Standard.Base.Warning.Warning") @ExportLibrary(TypesLibrary.class) -public final class Warning implements EnsoObject { +public final class Warning extends EnsoObject { private final Object value; private final Object origin; private final long sequenceId; diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/WithWarnings.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/WithWarnings.java index 5bd99c29db4a..38821c3f1e8e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/WithWarnings.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/WithWarnings.java @@ -54,7 +54,7 @@ @ExportLibrary(WarningsLibrary.class) @ExportLibrary(ReflectionLibrary.class) @ExportLibrary(value = InteropLibrary.class, delegateTo = "value") -public final class WithWarnings implements EnsoObject { +public final class WithWarnings extends EnsoObject { final Object value; /** From 3ab4f73aaea07ddf539154d24cd9d6723c69b9d9 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 12 Nov 2024 13:26:07 +0100 Subject: [PATCH 02/18] Implement public getters in BranchResult --- .../node/controlflow/caseexpr/BranchResult.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/BranchResult.java b/engine/runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/BranchResult.java index 9e45c94719af..e444af195b5c 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/BranchResult.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/BranchResult.java @@ -13,6 +13,14 @@ final class BranchResult extends EnsoObject { this.result = result; } + public boolean isMatched() { + return isMatched; + } + + public Object result() { + return result; + } + static BranchResult failure(Node node) { return new BranchResult(false, EnsoContext.get(node).getBuiltins().nothing()); } From 5c5b0b7fdf7eae55caab735e1cc85a377be8520e Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 12 Nov 2024 13:31:36 +0100 Subject: [PATCH 03/18] Fix compilation of EnsoFile --- .../org/enso/interpreter/runtime/data/EnsoFile.java | 7 ++++--- .../enso/interpreter/runtime/error/EnsoException.java | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java index 5431225df155..a396f925f851 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java @@ -43,6 +43,7 @@ import org.enso.interpreter.runtime.data.vector.ArrayLikeHelpers; import org.enso.interpreter.runtime.data.vector.ArrayLikeLengthNode; import org.enso.interpreter.runtime.error.DataflowError; +import org.enso.interpreter.runtime.error.EnsoException; import org.enso.interpreter.runtime.error.PanicException; import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; @@ -734,7 +735,7 @@ public boolean startsWith(EnsoFile parent) { autoRegister = false) @Builtin.Specialize @TruffleBoundary - public static EnsoObject fromString(EnsoContext context, String path) + public static Object fromString(EnsoContext context, String path) throws IllegalArgumentException { try { TruffleFile file = context.getPublicTruffleFile(path); @@ -745,7 +746,7 @@ public static EnsoObject fromString(EnsoContext context, String path) .getBuiltins() .error() .makeUnsupportedArgumentsError(new Object[] {Text.create(path)}, ex.getMessage()); - return DataflowError.withDefaultTrace(err, null); + return EnsoException.fromDataflowError(DataflowError.withDefaultTrace(err, null)); } } @@ -766,7 +767,7 @@ public static EnsoFile currentDirectory(EnsoContext context) { autoRegister = false) @Builtin.Specialize @TruffleBoundary - public static EnsoObject userHome(EnsoContext context) { + public static Object userHome(EnsoContext context) { return fromString(context, System.getProperty("user.home")); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java index fdd47e67d8ee..cc9ecaf45396 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java @@ -14,7 +14,7 @@ */ @ExportLibrary(value = InteropLibrary.class, delegateTo = "delegate") @ExportLibrary(value = TypesLibrary.class, delegateTo = "delegate") -class EnsoException extends AbstractTruffleException { +public class EnsoException extends AbstractTruffleException { final Object delegate; private EnsoException(Object delegate, Node location) { @@ -22,13 +22,18 @@ private EnsoException(Object delegate, Node location) { this.delegate = delegate; } - static EnsoException fromEnsoObject(EnsoObject ensoObject, Node location) { + public static EnsoException fromEnsoObject(EnsoObject ensoObject, Node location) { Objects.requireNonNull(ensoObject); return new EnsoException(ensoObject, location); } - static EnsoException fromPanicSentinel(PanicSentinel panicSentinel, Node location) { + public static EnsoException fromPanicSentinel(PanicSentinel panicSentinel, Node location) { Objects.requireNonNull(panicSentinel); return new EnsoException(panicSentinel, location); } + + public static EnsoException fromDataflowError(DataflowError err) { + Objects.requireNonNull(err); + return new EnsoException(err, err.getLocation()); + } } From 0e48f21d4d39ab851b83c23c09d6e642ae88de11 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 12 Nov 2024 13:39:46 +0100 Subject: [PATCH 04/18] Add test that all enso values must have language --- .../enso/interpreter/test/MetaObjectTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java index a41448435dc9..0abbc7c32601 100644 --- a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java +++ b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java @@ -9,6 +9,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import com.oracle.truffle.api.interop.InteropLibrary; import java.io.PrintWriter; import java.io.StringWriter; import java.net.URI; @@ -16,6 +17,7 @@ import java.util.LinkedHashSet; import java.util.Set; import org.enso.common.MethodNames; +import org.enso.interpreter.EnsoLanguage; import org.enso.interpreter.runtime.data.Type; import org.enso.interpreter.runtime.type.ConstantsGen; import org.enso.interpreter.test.ValuesGenerator.Language; @@ -272,6 +274,20 @@ public void numbersAreEitherIntegerOrFloat() throws Exception { } } + @Test + public void allEnsoValuesHaveLanguage() throws Exception { + var gen = ValuesGenerator.create(ctx, Language.ENSO); + var interop = InteropLibrary.getUncached(); + for (var value : gen.allValues()) { + var unwrappedValue = ContextUtils.unwrapValue(ctx, value); + assertThat( + "Value " + unwrappedValue + " should have associated language", + interop.hasLanguage(unwrappedValue), + is(true)); + assertEquals(interop.getLanguage(unwrappedValue), EnsoLanguage.class); + } + } + @Test public void compareQualifiedAndSimpleTypeName() throws Exception { var g = generator(); From aa419c099d40c0106c4a824fab8e0026d1b1695c Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 12 Nov 2024 17:42:57 +0100 Subject: [PATCH 05/18] Revert EnsoException - remove --- .../interpreter/runtime/data/EnsoFile.java | 3 +- .../runtime/error/EnsoException.java | 39 ------------------- 2 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java index a396f925f851..d442273402df 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java @@ -43,7 +43,6 @@ import org.enso.interpreter.runtime.data.vector.ArrayLikeHelpers; import org.enso.interpreter.runtime.data.vector.ArrayLikeLengthNode; import org.enso.interpreter.runtime.error.DataflowError; -import org.enso.interpreter.runtime.error.EnsoException; import org.enso.interpreter.runtime.error.PanicException; import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; @@ -746,7 +745,7 @@ public static Object fromString(EnsoContext context, String path) .getBuiltins() .error() .makeUnsupportedArgumentsError(new Object[] {Text.create(path)}, ex.getMessage()); - return EnsoException.fromDataflowError(DataflowError.withDefaultTrace(err, null)); + return DataflowError.withDefaultTrace(err, null); } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java deleted file mode 100644 index cc9ecaf45396..000000000000 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/EnsoException.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.enso.interpreter.runtime.error; - -import com.oracle.truffle.api.exception.AbstractTruffleException; -import com.oracle.truffle.api.interop.InteropLibrary; -import com.oracle.truffle.api.library.ExportLibrary; -import com.oracle.truffle.api.nodes.Node; -import java.util.Objects; -import org.enso.interpreter.runtime.data.EnsoObject; -import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; - -/** - * Base class for all exceptions (dataflow errors and panics) thrown within Enso. Just delegates all - * the interop messages to the delegate field. - */ -@ExportLibrary(value = InteropLibrary.class, delegateTo = "delegate") -@ExportLibrary(value = TypesLibrary.class, delegateTo = "delegate") -public class EnsoException extends AbstractTruffleException { - final Object delegate; - - private EnsoException(Object delegate, Node location) { - super(location); - this.delegate = delegate; - } - - public static EnsoException fromEnsoObject(EnsoObject ensoObject, Node location) { - Objects.requireNonNull(ensoObject); - return new EnsoException(ensoObject, location); - } - - public static EnsoException fromPanicSentinel(PanicSentinel panicSentinel, Node location) { - Objects.requireNonNull(panicSentinel); - return new EnsoException(panicSentinel, location); - } - - public static EnsoException fromDataflowError(DataflowError err) { - Objects.requireNonNull(err); - return new EnsoException(err, err.getLocation()); - } -} From b30f3961b724fb942ec1202e38175929e0baedeb Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 12 Nov 2024 17:53:30 +0100 Subject: [PATCH 06/18] DataflowError and PanicException implement hasLanguage and getLanguage --- .../runtime/error/DataflowError.java | 12 +++++++ .../runtime/error/PanicException.java | 31 +++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java index 1216a7c958f2..df731d94f9a7 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java @@ -3,6 +3,7 @@ import static org.enso.interpreter.runtime.error.PanicException.handleExceptionMessage; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.TruffleStackTrace; import com.oracle.truffle.api.TruffleStackTraceElement; import com.oracle.truffle.api.dsl.Bind; @@ -16,6 +17,7 @@ import com.oracle.truffle.api.library.ExportMessage; import com.oracle.truffle.api.nodes.Node; import java.util.Objects; +import org.enso.interpreter.EnsoLanguage; import org.enso.interpreter.node.callable.IndirectInvokeMethodNode; import org.enso.interpreter.node.expression.builtin.text.util.TypeToDisplayTextNode; import org.enso.interpreter.runtime.EnsoContext; @@ -211,4 +213,14 @@ boolean hasSpecialDispatch() { Type getType(@Bind("$node") Node node) { return EnsoContext.get(node).getBuiltins().dataflowError(); } + + @ExportMessage + boolean hasLanguage() { + return true; + } + + @ExportMessage + Class> getLanguage() { + return EnsoLanguage.class; + } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java index a21f0ad9b0bf..549a6ae0708f 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java @@ -1,8 +1,10 @@ package org.enso.interpreter.runtime.error; import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.exception.AbstractTruffleException; import com.oracle.truffle.api.interop.ExceptionType; @@ -13,6 +15,7 @@ import com.oracle.truffle.api.library.ExportMessage; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.source.SourceSection; +import org.enso.interpreter.EnsoLanguage; import org.enso.interpreter.node.BaseNode.TailStatus; import org.enso.interpreter.node.callable.IndirectInvokeMethodNode; import org.enso.interpreter.node.callable.InvokeCallableNode.ArgumentsExecutionMode; @@ -143,14 +146,26 @@ static UnresolvedSymbol toDisplayText(Object payload, IndirectInvokeMethodNode p return UnresolvedSymbol.build("to_display_text", scope); } + @ExportMessage + Object toDisplayString( + boolean allowSideEffects, @Shared @Cached IndirectInvokeMethodNode invokeMethodNode) { + try { + return toDisplayText(payload, invokeMethodNode); + } catch (UnsupportedMessageException e) { + logger().error("Cannot convert payload " + payload + " to string", e); + return null; + } + } + @ExportMessage Object getExceptionMessage( - @Cached IndirectInvokeMethodNode payloads, - @Cached(value = "toDisplayText(this.getPayload(), payloads)", allowUncached = true) + @Shared @Cached IndirectInvokeMethodNode invokeMethodNode, + @Cached(value = "toDisplayText(this.getPayload(), invokeMethodNode)", allowUncached = true) UnresolvedSymbol toDisplayText, @CachedLibrary(limit = "3") InteropLibrary strings, @Cached TypeToDisplayTextNode typeToDisplayTextNode) { - return handleExceptionMessage(payload, payloads, toDisplayText, strings, typeToDisplayTextNode); + return handleExceptionMessage( + payload, invokeMethodNode, toDisplayText, strings, typeToDisplayTextNode); } static Object handleExceptionMessage( @@ -230,6 +245,16 @@ SourceSection getSourceSection() throws UnsupportedMessageException { return getLocation().getEncapsulatingSourceSection(); } + @ExportMessage + boolean hasLanguage() { + return true; + } + + @ExportMessage + Class> getLanguage() { + return EnsoLanguage.class; + } + private static Logger logger() { CompilerDirectives.transferToInterpreter(); return LoggerFactory.getLogger(PanicException.class); From 613f380f54cacbd8641c8a5ee483cf20c6d6413f Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 12 Nov 2024 18:05:36 +0100 Subject: [PATCH 07/18] DataflowError is not EnsoObject - change signatures in some builtins --- .../java/org/enso/interpreter/runtime/data/EnsoFile.java | 2 ++ .../interpreter/runtime/warning/AppendWarningNode.java | 7 +++---- .../java/org/enso/interpreter/runtime/warning/Warning.java | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java index d442273402df..1efaed2b74f7 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java @@ -734,6 +734,7 @@ public boolean startsWith(EnsoFile parent) { autoRegister = false) @Builtin.Specialize @TruffleBoundary + @SuppressWarnings("generic-enso-builtin-type") public static Object fromString(EnsoContext context, String path) throws IllegalArgumentException { try { @@ -766,6 +767,7 @@ public static EnsoFile currentDirectory(EnsoContext context) { autoRegister = false) @Builtin.Specialize @TruffleBoundary + @SuppressWarnings("generic-enso-builtin-type") public static Object userHome(EnsoContext context) { return fromString(context, System.getProperty("user.home")); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/AppendWarningNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/AppendWarningNode.java index 1377816f5fd4..a4dda4e9d25e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/AppendWarningNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/AppendWarningNode.java @@ -13,7 +13,6 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.profiles.ConditionProfile; import org.enso.interpreter.runtime.EnsoContext; -import org.enso.interpreter.runtime.data.EnsoObject; import org.enso.interpreter.runtime.data.hash.EnsoHashMap; import org.enso.interpreter.runtime.data.hash.HashMapInsertAllNode; import org.enso.interpreter.runtime.data.hash.HashMapInsertNode; @@ -42,7 +41,7 @@ public static AppendWarningNode getUncached() { * It is expected that all the elements in the container are of {@link Warning} class. * @return A wrapped object with warnings */ - public abstract EnsoObject executeAppend(VirtualFrame frame, Object object, Object warnings); + public abstract Object executeAppend(VirtualFrame frame, Object object, Object warnings); @Specialization(guards = "!isError(object)") WithWarnings doSingleWarning( @@ -175,8 +174,8 @@ WithWarnings doMultipleWarningsInterop( } @Specialization(guards = "isError(object)") - EnsoObject dontAnnotateError(Object object, Object ignoreWarnings) { - return (EnsoObject) object; + Object dontAnnotateError(Object object, Object ignoreWarnings) { + return object; } /** Inserts all {@code warnings} to the {@code initialWarningMap}. */ diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java index 572cad30e5ba..1ca8ecae5ea6 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java @@ -57,7 +57,8 @@ public static Warning create(EnsoContext ctx, Object payload, Object origin) { description = "Attaches the given warning to the value.", autoRegister = false) @Builtin.Specialize - public static EnsoObject attach( + @SuppressWarnings("generic-enso-builtin-type") + public static Object attach( EnsoContext ctx, Object value, Object warning, From c682df035b4e9856f97d60120e7cedbf0f5c4506 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Wed, 13 Nov 2024 12:39:14 +0100 Subject: [PATCH 08/18] Add more members to Module.isMemberInvocable. Keep in sync with doInvoke. --- .../src/main/java/org/enso/interpreter/runtime/Module.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java index d227b22c5e4d..0f12d2dd9bf8 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/Module.java @@ -772,6 +772,10 @@ boolean hasMembers() { boolean isMemberInvocable(String member) { return member.equals(MethodNames.Module.GET_METHOD) || member.equals(MethodNames.Module.REPARSE) + || member.equals(MethodNames.Module.GATHER_IMPORT_STATEMENTS) + || member.equals(MethodNames.Module.GENERATE_DOCS) + || member.equals(MethodNames.Module.GET_NAME) + || member.equals(MethodNames.Module.GET_TYPE) || member.equals(MethodNames.Module.SET_SOURCE) || member.equals(MethodNames.Module.SET_SOURCE_FILE) || member.equals(MethodNames.Module.GET_ASSOCIATED_TYPE) From 993399a1fdc5d74e6d0de604cbab563f80a1284d Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Wed, 13 Nov 2024 13:15:57 +0100 Subject: [PATCH 09/18] Revert "DataflowError and PanicException implement hasLanguage and getLanguage" This reverts commit b30f3961b724fb942ec1202e38175929e0baedeb. --- .../runtime/error/DataflowError.java | 12 ------- .../runtime/error/PanicException.java | 31 ++----------------- 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java index df731d94f9a7..1216a7c958f2 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java @@ -3,7 +3,6 @@ import static org.enso.interpreter.runtime.error.PanicException.handleExceptionMessage; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.TruffleStackTrace; import com.oracle.truffle.api.TruffleStackTraceElement; import com.oracle.truffle.api.dsl.Bind; @@ -17,7 +16,6 @@ import com.oracle.truffle.api.library.ExportMessage; import com.oracle.truffle.api.nodes.Node; import java.util.Objects; -import org.enso.interpreter.EnsoLanguage; import org.enso.interpreter.node.callable.IndirectInvokeMethodNode; import org.enso.interpreter.node.expression.builtin.text.util.TypeToDisplayTextNode; import org.enso.interpreter.runtime.EnsoContext; @@ -213,14 +211,4 @@ boolean hasSpecialDispatch() { Type getType(@Bind("$node") Node node) { return EnsoContext.get(node).getBuiltins().dataflowError(); } - - @ExportMessage - boolean hasLanguage() { - return true; - } - - @ExportMessage - Class> getLanguage() { - return EnsoLanguage.class; - } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java index 549a6ae0708f..a21f0ad9b0bf 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/PanicException.java @@ -1,10 +1,8 @@ package org.enso.interpreter.runtime.error; import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.exception.AbstractTruffleException; import com.oracle.truffle.api.interop.ExceptionType; @@ -15,7 +13,6 @@ import com.oracle.truffle.api.library.ExportMessage; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.source.SourceSection; -import org.enso.interpreter.EnsoLanguage; import org.enso.interpreter.node.BaseNode.TailStatus; import org.enso.interpreter.node.callable.IndirectInvokeMethodNode; import org.enso.interpreter.node.callable.InvokeCallableNode.ArgumentsExecutionMode; @@ -146,26 +143,14 @@ static UnresolvedSymbol toDisplayText(Object payload, IndirectInvokeMethodNode p return UnresolvedSymbol.build("to_display_text", scope); } - @ExportMessage - Object toDisplayString( - boolean allowSideEffects, @Shared @Cached IndirectInvokeMethodNode invokeMethodNode) { - try { - return toDisplayText(payload, invokeMethodNode); - } catch (UnsupportedMessageException e) { - logger().error("Cannot convert payload " + payload + " to string", e); - return null; - } - } - @ExportMessage Object getExceptionMessage( - @Shared @Cached IndirectInvokeMethodNode invokeMethodNode, - @Cached(value = "toDisplayText(this.getPayload(), invokeMethodNode)", allowUncached = true) + @Cached IndirectInvokeMethodNode payloads, + @Cached(value = "toDisplayText(this.getPayload(), payloads)", allowUncached = true) UnresolvedSymbol toDisplayText, @CachedLibrary(limit = "3") InteropLibrary strings, @Cached TypeToDisplayTextNode typeToDisplayTextNode) { - return handleExceptionMessage( - payload, invokeMethodNode, toDisplayText, strings, typeToDisplayTextNode); + return handleExceptionMessage(payload, payloads, toDisplayText, strings, typeToDisplayTextNode); } static Object handleExceptionMessage( @@ -245,16 +230,6 @@ SourceSection getSourceSection() throws UnsupportedMessageException { return getLocation().getEncapsulatingSourceSection(); } - @ExportMessage - boolean hasLanguage() { - return true; - } - - @ExportMessage - Class> getLanguage() { - return EnsoLanguage.class; - } - private static Logger logger() { CompilerDirectives.transferToInterpreter(); return LoggerFactory.getLogger(PanicException.class); From 130180c04eed39ebf273eedc2e9b16e51cc3f7b8 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Wed, 13 Nov 2024 14:17:34 +0100 Subject: [PATCH 10/18] Update the test - test only non-primitive and non-exception values --- .../enso/interpreter/test/MetaObjectTest.java | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java index 0abbc7c32601..6b56f5c6d94d 100644 --- a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java +++ b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java @@ -16,8 +16,8 @@ import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; +import java.util.function.Predicate; import org.enso.common.MethodNames; -import org.enso.interpreter.EnsoLanguage; import org.enso.interpreter.runtime.data.Type; import org.enso.interpreter.runtime.type.ConstantsGen; import org.enso.interpreter.test.ValuesGenerator.Language; @@ -274,18 +274,31 @@ public void numbersAreEitherIntegerOrFloat() throws Exception { } } + /** + * Primitive values and exceptions currently don't have an associated language. + * + *

TODO[PM]: Will be implemented in https://github.com/enso-org/enso/pull/11468 + */ @Test - public void allEnsoValuesHaveLanguage() throws Exception { + public void allEnsoNonPrimitiveValuesHaveLanguage() throws Exception { var gen = ValuesGenerator.create(ctx, Language.ENSO); + Predicate isPrimitiveOrException = + (val) -> val.fitsInInt() || val.fitsInDouble() || val.isBoolean() || val.isException(); + var nonPrimitiveValues = + gen.allValues().stream().filter(isPrimitiveOrException.negate()).toList(); var interop = InteropLibrary.getUncached(); - for (var value : gen.allValues()) { - var unwrappedValue = ContextUtils.unwrapValue(ctx, value); - assertThat( - "Value " + unwrappedValue + " should have associated language", - interop.hasLanguage(unwrappedValue), - is(true)); - assertEquals(interop.getLanguage(unwrappedValue), EnsoLanguage.class); - } + ContextUtils.executeInContext( + ctx, + () -> { + for (var value : nonPrimitiveValues) { + var unwrappedValue = ContextUtils.unwrapValue(ctx, value); + assertThat( + "Value " + unwrappedValue + " should have associated language", + interop.hasLanguage(unwrappedValue), + is(true)); + } + return null; + }); } @Test From bea21a6b0b844ed7c4fd6de09e6be4c20a7699a5 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Wed, 13 Nov 2024 17:41:43 +0100 Subject: [PATCH 11/18] Fix indexes in CodeLocationsTest --- .../test/semantic/CodeLocationsTest.scala | 111 ++++++++++-------- 1 file changed, 63 insertions(+), 48 deletions(-) diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/interpreter/test/semantic/CodeLocationsTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/interpreter/test/semantic/CodeLocationsTest.scala index ccf25ea82211..b019106796e3 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/interpreter/test/semantic/CodeLocationsTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/interpreter/test/semantic/CodeLocationsTest.scala @@ -34,19 +34,25 @@ class CodeLocationsTest extends InterpreterTest { "be correct in simple arithmetic expressions" in withLocationsInstrumenter { instrumenter => - val code = "main = 2 + 45 * 20" - instrumenter.assertNodeExists(7, 11, classOf[ApplicationNode]) - instrumenter.assertNodeExists(11, 7, classOf[ApplicationNode]) - instrumenter.assertNodeExists(11, 2, classOf[LiteralNode]) + val code = + """from Standard.Base.Data.Numbers import all + |main = (2 + 45) * 20 + |""".stripMargin.replace("\r", "") + instrumenter.assertNodeExists(50, 13, classOf[ApplicationNode]) + instrumenter.assertNodeExists(51, 6, classOf[ApplicationNode]) + instrumenter.assertNodeExists(51, 1, classOf[LiteralNode]) eval(code) () } "be correct with parenthesized expressions" in withLocationsInstrumenter { instrumenter => - val code = "main = (2 + 45) * 20" - instrumenter.assertNodeExists(7, 13, classOf[ApplicationNode]) - instrumenter.assertNodeExists(8, 6, classOf[ApplicationNode]) + val code = + """from Standard.Base.Data.Numbers import all + |main = (2 + 45) * 20 + |""".stripMargin.replace("\r", "") + instrumenter.assertNodeExists(50, 13, classOf[ApplicationNode]) + instrumenter.assertNodeExists(51, 6, classOf[ApplicationNode]) eval(code) () } @@ -54,13 +60,12 @@ class CodeLocationsTest extends InterpreterTest { "be correct in applications and method calls" in withLocationsInstrumenter { instrumenter => val code = - """import Standard.Base.Data.List.List - |import Standard.Base.Any.Any + """from Standard.Base import all | |main = (2-2 == 0).if_then_else (List.Cons 5 6) 0 |""".stripMargin.linesIterator.mkString("\n") - instrumenter.assertNodeExists(73, 41, classOf[ApplicationNode]) - instrumenter.assertNodeExists(98, 13, classOf[ApplicationNode]) + instrumenter.assertNodeExists(38, 41, classOf[ApplicationNode]) + instrumenter.assertNodeExists(63, 13, classOf[ApplicationNode]) eval(code) () } @@ -69,18 +74,18 @@ class CodeLocationsTest extends InterpreterTest { withLocationsInstrumenter { instrumenter => val code = """ - |import Standard.Base.IO + |from Standard.Base import all | |main = | x = 2 + 2 * 2 | y = x * x | IO.println y |""".stripMargin.linesIterator.mkString("\n") - instrumenter.assertNodeExists(37, 13, classOf[AssignmentNode]) - instrumenter.assertNodeExists(55, 9, classOf[AssignmentNode]) - instrumenter.assertNodeExists(59, 1, classOf[ReadLocalVariableNode]) - instrumenter.assertNodeExists(63, 1, classOf[ReadLocalVariableNode]) - instrumenter.assertNodeExists(80, 1, classOf[ReadLocalVariableNode]) + instrumenter.assertNodeExists(43, 13, classOf[AssignmentNode]) + instrumenter.assertNodeExists(61, 9, classOf[AssignmentNode]) + instrumenter.assertNodeExists(65, 1, classOf[ReadLocalVariableNode]) + instrumenter.assertNodeExists(69, 1, classOf[ReadLocalVariableNode]) + instrumenter.assertNodeExists(86, 1, classOf[ReadLocalVariableNode]) eval(code) () } @@ -89,8 +94,7 @@ class CodeLocationsTest extends InterpreterTest { withLocationsInstrumenter { instrumenter => val code = """ - |import Standard.Base.Nothing - |import Standard.Base.IO + |from Standard.Base import all | |Nothing.method = | foo = a -> b -> @@ -102,10 +106,10 @@ class CodeLocationsTest extends InterpreterTest { |main = Nothing.method |""".stripMargin.linesIterator.mkString("\n") - instrumenter.assertNodeExists(137, 5, classOf[ApplicationNode]) - instrumenter.assertNodeExists(155, 1, classOf[ReadLocalVariableNode]) - instrumenter.assertNodeExists(151, 7, classOf[ApplicationNode]) - instrumenter.assertNodeExists(163, 9, classOf[ApplicationNode]) + instrumenter.assertNodeExists(114, 5, classOf[ApplicationNode]) + instrumenter.assertNodeExists(132, 1, classOf[ReadLocalVariableNode]) + instrumenter.assertNodeExists(128, 7, classOf[ApplicationNode]) + instrumenter.assertNodeExists(140, 9, classOf[ApplicationNode]) eval(code) () } @@ -114,7 +118,7 @@ class CodeLocationsTest extends InterpreterTest { withLocationsInstrumenter { instrumenter => val code = """ - |import Standard.Base.Data.List.List + |from Standard.Base import all | |main = | x = List.Cons 1 2 @@ -131,10 +135,10 @@ class CodeLocationsTest extends InterpreterTest { | | foo x + foo y |""".stripMargin.linesIterator.mkString("\n") - instrumenter.assertNodeExists(127, 0, 114, 1, classOf[CaseNode]) - instrumenter.assertNodeExists(178, 7, classOf[ApplicationNode]) - instrumenter.assertNodeExists(198, 9, classOf[AssignmentNode]) - instrumenter.assertNodeExists(235, 5, classOf[ApplicationNode]) + instrumenter.assertNodeExists(121, 0, 114, 1, classOf[CaseNode]) + instrumenter.assertNodeExists(172, 7, classOf[ApplicationNode]) + instrumenter.assertNodeExists(192, 9, classOf[AssignmentNode]) + instrumenter.assertNodeExists(229, 5, classOf[ApplicationNode]) eval(code) () } @@ -142,7 +146,8 @@ class CodeLocationsTest extends InterpreterTest { "be correct for lambdas" in withLocationsInstrumenter { instrumenter => val code = - """ + """from Standard.Base import all + | |main = | f = a -> b -> a + b | g = x -> y -> @@ -151,8 +156,8 @@ class CodeLocationsTest extends InterpreterTest { | | f 1 (g 2 3) |""".stripMargin.linesIterator.mkString("\n") - instrumenter.assertNodeExists(16, 15, classOf[CreateFunctionNode]) - instrumenter.assertNodeExists(40, 42, classOf[CreateFunctionNode]) + instrumenter.assertNodeExists(46, 15, classOf[CreateFunctionNode]) + instrumenter.assertNodeExists(70, 42, classOf[CreateFunctionNode]) eval(code) () } @@ -160,16 +165,17 @@ class CodeLocationsTest extends InterpreterTest { "be correct for defaulted arguments" in withLocationsInstrumenter { instrumenter => val code = - """ + """from Standard.Base import all + | |main = | bar = x -> x + x * x | foo = x -> (y = bar x) -> x + y | foo 0 |""".stripMargin.linesIterator.mkString("\n") - instrumenter.assertNodeExists(53, 5, classOf[ApplicationNode]) - instrumenter.assertNodeExists(53, 3, classOf[ReadLocalVariableNode]) - instrumenter.assertNodeExists(57, 1, classOf[ReadLocalVariableNode]) + instrumenter.assertNodeExists(93, 5, classOf[ApplicationNode]) + instrumenter.assertNodeExists(93, 1, classOf[ReadLocalVariableNode]) + instrumenter.assertNodeExists(97, 1, classOf[ReadLocalVariableNode]) eval(code) () } @@ -177,13 +183,14 @@ class CodeLocationsTest extends InterpreterTest { "be correct for lazy arguments" in withLocationsInstrumenter { instrumenter => val code = - """ + """from Standard.Base import all + | |main = | bar = a -> ~b -> ~c -> b | | bar 0 10 0 |""".stripMargin.linesIterator.mkString("\n") - instrumenter.assertNodeExists(35, 1, classOf[ForceNode]) + instrumenter.assertNodeExists(65, 1, classOf[ForceNode]) eval(code) () } @@ -198,19 +205,21 @@ class CodeLocationsTest extends InterpreterTest { "be correct for negated expressions" in withLocationsInstrumenter { instrumenter => val code = - """ + """from Standard.Base import all + | |main = | f = 1 | -f |""".stripMargin.linesIterator.mkString("\n") - instrumenter.assertNodeExists(22, 1, 2, 1, classOf[ApplicationNode]) + instrumenter.assertNodeExists(52, 1, 2, 1, classOf[ApplicationNode]) eval(code) } "be correct in sugared method definitions" in withLocationsInstrumenter { instrumenter => val code = - """ + """from Standard.Base.Data.Numbers import all + | |Test.foo a b = a * b - a | |main = Test.foo 2 3 @@ -221,7 +230,10 @@ class CodeLocationsTest extends InterpreterTest { val method = mod.getMethod(tpe, "foo").get method.value.invokeMember( MethodNames.Function.GET_SOURCE_START - ) shouldEqual 1 + ) should ( + equal(44) or + equal(45) + ) method.value.invokeMember( MethodNames.Function.GET_SOURCE_LENGTH ) should ( @@ -229,7 +241,7 @@ class CodeLocationsTest extends InterpreterTest { equal(25) ) - instrumenter.assertNodeExists(16, 9, classOf[ApplicationNode]) + instrumenter.assertNodeExists(59, 9, classOf[ApplicationNode]) eval(code) } @@ -237,20 +249,23 @@ class CodeLocationsTest extends InterpreterTest { "be correct in sugared function definitions" in withLocationsInstrumenter { instrumenter => val code = - """|main = + """|from Standard.Base import all + | + |main = | f a b = a - b | f 10 20 |""".stripMargin.linesIterator.mkString("\n") - instrumenter.assertNodeExists(11, 1, 13, 0, classOf[AssignmentNode]) - instrumenter.assertNodeExists(19, 1, 5, 0, classOf[ApplicationNode]) + instrumenter.assertNodeExists(41, 1, 13, 0, classOf[AssignmentNode]) + instrumenter.assertNodeExists(49, 1, 5, 0, classOf[ApplicationNode]) eval(code) } "be correct in the presence of comments" in withLocationsInstrumenter { instrumenter => val code = - """ + """from Standard.Base import all + | |# this is a comment |#this too |## But this is a doc. @@ -260,8 +275,8 @@ class CodeLocationsTest extends InterpreterTest { | # perform the addition | x + y # the addition is performed here |""".stripMargin.linesIterator.mkString("\n") - instrumenter.assertNodeExists(82, 1, classOf[LiteralNode]) - instrumenter.assertNodeExists(164, 5, classOf[ApplicationNode]) + instrumenter.assertNodeExists(112, 1, classOf[LiteralNode]) + instrumenter.assertNodeExists(194, 5, classOf[ApplicationNode]) eval(code) shouldEqual 3 } From a59a72a44e8b2f2694fe88175ab849014c4cdde3 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Wed, 13 Nov 2024 17:42:04 +0100 Subject: [PATCH 12/18] Add more members to Function.isMemberInvocable Keep in sync with doInvoke. --- .../interpreter/runtime/callable/function/Function.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/function/Function.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/function/Function.java index a0c249164262..f93932d807bc 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/function/Function.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/function/Function.java @@ -276,7 +276,9 @@ Object invokeMember(String member, Object... args) */ @ExportMessage boolean isMemberInvocable(String member) { - return member.equals(MethodNames.Function.EQUALS); + return member.equals(MethodNames.Function.EQUALS) + || member.equals(MethodNames.Function.GET_SOURCE_START) + || member.equals(MethodNames.Function.GET_SOURCE_LENGTH); } /** @@ -299,7 +301,10 @@ boolean hasMembers() { */ @ExportMessage Object getMembers(boolean includeInternal) { - return ArrayLikeHelpers.wrapStrings(MethodNames.Function.EQUALS); + return ArrayLikeHelpers.wrapStrings( + MethodNames.Function.EQUALS, + MethodNames.Function.GET_SOURCE_START, + MethodNames.Function.GET_SOURCE_LENGTH); } /** From 11405460f250d6ffbbbdae83a699a636612db1a7 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 14 Nov 2024 13:08:58 +0100 Subject: [PATCH 13/18] EnsoObject.toDisplayString delegates to toString method --- .../main/java/org/enso/interpreter/runtime/data/EnsoObject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java index 19566189a367..a899ac16766e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java @@ -22,6 +22,6 @@ public Class> getLanguage() { @ExportMessage public Object toDisplayString(boolean allowSideEffects) { - throw new UnsupportedOperationException("unimplemented"); + return toString(); } } From 7fa2022b8c6fd657057bc8da504e5c919df843ef Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 14 Nov 2024 13:51:57 +0100 Subject: [PATCH 14/18] EnsoObject.toDisplayString is behind TruffleBoundary --- .../main/java/org/enso/interpreter/runtime/data/EnsoObject.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java index a899ac16766e..4ca81883b7aa 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java @@ -1,5 +1,6 @@ package org.enso.interpreter.runtime.data; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.interop.TruffleObject; @@ -21,6 +22,7 @@ public Class> getLanguage() { } @ExportMessage + @TruffleBoundary public Object toDisplayString(boolean allowSideEffects) { return toString(); } From f0dae474dff22e9cfbeb0b48afbfaf879bbde3ac Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 14 Nov 2024 18:08:44 +0100 Subject: [PATCH 15/18] Warning exports InteropLibrary which delegates to value. With the exception of toDisplayString message. --- .../org/enso/interpreter/runtime/warning/Warning.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java index 1ca8ecae5ea6..b6025eb2abdc 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java @@ -20,8 +20,9 @@ @Builtin(pkg = "error", stdlibName = "Standard.Base.Warning.Warning") @ExportLibrary(TypesLibrary.class) +@ExportLibrary(value = InteropLibrary.class, delegateTo = "value") public final class Warning extends EnsoObject { - private final Object value; + final Object value; private final Object origin; private final long sequenceId; @@ -106,6 +107,12 @@ public static EnsoHashMap fromArrayToMap(Warning[] warnings, HashMapInsertNode m return map; } + @ExportMessage + @Override + public Object toDisplayString(boolean enableSideEffects) { + return toString(); + } + @CompilerDirectives.TruffleBoundary @Override public String toString() { From 5955ff33566f4d24b524d37e9f2eccf1092fc7ed Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 14 Nov 2024 18:09:23 +0100 Subject: [PATCH 16/18] WithWarnings needs to explicitly export toDisplayString. It is not automatically delegated because it is implemented in the super type. --- .../org/enso/interpreter/runtime/warning/WithWarnings.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/WithWarnings.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/WithWarnings.java index 38821c3f1e8e..5c42bb00a8f7 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/WithWarnings.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/WithWarnings.java @@ -270,6 +270,12 @@ RuntimeException throwException(@Bind("$node") Node node) { throw asException(node); } + @ExportMessage + public Object toDisplayString( + boolean allowSideEffects, @CachedLibrary("this.value") InteropLibrary interop) { + return interop.toDisplayString(value, allowSideEffects); + } + @Override public String toString() { return "WithWarnings{" From db225ed0a6bfee75cf7e989f3d4bd94e9ba4a476 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 14 Nov 2024 18:09:55 +0100 Subject: [PATCH 17/18] EnsoObject.toDisplayString just throws AssertionError --- .../java/org/enso/interpreter/runtime/data/EnsoObject.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java index 4ca81883b7aa..f70b676366d5 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java @@ -1,6 +1,5 @@ package org.enso.interpreter.runtime.data; -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.interop.TruffleObject; @@ -22,8 +21,8 @@ public Class> getLanguage() { } @ExportMessage - @TruffleBoundary public Object toDisplayString(boolean allowSideEffects) { - return toString(); + // Not implemented on purpose - should be implemented by subclasses. + throw new AssertionError("unimplemented"); } } From 06d1d4c9500ed493bb0d1a3c5e1f1c34945922d4 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 14 Nov 2024 18:58:15 +0100 Subject: [PATCH 18/18] AssertionError is behind TruffleBoundary --- .../main/java/org/enso/interpreter/runtime/data/EnsoObject.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java index f70b676366d5..9070cab2140e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java @@ -1,5 +1,6 @@ package org.enso.interpreter.runtime.data; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.interop.TruffleObject; @@ -21,6 +22,7 @@ public Class> getLanguage() { } @ExportMessage + @TruffleBoundary public Object toDisplayString(boolean allowSideEffects) { // Not implemented on purpose - should be implemented by subclasses. throw new AssertionError("unimplemented");