Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000375OCamlOCaml generalpublic2001-06-04 10:572001-06-12 16:20
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000375: simple expression evaluation
DescriptionFull_Name: Laszlo Nemeth
Version: 3.01
OS: SunOS ropas 5.7 Generic sun4u sparc SUNW,Ultra-4
Submission from: apnc209.216.216.211.in-addr.arpa (211.216.216.38)


Hi,

I can hardly believe that this has not been spotted before, checked the
listings and found nothing similar, so here it goes:

code:

module type EXPR =
  sig
    type expr = Const of float
      | Sum of expr * expr
      | Diff of expr * expr
      | Prod of expr * expr
      | Quot of expr * expr
      | Get of float

    val simpl : expr -> expr
  end

-- note: Expr is not matched against the signature *)
module Expr (* : EXPR *) =
  struct
    type expr = Const of float
      | Sum of expr * expr
      | Diff of expr * expr
      | Prod of expr * expr
      | Quot of expr * expr
      | Get of float

    let rec simpl e =
      match e with
        Const c -> Const c
      | Sum (f1, f2) ->
          let f1' = simpl f1
          and f2' = simpl f2 in
          begin
            match f1', f2' with
              Const c1, Const c2 -> Const (c1 +. c2)
            | e1, e2 -> Sum (e1, e2)
          end
      | x -> x
  end

caml's reply in an emacs shell:

        Objective Caml version 3.01

# #use "expr.ml";;
module type EXPR =
  sig
    type expr =
        Const of float
      | Sum of expr * expr
      | Diff of expr * expr
      | Prod of expr * expr
      | Quot of expr * expr
      | Get of float
    val simpl : expr -> expr
  end
module Expr :
  sig
    type expr =
        Const of float
      | Sum of expr * expr
      | Diff of expr * expr
      | Prod of expr * expr
      | Quot of expr * expr
      | Get of float
    val simpl : expr -> expr
  end
# let one = Expr.Const 1.0 and two = Expr.Const 2.0 in Expr.simpl (Expr.Sum
(one, two));;
- : Expr.expr = Expr.Const 3
# let e = Expr.Sum (Expr.Const 1.0, Expr.Const 2.0) in Expr.simpl e;;

Process inferior-caml bus error

Whatever the cause of this (I also tried it from a non-emacs shell, with the
same behaviour) it shouldn't die horribly.

Thanks, Laszlo

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0002268)
administrator (administrator)
2001-06-05 03:15

I couldn't reproduce your bug, even on Solaris 5.6/sparc.
Can you give more details?
Is there an old expr.cmi around, for instance, which might confuse the
toplevel?

Jacques Garrigue
(0002269)
administrator (administrator)
2001-06-05 10:23

Hi Jacques,

I only use ocaml (compiled from source with -O3, no custom libraries),
so the .cmi file never gets generated, and the bug shows up even in a
freshly started interpreter. If I have a bit of time later on today I
rebuild ocaml with a lower level of optimisation and let you know if
that changes anything.

Thanks,
  Laszlo

(0002270)
administrator (administrator)
2001-06-07 10:12

Hi,


I've recompiled caml as it comes (no higher level of optimisation) and
-O2. In both cases the code included in the bug report evaluates as
expected. So this appears to be a gcc bug related to compiling caml
with -O3.

I guess the 'fix' is not to compile with -O3.

Laszlo Nemeth

(0002271)
administrator (administrator)
2001-06-12 16:20

Over-optimization by the C compiler. Still, would be interesting to see where
it generated wrong code, because that could point to an undefined behavior in
the OCaml runtime system.

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker