Giter Site home page Giter Site logo

Comments (5)

 avatar commented on August 21, 2024

I'll take a look at this.

from ziria.

dimitriv avatar dimitriv commented on August 21, 2024

To help you see what is going on, arrays are allocated at the moment in two ways: (a) if they are very big OR their size is unknown at code-generation time (i.e. we are generating the code for the body of a length-polymorphic function) then they go through the wpl_alloca() path. This emulates a big stack for every function, which is finally popped all the way up (since Ziria can only return by-value, and never assign pointers -- with the caveat being that other weird bug you discovered a couple of days ago @siddhanathan :-)). However, what is happening here is that the wpl_alloca happens to be /inside/ a very large loop so before even getting the chance to deallocate memory, we run out of it. (b) if arrays are small and statically known then they are just declared locally in the current scope (but, again, we should be very careful that we don't just return their addresses when they go out of scope) . All this logic exists in CgTypes.hs which provides a lot of functionality for such things. I am not entirely sure actually that the fix is straightforward: I can think of several things: (1) execute the loop body using "inAllocFrame" which will ensure that we push/pop in every iteration -- this may be the simplest thing but introduces a slight perf penaly; i'd give this a try first. (2) Somehow hoist big allocations out of loops (seems harder as we have to inspect deeply all blocks of code, find declarations etc.).

from ziria.

dimitriv avatar dimitriv commented on August 21, 2024

(The actual test file is struct3.wpl, not struct03.wpl I think)

from ziria.

 avatar commented on August 21, 2024

There is at least one naive fix, and that is to abuse DeclPkg by doing the assignment during the declaration itself. So instead of DeclPkg ig [stmt] we could have DeclPkg ig [] and do wpl_alloca inside ig itself.

from ziria.

 avatar commented on August 21, 2024

Eh.... I didn't mean to link those commits here.

@dimitriv would https://github.com/siddhanathan/Ziria/commit/cd3a61d57b963fc8af15f0e86f62b27c09e103ec work? It essentially does the wpl_alloca at the declaration scope, ensuring that the wpl_alloca doesn't happen inside a loop. I know all tests pass. I tried other variations including pushing/popping on every iteration, and they either have bad performance or cause tests to fail.

from ziria.

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.