Closed mmisamore closed 5 years ago
We wanted to improve the user experience for the trampoline
function by giving the user hints when you're trampolining the wrong expression in your code. Turns out it's not a good idea according to this bug report.
If you would like a contribution opportunity, the fix to this is just removing the following lines in the runtime system: https://github.com/typelead/eta/blob/master/rts/src/main/java/eta/runtime/stg/Stg.java#L82-L88
If not, we'll get around to fixing this by the next release.
Thanks @rahulmutt! I see that it is trying to trampoline via an Eta Hackage patch here, but I'm not sure why it would fail in this specific case: https://github.com/typelead/eta-hackage/blob/master/patches/aeson-1.2.4.0.patch. As you said, maybe the aeson patch is trampolining on the wrong expression.
I'll pull down the eta compiler repo and see if I can get it to compile, because this looks like it would be educational.
If i remember correctly i got that error when using trampoline in a class instance method impl, so it seems internally it is not represented by a Thunk
like normal functions
@mmisamore Actually, the aeson
package is trampolining on the right expression, it's that the change in the trampolining implementation that I highlighted thinks that it's a wrong expression. That change was added very recently and I think we didn't test against an example like lens-aeson
. We should probably add this example to the test suite to catch future regressions.
The if
condition that determines whether an exception should be thrown was added because of what @jneira mentioned - if you use the trampoline
function wrong (try to trampoline a function directly that's not a thunk), it can throw really nasty exceptions that are less readable than the one you got.
The basic hierarchy for Eta values:
eta.runtime.stg.Closure
- The superclass of all Eta values
eta.runtime.thunk.Thunk
- The superclass of all yet-to-be evaluated expressions.eta.runtime.stg.Value
- The superclass of all thunks that have been evaluated to Weak Head Normal Formeta.runtime.stg.DataCon
- The superclass of all ADTseta.runtime.apply.Function
- The superclass of all functionseta.runtime.apply.PAP
- Stores "pending arguments" for curried functions and can be thought of as a function itself, though the hierarchy doesn't reflect it (yet).The trampoline
function calls the enter
method of the Closure
that is passed to it. The enter
method for subclasses of Value
other than Function
and PAP
simply returns itself because they don't have any code attached to them. For Function
and PAP
, enter
will execute the code of the respective function and retrieves the argument(s) from the ubiquitous StgContext
object (the object that stores the runtime state for the particular thread of execution).
The problem here is that trampoline
does not pass any arguments! So when you try to trampoline
against a function directly and not a thunk that evaluates a function, it will cause nasty errors that @jneira mentioned.
So I think the true fix has to be a better if
condition. Perhaps if (!(closure instanceof Thunk) && !(closure instanceof DataCon))
.
Awesome write-up! I'll see if I can fix it soon based on your suggestion.
On Wed, Oct 24, 2018, 10:23 PM Rahul Muttineni notifications@github.com wrote:
@mmisamore https://github.com/mmisamore Actually, the aeson package is trampolining on the right expression, it's that the change in the trampolining implementation that I highlighted thinks that it's a wrong expression. That change was added very recently and I think we didn't test against an example like lens-aeson. We should probably add this example to the test suite to catch future regressions.
The if condition that determines whether an exception should be thrown was added because of what @jneira https://github.com/jneira mentioned - if you use the trampoline function wrong (try to trampoline a function directly that's not a thunk), it can thrown really nasty exceptions that are less readable than the one you got.
The basic hierarchy for Eta values:
- eta.runtime.stg.Closure - The superclass of all Eta values
- eta.runtime.thunk.Thunk - The superclass of all yet-to-be evaluated expressions.
- eta.runtime.stg.Value - The superclass of all thunks that have been evaluated to Weak Head Normal Form
- eta.runtime.stg.DataCon - The superclass of all ADTs
- eta.runtime.apply.Function - The superclass of all functions
- eta.runtime.apply.PAP - Stores "pending arguments" for curried functions and can be thought of as a function itself, though the hierarchy doesn't reflect it (yet).
The trampoline function calls the enter method of the Closure that is passed to it. The enter method for subclasses of Value other than Function and PAP simply returns itself because they don't have any code attached to them. For Function and PAP, enter will execute the code of the respective function and retrieves the argument(s) from the ubiquitous StgContext object (the object that stores the runtime state for the particular thread of execution).
The problem here is that trampoline does not pass any arguments! So when you try to trampoline against a function directly and not a thunk that evaluates a function, it will cause nasty errors that @jneira https://github.com/jneira mentioned.
So I think the true fix has to be a better if condition. Perhaps if (!(closure instanceof Thunk) && !(closure instanceof DataCon)).
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/typelead/eta-hackage/issues/120#issuecomment-432890999, or mute the thread https://github.com/notifications/unsubscribe-auth/AGJUygetd6B1k662GNby_cjIkTAYrLqHks5uoSCDgaJpZM4X0bl_ .
Great. Btw, if you have successfully source installed the master
version of Eta, a fast way to test changes to the runtime can be done with:
stack exec eta-build -- rts-clean
All future Eta project compilations will use the new version of the runtime with your changes (unless you're using Gradle to compile your Eta projects, in which case you should wipe out ~/.gradle/caches/etlas
before doing that step).
Should be resolved after https://github.com/typelead/eta/pull/896 submitted by the OP.
Description
lens-aeson examples are throwing runtime exceptions.
Steps to Reproduce
or "42" ^? _Integer
Expected
Just 1.0 or Just 42
Actual
Environment