@@ -269,7 +269,7 @@ and push_pre is_guarded pos =
269269 | StructUpdate (p , e1 , l , e2 ) -> StructUpdate (p, r e1, l, r e2)
270270 | ArrayConstr (p , e1 , e2 ) -> ArrayConstr (p, r e1, e2)
271271 | ArrayIndex (p , e1 , e2 ) -> ArrayIndex (p, r e1, e2)
272- | Quantifier (p , e1 , l , e2 ) -> Quantifier (p, e1 , l, r e2 )
272+ | Quantifier (p , q , l , e ) -> Quantifier (p, q , l, r e )
273273 | AnyOp _ -> assert false (* desugared in lustreDesugarAnyOps *)
274274 | When _ as e -> LA. Pre (pos, e)
275275 | Condact _ as e -> LA. Pre (pos, e)
@@ -358,11 +358,21 @@ and simplify_expr ?(is_guarded = false) ctx =
358358 | Call (pos , ty_args , i , es ) ->
359359 let es' = List. map (fun e -> simplify_expr ~is_guarded: false ctx e) es in
360360 Call (pos, ty_args, i, es')
361+ | Quantifier (pos , q , tis , e ) ->
362+ (* 1. Don't inline constants that are shadowed by quantified vars (by removing these constants from the ctx)
363+ 2. Perform inlining within tis *)
364+ let ctx, tis = List. fold_left (fun (acc_ctx , acc_tis ) (p , id , ty ) ->
365+ let acc_ctx = TC. remove_const acc_ctx id in
366+ let acc_ti = (p, id, inline_constants_of_lustre_type acc_ctx ty) in
367+ acc_ctx, acc_tis @ [acc_ti]
368+ ) (ctx, [] ) tis in
369+ let e' = simplify_expr ~is_guarded: false ctx e in
370+ Quantifier (pos, q, tis, e')
361371 | e -> e
362372(* * Assumptions: These constants are arranged in dependency order,
363373 all of the constants have been type checked *)
364374
365- let rec inline_constants_of_lustre_type ctx ty = match ty with
375+ and inline_constants_of_lustre_type ctx ty = match ty with
366376 | LA. IntRange (pos , lbound , ubound ) ->
367377 let lbound' = match lbound with
368378 | None -> None
@@ -394,7 +404,8 @@ let rec inline_constants_of_lustre_type ctx ty = match ty with
394404 TArr (pos, ty1', ty2')
395405 | RefinementType (pos , (pos2 , id , ty ), expr ) ->
396406 let ty' = inline_constants_of_lustre_type ctx ty in
397- RefinementType (pos, (pos2, id, ty'), expr)
407+ let expr' = simplify_expr ctx expr in
408+ RefinementType (pos, (pos2, id, ty'), expr')
398409
399410 | History _ | Int _ | Bool _ | Real _
400411 | UserType _ | AbstractType _ | EnumType _ | SBitVector _ | UBitVector _ -> ty
0 commit comments