Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple expression evaluation #2774

Closed
vicuna opened this issue Jun 4, 2001 · 4 comments
Closed

simple expression evaluation #2774

vicuna opened this issue Jun 4, 2001 · 4 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Jun 4, 2001

Original bug ID: 375
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_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

@vicuna
Copy link
Author

vicuna commented Jun 5, 2001

Comment author: administrator

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

@vicuna
Copy link
Author

vicuna commented Jun 5, 2001

Comment author: administrator

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

@vicuna
Copy link
Author

vicuna commented Jun 7, 2001

Comment author: administrator

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

@vicuna
Copy link
Author

vicuna commented Jun 12, 2001

Comment author: administrator

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.

@vicuna vicuna closed this as completed Jun 12, 2001
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant