Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007661OCamlmiddle end (typedtree to clambda)public2017-10-26 16:522018-01-09 12:56
Reporterthizanne 
Assigned Tomaranget 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.05.0 
Target VersionFixed in Version4.06.1+dev/rc1/rc2 
Summary0007661: Odd behaviour of or-patterns with extensible typ
DescriptionOn this example, the evaluation of `f A B` doesn't go in the `(A | B) , B` branch. It works as intended if `t` is a non-extensible sum type. If the two first lines of the pattern matching are inverted, then `a` has the unexpected `'_'` value.

```
type t = ..
type t +=
  | A
  | B

let f x y = match x, y with
  | (A | B), A -> 'a'
  | (A | B), B -> 'b'
  | _, _ -> '_'

let a = f A A (* a : char = 'a' *)
let b = f A B (* b : char = '_' *)
```
TagsNo tags attached.
Attached Files

- Relationships
related to 0005788closedmaranget Exception rebinding breaks pattern matching 

-  Notes
(0018619)
thizanne (reporter)
2017-10-26 16:54

Original report by Abdelraouf Ouadjaout.
(0018620)
gasche (administrator)
2017-10-26 17:06

By "odd behavior" you mean "major bug" ! Thanks for the report.
(0018621)
gasche (administrator)
2017-10-26 17:11

I could reproduce the bug with all versions of OCaml that support extensible datatypes, from 4.02.1 to 4.06.0+beta2.
(0018622)
frisch (developer)
2017-10-26 17:18

Could reproduce with exceptions as well, of course.
(0018623)
yallop (developer)
2017-10-26 18:04

The bug appears to have been introduced in this commit, first released in 4.02.0:

https://github.com/ocaml/ocaml/commit/32bcc186ea16dd932f5369f5f5e7933b44ec4a9c [^]
(0018624)
gasche (administrator)
2017-10-26 18:09

I pinged Luc (and Jacques) so hopefully they will look at it. Incidentially, I'm meeting Thomas and Luc tomorrow to discuss pattern-matching things, so I guess that must be put on our list. (Of course anyone with a fix before that is warmly welcome.)
(0018625)
gasche (administrator)
2017-10-27 10:51
edited on: 2017-10-27 10:53

To reproduce with exceptions, just replace

    type t = .. type t += A | B

with

    exception A exception B

The correct lambda-code, from the state just before the faulty commit yallop found, looks like this:

(setglobal Repro!
  (let
    (A/1008 (makeblock 0 "Repro.A")
     B/1009 (makeblock 0 "Repro.B")
     f/1010
       (function x/1011 y/1012
         (catch
           (catch
             (if (== (field 0 x/1011) A/1008) (exit 5)
               (if (== (field 0 x/1011) B/1009) (exit 5) (exit 4)))
            with (5)
             (if (== (field 0 y/1012) A/1008) 'a'
               (if (== (field 0 y/1012) B/1009) 'b' (exit 4))))
          with (4) '_'))
     a/1013 (apply f/1010 (makeblock 0 A/1008) (makeblock 0 A/1008))
     b/1014 (apply f/1010 (makeblock 0 A/1008) (makeblock 0 B/1009))
     match/1020
       (seq (apply (field 25 (global Pervasives!)) b/1014)
         (apply (field 30 (global Pervasives!)) 0a)))
    (makeblock 0 A/1008 B/1009 f/1010 a/1013 b/1014)))

The incorrect lambda-code (after this commit) looks like

(setglobal Repro!
  (seq (opaque (global Pervasives!))
    (let
      (A/1199 = (makeblock 248 "Repro.A" (caml_fresh_oo_id 0))
       B/1200 = (makeblock 248 "Repro.B" (caml_fresh_oo_id 0))
       f/1201 =
         (function x/1202 y/1203
           (catch
             (catch
               (catch
                 (if (== x/1202 A/1199) (exit 7)
                   (if (== x/1202 B/1200) (exit 7)
                     (if (== x/1202 A/1199) (exit 8)
                       (if (== x/1202 B/1200) (exit 8) (exit 6)))))
                with (7) (if (== y/1203 A/1199) 'a' (exit 6)))
              with (8) (if (== y/1203 B/1200) 'b' (exit 6)))
            with (6) '_'))
       a/1204 = (apply f/1201 A/1199 A/1199)
       b/1205 = (apply f/1201 A/1199 B/1200)
       match/1214 =
         (seq (apply (field 25 (global Pervasives!)) b/1205)
           (apply (field 31 (global Pervasives!)) 0a)))
      (makeblock 0 A/1199 B/1200 f/1201 a/1204 b/1205))))

(0018633)
yallop (developer)
2017-10-31 11:00

Luc has implemented a fix: https://github.com/ocaml/ocaml/pull/1459 [^]
(0018681)
gasche (administrator)
2017-11-22 09:03

Fixed in trunk and the 4.06 maintenance branch.

Thanks thizanne for the report! May I recommend that you find your next major bug during the development or beta-testing period, rather than during the release-candidate period? :-)
(0018694)
hhugo (reporter)
2017-11-27 11:55

Compiling jbuilder with trunk gives:

Fatal error: exception Invalid_argument("index out of bounds")
Raised by primitive operation at file "bytecomp/matching.ml", line 1582, characters 34-59
Called from file "list.ml", line 100, characters 12-15
Called from file "bytecomp/matching.ml", line 1582, characters 2-73
Called from file "bytecomp/matching.ml", line 1589, characters 4-48
Called from file "bytecomp/matching.ml", line 155, characters 16-28
Called from file "bytecomp/matching.ml", line 176, characters 14-39
Called from file "bytecomp/matching.ml", line 1618, characters 15-56
Called from file "bytecomp/matching.ml", line 1175, characters 25-39
Called from file "bytecomp/matching.ml", line 1179, characters 8-27
Called from file "bytecomp/matching.ml", line 2756, characters 40-59
Called from file "bytecomp/matching.ml", line 2683, characters 6-145
Called from file "bytecomp/matching.ml", line 2501, characters 36-64
Called from file "bytecomp/matching.ml", line 2543, characters 14-47
Called from file "bytecomp/matching.ml", line 2620, characters 20-131
Called from file "bytecomp/matching.ml", line 2623, characters 18-151
Called from file "bytecomp/matching.ml", line 2634, characters 6-31
Called from file "bytecomp/matching.ml", line 2683, characters 6-145
Called from file "bytecomp/matching.ml", line 2879, characters 28-71
Called from file "bytecomp/translcore.ml", line 700, characters 59-76
Called from file "bytecomp/translcore.ml", line 1074, characters 30-46
Called from file "bytecomp/translcore.ml", line 1081, characters 9-35
Called from file "list.ml", line 82, characters 20-23
Called from file "bytecomp/translcore.ml", line 1204, characters 9-29
Called from file "bytecomp/translcore.ml", line 1181, characters 8-68
Called from file "bytecomp/translcore.ml", line 1181, characters 8-68
Called from file "bytecomp/translcore.ml", line 1181, characters 8-68
Called from file "bytecomp/translcore.ml", line 703, characters 8-213
Called from file "bytecomp/translobj.ml", line 182, characters 17-20
Re-raised at file "bytecomp/translobj.ml", line 199, characters 4-13
Called from file "bytecomp/translcore.ml", line 1213, characters 20-35
Called from file "bytecomp/translmod.ml", line 519, characters 10-48
Called from file "bytecomp/translmod.ml", line 517, characters 12-69
Called from file "bytecomp/translmod.ml", line 517, characters 12-69
Called from file "bytecomp/translmod.ml", line 517, characters 12-69
Called from file "bytecomp/translmod.ml", line 435, characters 14-52
Called from file "bytecomp/translmod.ml", line 904, characters 16-74
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 871, characters 37-188
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 915, characters 27-78
Called from file "bytecomp/translmod.ml", line 898, characters 37-188
Called from file "bytecomp/translmod.ml", line 871, characters 37-188
Called from file "bytecomp/translmod.ml", line 871, characters 37-188
Called from file "bytecomp/translmod.ml", line 871, characters 37-188
Called from file "bytecomp/translmod.ml", line 1031, characters 21-78
Called from file "bytecomp/translobj.ml", line 138, characters 13-18
Called from file "bytecomp/translmod.ml", line 1097, characters 18-65
Called from file "utils/misc.ml", line 28, characters 20-27
Re-raised at file "utils/misc.ml", line 28, characters 50-57
Called from file "driver/optcompile.ml" (inlined), line 67, characters 15-18
Called from file "driver/optcompile.ml", line 121, characters 10-133
Called from file "driver/optcompile.ml", line 139, characters 8-68
Re-raised at file "driver/optcompile.ml", line 144, characters 6-13
Called from file "utils/misc.ml", line 28, characters 20-27
Re-raised at file "utils/misc.ml", line 28, characters 50-57
Called from file "driver/compenv.ml", line 576, characters 6-35
Called from file "list.ml", line 100, characters 12-15
Called from file "driver/compenv.ml", line 652, characters 2-61
Called from file "driver/optmain.ml", line 253, characters 6-163
Re-raised at file "parsing/location.ml", line 465, characters 14-25
Re-raised at file "parsing/location.ml", line 465, characters 14-25
Re-raised at file "parsing/location.ml", line 465, characters 14-25
Re-raised at file "parsing/location.ml", line 465, characters 14-25
Re-raised at file "parsing/location.ml", line 465, characters 14-25
Re-raised at file "parsing/location.ml", line 465, characters 14-25
Called from file "parsing/location.ml" (inlined), line 470, characters 31-61
Called from file "driver/optmain.ml", line 313, characters 6-37
Called from file "driver/optmain.ml", line 317, characters 2-9
(0018695)
shinwell (developer)
2017-11-27 11:56

Re-assigned to Luc for fixing.
(0018696)
hhugo (reporter)
2017-11-27 11:57

instructions to reproduce the issue:

opam switch 4.07.0+trunk
opam install jbuilder
(0018699)
maranget (manager)
2017-11-28 17:44

Ok, I have reproduced the bug, then reduced it, and then, hopefully, fixed it.
Please see pull request 1493 on github.

https://github.com/ocaml/ocaml/pull/1493 [^]
(0018802)
trefis (manager)
2018-01-02 12:48

Since https://github.com/ocaml/ocaml/pull/1538 [^] was merged I think we can mark this as resolved again.

- Issue History
Date Modified Username Field Change
2017-10-26 16:52 thizanne New Issue
2017-10-26 16:54 thizanne Note Added: 0018619
2017-10-26 17:00 shinwell Assigned To => lpw25
2017-10-26 17:00 shinwell Status new => assigned
2017-10-26 17:00 shinwell Severity minor => major
2017-10-26 17:06 gasche Note Added: 0018620
2017-10-26 17:11 gasche Note Added: 0018621
2017-10-26 17:18 frisch Note Added: 0018622
2017-10-26 18:04 yallop Note Added: 0018623
2017-10-26 18:06 yallop Assigned To lpw25 => maranget
2017-10-26 18:09 gasche Note Added: 0018624
2017-10-27 10:51 gasche Note Added: 0018625
2017-10-27 10:52 gasche Note Edited: 0018625 View Revisions
2017-10-27 10:53 gasche Note Edited: 0018625 View Revisions
2017-10-27 10:59 xleroy Relationship added related to 0005788
2017-10-31 11:00 yallop Note Added: 0018633
2017-11-22 09:03 gasche Note Added: 0018681
2017-11-22 09:03 gasche Status assigned => resolved
2017-11-22 09:03 gasche Fixed in Version => 4.06.1+dev/rc1/rc2
2017-11-22 09:03 gasche Resolution open => fixed
2017-11-27 11:55 hhugo Note Added: 0018694
2017-11-27 11:55 shinwell Status resolved => assigned
2017-11-27 11:56 shinwell Note Added: 0018695
2017-11-27 11:57 hhugo Note Added: 0018696
2017-11-28 17:44 maranget Note Added: 0018699
2018-01-02 12:48 trefis Note Added: 0018802
2018-01-09 12:56 trefis Status assigned => resolved


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker