Skip to content

Commit

Permalink
chore(compiler)!: Remove recursive_types and principal config (grain-…
Browse files Browse the repository at this point in the history
…lang#1751)

* chore(compiler)!: Remove recursive_types config

* chore(compiler)!: Remove principal config

* Update compiler/src/typed/typecore.re

Co-authored-by: Oscar Spencer <oscar@grain-lang.org>

---------

Co-authored-by: Oscar Spencer <oscar@grain-lang.org>
  • Loading branch information
2 people authored and av8ta committed Apr 11, 2023
1 parent ed2159a commit d42f3a5
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 215 deletions.
1 change: 0 additions & 1 deletion compiler/src/typed/cmi_format.re
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ open Wasm_utils;

[@deriving (sexp, yojson)]
type pers_flags =
| Rectypes
| Opaque
| Unsafe_string;

Expand Down
1 change: 0 additions & 1 deletion compiler/src/typed/cmi_format.rei
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
/**************************************************************************/

type pers_flags =
| Rectypes
| Opaque
| Unsafe_string;

Expand Down
23 changes: 2 additions & 21 deletions compiler/src/typed/ctype.re
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ let is_object_type = path => {
let simple_abbrevs = ref(TMemNil);

let proper_abbrevs = (path, tl, abbrev) =>
if (tl != [] || Grain_utils.Config.principal^ || is_object_type(path)) {
if (tl != [] || is_object_type(path)) {
abbrev;
} else {
simple_abbrevs;
Expand Down Expand Up @@ -1447,8 +1447,7 @@ let merge = (r, b) =>
};

let occur = (env, ty0, ty) => {
let allow_recursive =
Grain_utils.Config.recursive_types^ || umode^ == Pattern;
let allow_recursive = umode^ == Pattern;
let old = type_changed^;
try(
{
Expand Down Expand Up @@ -2400,24 +2399,6 @@ and unify2 = (env, t1, t2) => {
if lv1 > lv2 then Env.add_gadt_instance_chain !env lv1 t2 else
if lv2 > lv1 then Env.add_gadt_instance_chain !env lv2 t1
end;*/
let (t1, t2) =
if (Grain_utils.Config.principal^
&& (find_lowest_level(t1') < lv || find_lowest_level(t2') < lv)) {
(
/* Expand abbreviations hiding a lower level */
/* Should also do it for parameterized types, after unification... */
switch (t1.desc) {
| TTyConstr(_, [], _) => t1'
| _ => t1
},
switch (t2.desc) {
| TTyConstr(_, [], _) => t2'
| _ => t2
},
);
} else {
(t1, t2);
};

if (unify_eq(t1, t1') || !unify_eq(t2, t2')) {
unify3(env, t1, t1', t2, t2');
Expand Down
35 changes: 3 additions & 32 deletions compiler/src/typed/env.re
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ type dependency_chain = list(Location.loc(string));
type error =
| Illegal_renaming(string, string, string)
| Inconsistent_import(string, string, string)
| Need_recursive_types(string, string)
| Depend_on_unsafe_string_unit(string, string)
| Missing_module(Location.t, Path.t, Path.t)
| Unbound_module(Location.t, string)
Expand Down Expand Up @@ -678,7 +677,7 @@ let is_runtime_mode = () => {

/* Persistent structure descriptions */

type pers_flags = Cmi_format.pers_flags = | Rectypes | Opaque | Unsafe_string;
type pers_flags = Cmi_format.pers_flags = | Opaque | Unsafe_string;

type pers_struct = {
ps_name: string,
Expand Down Expand Up @@ -765,7 +764,6 @@ let save_pers_struct = (crc, ps) => {
Hashtbl.add(persistent_structures, filename, Some(ps));
List.iter(
fun
| Rectypes => ()
| Unsafe_string => ()
| Opaque => add_imported_opaque(filename),
ps.ps_flags,
Expand Down Expand Up @@ -854,11 +852,6 @@ let acknowledge_pers_struct = (check, {Persistent_signature.filename, cmi}) => {

List.iter(
fun
| Rectypes =>
if (! Clflags.recursive_types^) {
let (unit_name, _, _) = get_unit();
error(Need_recursive_types(ps.ps_name, unit_name));
}
| Unsafe_string =>
if (Config.safe_string^) {
let (unit_name, _, _) = get_unit();
Expand Down Expand Up @@ -929,8 +922,6 @@ let check_pers_struct = (~loc, name, filename) =>
name,
)
| Inconsistent_import(_) => assert(false)
| Need_recursive_types(name, _) =>
Format.sprintf("%s uses recursive types", name)
| Depend_on_unsafe_string_unit(name, _) =>
Printf.sprintf("%s uses -unsafe-string", name)
| Unbound_label(_) => assert(false)
Expand Down Expand Up @@ -2289,11 +2280,7 @@ let is_imported_opaque = s => StringSet.mem(s, imported_opaque_units^);
Btype.cleanup_abbrev ();
Subst.reset_for_saving ();
let sg = Subst.signature (Subst.for_saving Subst.identity) sg in
let flags =
List.concat [
if !Grain_utils.Config.recursive_types then [Cmi_format.Rectypes] else [];
(*if !Grain_utils.Config.opaque then [Cmi_format.Opaque] else [];*)
]
let flags = []
in
try
let cmi = {
Expand Down Expand Up @@ -2338,15 +2325,7 @@ let build_signature_with_imports =
Btype.cleanup_abbrev();
Subst.reset_for_saving();
let sg = Subst.signature(Subst.for_saving(Subst.identity), sg);
let flags =
List.concat([
if (Grain_utils.Config.recursive_types^) {
[Cmi_format.Rectypes];
} else {
[];
},
/*if !Grain_utils.Config.opaque then [Cmi_format.Opaque] else [];*/
]);
let flags = [];

try({
let full_cmi =
Expand Down Expand Up @@ -2552,14 +2531,6 @@ let report_error = ppf =>
source2,
name,
)
| Need_recursive_types(import, export) =>
fprintf(
ppf,
"@[<hov>Unit %s imports from %s, which uses recursive types.@ %s@]",
export,
import,
"The compilation flag -rectypes is required",
)
| Depend_on_unsafe_string_unit(import, export) =>
fprintf(
ppf,
Expand Down
1 change: 0 additions & 1 deletion compiler/src/typed/env.rei
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type dependency_chain = list(Location.loc(string));
type error =
| Illegal_renaming(string, string, string)
| Inconsistent_import(string, string, string)
| Need_recursive_types(string, string)
| Depend_on_unsafe_string_unit(string, string)
| Missing_module(Location.t, Path.t, Path.t)
| Unbound_module(Location.t, string)
Expand Down

0 comments on commit d42f3a5

Please sign in to comment.