Giter Site home page Giter Site logo

Comments (4)

nojb avatar nojb commented on June 1, 2024

Thanks for the report. Indeed there seems to be a miscompilation in this case. The lambda code of the "dps" (destination-passing style) transform of the function in your example is

      test_1_dps/280
        (function dst/287 offset/286[int] param/285 tail_mod_cons
          (if param/285
            (let (tl/288 =a (field 1 param/285))
              (try
                (makeblock 0 (int,*) (caml_int_of_string (field 0 param/285))
                  (apply test_1/269 tl/288 tailcall(false)))
               with exn/289
                (if (== (field 0 exn/289) (field 6 (global Stdlib!)))
                  (let (block/290 = (makemutable 0 (int,*) -1 24029))
                    (seq
                      (setfield_ptr(heap-init)_computed dst/287 offset/286
                        block/290)
                      (apply test_1_dps/280 block/290 1 tl/288 tailcall)))
                  (setfield_ptr(heap-init)_computed dst/287 offset/286
                    (reraise exn/289)))))
            (setfield_ptr(heap-init)_computed dst/287 offset/286 0))))

The problem is that in the body of the try-with, the code does not "fill" the destination dst/287, so the block is left filled with garbage.

A tentative fix is in #12958

from ocaml.

gasche avatar gasche commented on June 1, 2024

This is indeed a bug! The following patch fixes it, but I need to understand it better and audit the rest of the transformation for similar issues.

diff --git i/lambda/tmc.ml w/lambda/tmc.ml
index 5edbcdf8b5..a9bc1d1baa 100644
--- i/lambda/tmc.ml
+++ w/lambda/tmc.ml
@@ -644,8 +644,8 @@ let rec choice ctx t =
            not in tail-call position (after it returns
            we need to remove the exception handler),
            so it is not transformed here *)
-        let l1 = traverse ctx l1 in
-        let+ l2 = choice ctx ~tail l2 in
+        let+ l1 = Choice.lambda (traverse ctx l1)
+        and+ l2 = choice ctx ~tail l2 in
         Ltrywith (l1, id, l2)
     | Lstaticcatch (l1, ids, l2) ->
         (* In [static-catch l1 with ids -> l2],

from ocaml.

gasche avatar gasche commented on June 1, 2024

@SylvainBoilard this should now be fixed (in development versions). Thanks again for the report!

from ocaml.

SylvainBoilard avatar SylvainBoilard commented on June 1, 2024

Thank you for the quick fix, looking forward for the next release!

from ocaml.

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.