-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speedup DataflowError.withDefaultTrace (#11153)
Improves the speed of `ExecutionEnvironment.hasContextEnabled`. # Important Notes Local speedup of `Map_Error_Benchmark_Vector_ignore.Map_Id_All_Errors` benchmark is roughly ???.
- Loading branch information
Showing
8 changed files
with
157 additions
and
81 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
4 changes: 4 additions & 0 deletions
4
engine/runtime/src/main/java/org/enso/interpreter/runtime/state/ContextPermissions.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,4 @@ | ||
package org.enso.interpreter.runtime.state; | ||
|
||
/** Fields correspond to the constructors of {@code Standard.Base.Runtime.Context} builtin type. */ | ||
record ContextPermissions(boolean input, boolean output, boolean dataflowStacktrace) {} |
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
62 changes: 62 additions & 0 deletions
62
engine/runtime/src/main/java/org/enso/interpreter/runtime/state/HasContextEnabledNode.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,62 @@ | ||
package org.enso.interpreter.runtime.state; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Cached; | ||
import com.oracle.truffle.api.dsl.GenerateUncached; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.nodes.Node; | ||
import org.enso.interpreter.runtime.EnsoContext; | ||
import org.enso.interpreter.runtime.data.atom.AtomConstructor; | ||
|
||
/** | ||
* A node representing the functionality done by {@code Standard.Base.Runtime.Context.is_enabled}. | ||
*/ | ||
@GenerateUncached | ||
public abstract class HasContextEnabledNode extends Node { | ||
|
||
public static HasContextEnabledNode getUncached() { | ||
return HasContextEnabledNodeGen.getUncached(); | ||
} | ||
|
||
public static HasContextEnabledNode create() { | ||
return HasContextEnabledNodeGen.create(); | ||
} | ||
|
||
/** | ||
* Returns true if the context represented by the given {@code runtimeCtxCtor} is enabled in the | ||
* given {@code executionEnvironment}. | ||
* | ||
* @param runtimeCtxCtor Constructor of {@code Standard.Base.Runtime.Context}. | ||
*/ | ||
public abstract boolean executeHasContextEnabled( | ||
ExecutionEnvironment executionEnvironment, AtomConstructor runtimeCtxCtor); | ||
|
||
@Specialization(guards = "executionEnvironment == cachedEnv", limit = "3") | ||
boolean cachedHasContextEnabled( | ||
ExecutionEnvironment executionEnvironment, | ||
AtomConstructor runtimeCtxCtor, | ||
@Cached("executionEnvironment") ExecutionEnvironment cachedEnv) { | ||
return doIt(cachedEnv, runtimeCtxCtor); | ||
} | ||
|
||
@Specialization(replaces = "cachedHasContextEnabled") | ||
boolean uncachedHasContextEnabled( | ||
ExecutionEnvironment executionEnvironment, AtomConstructor runtimeCtxCtor) { | ||
return doIt(executionEnvironment, runtimeCtxCtor); | ||
} | ||
|
||
private boolean doIt(ExecutionEnvironment executionEnvironment, AtomConstructor runtimeCtxCtor) { | ||
var ensoCtx = EnsoContext.get(this); | ||
var contextBuiltin = ensoCtx.getBuiltins().context(); | ||
if (runtimeCtxCtor == contextBuiltin.getInput()) { | ||
return executionEnvironment.permissions.input(); | ||
} else if (runtimeCtxCtor == contextBuiltin.getOutput()) { | ||
return executionEnvironment.permissions.output(); | ||
} else if (runtimeCtxCtor == contextBuiltin.getDataflowStackTrace()) { | ||
return executionEnvironment.permissions.dataflowStacktrace(); | ||
} else { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw ensoCtx.raiseAssertionPanic(this, "Unknown context: " + runtimeCtxCtor, null); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
engine/runtime/src/main/java/org/enso/interpreter/runtime/state/WithContextNode.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,60 @@ | ||
package org.enso.interpreter.runtime.state; | ||
|
||
import com.oracle.truffle.api.dsl.GenerateUncached; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.nodes.Node; | ||
import org.enso.interpreter.runtime.EnsoContext; | ||
import org.enso.interpreter.runtime.data.atom.Atom; | ||
|
||
/** | ||
* A node representing functionality done by {@code Standard.Base.Runtime.Context.with_enabled} and | ||
* {@code Standard.Base.Runtime.Context.with_disabled}. That is, it enables or disables the given | ||
* context in the current {@link ExecutionEnvironment execution environment}. | ||
*/ | ||
@GenerateUncached | ||
public abstract class WithContextNode extends Node { | ||
public static WithContextNode getUncached() { | ||
return WithContextNodeGen.getUncached(); | ||
} | ||
|
||
public static WithContextNode create() { | ||
return WithContextNodeGen.create(); | ||
} | ||
|
||
/** | ||
* Returns a new {@link ExecutionEnvironment} with the given context enabled or disabled. | ||
* | ||
* @param current Current execution environment. | ||
* @param context Atom of type {@code Standard.Base.Runtime.Context}. | ||
* @param enabled Whether to enable or disable the context. | ||
*/ | ||
public abstract ExecutionEnvironment executeEnvironmentUpdate( | ||
ExecutionEnvironment current, Atom context, boolean enabled); | ||
|
||
@Specialization | ||
ExecutionEnvironment doIt(ExecutionEnvironment current, Atom context, boolean enabled) { | ||
var ensoCtx = EnsoContext.get(this); | ||
var contextBuiltin = ensoCtx.getBuiltins().context(); | ||
if (context.getConstructor().getType() != contextBuiltin.getType()) { | ||
throw ensoCtx.raiseAssertionPanic(this, "Invalid context type", null); | ||
} | ||
var ctor = context.getConstructor(); | ||
ContextPermissions newPermissions; | ||
if (ctor == contextBuiltin.getInput()) { | ||
newPermissions = | ||
new ContextPermissions( | ||
enabled, current.permissions.output(), current.permissions.dataflowStacktrace()); | ||
} else if (ctor == contextBuiltin.getOutput()) { | ||
newPermissions = | ||
new ContextPermissions( | ||
current.permissions.input(), enabled, current.permissions.dataflowStacktrace()); | ||
} else if (ctor == contextBuiltin.getDataflowStackTrace()) { | ||
newPermissions = | ||
new ContextPermissions( | ||
current.permissions.input(), current.permissions.output(), enabled); | ||
} else { | ||
throw ensoCtx.raiseAssertionPanic(this, "Unknown context: " + ctor, null); | ||
} | ||
return new ExecutionEnvironment(current.getName(), newPermissions); | ||
} | ||
} |