Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006211OCamlOCaml backend (code generation)public2013-10-25 08:092014-04-23 18:14
ReporterHiroaki Yamanouchi 
Assigned To 
PriorityhighSeveritymajorReproducibilityalways
StatusnewResolutionopen 
PlatformOSOS Version
Product Version3.11.2 
Target VersionFixed in Version 
Summary0006211: An unexpected behavior in toplevel: combination of consecutive let bindings and exceptions
DescriptionAn unexpected behavior in consecutive let bindings at toplevel, say, “let x1 = e1 let x2 = e2;;”. If e2 raises an exception, the result of “x;;” afterwards depends on whether x1 had been already bound before the evaluation of the first phrase.

----- Here is a case when a variable is not bound. -----

(* x is not bound *)

# let x = 2 let y = 1 / 0;;

Exception: Division_by_zero.

# x;;

Error: Unbound value x

----- Here is a case when a variable is bound. -----

# let x = 1;;

val x : int = 1

(* now, x is bound to 1 *)

# let x = 3 let y = 1 / 0;;

Exception: Division_by_zero.

# x;;

- : int = 3 (* I suppose that the result should be 1 *)
Steps To ReproduceAt toplevel, input the following codes.

1. "let x = 1;;"
2. "let x = 3 let y = 1 / 0;;"
3. "x;;"
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0010526)
garrigue (manager)
2013-10-25 09:59

This is a "serious" bug:

# let x = "hello";;
val x : string = "hello"
# let x = 2 let y = 1/0;;
Exception: Division_by_zero.
# x;;
Segmentation fault
(0010527)
garrigue (manager)
2013-10-25 10:28

I see two ways to fix this:

1) generalize the approach taken for modules of using a unique name for toplevel values

or

2) remember old values and backtrack in case of failure

Personally I would prefer (1), as it is looks like the "right" thing.
However, IIRC correctly, the goal of the current approach of using just a string is to avoid memory leaks.
We would probably have to do something about that too.
WIth (2), we get this for free.
(0011317)
frisch (developer)
2014-04-23 18:14

Couldn't we typecheck+run each structure item separately (and fail on the first error)? As in:

Index: toplevel/toploop.ml
===================================================================
--- toplevel/toploop.ml	(revision 14658)
+++ toplevel/toploop.ml	(working copy)
@@ -236,8 +236,11 @@
 
 (* Execute a toplevel phrase *)
 
-let execute_phrase print_outcome ppf phr =
+let rec execute_phrase print_outcome ppf phr =
   match phr with
+  | Ptop_def (x :: (_ :: _ as tl)) ->
+      execute_phrase print_outcome ppf (Ptop_def [x]) &&
+      execute_phrase print_outcome ppf (Ptop_def tl)
   | Ptop_def sstr ->
       let oldenv = !toplevel_env in
       Typecore.reset_delayed_checks ();

- Issue History
Date Modified Username Field Change
2013-10-25 08:09 Hiroaki Yamanouchi New Issue
2013-10-25 09:59 garrigue Note Added: 0010526
2013-10-25 10:28 garrigue Note Added: 0010527
2014-04-23 18:14 frisch Note Added: 0011317


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker