-
Notifications
You must be signed in to change notification settings - Fork 323
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
Use enso.dev.insight
property to turn Insight on
#11385
Conversation
…M Insight in the IDE as well as CLI
Insight & Enso ManualCreate Insight ScriptSimple script to start with is for example print("Initializing Insight: " + insight);
insight.on("enter", function(ctx) {
print("Calling " + ctx.name);
}, {
roots: true
});
Learn more about writing Insight Scripts:
Usage in CLIExecute either a script or use REPL: sbt:enso> runEngineDistribution --vm.D=enso.dev.insight=methods.js --repl
[info] Executing enso/built-distribution/enso-engine-*/enso-*/bin/enso --vm.D=enso.dev.insight=methods.js --repl
Initializing Insight: [object Object]
Calling Internal_Repl_Module___::Internal_Repl_Module___::internal_repl_entry_point___
> "Ahoj".reverse
Calling Standard.Base.Data.Text.Extensions::Standard.Base.Data.Text.Text::reverse
Calling Text.reverse.iterate
Calling Text.reverse.iterate
Calling Text.reverse.iterate
Calling Text.reverse.iterate
Calling Text.reverse.iterate
>>> johA Usage in IDECreate an Insight script like the enso$ ENSO_JVM_OPTS=-Denso.dev.insight=`pwd`/methods.js ./project-manager use absolute path to reference the Insight script file. In another terminal launch the IDE: enso$ corepack pnpm run dev:gui open a project. Output of your Insight script will be displayed in the
with the above project one gets following output:
modification of the code causes re-execution of the code and produces more messages. E.g. GraalVM Insight is active. Developer's WorkflowWhen you make a change to the Insight script, there is no need to restart everything, just:
The new script will be used. Enough for now or do you want more? |
enso.dev.insight=insightScript.js
property to play with GraalVM Insightenso.dev.insight=insightScript.js
property to turn Insight on
enso.dev.insight=insightScript.js
property to turn Insight onenso.dev.insight=in.js
property to turn Insight on
enso.dev.insight=in.js
property to turn Insight onenso.dev.insight
property to turn Insight on
QuirksThe biggest problem right now is multi-threaded execution. CLI is fine (as it is single threaded), but IDE tends to sometimes execute the program in parallel and Graal.js doesn't like it. Graal.js insists on enforcing single threaded ness. That causes issue that we need to work around:
None of the above shall stop us from integrating this Less Damage than ExpectedI was experiencing multi threaded execution problems with the simple Insight script that instruments invocations of all methods in any file, including methods in visualizations. That seems to cause issues. However the primary use-case we have is to instrument statements in |
var instrument = ctx.getEngine().getInstruments().get("insight"); | ||
@SuppressWarnings("unchecked") | ||
var insight = (Function<Source, AutoCloseable>) instrument.lookup(Function.class); | ||
insightHandle = insight.apply(insightSrc); |
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.
We could detect changes to the insightFile
via filesystem watcher and re-initialize the Insight script automatically. Just:
insightHandle.close()
to disable the currently active insights- load the new content
insight.apply(theNewSrc)
that way the speed of development would be closer to JavaScript development experience.
Useful Scripts: Detect Assign StatementsFollowing script attaches to print("Initializing Insight: " + insight);
insight.on("return", function(ctx, frame) {
let equals = ctx.characters.indexOf('\n') == -1 ? ctx.characters.indexOf('=') : -1;
let text = equals == -1 ? "" : `variable ${ctx.characters.substring(0, equals)} has just assigned`;
print(`At ${ctx.name}:${ctx.line} ${text}`);
for (let p in frame) {
let v = frame[p]
if (v != null) {
print(` property ${p} has value ${v}`);
}
}
}, {
statements: true,
rootNameFilter: ".*main"
}); a sample output may look like:
|
…efined in GraalVM Insight scripts using JavaScript. That also means self argument is available next to this in foreign js functions.
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.
approving the libs bit
Jaroslav Tulach reports a new STANDUP for yesterday (2024-10-23): Progress: .
|
Let's merge it! |
} | ||
var insightSrc = | ||
Source.newBuilder("epb", insightFile.toFile()) | ||
.content(language + ":0#" + insightCode) |
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.
Where is this cryptic :0#
string constant comming from? What does it mean?
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.
epb
is just an internal language. As such the documentation is provided on the level of tests https://github.com/enso-org/enso/pull/11385/files#diff-208ccc44a38434f59f03b9e2f77d891939bcd11de260a8a9c00c2e652fa3df5dR25 and sibling source code only.
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.
The support is primarily for foreign
functions. Language is language. The number is the line number where the script is located in the original file. The text behind #
is the code of the foreign
function.
We are re-using epb
as it has special support for invoking JavaScript in its own inner context to workaround the single threaded limitation.
Pull Request Description
This PR provides development only (e.g. no long term) API to enable (simple) usage of GraalVM Insight in the IDE and also in CLI. The insight script is sent to the internal EPB language responsible for interop with JavaScript, Python and other languages. Such integration revealed an inconsistency as
insight
object in the Insight script wasn't visible under the right name. Fixed by f50329a - which also changes behavior offoreign js
-self
is available (next to already availablethis
) in instance foreign methods.Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,