Skip to content

Commit

Permalink
Merge pull request kind2-mc#1109 from daniel-larraz/fix-subrange-free…
Browse files Browse the repository at this point in the history
…-const

Fix handling of subrange constraints for free constants
  • Loading branch information
daniel-larraz authored Nov 16, 2024
2 parents 77596fe + f7c3585 commit f014d1e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lustre/lustreAstNormalizer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1194,19 +1194,19 @@ and normalize_node info map
let gids7 = locals
|> List.filter (function
| A.NodeVarDecl (_, (_, id, _, _))
| A.NodeConstDecl (_, FreeConst (_, id, _))
| A.NodeConstDecl (_, TypedConst (_, id, _, _)) ->
let ty = get_type_of_id info node_id id in
Ctx.type_contains_subrange ctx ty || Ctx.type_contains_ref ctx ty
| A.NodeConstDecl (_, FreeConst _)
| A.NodeConstDecl (_, UntypedConst _) -> false)
|> List.fold_left (fun acc l -> match l with
| A.NodeVarDecl (p, (_, id, _, _))
| A.NodeConstDecl (p, FreeConst (_, id, _))
| A.NodeConstDecl (p, TypedConst (_, id, _, _)) ->
let ty = get_type_of_id info node_id id in
let ty = AIC.inline_constants_of_lustre_type info.context ty in
let gids = union acc (mk_fresh_subrange_constraint Local info p (Some node_id) id ty)
in union gids (mk_fresh_refinement_type_constraint Local info p (A.Ident (p, id)) ty)
| A.NodeConstDecl (_, FreeConst _)
| A.NodeConstDecl (_, UntypedConst _)-> assert false)
(empty ())
in
Expand Down
1 change: 1 addition & 0 deletions src/lustre/lustreNodeGen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,7 @@ and compile_const_decl ?(ghost = false) cstate ctx map scope = function
let ty = Ctx.expand_type_syn ctx ty in
if Ctx.type_contains_subrange ctx ty then (
let range_exprs =
let ctx = Ctx.add_ty ctx i ty in
AN.mk_range_expr ctx None ty (A.Ident (p, i)) |> List.map fst
in
List.map (fun expr ->
Expand Down
7 changes: 7 additions & 0 deletions tests/regression/success/subrange_local_free_const.lus
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Nat = subrange [0,*] of int;

node M() returns ();
const C: Nat;
let
check "P1" 0 <= C;
tel

0 comments on commit f014d1e

Please sign in to comment.