Skip to content

Commit 13296e5

Browse files
committed
In subst, when crossing a binding, remove the bound variable.
If not, the substitution can lead to name captures.
1 parent 8fa2f94 commit 13296e5

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

src/ecCoreFol.ml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,9 +1643,21 @@ module Fsubst = struct
16431643
{ s with fs_esloc = Mid.change merger xfrom s.fs_esloc }
16441644

16451645
(* ------------------------------------------------------------------ *)
1646+
let f_rem_local s x =
1647+
{ s with fs_loc = Mid.remove x s.fs_loc;
1648+
fs_esloc = Mid.remove x s.fs_esloc; }
1649+
16461650
let f_rem_mem s m =
16471651
{ s with fs_mem = Mid.remove m s.fs_mem }
16481652

1653+
let f_rem_mod s x =
1654+
{ s with
1655+
fs_ty = { (s.fs_ty) with
1656+
ts_absmod = Mid.remove x s.fs_ty.ts_absmod;
1657+
ts_modtglob = Mid.remove x s.fs_ty.ts_modtglob;
1658+
ts_cmod = Mid.remove x s.fs_ty.ts_cmod; };
1659+
fs_modglob = Mid.remove x s.fs_modglob; }
1660+
16491661
(* ------------------------------------------------------------------ *)
16501662
let add_local s (x,t as xt) =
16511663
let x' = if s.fs_freshen then EcIdent.fresh x else x in
@@ -1999,12 +2011,17 @@ module Fsubst = struct
19992011
let mt' = EcMemory.mt_subst (ty_subst s.fs_ty) mt in
20002012
if mt == mt' then gty else GTmem mt'
20012013

2002-
and add_binding ~tx s (x, gty) =
2014+
and add_binding ~tx s (x, gty as xt) =
20032015
let gty' = subst_gty ~tx s gty in
20042016
let x' = if s.fs_freshen then EcIdent.fresh x else x in
20052017

2006-
if x == x' then
2007-
(s, (x, gty'))
2018+
if x == x' && gty == gty' then
2019+
let s = match gty with
2020+
| GTty _ -> f_rem_local s x
2021+
| GTmodty _ -> f_rem_mod s x
2022+
| GTmem _ -> f_rem_mem s x
2023+
in
2024+
(s, xt)
20082025
else
20092026
let s = match gty' with
20102027
| GTty ty -> f_bind_rename s x x' ty

0 commit comments

Comments
 (0)