-
Notifications
You must be signed in to change notification settings - Fork 188
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
File.directory? calls to_i in RC15, but not in RC14 #1665
Comments
Thank you for the report. I'm confused by the following lines in galaaz master: def self.eval(string)
begin
Polyglot.eval("R", string)
rescue RuntimeError
raise NoMethodError.new("Method #{string} not found in R environment")
end
end Throwing a NoMethodError manually is already unusual, but then assuming it's a NoMethodError without checking what was the RuntimeError seems incorrect in general. From the error above, it looks like galaaz is trying to |
Benoit,
You are completely right... this is bad code and incorrect in general.
Removing the rescue clause gives the following output:
=====
******* method_missing
["(eval):1:in `attach_function_eagerly'", "(eval):1:in
`truffleposix_stat_mode'", "(eval):1:in `directory?'", "(eval):1:in `<top
(required)>'", "<eval wrapper>:7:in `instance_eval'", "<eval wrapper>:7:in
`<top (required)>'", "<REPL>:1:in `<repl wrapper>'", "<REPL>:1"]
uint32[[-2:-1]]
to_i
[]
An internal error occurred.
Please report an issue at https://github.com/oracle/fastr including the
commands. You can rerun FastR with --R.PrintErrorStacktracesToFile=true to
turn on internal errors logging. Please attach the log file to the issue if
possible.
====
And you are also correct that the code is trying to call 'to_i'. Sorry if
I'm repeating the question, but this just what I'm wondering, why is to_i
being called in RC15 and not in RC14? The code is just calling
File.directory?('.') which should be true and I don't see how it could
reach method 'eval' in R::Support module.
Not trying to justify the bad code, but this rescue clause was added
because for some reason unknown to me, Rspec was implicitly calling to_ary
in an R::Object which ended up with the same 'internal error'. In
robject.rb I`ve added the following code:
#--------------------------------------------------------------------------------------
# @todo: rspec sometimes calls to_ary when an expected value is false.
I still don't
# understand this call. Returning an array with a number inside seems
to make
# rspec happy, however this could have other consequences I don't know
of.
#--------------------------------------------------------------------------------------
def to_ary
[1]
end
If you have any clue as why this happens, it would be great!
Thanks...
Em ter, 16 de abr de 2019 às 19:29, Benoit Daloze <[email protected]>
escreveu:
… Thank you for the report.
I'm confused by the following lines in galaaz master:
https://github.com/rbotafogo/galaaz/blob/2e73b3019af705a2a00df0c507bfbabcee877c4a/lib/R_interface/rsupport.rb#L88-L94
def self.eval(string)
begin
Polyglot.eval("R", string)
rescue RuntimeError
raise NoMethodError.new("Method #{string} not found in R environment")
end
end
Throwing a NoMethodError manually is already unusual, but then assuming
it's a NoMethodError without checking what was the RuntimeError seems
incorrect in general.
From the error above, it looks like galaaz is trying to Polyglot.eval("R",
"to_i")?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1665 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AD0H8e4DPoVdwu0OdsATbZZz3WX1YjdVks5vhk7FgaJpZM4cyjyw>
.
--
Rodrigo Botafogo
|
I'm trying to debug this in RC16, the first thing I noticed is the same issue as #1653:
But then once I worked around that (with
That's using the latest Galaaz gem release (0.4.8). |
I can reproduce with Galaaz master: print("Hi")
res <- eval.polyglot("ruby", "\
$0=%q(test.R)\
$LOAD_PATH.unshift %q(/home/eregon/code/galaaz/lib)\
require(%q(galaaz))\
class RbChunk\
end\
RbChunk.new\
RbChunk.instance_eval(%q(File.directory?(%q(.))))
")
print(res)
|
The actual issue is that https://github.com/rbotafogo/galaaz/blob/a670116b0251a3c55ad4caac437ebed4e6be04fd/lib/R_interface/ruby_extensions.rb#L178-L180 redefines truffleruby/src/main/ruby/core/posix.rb Line 121 in 04afba2
Symbol#[] is a standard Ruby method: http://ruby-doc.org/core-2.6.3/Symbol.html#method-i-5B-5D
I can workaround in that code to use |
Other notes:
( It's unfortunate that |
I redefine Kernel#puts because for some weird reason if I don't do it, then
nothing gets printed. Can you try running:
puts R.c(1, 2, 3)
with both puts redefined and not? You'll see that when puts is redefined
it does print fine, without it nothing gets printed on the output.
I've realized that there is no need in my code to redefine Symbol#[], so
I'm just removing it.... thanks for finding this.
Em dom, 28 de abr de 2019 às 16:52, Benoit Daloze <[email protected]>
escreveu:
… Kernel#puts is redefined in
https://github.com/rbotafogo/galaaz/blob/a670116b0251a3c55ad4caac437ebed4e6be04fd/lib/R_interface/ruby_extensions.rb#L24-L31,
that's a bit confusing and that's the reason we see the unexpected output
for puts caller.
The actual issue is that
https://github.com/rbotafogo/galaaz/blob/a670116b0251a3c55ad4caac437ebed4e6be04fd/lib/R_interface/ruby_extensions.rb#L178-L180
redefines Symbol#[] and that's used by our internal implementation of FFI
to call truffleposix_stat_mode for File.directory? (nfi_return_type is a
Symbol):
https://github.com/oracle/truffleruby/blob/04afba28d4ab1bdbfd8d92027f1ccc48b9a50bcb/src/main/ruby/core/posix.rb#L121
Symbol#[] is a standard Ruby method:
http://ruby-doc.org/core-2.6.3/Symbol.html#method-i-5B-5D
I can workaround in that code to use String#[] instead like
nfi_return_type.to_s[-2..-1].to_i, and that fixes this example. I'll do
that change in TruffleRuby.
But this shows overriding Symbol#[] might have non-trivial consequences.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1665 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA6QP4IN4KFROSLUWOW67QLPSX6BBANCNFSM4HGKHSYA>
.
--
Rodrigo Botafogo
|
Another and probably simpler way is using
|
I'm not sure I understand that R::Object#method_missing can just call
super. This method has a lot of code to call R when the method is missing,
for example, R.c(1, 2, 3) will go through method missing.
Em dom, 28 de abr de 2019 às 17:08, Benoit Daloze <[email protected]>
escreveu:
… Other notes:
- R::Object#method_missing can use just super or super(symbol, *args,
&block) to trigger a NoMethodError, this will gives better information.
- To find out which file/line called to_i, the easiest for now is with:
--ruby.core-load-path=/path/to/truffleruby-checkout-of-the-same-version/src/main/ruby
and that gives in this case:
/home/eregon/code/galaaz/lib/R_interface/rsupport.rb:272:in `exec_function_name'
/home/eregon/code/galaaz/lib/R_interface/robject.rb:176:in `method_missing'
/home/eregon/code/truffleruby-ws/truffleruby/src/main/ruby/core/posix.rb:121:in `attach_function_eagerly'
/home/eregon/code/truffleruby-ws/truffleruby/src/main/ruby/core/posix.rb:90:in `truffleposix_stat_mode'
/home/eregon/code/truffleruby-ws/truffleruby/src/main/ruby/core/file.rb:372:in `directory?'
(eval):1:in `<top (required)>'
<eval wrapper>:8:in `instance_eval'
<eval wrapper>:8:in `<top (required)>'
/home/eregon/tmp/test.R:3:in `<repl wrapper>'
/home/eregon/tmp/test.R:1
(truffleruby/src/main/ruby/core/posix.rb:121 being the one calling to_i)
It's unfortunate that caller does not show core library files, but this
is required for Ruby compatibility.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1665 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA6QP4JJQVMZ4VT45KPN26LPSX72BANCNFSM4HGKHSYA>
.
--
Rodrigo Botafogo
|
You are right, I can reproduce, that must be a bug. I'll file a bug.
I meant for the |
@rbotafogo I filed #1679. |
* Symbol#[] might be overridden, for instance see #1665
I merged a fix to use |
The following code
When executed in RC14 returns the expected result '[1] TRUE', since '.' is a directory and Ruby 'true' becomes R vector with 1 element 'TRUE'.
Now, when ran against RC15 results in:
Note that although Galaaz was required, there is no call to anything in Galaaz. Class RbChunk was locally defined and is an empty class. Then I evaluate File.directory?('.') in the scope of RbChunk. I can't see why 'method_missing' is called with R::Object, since I'm giving a String '.' to File.directory?
I might have done something strange, but I really can't see it.
Adding the following code at the beginning of method_missing:
shows:
I couldn't reproduce the error without loading Galaaz.
Thanks
The text was updated successfully, but these errors were encountered: