oracle / fastr

A high-performance implementation of the R programming language, built on GraalVM.
Other
626 stars 64 forks source link

Should not reach here #73

Open rbotafogo opened 5 years ago

rbotafogo commented 5 years ago

The following code in Galaaz get "should not reach here" message:

require 'galaaz'
R.library 'tidyverse'
# read data file
@financas = R.read_csv2('finance.csv',
                        locale: R.locale(date_names: "br", decimal_mark: ",", 
                                         grouping_mark: "."))

@financas =
  @financas.
    mutate('Valor BRR': :'Valor Nominal' *
                        E.if_else((:Data.eq "04/12/2018"), 1, 3.86))
/home/rbotafogo/desenv/galaaz/lib/R_interface/rsupport.rb:235:in `exec_function': java.lang.RuntimeException: com.oracle.truffle.r.runtime.RInternalError: java.lang.RuntimeException: com.oracle.truffle.r.runtime.RInternalError: should not reach here: invalid wrapping: DynamicObjectBasic (RInternalError) (RuntimeError)
    from com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:330)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:325)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:315)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:302)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:284)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:239)
    from org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:63)
    from com.oracle.truffle.r.nodes.function.call.CallRFunctionNode.execute(CallRFunctionNode.java:63)
    from com.oracle.truffle.r.nodes.function.RCallNode$DispatchedCallNode.execute(RCallNode.java:1212)
    from com.oracle.truffle.r.nodes.function.RCallNode$FunctionDispatch.dispatch(RCallNode.java:918)
Caused by:
com.oracle.truffle.r.runtime.RInternalError: java.lang.RuntimeException: com.oracle.truffle.r.runtime.RInternalError: should not reach here: invalid wrapping: DynamicObjectBasic (RuntimeException)
    from com.oracle.truffle.r.ffi.impl.nfi.HandleNFIUpCallExceptionNode.execute(HandleNFIUpCallExceptionNode.java:48)
    from com.oracle.truffle.r.ffi.impl.upcalls.Rf_evalCall$Rf_evalCallFactory$1.execute(Rf_evalCall.java:80)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:325)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:315)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:302)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:284)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:239)
    from org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:63)
    from com.oracle.truffle.api.interop.InteropAccessNode$CachedNode.doCached(InteropAccessNode.java:304)
    from com.oracle.truffle.api.interop.InteropAccessNodeFactory$CachedNodeGen.executeImpl(InteropAccessNodeFactory.java:42)
Caused by:
java.lang.RuntimeException: com.oracle.truffle.r.runtime.RInternalError: should not reach here: invalid wrapping: DynamicObjectBasic (RInternalError)
    from com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:330)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:325)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:315)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:302)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:284)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:239)
    from org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:63)
    from com.oracle.truffle.r.nodes.function.call.CallRFunctionNode.execute(CallRFunctionNode.java:63)
    from com.oracle.truffle.r.nodes.function.RCallNode$DispatchedCallNode.execute(RCallNode.java:1212)
    from com.oracle.truffle.r.nodes.function.RCallNode$FunctionDispatch.dispatch(RCallNode.java:918)
Caused by:
com.oracle.truffle.r.runtime.RInternalError: should not reach here: invalid wrapping: DynamicObjectBasic (RuntimeException)
    from com.oracle.truffle.r.ffi.impl.nfi.HandleNFIUpCallExceptionNode.execute(HandleNFIUpCallExceptionNode.java:48)
    from com.oracle.truffle.r.ffi.impl.upcalls.CARCall$CARCallFactory$1.execute(CARCall.java:78)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:325)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:315)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:302)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:284)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:239)
    from org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:63)
    from com.oracle.truffle.api.interop.InteropAccessNode$CachedNode.doCached(InteropAccessNode.java:304)
    from com.oracle.truffle.api.interop.InteropAccessNodeFactory$CachedNodeGen.executeImpl(InteropAccessNodeFactory.java:42)
Caused by:
should not reach here: invalid wrapping: DynamicObjectBasic (RInternalError)
    from com.oracle.truffle.r.runtime.RInternalError.shouldNotReachHere(RInternalError.java:132)
    from com.oracle.truffle.r.runtime.ffi.FFIWrapNode.wrap(FFIWrapNode.java:129)
    from com.oracle.truffle.r.runtime.ffi.FFIWrapNodeGen.executeAndSpecialize(FFIWrapNodeGen.java:183)
    from com.oracle.truffle.r.runtime.ffi.FFIWrapNodeGen.execute(FFIWrapNodeGen.java:100)
    from com.oracle.truffle.r.ffi.impl.upcalls.CARCall$CARCallFactory$1.execute(CARCall.java:71)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:325)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:315)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:302)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:284)
    from org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:239)
Translated to internal error
    from /home/rbotafogo/desenv/galaaz/lib/R_interface/rsupport.rb:271:in `exec_function_name'
    from /home/rbotafogo/desenv/galaaz/lib/R_interface/robject.rb:180:in `method_missing'
    from bugs/should_not.rb:12:in `<main>'
rake aborted!

To reproduce:

chrisseaton commented 5 years ago

Thanks for the report. I'll move it to FastR though, as it's their exception. It many eventually be something that Ruby is done wrong, but it should probably start with them.

steve-s commented 5 years ago

Hello Rodrigo,

thank you for the report. This issue happens when the R code sends TruffleRuby object to the native code of the rlang package. That is something we haven't encountered yet. It seems that we should allow foreign objects to leak into native code and be able to retrieve them back as results from the native code, with that implemented, I am now getting this output:

cols(
  ID = col_double(),
  `CONTA / INVESTIMENTO` = col_character(),
  Data = col_character(),
  `Quantidade Cotas` = col_double(),
  `Valor Cota` = col_double(),
  `Valor Nominal` = col_number(),
  `Valor R$` = col_number(),
  `IR + IOF` = col_logical(),
  `Valor Líquido` = col_number(),
  Percent = col_logical(),
  Diferença = col_logical()
)
/home/steve/Development/Graal/graalvm-bin/graalvm/galaaz/lib/R_interface/rsupport.rb:235:in `exec_function': Error in mutate_impl(.data, dots) : (RuntimeError)
  Evaluation error: `false` must be type integer, not double.
In addition: Warning message:
In mutate_impl(.data, dots) :
  mismatched protect/unprotect (unprotect with empty protect stack) (RError)
Translated to internal error
    from /home/steve/Development/Graal/graalvm-bin/graalvm-dev/galaaz/lib/R_interface/rsupport.rb:271:in `exec_function_name'
    from /home/steve/Development/Graal/graalvm-bin/graalvm/galaaz/lib/R_interface/robject.rb:170:in `method_missing'
    from bugs/should_not.rb:13:in `<main>'

Note that the mismatched protect/unprotect warning is a known issue of the Rcpp package. I assume that is still not the expected output? The error seems to be issued by galaaz. Do you have any insight into what could be going wrong here? /CC @chrisseaton

P.S.: I reduced the set of necessary packages to dplyr and readr to avoid having to install whole tidyverse

rbotafogo commented 5 years ago

Hi Stepan,

I'm not sure why a TruffleObject is being sent to rlang. Galaaz should (in principle) convert or wrap all Ruby Objects into R objects before calling any functions. So, in principle, rlang should only see R objects. But, I might have overlooked something. If a Ruby Object is being sent to R, I`d like to get an error message. I don't think that R should see leaked Ruby objects, other than by following the Truffle API, i.e., if it has a Ruby object and calls methods on them according to the API.

In the code you've executed, the expected value was the creation of a new column 'Valor BRR' with the exact same values as column 'Valor Nominal'. The expression E.if_else((:Data.eq "04/12/2018"), 1, 3.86), should be converted to the equivalent R expression => if_else((Data == "04/12/2018"), 1, 3.86). Since all elements in column 'Data' are equal to "04/12/2018", this should always evaluate to 'true' and thus the if_else should always return 1 and this multiplies the value in 'Valor Nominal'. So 'Valor BRR' = 'Valor Nominal' * 1.

Here, is a similar code that works fine. The main difference is that the data frame comes with R:

require 'galaaz'
R.install_and_loads('nycflights13')
R.library('dplyr')

@flights = ~:flights
@flights = @flights.
             mutate("Diff Chegada": :arr_time - :sched_arr_time,
                         'Total Delay': :'Diff Chegada' *
                                              E.if_else(((:arr_time -

:sched_arr_time) < 0), 1, 2), 'Moeda.x': "R$", 'Valor BRR': :'Diff Chegada' * E.if_else((:'Moeda.x'.eq "R$"), :'Total Delay', 100))

puts @flights.head.as__data__frame

Note that 'Valor BRR' has the same construct in here and in the example you are running. In this case if_else(Moeda.x == "R$") is always true, so it returns 'Total Delay' and 'Valor BRR' = 'Diff Chegada' * 'Total Delay'.

The output of this code is

year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time 1 2013 1 1 517 515 2 830 819 2 2013 1 1 533 529 4 850 830 3 2013 1 1 542 540 2 923 850 4 2013 1 1 544 545 -1 1004 1022 5 2013 1 1 554 600 -6 812 837 6 2013 1 1 554 558 -4 740 728 arr_delay carrier flight tailnum origin dest air_time distance hour minute 1 11 UA 1545 N14228 EWR IAH 227 1400 5 15 2 20 UA 1714 N24211 LGA IAH 227 1416 5 29 3 33 AA 1141 N619AA JFK MIA 160 1089 5 40 4 -18 B6 725 N804JB JFK BQN 183 1576 5 45 5 -25 DL 461 N668DN LGA ATL 116 762 6 0 6 12 UA 1696 N39463 EWR ORD 150 719 5 58 time_hour Diff Chegada Total Delay Moeda.x Valor BRR 1 2013-01-01 05:00:00 11 22 R$ 242 2 2013-01-01 05:00:00 20 40 R$ 800 3 2013-01-01 05:00:00 73 146 R$ 10658 4 2013-01-01 05:00:00 -18 -18 R$ 324 5 2013-01-01 06:00:00 -25 -25 R$ 625 6 2013-01-01 05:00:00 12 24 R$ 288

Hope this helps!

Em sex, 3 de mai de 2019 às 09:57, Stepan Sindelar notifications@github.com escreveu:

Hello Rodrigo,

thank you for the report. This issue happens when the R code sends TruffleRuby object to the native code of the rlang package. That is something we haven't encountered yet. It seems that we should allow foreign objects to leak into native code and be able to retrieve them back as results from the native code, with that implemented, I am now getting this output:

cols(

ID = col_double(),

CONTA / INVESTIMENTO = col_character(),

Data = col_character(),

Quantidade Cotas = col_double(),

Valor Cota = col_double(),

Valor Nominal = col_number(),

Valor R$ = col_number(),

IR + IOF = col_logical(),

Valor Líquido = col_number(),

Percent = col_logical(),

Diferença = col_logical()

)

/home/steve/Development/Graal/graalvm-bin/graalvm-ce-19.0.0-dev/galaaz/lib/R_interface/rsupport.rb:235:in `exec_function': Error in mutate_impl(.data, dots) : (RuntimeError)

Evaluation error: false must be type integer, not double.

In addition: Warning message:

In mutate_impl(.data, dots) :

mismatched protect/unprotect (unprotect with empty protect stack) (RError)

Translated to internal error

from /home/steve/Development/Graal/graalvm-bin/graalvm-ce-19.0.0-dev/galaaz/lib/R_interface/rsupport.rb:271:in `exec_function_name'

from /home/steve/Development/Graal/graalvm-bin/graalvm-ce-19.0.0-dev/galaaz/lib/R_interface/robject.rb:170:in `method_missing'

from bugs/should_not.rb:13:in `

'

Note that the mismatched protect/unprotect warning is a known issue of the Rcpp package. I assume that is still not the expected output? The error seems to be issued by galaaz. Do you have any insight into what could be going wrong here? /CC @chrisseaton https://github.com/chrisseaton

P.S.: I reduced the set of necessary packages to dplyr and readr to avoid having to install whole tidyverse

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/oracle/fastr/issues/73#issuecomment-489086206, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6QP4KY3XEASBOXRVYTHKDPTQZFHANCNFSM4HJFIOVA .

-- Rodrigo Botafogo