caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* (no subject)
@ 2000-06-28 17:16 Juergen Pfitzenmaier
  2000-06-30  0:40 ` Jacques Garrigue
  2000-06-30 13:15 ` too many constructors Xavier Leroy
  0 siblings, 2 replies; 3+ messages in thread
From: Juergen Pfitzenmaier @ 2000-06-28 17:16 UTC (permalink / raw)
  To: caml-list

Dear maintainers of OCaml,
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 ?

pfitzen



^ permalink raw reply	[flat|nested] 3+ messages in thread

* (no subject)
  2000-06-28 17:16 Juergen Pfitzenmaier
@ 2000-06-30  0:40 ` Jacques Garrigue
  2000-06-30 13:15 ` too many constructors Xavier Leroy
  1 sibling, 0 replies; 3+ messages in thread
From: Jacques Garrigue @ 2000-06-30  0:40 UTC (permalink / raw)
  To: pfitzen; +Cc: caml-list

From: Juergen Pfitzenmaier <pfitzen@informatik.uni-tuebingen.de>

> 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 ?

This is a hard-coded limit, so there is no magical compiler option to
raise it. There can be no more than 248 nonconstant constructors in a
variant type.

However, if your constructors are constant (they have no parameter),
then this is a now corrected bug. See PR#117 in the caml bug tracking
system.
With the corrected version of the compiler, you may use 2^31 constant
constructors independently of the 248 nonconstant ones.

As a temporary workaround you may use polymorphic variants: it should
be possible to use tens of thousands of both constant and nonconstant
constructors in the same type.

Jacques
---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* 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

end of thread, other threads:[~2000-06-30 15:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-28 17:16 Juergen Pfitzenmaier
2000-06-30  0:40 ` Jacques Garrigue
2000-06-30 13:15 ` too many constructors Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).