-
Notifications
You must be signed in to change notification settings - Fork 125
/
qmlGenericScheme.ml
91 lines (74 loc) · 2.76 KB
/
qmlGenericScheme.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(* aliases *)
module Tv = QmlTypeVars
type ordered_quantif =
(Tv.TypeVar.t list, Tv.RowVar.t list, Tv.ColVar.t list) Tv.generic_quantif
type ('t, 'c) tsc =
{
mutable freevars : Tv.quantif option ; (** optimization : in order not to recompute freevars each time *)
mutable phantomvars : Tv.quantif option ; (** optimization : in order not to recompute phantomvars each time *)
(* note : phantomvars + vars of the body = quantif + freevars*)
quantif : Tv.quantif ;
nf_constraint : 'c ; (* used in env of typers *)
body : 't
}
(** used for specialization of named-type *)
let export_ordered_quantif tsc =
{
Tv.typevar = Tv.TypeVarSet.elements tsc.quantif.Tv.typevar;
Tv.rowvar = Tv.RowVarSet.elements tsc.quantif.Tv.rowvar;
Tv.colvar = Tv.ColVarSet.elements tsc.quantif.Tv.colvar
}
let import vars t c =
{
freevars = None ;
phantomvars = None;
quantif = vars ;
nf_constraint = c ;
body = t
}
let export_unsafe tsc =
(tsc.quantif, tsc.body, tsc.nf_constraint)
let freevars_with_cache count_t_c_freevars tsc =
match tsc.freevars with
| Some set -> set
| None ->
let free = count_t_c_freevars tsc.body tsc.nf_constraint in
let free = Tv.FreeVars.diff free tsc.quantif in
begin tsc.freevars <- Some free end;
free
let phantomvars_with_cache count_t_c_freevars tsc =
match tsc.phantomvars with
| Some set -> set
| None ->
let free = count_t_c_freevars tsc.body tsc.nf_constraint in
let phantom = Tv.FreeVars.diff tsc.quantif free in
begin tsc.phantomvars <- Some phantom end;
phantom
let export_vars t = t.quantif
let arity t = Tv.TypeVarSet.cardinal t.quantif.Tv.typevar
let is_empty t =
Tv.TypeVarSet.is_empty t.quantif.Tv.typevar &&
Tv.RowVarSet.is_empty t.quantif.Tv.rowvar &&
Tv.ColVarSet.is_empty t.quantif.Tv.colvar
let full_arity t =
(Tv.TypeVarSet.cardinal t.quantif.Tv.typevar,
Tv.RowVarSet.cardinal t.quantif.Tv.rowvar,
Tv.ColVarSet.cardinal t.quantif.Tv.colvar)
let map_body_unsafe f t =
{t with body = f t.body}
let map_body_unsafe2 f t =
let (t', v) = f t.body in
({t with body = t'}, v)