Skip to content
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

Version the graph examples #84

Merged
merged 11 commits into from
Mar 20, 2024
Merged

Version the graph examples #84

merged 11 commits into from
Mar 20, 2024

Conversation

nirvdrum
Copy link
Contributor

@nirvdrum nirvdrum commented Mar 15, 2024

This PR restores the script for generating examples and modernizes it.

We were unable to run the Ruby examples with GraalVM 21.2.0 because Graal was missing a necessary option. When those results were generated manually they were done with a patched version of Graal. Subsequent versions of Graal have the option enabled so this script can now process the Ruby examples.

To help keep storage size down, I've switched all the top-level examples to symlinks to a GraalVM-versioned set of files. Now that the Ruby example graphs are generated automatically, I've compressed them just like the Java example graphs.

I think is in keeping with what @chrisseaton had in mind in #37. I haven't yet added the ability to directly compare graphs from different GraalVM versions, although that can be done approximately with the seafoam describe command.

* Run the Ruby examples on GraalVM distributions that support it.
* Added GraalVM 22.3.1 to the list of GraalVM distributions used for graph generation.
* Restructure the way we run commands to enable code reuse.
@nirvdrum nirvdrum requested a review from rwstauner March 15, 2024 22:56
Copy link
Contributor

@rwstauner rwstauner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me.
A few minor nits but fine as is.

tools/generate-examples.rb Outdated Show resolved Hide resolved
tools/generate-examples.rb Show resolved Hide resolved
tools/generate-examples.rb Outdated Show resolved Hide resolved
…rmat.

GraalVM used to ship as a JVM into which one could install multiple languages with a tool named `gu`. The `gu` utility was removed and languages are now avaliable as Maven artifacts. While that's considerably more convenient for applications embedding Truffle languages, it complicates using each language's launcher. Consequently, we now need to install separate distributions for each language in order to run the examples for that language.
@nirvdrum nirvdrum changed the title Version examples Version the graph examples Mar 19, 2024
@nirvdrum nirvdrum force-pushed the version-examples branch 2 times, most recently from 5d082a8 to 94e5dda Compare March 19, 2024 21:31
@nirvdrum nirvdrum marked this pull request as ready for review March 19, 2024 21:36
FileUtils.cp("fib-java.bgv.gz", "#{__dir__}/../examples/#{graalvm.name}")

if reference_graalvm?(graalvm)
FileUtils.ln_sf("#{__dir__}/../examples/#{graalvm.name}/fib-java.bgv.gz", "#{__dir__}/../examples")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is creating symlinks with absolute paths

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work?

Suggested change
FileUtils.ln_sf("#{__dir__}/../examples/#{graalvm.name}/fib-java.bgv.gz", "#{__dir__}/../examples")
FileUtils.ln_sf("#{graalvm.name}/fib-java.bgv.gz", "#{__dir__}/../examples")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh. I thought I fixed all of those. I'll take another look. Thanks!

tools/generate-examples.rb Outdated Show resolved Hide resolved
Comment on lines 328 to 329
FileUtils.ln_sf("#{__dir__}/../examples/#{graalvm.name}/fib-js.bgv.gz", "#{__dir__}/../examples/")
FileUtils.ln_sf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also these

Comment on lines 374 to 375
FileUtils.ln_sf("#{__dir__}/../examples/#{graalvm.name}/fib-ruby.bgv.gz", "#{__dir__}/../examples")
FileUtils.ln_sf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and these

Comment on lines +317 to +339
raise unless bgv.size == 1
raise if bgv_ast.size > 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good error message we could include here? Like a pointer as to what file to go look at if these sizes aren't right? Or would it be more likely to be a failure in a command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't know. It's a sanity check so the code that follows makes sense. I can't think of a reason why there would ever be more than one AST file unless Graal changes something unexpectedly. If that's the case, all we can really do is look at the error and reevaluate what assumption no longer holds.

tools/generate-examples.rb Show resolved Hide resolved
Copy link
Contributor

@rwstauner rwstauner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as we fix the symlinks the rest of the comments aren't blockers, feel free to take them or leave them.

Comment on lines +363 to +385
raise unless bgv.size == 1
raise if bgv_ast.size > 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, is there any hint worth providing about what to look into if this was an issue?

Copy link
Contributor

@rwstauner rwstauner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests pass for me locally.
I tried the tool and it updates all the examples, but then I get a single test failure:

rspec spec
........................................................F........................................................................................

Failures:

  1) Seafoam::Commands#props prints properties for a file
     Failure/Error: expect(@out.string.gsub("\n\n", "\n")).to(eq("{\n  \"vm.uuid\": \"21734\"\n}\n"))
     
       expected: "{\n  \"vm.uuid\": \"21734\"\n}\n"
            got: "{\n  \"vm.uuid\": \"64368\"\n}\n"
     
       (compared using ==)
     
       Diff:
       @@ -1,4 +1,4 @@
        {
       -  "vm.uuid": "21734"
       +  "vm.uuid": "64368"
        }
       
     # ./spec/seafoam/command_spec.rb:253:in `block (3 levels) in <top (required)>'

Finished in 1.1 seconds (files took 0.10114 seconds to load)
145 examples, 1 failure

Failed examples:

rspec ./spec/seafoam/command_spec.rb:251 # Seafoam::Commands#props prints properties for a file

rake aborted!
Command failed with status (1): [rspec spec...]
/Users/rwstauner/src/github.com/Shopify/seafoam/Rakefile:8:in `block in <top (required)>'
/Users/rwstauner/ruby/rbenv/versions/3.3.0/bin/bundle:25:in `load'
/Users/rwstauner/ruby/rbenv/versions/3.3.0/bin/bundle:25:in `<main>'
Tasks: TOP => specs
(See full trace by running task with --trace)

Any idea why that is or what it means? Is it worth fixing

expect(@out.string.gsub("\n\n", "\n")).to(eq("{\n \"vm.uuid\": \"21734\"\n}\n"))

somehow? Do we care what the value is, or could we change it to just match digits?

expect(@out.string.gsub("\n\n", "\n")).to(match(/{\n  "vm\.uuid": "\d+"\n}/))

@nirvdrum
Copy link
Contributor Author

The UUID is unique for each graph. If you regenerate the examples, you'll get a new graph. While it's inconvenient that the one spec would fail, the expectation is that you'll go verify the UUID is correct by other means and ensure the test is checking for the correct value. If we made it a regex pattern it could result in the parser breaking without anyone noticing.

@rwstauner
Copy link
Contributor

I did notice that in 2 different runs I got different values, but I thought if it was always different I would have seen you update it... which I didn't. I do see it has changed a few times in the history.

What does the value mean? Or what is it tied to?

Now I realize that when I run the script I have updates to examples/graalvm-ce-java11-21.2.0 but this PR doesn't change those. If I just restore that dir the spec passes, which explains why you didn't have to update the value in your PR.
Just to check my sanity: does the script update your examples/graalvm-ce-java11-21.2.0 dir? Did you just not include them because they didn't need to change (to keep the diff down)?

…he reference examples to use GraalVM 23.1.2.
@nirvdrum
Copy link
Contributor Author

Now I realize that when I run the script I have updates to examples/graalvm-ce-java11-21.2.0 but this PR doesn't change those. If I just restore that dir the spec passes, which explains why you didn't have to update the value in your PR. Just to check my sanity: does the script update your examples/graalvm-ce-java11-21.2.0 dir? Did you just not include them because they didn't need to change (to keep the diff down)?

I didn't include them because there was no real need to regenerate them. Moreover, we can't fully regenerate them without patching Graal since GraalVM 21.1.0 did not support the --engine.InlineOnly option. Those graphs were generated manually with a patched version of Graal.

I suppose I could just not regenerate the graphs if the directory exists, but if we add new examples or change any of the engine options, we could then miss updates. In either case the person running the tool needs to be aware of what they're pushing. Given the node IDs change, this operation will never be idempotent, so it's incumbent on the person running the script to only commit meaningful changes.

@rwstauner
Copy link
Contributor

Thanks, that makes sense to me 👍

* Added optional logging of commands being run.
* Fixed deprecated usage of Graal options.
* Cleaned up the reference to the examples directory.
@nirvdrum nirvdrum merged commit e1d0afa into main Mar 20, 2024
17 checks passed
@nirvdrum nirvdrum deleted the version-examples branch March 20, 2024 17:54
@nirvdrum nirvdrum restored the version-examples branch March 20, 2024 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants