Version
110.99.3 (Latest)
Operating System
OS Version
No response
Processor
System Component
SML/NJ Library
Severity
Major
Description
The HashSetFn functor (hash-set-fn.sml) calculates maxSize as the largest power of 2 that is still less than Array.maxLen.
However, the calculation does not properly handle systems in which Int.maxInt = SOME Array.maxLen, causing an exception to be raised during functor instantiation.
Note: This bug does not occur on the SML/NJ compiler, since Array.maxLen is much smaller than Int.maxInt.
The issue is reproducible for MLton (latest version: 20230523-gd082c4a36), since there SOME Array.maxLen = Int.maxInt.
Transcript
(* test.sml *)
structure X = HashSetFn(
struct
type hash_key = int
val hashVal = Word.fromInt
val sameKey: int * int -> bool = op =
end)
val () = print "Okay!\n"
(* test.mlb *)
$(SML_LIB)/basis/basis.mlb
$(SML_LIB)/smlnj-lib/Util/smlnj-lib.mlb
test.sml
$ mlton -output a.out test.mlb
$ ./a.out
unhandled exception: Overflow
$ # The `-default-type intinf` flag causes Int.int to have infinite precision, but keeps Array.maxLen the same
$ mlton -output a.out -default-type intinf test.mlb
$ ./a.out
Okay!
Expected Behavior
Instantiating the HashSetFn should never raise Overflow.
Steps to Reproduce
Just run the code from the transcript.
Additional Information
This can be fixed by modifying the code at line 37 in hash-set-fn.sml:
(* old *)
val maxSize = let
fun f i = let
val i' = i+i
in
if i' < Array.maxLen then f i' else i
end
in
f 0x10000
end
(* new*)
val maxSize = let
fun f i = let
val i' = i+i
in
if i' < Array.maxLen then f i' else i
end
handle Overflow => i
in
f 0x10000
end
Email address
ssoss AT uchicago DOT edu
Version
110.99.3 (Latest)
Operating System
OS Version
No response
Processor
System Component
SML/NJ Library
Severity
Major
Description
The
HashSetFnfunctor (hash-set-fn.sml) calculatesmaxSizeas the largest power of 2 that is still less thanArray.maxLen.However, the calculation does not properly handle systems in which
Int.maxInt = SOME Array.maxLen, causing an exception to be raised during functor instantiation.Note: This bug does not occur on the SML/NJ compiler, since
Array.maxLenis much smaller thanInt.maxInt.The issue is reproducible for MLton (latest version: 20230523-gd082c4a36), since there
SOME Array.maxLen = Int.maxInt.Transcript
Expected Behavior
Instantiating the
HashSetFnshould never raiseOverflow.Steps to Reproduce
Just run the code from the transcript.
Additional Information
This can be fixed by modifying the code at line 37 in hash-set-fn.sml:
Email address
ssoss AT uchicago DOT edu