Skip to content

Commit 2f8288d

Browse files
riaqngoldfirere
andauthored
New mode solver supporting multiple axes with morphisms (#1760)
* new solver * better printing * remove solver_mono from mode_intf * document solver_polarized * address some comments * address more comments * rename "constrain" to "zap" * rename constrain_legacy * make depend * make fmt * remove _intf.ml * use comonadic in env * Add Allow_Disallow, restricting types of Obj.magic * Fix type errors discovered in previous commit * Use Allow_disallow in more places * show soundness of allow_disallow * Prevent chance of forgetting the "sound" version * minor changes * Remove the Solver_polarized.morph type (#1) * adjust comments * remove address_of * more comments * make [log] non-optional * better comments * More fixes * bind temp results * add C.eq_morph * set_append_changes * compare Value with Alloc * more comments * warn about infinite lattices * Small simplification to set_obj * example of variable cycle * say "uniqueness_op" because monotonicity * rename set to lift * exhaustive match * inline unusual helper functions * fix rebase issues * Small simplification * some renaming and comments * more comment * remove un-needed assertions. * fix chamelon * make fmt * add file header comments * exhausive match * use ref for morph counting * Reorder in maybe_compose * switch from lift to map * avoid caml_curry * dedup in join and meet * better error message * fix tests * comments * inlining newvar_above/blow, and more uncurrying * remove ?logging * make sure arity is correct and avoid closure allocation * remove morphism counting * force inline to avoid caml_applyX * address comments * rename and phy eq in eq_morphvar * Small improvement to [eq_morphvar] * better comments about lattices * don't hint to use exclave when useless * fix type_argument * comments about inner_alloc_mode * magic for eq_obj and eq_morph * allow/disallow for Value.List * Add comment about actual vs expected * comment mode_argument * eq_morph doesn't take dst * Magic_equal * better comment about adjunction * abstraction in ctype * comment close_over and partial_apply * fix eta expansion bug * Alloc.Const.t is record, not tuple * Simplify interface to [close_over] * Generalize the type of close_over * fixed definition of partial adjoint * better comment about partial adjoint * even better comments * make fmt * bootstrap --------- Co-authored-by: Richard Eisenberg <reisenberg@janestreet.com> Co-authored-by: Richard Eisenberg <rae@richarde.dev>
1 parent 2933994 commit 2f8288d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3994
-2020
lines changed

chamelon/compat.jst.ml

+21-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ open Types
33
open Mode
44

55
let dummy_jkind = Jkind.value ~why:(Unknown "dummy_layout")
6-
let dummy_value_mode = Value.legacy
6+
let dummy_value_mode = Value.disallow_right Value.legacy
77
let mkTvar name = Tvar { name; jkind = dummy_jkind }
88

99
let mkTarrow (label, t1, t2, comm) =
@@ -16,30 +16,33 @@ let mkTexp_ident ?id:(ident_kind, uu = (Id_value, shared_many_use))
1616
Texp_ident (path, longident, vd, ident_kind, uu)
1717

1818
type nonrec apply_arg = apply_arg
19-
type texp_apply_identifier = apply_position * Locality.t
19+
type texp_apply_identifier = apply_position * Locality.l
2020

21-
let mkTexp_apply ?id:(pos, mode = (Default, Locality.legacy)) (exp, args) =
21+
let mkTexp_apply
22+
?id:(pos, mode = (Default, Locality.disallow_right Locality.legacy))
23+
(exp, args) =
2224
Texp_apply (exp, args, pos, mode)
2325

24-
type texp_tuple_identifier = string option list * Alloc.t
26+
type texp_tuple_identifier = string option list * Alloc.r
2527

2628
let mkTexp_tuple ?id exps =
2729
let labels, alloc =
2830
match id with
29-
| None -> (List.map (fun _ -> None) exps, Alloc.legacy)
31+
| None -> (List.map (fun _ -> None) exps, Alloc.disallow_left Alloc.legacy)
3032
| Some id -> id
3133
in
3234
let exps = List.combine labels exps in
3335
Texp_tuple (exps, alloc)
3436

35-
type texp_construct_identifier = Alloc.t option
37+
type texp_construct_identifier = Alloc.r option
3638

37-
let mkTexp_construct ?id:(mode = Some Alloc.legacy) (name, desc, args) =
39+
let mkTexp_construct ?id:(mode = Some (Alloc.disallow_left Alloc.legacy))
40+
(name, desc, args) =
3841
Texp_construct (name, desc, args, mode)
3942

4043
type texp_function_param_identifier = {
4144
param_sort : Jkind.Sort.t;
42-
param_mode : Alloc.t;
45+
param_mode : Alloc.l;
4346
param_curry : function_curry;
4447
param_newtypes : (string Location.loc * Jkind.annotation option) list;
4548
}
@@ -54,7 +57,7 @@ type texp_function_param = {
5457
}
5558

5659
type texp_function_cases_identifier = {
57-
last_arg_mode : Alloc.t;
60+
last_arg_mode : Alloc.l;
5861
last_arg_sort : Jkind.Sort.t;
5962
last_arg_exp_extra : exp_extra option;
6063
last_arg_attributes : attributes;
@@ -75,15 +78,15 @@ type texp_function = {
7578
}
7679

7780
type texp_function_identifier = {
78-
alloc_mode : Alloc.t;
81+
alloc_mode : Alloc.r;
7982
ret_sort : Jkind.sort;
8083
region : bool;
81-
ret_mode : Alloc.t;
84+
ret_mode : Alloc.l;
8285
}
8386

8487
let texp_function_cases_identifier_defaults =
8588
{
86-
last_arg_mode = Alloc.legacy;
89+
last_arg_mode = Alloc.disallow_right Alloc.legacy;
8790
last_arg_sort = Jkind.Sort.value;
8891
last_arg_exp_extra = None;
8992
last_arg_attributes = [];
@@ -92,16 +95,16 @@ let texp_function_cases_identifier_defaults =
9295
let texp_function_param_identifier_defaults =
9396
{
9497
param_sort = Jkind.Sort.value;
95-
param_mode = Alloc.legacy;
96-
param_curry = More_args { partial_mode = Alloc.legacy };
98+
param_mode = Alloc.disallow_right Alloc.legacy;
99+
param_curry = More_args { partial_mode = Alloc.disallow_right Alloc.legacy };
97100
param_newtypes = [];
98101
}
99102

100103
let texp_function_defaults =
101104
{
102-
alloc_mode = Alloc.legacy;
105+
alloc_mode = Alloc.disallow_left Alloc.legacy;
103106
ret_sort = Jkind.Sort.value;
104-
ret_mode = Alloc.legacy;
107+
ret_mode = Alloc.disallow_right Alloc.legacy;
105108
region = false;
106109
}
107110

@@ -249,12 +252,12 @@ let view_texp (e : expression_desc) =
249252
| Texp_match (e, sort, cases, partial) -> Texp_match (e, cases, partial, sort)
250253
| _ -> O e
251254

252-
type tpat_var_identifier = Value.t
255+
type tpat_var_identifier = Value.l
253256

254257
let mkTpat_var ?id:(mode = dummy_value_mode) (ident, name) =
255258
Tpat_var (ident, name, Uid.internal_not_actually_unique, mode)
256259

257-
type tpat_alias_identifier = Value.t
260+
type tpat_alias_identifier = Value.l
258261

259262
let mkTpat_alias ?id:(mode = dummy_value_mode) (p, ident, name) =
260263
Tpat_alias (p, ident, name, Uid.internal_not_actually_unique, mode)

native_toplevel/opttoploop.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ let name_expression ~loc ~attrs sort exp =
348348
in
349349
let sg = [Sig_value(id, vd, Exported)] in
350350
let pat =
351-
{ pat_desc = Tpat_var(id, mknoloc name, vd.val_uid, Mode.Value.legacy);
351+
{ pat_desc = Tpat_var(id, mknoloc name, vd.val_uid, Mode.Value.disallow_right Mode.Value.legacy);
352352
pat_loc = loc;
353353
pat_extra = [];
354354
pat_type = exp.exp_type;

ocaml/.depend

+21-1
Original file line numberDiff line numberDiff line change
@@ -1114,12 +1114,22 @@ typing/jkind.cmi : \
11141114
parsing/jane_asttypes.cmi \
11151115
typing/ident.cmi
11161116
typing/mode.cmo : \
1117+
typing/solver_intf.cmi \
1118+
typing/solver.cmi \
1119+
typing/mode_intf.cmi \
11171120
utils/misc.cmi \
11181121
typing/mode.cmi
11191122
typing/mode.cmx : \
1123+
typing/solver_intf.cmi \
1124+
typing/solver.cmx \
1125+
typing/mode_intf.cmi \
11201126
utils/misc.cmx \
11211127
typing/mode.cmi
1122-
typing/mode.cmi :
1128+
typing/mode.cmi : \
1129+
typing/mode_intf.cmi
1130+
typing/mode_intf.cmi : \
1131+
typing/solver_intf.cmi \
1132+
typing/solver.cmi
11231133
typing/mtype.cmo : \
11241134
typing/types.cmi \
11251135
typing/subst.cmi \
@@ -1507,6 +1517,16 @@ typing/signature_group.cmx : \
15071517
typing/signature_group.cmi
15081518
typing/signature_group.cmi : \
15091519
typing/types.cmi
1520+
typing/solver.cmo : \
1521+
typing/solver_intf.cmi \
1522+
typing/solver.cmi
1523+
typing/solver.cmx : \
1524+
typing/solver_intf.cmi \
1525+
typing/solver.cmi
1526+
typing/solver.cmi : \
1527+
typing/solver_intf.cmi
1528+
typing/solver_intf.cmi : \
1529+
utils/misc.cmi
15101530
typing/stypes.cmo : \
15111531
typing/typedtree.cmi \
15121532
typing/printtyp.cmi \

ocaml/boot/ocamlc

36.8 KB
Binary file not shown.

ocaml/compilerlibs/Makefile.compilerlibs

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ PARSING_CMI = \
8282
parsing/parsetree.cmi
8383

8484
TYPING = \
85+
typing/solver.cmo \
8586
typing/path.cmo \
8687
typing/jkind.cmo \
8788
typing/primitive.cmo \

ocaml/dune

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
parser)))
6969
(library_flags -linkall)
7070
(modules_without_implementation
71-
annot asttypes cmo_format outcometree parsetree debug_event)
71+
annot asttypes cmo_format outcometree parsetree debug_event solver_intf mode_intf)
7272
(modules
7373
;; UTILS
7474
config build_path_prefix_map misc identifiable numbers arg_helper clflags
@@ -91,7 +91,7 @@
9191
tast_iterator tast_mapper signature_group cmt_format cms_format untypeast
9292
includemod includemod_errorprinter
9393
typetexp patterns printpat parmatch stypes typedecl typeopt rec_check
94-
typecore mode uniqueness_analysis
94+
typecore solver_intf solver mode_intf mode uniqueness_analysis
9595
typeclass typemod typedecl_variance typedecl_properties
9696
typedecl_separability cmt2annot
9797
; manual update: mli only files
@@ -317,6 +317,7 @@
317317
(typeopt.mli as compiler-libs/typeopt.mli)
318318
(rec_check.mli as compiler-libs/rec_check.mli)
319319
(typecore.mli as compiler-libs/typecore.mli)
320+
(solver.mli as compiler-libs/solver.mli)
320321
(mode.mli as compiler-libs/mode.mli)
321322
(uniqueness_analysis.mli as compiler-libs/uniqueness_analysis.mli)
322323
(typeclass.mli as compiler-libs/typeclass.mli)

0 commit comments

Comments
 (0)