Code Monkey home page Code Monkey logo

Comments (7)

rahulmutt avatar rahulmutt commented on July 18, 2024

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.

from eta-hackage.

mmisamore avatar mmisamore commented on July 18, 2024

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.

from eta-hackage.

jneira avatar jneira commented on July 18, 2024

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

from eta-hackage.

rahulmutt avatar rahulmutt commented on July 18, 2024

@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 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 mentioned.

So I think the true fix has to be a better if condition. Perhaps if (!(closure instanceof Thunk) && !(closure instanceof DataCon)).

from eta-hackage.

mmisamore avatar mmisamore commented on July 18, 2024

from eta-hackage.

rahulmutt avatar rahulmutt commented on July 18, 2024

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).

from eta-hackage.

rahulmutt avatar rahulmutt commented on July 18, 2024

Should be resolved after typelead/eta#896 submitted by the OP.

from eta-hackage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.