MantisBT - OCaml
View Issue Details
0006359OCamlback end (clambda to assembly)public2014-04-01 19:562015-12-11 19:26
0006359: not merged equal pattern matching branches
In the following example (extracted from ocamlnet), the fields extractions of n and g for cases `A and `D are not merged.

match `C with
| `A(n,g)
| `D(n,g) -> n + g
| _ -> 0

In the resulting lambda
# ocamlc -c -drawlambda
(setglobal Example!
    (let (match/1012 67a)
          (if (isint match/1012) (exit 2)
            (let (variant/1019 (field 0 match/1012))
              (if (!= variant/1019 65)
                (if (!= variant/1019 68) (exit 2)
                    (match/1017 (field 1 match/1012)
                     g/1016 (field 1 match/1017)
                     n/1015 (field 0 match/1017))
                    (exit 1 n/1015 g/1016)))
                  (match/1017 (field 1 match/1012)
                   g/1016 (field 1 match/1017)
                   n/1015 (field 0 match/1017))
                  (exit 1 n/1015 g/1016)))))
         with (2) 0)
       with (1 n/1008 g/1009) (+ n/1008 g/1009)))
    (makeblock 0)))

This is not strictly speaking a bug since it does not impact anything,
but I would like to assume that identifiers can't be bound multiple times
(in my backend patches) and this is the only case I know (in the opam
repository) where this don't hold.
No tags attached.
Issue History
2014-04-01 19:56chambartNew Issue
2014-04-02 04:28garrigueNote Added: 0011169
2014-04-02 11:20marangetNote Added: 0011171
2014-04-02 11:22marangetAssigned To => maranget
2014-04-02 11:22marangetStatusnew => confirmed
2014-04-02 15:23marangetStatusconfirmed => resolved
2014-04-02 15:23marangetResolutionopen => fixed
2014-04-02 15:23marangetFixed in Version => 4.02.0+dev
2014-04-02 15:24marangetNote Added: 0011173
2015-12-11 19:26xleroyStatusresolved => closed
2017-02-23 16:35doligezCategoryOCaml backend (code generation) => Back end (clambda to assembly)
2017-02-23 16:44doligezCategoryBack end (clambda to assembly) => back end (clambda to assembly)

2014-04-02 04:28   
Multiple binding of the same identifier is a bug: there are already parts of the backend where this invariant is assumed, and I have generated wrong code by just breaking it.
Whether to merge the branches or not is another question.
2014-04-02 11:20   
This is indeed a bug, and it is related to sharing!
(The match compiler re-shares actions which are alpha-equivalent
but this sharing is lost in the case for instance of variants.

2014-04-02 15:24   
Bug fixed in trunk. Thanks to all.