Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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