Erase all linearities if memalloc is not activated
This commit is contained in:
parent
08437bf448
commit
eb0a19926c
4 changed files with 21 additions and 4 deletions
|
@ -86,6 +86,12 @@ let rec unify_lin expected_lin lin =
|
|||
| Lat r, Lvar _ -> Lat r
|
||||
| _, _ -> raise UnifyFailed
|
||||
|
||||
let check_linearity lin =
|
||||
if is_linear lin && not !Compiler_options.do_mem_alloc then
|
||||
Ltop
|
||||
else
|
||||
lin
|
||||
|
||||
let rec lin_to_string = function
|
||||
| Ltop -> "at T"
|
||||
| Lat r -> "at "^r
|
||||
|
|
|
@ -56,6 +56,7 @@ type error =
|
|||
| Estatic_constraint of constrnt
|
||||
| Esplit_enum of ty
|
||||
| Esplit_tuple of ty
|
||||
| Eenable_memalloc
|
||||
|
||||
exception Unify
|
||||
exception TypingError of error
|
||||
|
@ -194,6 +195,11 @@ let message loc kind =
|
|||
be a tuple (found: %a).@."
|
||||
print_location loc
|
||||
print_type ty
|
||||
| Eenable_memalloc ->
|
||||
eprintf
|
||||
"%aThis function was compiled with linear types. \
|
||||
Enable memory allocation to call it.@."
|
||||
print_location loc
|
||||
end;
|
||||
raise Errors.Error
|
||||
|
||||
|
@ -228,7 +234,11 @@ let flatten_ty_list l =
|
|||
(fun arg args -> match arg with Tprod l -> l@args | a -> a::args ) l []
|
||||
|
||||
let kind f ty_desc =
|
||||
let ty_of_arg v = v.a_type in
|
||||
let ty_of_arg v =
|
||||
if Linearity.is_linear v.a_linearity && not !Compiler_options.do_mem_alloc then
|
||||
error Eenable_memalloc;
|
||||
v.a_type
|
||||
in
|
||||
let op = if ty_desc.node_stateful then Enode f else Efun f in
|
||||
op, List.map ty_of_arg ty_desc.node_inputs,
|
||||
List.map ty_of_arg ty_desc.node_outputs
|
||||
|
|
|
@ -104,8 +104,9 @@ let rec vd_mem n = function
|
|||
|
||||
let args_of_var_decs =
|
||||
(* before the clocking the clock is wrong in the signature *)
|
||||
List.map (fun vd -> Signature.mk_arg (Some (Idents.source_name vd.v_ident))
|
||||
vd.v_type vd.v_linearity Signature.Cbase)
|
||||
List.map
|
||||
(fun vd -> Signature.mk_arg (Some (Idents.source_name vd.v_ident))
|
||||
vd.v_type (Linearity.check_linearity vd.v_linearity) Signature.Cbase)
|
||||
|
||||
let signature_of_node n =
|
||||
{ node_inputs = args_of_var_decs n.n_input;
|
||||
|
|
|
@ -409,7 +409,7 @@ and translate_var_dec env vd =
|
|||
(* env is initialized with the declared vars before their translation *)
|
||||
{ Heptagon.v_ident = Rename.var vd.v_loc env vd.v_name;
|
||||
Heptagon.v_type = translate_type vd.v_loc vd.v_type;
|
||||
Heptagon.v_linearity = vd.v_linearity;
|
||||
Heptagon.v_linearity = Linearity.check_linearity vd.v_linearity;
|
||||
Heptagon.v_last = translate_last vd.v_last;
|
||||
Heptagon.v_clock = translate_some_clock vd.v_loc env vd.v_clock;
|
||||
Heptagon.v_loc = vd.v_loc }
|
||||
|
|
Loading…
Reference in a new issue