Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: typing/ctype.mli
- ===================================================================
- --- typing/ctype.mli (revision 13527)
- +++ typing/ctype.mli (working copy)
- @@ -83,6 +83,9 @@
- val filter_row_fields:
- bool -> (label * row_field) list -> (label * row_field) list
- +val in_current_module: Path.t -> bool
- +val in_pervasives: Path.t -> bool
- +
- val generalize: type_expr -> unit
- (* Generalize in-place the given type *)
- val iterative_generalization: int -> type_expr list -> type_expr list
- Index: typing/typedecl.ml
- ===================================================================
- --- typing/typedecl.ml (revision 13527)
- +++ typing/typedecl.ml (working copy)
- @@ -476,11 +476,22 @@
- (* Compute variance *)
- -let compute_variance env tvl nega posi cntr ty =
- +(* membership robust to unification *)
- +let rec mem_repr ty s =
- + TypeSet.mem ty s ||
- + match ty.desc with
- + Tlink ty' -> mem_repr ty' s
- + | _ -> false
- +
- +(* widen = assume abstract types not accessibke from the initial
- + environment to be bivariant *)
- +let compute_variance widen env tvl nega posi cntr ty =
- let pvisited = ref TypeSet.empty
- and nvisited = ref TypeSet.empty
- and cvisited = ref TypeSet.empty in
- let rec compute_variance_rec posi nega cntr ty =
- + (* Is expand_head really safe here? In theory, unification always
- + keeps nodes from the right hand term... *)
- let ty = Ctype.repr ty in
- if (not posi || TypeSet.mem ty !pvisited)
- && (not nega || TypeSet.mem ty !nvisited)
- @@ -501,16 +512,24 @@
- if tl = [] then () else begin
- try
- let decl = Env.find_type path env in
- - List.iter2
- - (fun ty (co,cn,ct) ->
- - compute_variance_rec
- - (posi && co || nega && cn)
- - (posi && cn || nega && co)
- - (cntr || ct)
- - ty)
- - tl decl.type_variance
- + if widen && decl.type_manifest <> None then
- + compute_variance_rec posi nega cntr (Ctype.expand_head env ty)
- + else if widen
- + && decl.type_kind = Type_abstract
- + && not (Ctype.in_pervasives path)
- + then ()
- + else
- + List.iter2
- + (fun ty (co,cn,ct) ->
- + compute_variance_rec
- + (posi && co || nega && cn)
- + (posi && cn || nega && co)
- + (cntr || ct)
- + ty)
- + tl decl.type_variance
- with Not_found ->
- - List.iter (compute_variance_rec true true true) tl
- + if not widen then
- + List.iter (compute_variance_rec true true true) tl
- end
- | Tobject (ty, _) ->
- compute_same ty
- @@ -541,9 +560,9 @@
- compute_variance_rec nega posi cntr ty;
- List.iter
- (fun (ty, covar, convar, ctvar) ->
- - if TypeSet.mem ty !pvisited then covar := true;
- - if TypeSet.mem ty !nvisited then convar := true;
- - if TypeSet.mem ty !cvisited then ctvar := true)
- + if mem_repr ty !pvisited then covar := true;
- + if mem_repr ty !nvisited then convar := true;
- + if mem_repr ty !cvisited then ctvar := true)
- tvl
- let make_variance ty = (ty, ref false, ref false, ref false)
- @@ -569,7 +588,7 @@
- let tvl1 = List.map make_variance fvl in
- let tvl2 = List.map make_variance fvl in
- let tvl = tvl0 @ tvl1 in
- - List.iter (fun (cn,ty) -> compute_variance env tvl true cn cn ty) tyl;
- + List.iter (fun (cn,ty) -> compute_variance false env tvl true cn cn ty) tyl;
- let required =
- List.map (fun (c,n as r) -> if c || n then r else (true,true))
- required
- @@ -578,17 +597,18 @@
- (fun (ty, co, cn, ct) (c, n) ->
- if not (Btype.is_Tvar ty) then begin
- co := c; cn := n; ct := n;
- - compute_variance env tvl2 c n n ty
- + compute_variance true env tvl2 c n n ty
- end)
- tvl0 required;
- List.iter2
- (fun (ty, c1, n1, t1) (_, c2, n2, t2) ->
- - if !c1 && not !c2 || !n1 && not !n2
- - then raise (Error(loc, Bad_variance (0, (!c1,!n1), (!c2,!n2)))))
- + if !c1 && not !c2 || !n1 && not !n2 then
- + let code = if !c2 || !n2 then -1 else -2 in
- + raise (Error(loc, Bad_variance (code, (!c1,!n1), (!c2,!n2)))))
- tvl1 tvl2;
- let pos = ref 0 in
- List.map2
- - (fun (_, co, cn, ct) (c, n) ->
- + (fun (ty, co, cn, ct) (c, n) ->
- incr pos;
- if !co && not c || !cn && not n
- then raise (Error(loc, Bad_variance (!pos, (!co,!cn), (c,n))));
- @@ -1152,10 +1172,14 @@
- | 3 when not teen -> "rd"
- | _ -> "th"
- in
- - if n < 1 then
- + if n = -1 then
- fprintf ppf "@[%s@ %s@]"
- "In this definition, a type variable has a variance that"
- "is not reflected by its occurrence in type parameters."
- + else if n = -2 then
- + fprintf ppf "@[%s@ %s@]"
- + "In this definition, a type variable cannot be deduced"
- + "from the type parameters."
- else
- fprintf ppf "@[%s@ %s@ %s %d%s %s %s,@ %s %s@]"
- "In this definition, expected parameter"
- Index: testsuite/tests/typing-gadts/omega07.ml
- ===================================================================
- --- testsuite/tests/typing-gadts/omega07.ml (revision 13527)
- +++ testsuite/tests/typing-gadts/omega07.ml (working copy)
- @@ -10,7 +10,7 @@
- type ('a,'b) sum = Inl of 'a | Inr of 'b
- type zero = Zero
- -type _ succ
- +type 'a succ = Succ of 'a
- type _ nat =
- | NZ : zero nat
- | NS : 'a nat -> 'a succ nat
- @@ -60,7 +60,7 @@
- type tp
- type nd
- -type (_,_) fk
- +type ('a,'b) fk = Fk of 'a * 'b
- type _ shape =
- | Tp : tp shape
- | Nd : nd shape
- @@ -559,7 +559,7 @@
- (* 5.9/5.10 Language with binding *)
- type rnil
- -type (_,_,_) rcons
- +type ('a,'b,'c) rcons = RCons of 'a * 'b * 'c
- type _ is_row =
- | Rnil : rnil is_row
- @@ -714,7 +714,7 @@
- | Pexp : pexp mode
- | Pval : pval mode
- -type (_,_) tarr
- +type ('a,'b) tarr = Tarr of 'a * 'b
- type tint
- type (_,_) rel =
- Index: testsuite/tests/typing-gadts/omega07.ml.principal.reference
- ===================================================================
- --- testsuite/tests/typing-gadts/omega07.ml.principal.reference (revision 13527)
- +++ testsuite/tests/typing-gadts/omega07.ml.principal.reference (working copy)
- @@ -1,7 +1,7 @@
- # * * * * * type ('a, 'b) sum = Inl of 'a | Inr of 'b
- type zero = Zero
- -type _ succ
- +type 'a succ = Succ of 'a
- type _ nat = NZ : zero nat | NS : 'a nat -> 'a succ nat
- # type (_, _) seq =
- Snil : ('a, zero) seq
- @@ -16,7 +16,7 @@
- val app : ('a, 'n) seq -> ('a, 'm) seq -> ('a, 'n, 'm) app = <fun>
- # * type tp
- type nd
- -type (_, _) fk
- +type ('a, 'b) fk = Fk of 'a * 'b
- type _ shape =
- Tp : tp shape
- | Nd : nd shape
- @@ -176,7 +176,7 @@
- Const 3)
- val v4 : int = 6
- # type rnil
- -type (_, _, _) rcons
- +type ('a, 'b, 'c) rcons = RCons of 'a * 'b * 'c
- type _ is_row =
- Rnil : rnil is_row
- | Rcons : 'c is_row -> ('a, 'b, 'c) rcons is_row
- @@ -280,7 +280,7 @@
- # type pexp
- type pval
- type _ mode = Pexp : pexp mode | Pval : pval mode
- -type (_, _) tarr
- +type ('a, 'b) tarr = Tarr of 'a * 'b
- type tint
- type (_, _) rel =
- IntR : (tint, int) rel
- Index: testsuite/tests/typing-gadts/omega07.ml.reference
- ===================================================================
- --- testsuite/tests/typing-gadts/omega07.ml.reference (revision 13527)
- +++ testsuite/tests/typing-gadts/omega07.ml.reference (working copy)
- @@ -1,7 +1,7 @@
- # * * * * * type ('a, 'b) sum = Inl of 'a | Inr of 'b
- type zero = Zero
- -type _ succ
- +type 'a succ = Succ of 'a
- type _ nat = NZ : zero nat | NS : 'a nat -> 'a succ nat
- # type (_, _) seq =
- Snil : ('a, zero) seq
- @@ -16,7 +16,7 @@
- val app : ('a, 'n) seq -> ('a, 'm) seq -> ('a, 'n, 'm) app = <fun>
- # * type tp
- type nd
- -type (_, _) fk
- +type ('a, 'b) fk = Fk of 'a * 'b
- type _ shape =
- Tp : tp shape
- | Nd : nd shape
- @@ -176,7 +176,7 @@
- Const 3)
- val v4 : int = 6
- # type rnil
- -type (_, _, _) rcons
- +type ('a, 'b, 'c) rcons = RCons of 'a * 'b * 'c
- type _ is_row =
- Rnil : rnil is_row
- | Rcons : 'c is_row -> ('a, 'b, 'c) rcons is_row
- @@ -280,7 +280,7 @@
- # type pexp
- type pval
- type _ mode = Pexp : pexp mode | Pval : pval mode
- -type (_, _) tarr
- +type ('a, 'b) tarr = Tarr of 'a * 'b
- type tint
- type (_, _) rel =
- IntR : (tint, int) rel
Add Comment
Please, Sign In to add comment