-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Benchmark and speed processing of polyglot java imports up #10899
Changes from all commits
f4a29a1
f93ee21
183ca7a
44ca279
0fba66b
6ee9c8f
e2c7bd3
a731929
5aa0bfd
6c00db4
7fa5662
53eece8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,16 +148,27 @@ private void assertWarningsForAType(Value v) { | |
assertEquals("Types without and with warnings are the same", type, warningType); | ||
assertTrue("It is an exception. Type: " + type, warning2.isException()); | ||
try { | ||
warning2.throwException(); | ||
throw warning2.throwException(); | ||
} catch (PolyglotException ex) { | ||
if (ex.getMessage() == null) { | ||
assertEquals(generator.typeError(), type); | ||
assertEquals(generator.typeError(), warningType); | ||
} else { | ||
assertThat( | ||
"Warning found for " + type, | ||
ex.getMessage(), | ||
AllOf.allOf(containsString("warn:once"), containsString("warn:twice"))); | ||
try { | ||
assertThat( | ||
"Warning found for " + type, | ||
ex.getMessage(), | ||
AllOf.allOf(containsString("warn:once"), containsString("warn:twice"))); | ||
} catch (AssertionError err) { | ||
if (type != null && v.equals(warning1) && v.equals(warning2)) { | ||
assertEquals( | ||
"Cannot attach warnings to Error - check it is an error", | ||
"Standard.Base.Error.Error", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Special case to handle DataflowErrors that cannot have Warnings. |
||
type.getMetaQualifiedName()); | ||
return; | ||
} | ||
throw err; | ||
} | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.enso.interpreter.node.expression.constant; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.interop.TruffleObject; | ||
import com.oracle.truffle.api.nodes.NodeInfo; | ||
import java.util.function.Supplier; | ||
import org.enso.interpreter.node.ExpressionNode; | ||
import org.enso.interpreter.runtime.data.text.Text; | ||
import org.enso.interpreter.runtime.error.DataflowError; | ||
import org.enso.interpreter.runtime.util.CachingSupplier; | ||
|
||
@NodeInfo( | ||
shortName = "lazy", | ||
description = "Represents an arbitrary compile-time constant computed lazily.") | ||
public final class LazyObjectNode extends ExpressionNode { | ||
|
||
private final String error; | ||
private final CachingSupplier<? extends Object> supply; | ||
|
||
private LazyObjectNode(String error, Supplier<? extends Object> supply) { | ||
this.error = error; | ||
this.supply = CachingSupplier.wrap(supply); | ||
} | ||
|
||
/** | ||
* Creates a node that returns lazily computed value. | ||
* | ||
* @param errorMessage the error message to show when the value is {@code null} | ||
* @param supplier computes the value lazily. Can return {@code null} and then the {@code | ||
* errorMessage} error is created | ||
*/ | ||
public static ExpressionNode build(String errorMessage, Supplier<TruffleObject> supplier) { | ||
return new LazyObjectNode(errorMessage, supplier); | ||
} | ||
|
||
@Override | ||
public Object executeGeneric(VirtualFrame frame) { | ||
var result = supply.get(); | ||
if (result instanceof TruffleObject) { | ||
return result; | ||
} | ||
return DataflowError.withDefaultTrace(Text.create(error), this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You only check if it is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean the Javadoc of build method that takes If typing is on, then check for |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolving
polyglot java import
s lazily prevents us to emit error during compilation. Instead we get a (dataflow)Error
when we execute therun
function and try to resolveRandom
function. Such an error is then returned as a value and needs to bethrowException
manually.