Shopify / seafoam

A tool for working with compiler graphs dumped by the GraalVM compiler
MIT License
125 stars 22 forks source link

The Truffle language translator misses proper language detection #77

Open nirvdrum opened 1 year ago

nirvdrum commented 1 year ago

When looking at the graph generated by the following Ruby code:

def foo(a, b)
  a + b
end

vals = (1...100).to_a
100_000.times { foo(vals.sample, vals.sample) }

you'll see that the two arguments a and b are represented in the Seafoam's simplified output as T(8) and T(9). These should render as T(args[0]) and T(args[1]) using the language translator pass. However, the translator is failing to detect that these are correspond to a TruffleRuby method.

nirvdrum commented 1 year ago

I looked into this a bit today and the language isn't being detected because at this point in the graph all we see are org.graalvm and java.lang nodes. We may need to broaden the heuristic used for language detection, but we need to be careful to not misattribute the language in polyglot cases.

eregon commented 1 year ago

For this case, many other nodes, including BoxNode feeding into the Return, have org.truffleruby in their node source sections. I wouldn't be too worried about polyglot cases, those are likely too big to look at with seafoam (IGV would work better for such cases), and one could override this detection via a command-line option maybe.

eregon commented 1 year ago

One way would be to look at the AST subdirectory and the graph there. That has a RubyMethodRootNode and even a field.polyglotRef = org.truffleruby.RubyLanguage@65a3abc7

nirvdrum commented 3 months ago

I just took a look at this with TruffleRuby 24.1.0-dev JVM CE and none of the source positions mentioned "org.truffleruby" as far as I can tell. The AST graphs are now merged into the same BGV file as the compilation graphs. I suppose we could strip the phase number off the command input and then look at a higher level phase to determine the language. It's a bit ugly, but should work.

eregon commented 3 months ago

I checked on 24.0.0 native, and https://github.com/Shopify/seafoam/issues/77#issuecomment-1624028358 is still accurate and seems the easiest way to find if it's a Ruby graph. IOW we need to look at the AST graph as the compilation graphs or Call Tree indeed have no trace left of TruffleRuby (on 24.0.0 Native, on JVM nodeSourcePosition usually helps (seen in IGV)). AST graph on Native: Screenshot from 2024-03-22 13-58-35