[MLton-commit] r5369

Matthew Fluet fluet at mlton.org
Wed Feb 28 17:53:21 PST 2007


Ensure that setInitExtra and setExtendExtra are initialized.

This is required for situation where the Basis Library raises (and
handles) exceptions during initialization.

(For example, raising and handling Overflow to compute Array.maxLen
from SeqIndex.maxInt using SeqIndex.toInt.  Thraises Overflow if
SeqIndex == Int64 and Int == Int32, which indicates that we should use
Int.maxInt for Array.maxLen.  On the other hand, this does not raise
Overflow if SeqIndex == Int32 and Int == Int64, which indicates that
we should use SeqIndex.toInt (SeqIndex.maxInt) for Array.maxLen.)

Befor this commit, when such a program is compiled with "-const
'Exn.keepHistory true'", it would immediately terminate with
'MLton_bug "setExtendExtra unimplemented"'.  This corresponds to
trying to raise an exception before basis-library/mlton/exn.sml
executed, which would setExtendExtra.

Now, such a program is able to raise an exception during
initialization (without an associated call-stack).


----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-mlton.sml

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-mlton.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-mlton.sml	2007-02-28 18:13:37 UTC (rev 5368)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-mlton.sml	2007-03-01 01:53:20 UTC (rev 5369)
@@ -90,6 +90,22 @@
       val setExtendExtra: (extra -> extra) -> unit = setExtendExtra
       val setInitExtra = _prim "Exn_setInitExtra": 'a -> unit;
       val setInitExtra: extra -> unit = setInitExtra
+
+      (* Ensure that setInitExtra and setExtendExtra are initialized.
+       * Important for -const 'Exn.keepHistory true', so that 
+       * exceptions can be raised (and handled) during Basis Library
+       * initialization.
+       *)
+      val setInitExtra : extra -> unit =
+         if keepHistory
+            then (setInitExtra (NONE: extra)
+                  ; fn _ => ())
+         else fn _ => ()
+      val setExtendExtra : (extra -> extra) -> unit =
+         if keepHistory
+            then (setExtendExtra (fn _ => NONE)
+                  ; setExtendExtra)
+         else fn _ => ()
    end
 
 structure FFI =




More information about the MLton-commit mailing list