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

The Truffle language translator misses proper language detection #77

Open
nirvdrum opened this issue Jul 5, 2023 · 5 comments
Open
Labels
bug Something isn't working

Comments

@nirvdrum
Copy link
Contributor

nirvdrum commented Jul 5, 2023

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
Copy link
Contributor Author

nirvdrum commented Jul 5, 2023

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.

@nirvdrum nirvdrum added the bug Something isn't working label Jul 5, 2023
@eregon
Copy link
Contributor

eregon commented Jul 6, 2023

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
Copy link
Contributor

eregon commented Jul 6, 2023

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
Copy link
Contributor Author

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
Copy link
Contributor

eregon commented Mar 22, 2024

I checked on 24.0.0 native, and #77 (comment) 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants