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

Fix handling of subrange constraints for free constants #1109

Merged
merged 2 commits into from
Nov 16, 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
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
Loading