enso/tools/enso4igv
Pavel Marek f0de43a970
Add org.enso.compiler.dumpIr system prop (#10740)
Working on compiler IR is a daunting task. I have therefore added a new system property `enso.compiler.dumpIr` that will help with that. It dumps the encountered IRs to `ir-dumps` directory in the [GraphViz](www.graphviz.org) format. More info in updated docs.

Note that all the functionality to dump IRs to `dot` files was already implemented. This PR just adds the command line option and updates docs.

# Important Notes
- `--dump-graphs` cmd line option is removed as per [Jaroslav's request](https://github.com/enso-org/enso/pull/10740#pullrequestreview-2216676140).
- To dump graphs, use `-Dgraal.Dump=Truffle:2` system property passed via `JAVA_OPTS` env var.

If you run `env JAVA_OPTS='-Denso.compiler.dumpIr=true' enso --run tmp.enso` where `tmp.enso` is, e.g.:
```
from Standard.Base import all
main = 42
```
You will then have something like:
```
$ ls ir-dumps
Standard.Base.Data.Filter_Condition.dot     Standard.Base.Data.Time.dot              Standard.Base.System.Advanced.dot       Standard.Base.Warning.dot
Standard.Base.Data.Locale.dot               Standard.Base.Enso_Cloud.Enso_File.dot   Standard.Base.System.File.Advanced.dot  tmp.dot
Standard.Base.Data.Numeric.dot              Standard.Base.Errors.dot                 Standard.Base.System.File.dot
Standard.Base.Data.Numeric.Internal.dot     Standard.Base.Network.HTTP.Internal.dot  Standard.Base.System.File.Generic.dot
Standard.Base.Data.Text.Regex.Internal.dot  Standard.Base.Runtime.dot                Standard.Base.System.Internal.dot
```
You can then visualize any of these with `dot -Tsvg -O ir-dumps/tmp.dot`.

An example how that could look like is
![image.svg](https://github.com/user-attachments/assets/26ab8415-72cf-46da-bc63-f475e9fa628e)
2024-08-06 12:00:27 +00:00
..
nbproject Syntax Color and Debug JavaScript/Python in Enso Source (#9440) 2024-03-15 10:28:13 +01:00
src Add org.enso.compiler.dumpIr system prop (#10740) 2024-08-06 12:00:27 +00:00
.gitignore Icon and documentation for Enso VSCode extension (#8051) 2023-10-15 04:43:26 +00:00
.vscodeignore Basic VSCode support for Enso language and development (#4014) 2023-01-06 14:18:20 +00:00
IGV.md Add org.enso.compiler.dumpIr system prop (#10740) 2024-08-06 12:00:27 +00:00
package-lock.json Enso language support with parser in VSCode, IGV, etc. (#7054) 2024-06-14 14:01:37 +00:00
package.json Enso language support with parser in VSCode, IGV, etc. (#7054) 2024-06-14 14:01:37 +00:00
pom.xml Enso language support with parser in VSCode, IGV, etc. (#7054) 2024-06-14 14:01:37 +00:00
README.md Enso language support with parser in VSCode, IGV, etc. (#7054) 2024-06-14 14:01:37 +00:00
tsconfig.json Basic VSCode support for Enso language and development (#4014) 2023-01-06 14:18:20 +00:00
webpack.config.js Format TS code (#10648) 2024-07-26 17:47:59 +10:00

Enso Language Support for VSCode

Enso Language Support for VSCode

Downloading

Enso Tools for VSCode is available from VSCode marketplace. Simply install it from there.

It is possible to download the latest development version of the "VSCode Extension" artifact from the latest actions run. After downloading the ZIP file unzip a .vsix from it and install the .vsix file into VSCode.

Your Enso files will get proper syntax coloring. You'll be able to debug Java/Enso code interchangeably.

After installing the Enso .vsix file (and reloading window) we can find following two extensions in the system:

Installed VSCode extensions

Outline View

Since version 1.40 the extension fills content of Outline View on supported platforms (Linux amd64, Mac, Windows):

image

Debugging a Single Enso File

Open any .enso files. Click left editor gutter to place breakpoints. Then choose Run/Start Debugging. If asked, choose debug with Java+ (Enso is Java virtual machine friendly). A prompt appears asking for path to bin/enso binary:

Select enso executable

Locate bin/enso executable in the Enso engine download. If binding from source code, the executable is located at root of Enso repository in ./built-distribution/enso-engine-*/enso-*/bin/enso. The .enso file gets executed and output is printed in the area below editor:

Executed

Workspace Debugging

To work with all Enso code base continue with choosing File/Open Folder... and opening root of Enso Git Repository (presumably already built with sbt buildEngineDistribution). Following set of projects is opened and ready for use:

Enso Projects

With the workspace opened, you can open any Enso or Java file. Let's open for example Vector_Spec.enso - a set of unit tests for Vector - a core class of Enso standard library:

Openning Vector

It is now possible to place breakpoints into the Vector_Spec.enso file. Let's place one on line 120:

Breakpoint

To debug the test/Base_Tests/src/Data/Vector_Spec.enso file with the root of Enso repository opened in the VSCode workspace, choose preconfigured Launch Enso File debug configuration before Run/Start Debugging.:

Launch Enso File in a Project

The rest of the workflow remains the same as in case of individual (without any project ).enso file case.

Attach Debugger to a Process

Let's do a bit of debugging. Select "Listen to 5005" debug configuration:

Listen to 5005

And then just execute the engine distribution in debug mode:

sbt:enso> runEngineDistribution --debug --run test/Base_Tests/src/Data/Vector_Spec.enso

After a while the breakpoint is hit and one can inspect variables, step over the statements and more...

Breakpoint in Enso

...as one can seamlessly switch to debugging on the Enso interpreter itself! One can place breakpoint into Java class like PanicException.java and continue debugging with F5:

Breakpoint in Java

Should one ever want to jump back from Java to Enso one can use the "Pause in GraalVM Script" action. Select it and continue with F5 - as soon as the code reaches a statement in Enso, it stops:

Pause in GraalVM

Read more on Enso & Java Debugging

Building VSCode Extension

To build this VSCode extension and obtain Enso syntax coloring as well as support for editing and debugging of engine/runtime sources in VSCode:

enso/tools/enso4igv$ mvn clean install -Pvsix
enso/tools/enso4igv$ ls *.vsix
enso4vscode-*.vsix

one needs to have npm, Java and mvn available to successfully build the VSCode extension.

Install from VSIX...

Once the .vsix file is created, it can be installed into VSCode. Select Extension perspective and choose Install from VSIX... menu item.

Reference

There are extensions for NetBeans and also for IGV. Read more here.