* Re: too many constructors
2000-06-28 17:16 Juergen Pfitzenmaier
2000-06-30 0:40 ` Jacques Garrigue
@ 2000-06-30 13:15 ` Xavier Leroy
1 sibling, 0 replies; 3+ messages in thread
From: Xavier Leroy @ 2000-06-30 13:15 UTC (permalink / raw)
To: Juergen Pfitzenmaier, caml-list
> when defining a lot of variants the following message seems to restrictive:
> Too many constructors -- maximum is 248 constructors
> What is the reason for this ? Can this limit be pushed higher ?
Actually, the limit is 248 non-constant constructors. The reason is
that the "tag" that identifies a non-constant constructor is stored in
a 8-bit field in the block header, and some values for this "tag"
field are reserved by the runtime system, leaving only 248 tags for
non-constant constructors.
As for constant constructors, these are represented by integers, so
there is essentially no limit.
This said, there is a small bug in the compiler: it limits the total
number of constructors to 248, instead of the number of non-constant
constructors. This bug was recently reported to us, and a patch for
OCaml 3.00 is included below.
- Xavier Leroy
Index: csl/typing/typedecl.ml
diff -c csl/typing/typedecl.ml:1.36 csl/typing/typedecl.ml:1.37
*** csl/typing/typedecl.ml:1.36 Tue Mar 21 15:43:24 2000
--- csl/typing/typedecl.ml Mon May 22 10:24:05 2000
***************
*** 10,16 ****
(* *)
(***********************************************************************)
! (* $Id: typedecl.ml,v 1.36 2000/03/21 14:43:24 xleroy Exp $ *)
(**** Typing of type definitions ****)
--- 10,16 ----
(* *)
(***********************************************************************)
! (* $Id: typedecl.ml,v 1.37 2000/05/22 08:24:05 xleroy Exp $ *)
(**** Typing of type definitions ****)
***************
*** 141,147 ****
raise(Error(sdecl.ptype_loc, Duplicate_constructor name));
all_constrs := StringSet.add name !all_constrs)
cstrs;
! if List.length cstrs > Config.max_tag then
raise(Error(sdecl.ptype_loc, Too_many_constructors));
Type_variant(List.map
(fun (name, args) ->
--- 141,148 ----
raise(Error(sdecl.ptype_loc, Duplicate_constructor name));
all_constrs := StringSet.add name !all_constrs)
cstrs;
! if List.length (List.filter (fun (name, args) -> args <> []) cstrs)
! > Config.max_tag then
raise(Error(sdecl.ptype_loc, Too_many_constructors));
Type_variant(List.map
(fun (name, args) ->
***************
*** 355,361 ****
| Duplicate_constructor s ->
fprintf ppf "Two constructors are named %s" s
| Too_many_constructors ->
! fprintf ppf "Too many constructors -- maximum is %i constructors"
Config.max_tag
| Duplicate_label s ->
fprintf ppf "Two labels are named %s" s
--- 356,363 ----
| Duplicate_constructor s ->
fprintf ppf "Two constructors are named %s" s
| Too_many_constructors ->
! fprintf ppf "Too many non-constant constructors -- \
! maximum is %i non-constant constructors"
Config.max_tag
| Duplicate_label s ->
fprintf ppf "Two labels are named %s" s
^ permalink raw reply [flat|nested] 3+ messages in thread