Skip to content

Commit

Permalink
Merge pull request kind2-mc#1022 from daniel-larraz/const-inlining-fix
Browse files Browse the repository at this point in the history
Fix constant inlining for type declarations
  • Loading branch information
daniel-larraz authored Nov 2, 2023
2 parents 2e3cd5c + c2d6105 commit 5ef47ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 15 additions & 5 deletions src/lustre/lustreAstInlineConstants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,16 @@ let rec inline_constants_of_contract: TC.tc_context -> LA.contract -> LA.contrac
let substitute: TC.tc_context -> LA.declaration -> (TC.tc_context * LA.declaration) = fun ctx ->
function
| TypeDecl (span, AliasType (pos, i, t)) ->
let t' = inline_constants_of_lustre_type ctx t in
ctx, LA.TypeDecl (span, AliasType (pos, i, t'))
let ctx', t' =
match t with
| LA.EnumType _ ->
(* Special handling is applied to enum types (see type_check_infer_globals) *)
ctx, t
| _ ->
let t' = inline_constants_of_lustre_type ctx t in
TC.add_ty_syn ctx i t', t'
in
ctx', LA.TypeDecl (span, AliasType (pos, i, t'))
| ConstDecl (span, FreeConst (pos, id, ty)) ->
let ty' = inline_constants_of_lustre_type ctx ty in
ctx, ConstDecl (span, FreeConst (pos, id, ty'))
Expand All @@ -501,11 +509,13 @@ let substitute: TC.tc_context -> LA.declaration -> (TC.tc_context * LA.declarati
, ConstDecl (span, UntypedConst (pos', i, e')))
| Some ty ->
let ty' = inline_constants_of_lustre_type ctx ty in
(TC.add_const ctx i e' ty', ConstDecl (span, UntypedConst (pos', i, e'))))
let ctx' = TC.add_ty (TC.add_const ctx i e' ty') i ty' in
(ctx', ConstDecl (span, UntypedConst (pos', i, e'))))
| ConstDecl (span, TypedConst (pos', i, e, ty)) ->
let ty' = inline_constants_of_lustre_type ctx ty in
let e' = simplify_expr ctx e in
(TC.add_const ctx i e' ty', ConstDecl (span, TypedConst (pos', i, e', ty')))
let e' = simplify_expr ctx e in
let ctx' = TC.add_ty (TC.add_const ctx i e' ty') i ty' in
(ctx', ConstDecl (span, TypedConst (pos', i, e', ty')))
| (LA.NodeDecl (span, (i, imported, params, ips, ops, ldecls, items, contract))) ->
let ips' = inline_constants_of_const_clocked_type_decl ctx ips in
let ops' = inline_constants_of_clocked_type_decl ctx ops in
Expand Down
8 changes: 6 additions & 2 deletions tests/regression/success/test_const_decls.lus
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ const j = complex1 { re = -(3.0)/2.0; im = 3.0/2.0 };
const c100:int = 1 + 1;
const c101:real = 1.0 + 1.0;

node main () returns (x:int;)
type s1 = subrange [-1,1] of int;

node imported R(x: s1) returns (y:s1);

node main (x: s1) returns (y: s1)
let
x = 0;
y = R(pre x);
tel

0 comments on commit 5ef47ad

Please sign in to comment.