-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmark and speed processing of polyglot java imports up (#10899)
- Loading branch information
1 parent
1f9a856
commit 339c275
Showing
17 changed files
with
275 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...e/runtime/src/main/java/org/enso/interpreter/node/expression/constant/LazyObjectNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.