Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(compiler): Make locs on anf_helper non optional #1942

Merged
merged 2 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 89 additions & 119 deletions compiler/src/middle_end/anf_helper.re
Original file line number Diff line number Diff line change
Expand Up @@ -9,223 +9,193 @@ type env = Env.t;
type ident = Ident.t;
type attributes = Typedtree.attributes;

let default_loc = Location.dummy_loc;
let default_env = Env.empty;
let default_attributes = [];
let default_allocation_type = Managed;

let or_default_loc = Option.value(~default=default_loc);
let or_default_env = Option.value(~default=default_env);
let or_default_attributes = Option.value(~default=default_attributes);
let or_default_allocation_type =
Option.value(~default=default_allocation_type);

module Imm = {
let mk = (~loc=?, ~env=?, d) => {
let mk = (~loc, ~env=?, d) => {
imm_desc: d,
imm_loc: or_default_loc(loc),
imm_loc: loc,
imm_env: or_default_env(env),
imm_analyses: ref([]),
};
let id = (~loc=?, ~env=?, id) => mk(~loc?, ~env?, ImmId(id));
let const = (~loc=?, ~env=?, const) => mk(~loc?, ~env?, ImmConst(const));
let trap = (~loc=?, ~env=?, ()) => mk(~loc?, ~env?, ImmTrap);
let id = (~loc, ~env=?, id) => mk(~loc, ~env?, ImmId(id));
let const = (~loc, ~env=?, const) => mk(~loc, ~env?, ImmConst(const));
let trap = (~loc, ~env=?, ()) => mk(~loc, ~env?, ImmTrap);
};

module Comp = {
let mk = (~loc=?, ~attributes=?, ~allocation_type=?, ~env=?, d) => {
let mk = (~loc, ~attributes=?, ~allocation_type=?, ~env=?, d) => {
comp_desc: d,
comp_loc: or_default_loc(loc),
comp_loc: loc,
comp_env: or_default_env(env),
comp_attributes: or_default_attributes(attributes),
comp_allocation_type: or_default_allocation_type(allocation_type),
comp_analyses: ref([]),
};
let imm = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, imm) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CImmExpr(imm));
let number = (~loc=?, ~attributes=?, ~env=?, i) =>
mk(~loc?, ~attributes?, ~allocation_type=Managed, ~env?, CNumber(i));
let int32 = (~loc=?, ~attributes=?, ~env=?, i) =>
mk(~loc?, ~attributes?, ~allocation_type=Managed, ~env?, CInt32(i));
let int64 = (~loc=?, ~attributes=?, ~env=?, i) =>
mk(~loc?, ~attributes?, ~allocation_type=Managed, ~env?, CInt64(i));
let uint32 = (~loc=?, ~attributes=?, ~env=?, i) =>
mk(~loc?, ~attributes?, ~allocation_type=Managed, ~env?, CUint32(i));
let uint64 = (~loc=?, ~attributes=?, ~env=?, i) =>
mk(~loc?, ~attributes?, ~allocation_type=Managed, ~env?, CUint64(i));
let float32 = (~loc=?, ~attributes=?, ~env=?, i) =>
mk(~loc?, ~attributes?, ~allocation_type=Managed, ~env?, CFloat32(i));
let float64 = (~loc=?, ~attributes=?, ~env=?, i) =>
mk(~loc?, ~attributes?, ~allocation_type=Managed, ~env?, CFloat64(i));
let prim0 = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, p0) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CPrim0(p0));
let prim1 = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, p1, a) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CPrim1(p1, a));
let prim2 = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, p2, a1, a2) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CPrim2(p2, a1, a2));
let primn = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, p, args) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CPrimN(p, args));
let box_assign = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, a1, a2) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CBoxAssign(a1, a2));
let local_assign = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, a1, a2) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CLocalAssign(a1, a2));
let assign = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, a1, a2) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CAssign(a1, a2));
let tuple = (~loc=?, ~attributes=?, ~env=?, elts) =>
mk(~loc?, ~attributes?, ~allocation_type=Managed, ~env?, CTuple(elts));
let array = (~loc=?, ~attributes=?, ~env=?, elts) =>
mk(~loc?, ~attributes?, ~allocation_type=Managed, ~env?, CArray(elts));
let array_get = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, arr, i) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CArrayGet(arr, i));
let array_set = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, arr, i, a) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CArraySet(arr, i, a));
let record = (~loc=?, ~attributes=?, ~env=?, type_hash, ttag, elts) =>
let imm = (~loc, ~attributes=?, ~allocation_type, ~env=?, imm) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CImmExpr(imm));
let number = (~loc, ~attributes=?, ~env=?, i) =>
mk(~loc, ~attributes?, ~allocation_type=Managed, ~env?, CNumber(i));
let int32 = (~loc, ~attributes=?, ~env=?, i) =>
mk(~loc, ~attributes?, ~allocation_type=Managed, ~env?, CInt32(i));
let int64 = (~loc, ~attributes=?, ~env=?, i) =>
mk(~loc, ~attributes?, ~allocation_type=Managed, ~env?, CInt64(i));
let uint32 = (~loc, ~attributes=?, ~env=?, i) =>
mk(~loc, ~attributes?, ~allocation_type=Managed, ~env?, CUint32(i));
let uint64 = (~loc, ~attributes=?, ~env=?, i) =>
mk(~loc, ~attributes?, ~allocation_type=Managed, ~env?, CUint64(i));
let float32 = (~loc, ~attributes=?, ~env=?, i) =>
mk(~loc, ~attributes?, ~allocation_type=Managed, ~env?, CFloat32(i));
let float64 = (~loc, ~attributes=?, ~env=?, i) =>
mk(~loc, ~attributes?, ~allocation_type=Managed, ~env?, CFloat64(i));
let prim0 = (~loc, ~attributes=?, ~allocation_type, ~env=?, p0) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CPrim0(p0));
let prim1 = (~loc, ~attributes=?, ~allocation_type, ~env=?, p1, a) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CPrim1(p1, a));
let prim2 = (~loc, ~attributes=?, ~allocation_type, ~env=?, p2, a1, a2) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CPrim2(p2, a1, a2));
let primn = (~loc, ~attributes=?, ~allocation_type, ~env=?, p, args) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CPrimN(p, args));
let box_assign = (~loc, ~attributes=?, ~allocation_type, ~env=?, a1, a2) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CBoxAssign(a1, a2));
let local_assign = (~loc, ~attributes=?, ~allocation_type, ~env=?, a1, a2) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CLocalAssign(a1, a2));
let assign = (~loc, ~attributes=?, ~allocation_type, ~env=?, a1, a2) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CAssign(a1, a2));
let tuple = (~loc, ~attributes=?, ~env=?, elts) =>
mk(~loc, ~attributes?, ~allocation_type=Managed, ~env?, CTuple(elts));
let array = (~loc, ~attributes=?, ~env=?, elts) =>
mk(~loc, ~attributes?, ~allocation_type=Managed, ~env?, CArray(elts));
let array_get = (~loc, ~attributes=?, ~allocation_type, ~env=?, arr, i) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CArrayGet(arr, i));
let array_set = (~loc, ~attributes=?, ~allocation_type, ~env=?, arr, i, a) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CArraySet(arr, i, a));
let record = (~loc, ~attributes=?, ~env=?, type_hash, ttag, elts) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type=Managed,
~env?,
CRecord(type_hash, ttag, elts),
);
let adt = (~loc=?, ~attributes=?, ~env=?, type_hash, ttag, vtag, elts) =>
let adt = (~loc, ~attributes=?, ~env=?, type_hash, ttag, vtag, elts) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type=Managed,
~env?,
CAdt(type_hash, ttag, vtag, elts),
);
let tuple_get = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, idx, tup) =>
mk(
~loc?,
~attributes?,
~allocation_type,
~env?,
CGetTupleItem(idx, tup),
);
let tuple_get = (~loc, ~attributes=?, ~allocation_type, ~env=?, idx, tup) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CGetTupleItem(idx, tup));
let tuple_set =
(~loc=?, ~attributes=?, ~allocation_type, ~env=?, idx, tup, value) =>
(~loc, ~attributes=?, ~allocation_type, ~env=?, idx, tup, value) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type,
~env?,
CSetTupleItem(idx, tup, value),
);
let adt_get = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, idx, value) =>
mk(
~loc?,
~attributes?,
~allocation_type,
~env?,
CGetAdtItem(idx, value),
);
let adt_get_tag = (~loc=?, ~attributes=?, ~env=?, value) =>
let adt_get = (~loc, ~attributes=?, ~allocation_type, ~env=?, idx, value) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CGetAdtItem(idx, value));
let adt_get_tag = (~loc, ~attributes=?, ~env=?, value) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type=Unmanaged(WasmI32),
~env?,
CGetAdtTag(value),
);
let record_get =
(~loc=?, ~attributes=?, ~allocation_type, ~env=?, idx, record) =>
(~loc, ~attributes=?, ~allocation_type, ~env=?, idx, record) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type,
~env?,
CGetRecordItem(idx, record),
);
let record_set =
(~loc=?, ~attributes=?, ~allocation_type, ~env=?, idx, record, arg) =>
(~loc, ~attributes=?, ~allocation_type, ~env=?, idx, record, arg) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type,
~env?,
CSetRecordItem(idx, record, arg),
);
let if_ = (~loc=?, ~attributes=?, ~allocation_type, ~env=?, cond, tru, fals) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CIf(cond, tru, fals));
let for_ = (~loc=?, ~attributes=?, ~env=?, cond, inc, body) =>
let if_ = (~loc, ~attributes=?, ~allocation_type, ~env=?, cond, tru, fals) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CIf(cond, tru, fals));
let for_ = (~loc, ~attributes=?, ~env=?, cond, inc, body) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type=Unmanaged(WasmI32),
~env?,
CFor(cond, inc, body),
);
let continue = (~loc=?, ~attributes=?, ~env=?, ()) =>
let continue = (~loc, ~attributes=?, ~env=?, ()) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type=Unmanaged(WasmI32),
~env?,
CContinue,
);
let break = (~loc=?, ~attributes=?, ~env=?, ()) =>
let break = (~loc, ~attributes=?, ~env=?, ()) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type=Unmanaged(WasmI32),
~env?,
CBreak,
);
let return = (~loc=?, ~attributes=?, ~env=?, ret) =>
let return = (~loc, ~attributes=?, ~env=?, ret) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type=Unmanaged(WasmI32),
~env?,
CReturn(ret),
);
let switch_ =
(
~loc=?,
~attributes=?,
~allocation_type,
~env=?,
arg,
branches,
partial,
) =>
(~loc, ~attributes=?, ~allocation_type, ~env=?, arg, branches, partial) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type,
~env?,
CSwitch(arg, branches, partial),
);
let app =
(
~loc=?,
~attributes=?,
~allocation_type,
~env=?,
~tail=false,
func,
args,
) =>
mk(~loc?, ~attributes?, ~allocation_type, ~env?, CApp(func, args, tail));
let lambda = (~loc=?, ~attributes=?, ~env=?, ~name=?, args, body) =>
(~loc, ~attributes=?, ~allocation_type, ~env=?, ~tail=false, func, args) =>
mk(~loc, ~attributes?, ~allocation_type, ~env?, CApp(func, args, tail));
let lambda = (~loc, ~attributes=?, ~env=?, ~name=?, args, body) =>
mk(
~loc?,
~loc,
~attributes?,
~allocation_type=Managed,
~env?,
CLambda(name, args, body, Uncomputed),
);
let bytes = (~loc=?, ~attributes=?, ~env=?, b) =>
mk(~loc?, ~attributes?, ~allocation_type=Managed, ~env?, CBytes(b));
let string = (~loc=?, ~attributes=?, ~env=?, s) =>
mk(~loc?, ~attributes?, ~allocation_type=Managed, ~env?, CString(s));
let bytes = (~loc, ~attributes=?, ~env=?, b) =>
mk(~loc, ~attributes?, ~allocation_type=Managed, ~env?, CBytes(b));
let string = (~loc, ~attributes=?, ~env=?, s) =>
mk(~loc, ~attributes?, ~allocation_type=Managed, ~env?, CString(s));
};

module AExp = {
let mk = (~loc=?, ~env=?, ~alloc_type, d) => {
let mk = (~loc, ~env=?, ~alloc_type, d) => {
anf_desc: d,
anf_loc: or_default_loc(loc),
anf_loc: loc,
anf_env: or_default_env(env),
anf_analyses: ref([]),
anf_allocation_type: alloc_type,
Expand All @@ -240,7 +210,7 @@ module AExp = {

let let_ =
(
~loc=?,
~loc,
~env=?,
~global=Nonglobal,
~mut_flag=Immutable,
Expand All @@ -249,15 +219,15 @@ module AExp = {
body,
) =>
mk(
~loc?,
~loc,
~env?,
~alloc_type=alloc_type(body),
AELet(global, rec_flag, mut_flag, binds, body),
);
let seq = (~loc=?, ~env=?, hd, tl) =>
mk(~loc?, ~env?, ~alloc_type=alloc_type(tl), AESeq(hd, tl));
let comp = (~loc=?, ~env=?, e) =>
mk(~loc?, ~env?, ~alloc_type=e.comp_allocation_type, AEComp(e));
let seq = (~loc, ~env=?, hd, tl) =>
mk(~loc, ~env?, ~alloc_type=alloc_type(tl), AESeq(hd, tl));
let comp = (~loc, ~env=?, e) =>
mk(~loc, ~env?, ~alloc_type=e.comp_allocation_type, AEComp(e));
};

module IncludeDeclaration = {
Expand Down
Loading
Loading