Skip to content

Commit 647594b

Browse files
authored
Merge pull request #480 from FStarLang/gebner_readable_binder_names
Do not discard names in elab_env.
2 parents 3a96f1a + ae5b018 commit 647594b

11 files changed

+47
-25
lines changed

src/checker/Pulse.Checker.Bind.fst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ let check_bind'
143143
)
144144
else (
145145
let dflt () =
146+
let binder =
147+
// do not generate null binders, those are ignored by SMT...
148+
if T.unseal binder.binder_ppname.name = "_" then
149+
{ binder with binder_ppname = ppname_default }
150+
else
151+
binder in
146152
let r0 = check g ctxt ctxt_typing NoHint binder.binder_ppname e1 in
147153
check_if_seq_lhs g ctxt _ r0 e1;
148154
check_binder_typ g ctxt _ r0 binder e1;

src/checker/Pulse.Checker.Match.fst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ let ctag_of_br (#g #pre #post_hint #sc_u #sc_ty #sc:_)
351351
: ctag
352352
= let (|_, c, _|) = l in ctag_of_comp_st c
353353

354+
#push-options "--admit_smt_queries true" // Z3 crash
354355
let weaken_branch_observability
355356
(obs:observability)
356357
(#g #pre:_) (#post_hint:post_hint_for_env g)
@@ -377,6 +378,7 @@ let weaken_branch_observability
377378
in
378379
(| br, d |)
379380
)
381+
#pop-options
380382

381383
let rec max_obs
382384
(checked_brs : list comp_st)

src/checker/Pulse.Checker.fst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,12 @@ let rec check
244244
else (
245245
maybe_trace t g0 pre0 t.range;
246246
if RU.debug_at_level (fstar_env g0) "pulse.checker" then (
247-
T.print (Printf.sprintf "At %s{\nerr context:\n>%s\n\n{\n\tenv=%s\ncontext:\n%s,\n\nst_term: %s\nis_source: %s}}\n"
247+
T.print (Printf.sprintf "At %s{\nerr context:\n>%s\n\n{\n\tenv=%s\ncontext:\n%s,\n\nres_ppname: %s\nst_term: %s\nis_source: %s}}\n"
248248
(show t.range)
249249
(RU.print_context (get_context g0))
250250
(show g0)
251251
(show pre0)
252+
(show (T.unseal res_ppname.name))
252253
(show t)
253254
(show (T.unseal t.source)))
254255
);

src/checker/Pulse.Extract.Main.fst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ let is_internal_binder (b:binder) : T.Tac bool =
111111
s = "_tbind_c" ||
112112
s = "_if_br" ||
113113
s = "_br" ||
114-
s = "_"
114+
s = "__"
115115

116116
let is_return (e:st_term) : option term =
117117
match e.term with
@@ -347,7 +347,12 @@ let extract_dv_binder (b:Pulse.Syntax.Base.binder) (q:option Pulse.Syntax.Base.q
347347
: T.Tac R.binder =
348348
R.pack_binder {
349349
sort = b.binder_ty;
350-
ppname = b.binder_ppname.name;
350+
ppname =
351+
// "__" binders become `int __1 = f();` in karamel
352+
if T.unseal b.binder_ppname.name = "__" then
353+
T.seal "_"
354+
else
355+
b.binder_ppname.name;
351356
attrs = T.unseal b.binder_attrs;
352357
qual = (match q with
353358
| Some Implicit -> R.Q_Implicit

src/checker/Pulse.Syntax.Base.fsti

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ type ppname = {
4343
}
4444

4545
let ppname_default = {
46-
name = FStar.Sealed.seal "_";
46+
// This used to be "_", but that is a *null binder* and behaves very magically
47+
name = FStar.Sealed.seal "__";
4748
range = FStar.Range.range_0
4849
}
4950

src/checker/Pulse.Typing.Env.fst

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type env = {
4141
f : RT.fstar_top_env;
4242
bs : list (var & typ);
4343
f_bs : (f_bs : R.env { f_bs == extend_env_l f bs });
44-
names : list ppname;
44+
names : ns:list ppname { List.length ns == List.length bs };
4545
m : m:bmap { related bs m /\ L.length names == L.length bs };
4646
ctxt: Pulse.RuntimeUtils.context;
4747

@@ -52,13 +52,11 @@ type env = {
5252
let fstar_env g = RU.env_set_context g.f g.ctxt
5353

5454
let bindings g = g.bs
55-
let rec bindings_with_ppname_aux (bs:list (var & typ)) (names:list ppname)
56-
: T.Tac (list (ppname & var & typ)) =
57-
55+
let rec bindings_with_ppname_aux (bs:list (var & typ)) (names:list ppname { List.length bs == List.length names })
56+
: list (ppname & var & typ) =
5857
match bs, names with
5958
| [], [] -> []
6059
| (x, t)::bs, n::names -> (n, x, t)::(bindings_with_ppname_aux bs names)
61-
| _ -> T.fail "impossible! env bs and names have different lengths"
6260
let bindings_with_ppname g = bindings_with_ppname_aux g.bs g.names
6361

6462

@@ -104,7 +102,7 @@ let mk_env_dom _ = assert (Set.equal (Map.domain empty_bmap) Set.empty)
104102
let push_binding g x p t =
105103
{ g with bs = (x, t)::g.bs;
106104
names = p::g.names;
107-
f_bs = RT.extend_env g.f_bs x t;
105+
f_bs = R.push_binding g.f_bs { ppname = p.name; uniq = x; sort = t };
108106
m = Map.upd g.m x t }
109107

110108
let push_binding_bs _ _ _ _ = ()
@@ -129,12 +127,20 @@ let rec append_memP (#a:Type) (l1 l2:list a) (x:a)
129127
| [] -> ()
130128
| _::tl -> append_memP tl l2 x
131129

130+
let rec extend_env_impl (f:R.env) (g:env_bindings) (ns:list ppname { List.length ns == List.length g }) :
131+
f':R.env { f' == extend_env_l f g } =
132+
match g, ns with
133+
| [], [] -> f
134+
| (x, t)::g, n::ns ->
135+
let f = extend_env_impl f g ns in
136+
R.push_binding f { ppname = (n <: ppname).name; uniq = x; sort = t }
137+
132138
let push_env (g1:env) (g2:env { disjoint g1 g2 }) : env =
133139
assume (extend_env_l (extend_env_l g1.f g1.bs) g2.bs == extend_env_l g1.f (g2.bs @ g1.bs));
134140
{
135141
f = g1.f;
136142
bs = g2.bs @ g1.bs;
137-
f_bs = extend_env_l g1.f_bs g2.bs;
143+
f_bs = extend_env_impl g1.f_bs g2.bs g2.names;
138144
names= g2.names @ g1.names;
139145
m = Map.concat g2.m g1.m;
140146
ctxt = g1.ctxt ;
@@ -177,7 +183,7 @@ let rec remove_binding_aux (g:env)
177183
fst b =!= x));
178184

179185
let g' = {g with bs = prefix;
180-
f_bs = extend_env_l g.f prefix; // Recomputing, not ideal
186+
f_bs = extend_env_impl g.f prefix prefix_names; // Recomputing, not ideal
181187
names=prefix_names;
182188
m
183189
} in
@@ -192,14 +198,14 @@ let remove_binding g =
192198
remove_binding_aux g [] [] g.bs g.names
193199

194200
let remove_latest_binding g =
195-
match g.bs with
196-
| (x, t)::rest ->
201+
match g.bs, g.names with
202+
| (x, t)::rest, _::names_rest ->
197203
let m = Map.restrict (Set.complement (Set.singleton x)) (Map.upd g.m x tm_unknown) in
198204
// we need uniqueness invariant in the representation
199205
assume (forall (b:var & typ). List.Tot.memP b rest <==> (List.Tot.memP b g.bs /\
200206
fst b =!= x));
201207
let g' = {g with bs = rest;
202-
f_bs = extend_env_l g.f rest; // Recomputing, not ideal
208+
f_bs = extend_env_impl g.f rest names_rest; // Recomputing, not ideal
203209
names=L.tl g.names;
204210
m;
205211
} in
@@ -278,7 +284,7 @@ let diff g1 g2 =
278284
let g3 = {
279285
f = g1.f;
280286
bs = bs3;
281-
f_bs = extend_env_l g1.f bs3; // Recomputing, but probably ok
287+
f_bs = extend_env_impl g1.f bs3 names3; // Recomputing, but probably ok
282288
names = names3;
283289
m = m3;
284290
ctxt = g1.ctxt;
@@ -393,7 +399,7 @@ let env_to_doc' (simplify:bool) (e:env) : T.Tac document =
393399
vtns |> T.filter (fun ((n, t), x) ->
394400
let is_unit = FStar.Reflection.TermEq.term_eq t (`unit) in
395401
let x : ppname = x in
396-
let is_wild = T.unseal x.name = "_" in
402+
let is_wild = T.unseal x.name = "__" in
397403
not (is_unit && is_wild)
398404
)
399405
else

src/checker/Pulse.Typing.Env.fsti

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ module Pprint = FStar.Pprint
3030
type binding = var & typ
3131
type env_bindings = list binding
3232

33-
let extend_env_l (f:R.env) (g:env_bindings) : Tot R.env =
33+
// This function is marked ghost because it should not be used as it renames all variables to "x"
34+
let extend_env_l (f:R.env) (g:env_bindings) : GTot R.env =
3435
L.fold_right
3536
(fun (x, b) g ->
3637
RT.extend_env g x b)
@@ -45,7 +46,7 @@ val fstar_env (g:env) : RT.fstar_top_env
4546
// most recent binding at the head of the list
4647
//
4748
val bindings (g:env) : env_bindings
48-
val bindings_with_ppname (g:env) : T.Tac (list (ppname & var & typ))
49+
val bindings_with_ppname (g:env) : list (ppname & var & typ)
4950

5051
(* Returns an F* reflection environment.
5152
The result is the same as taking the initial F*

test/bug-reports/Bug.SpinLock.fst.output.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
* Info at Bug.SpinLock.fst(45,2-45,4):
22
- Expected failure:
33
- Cannot prove:
4-
Pulse.Lib.Reference.pts_to _ ?uu___
4+
Pulse.Lib.Reference.pts_to __ ?__
55
- In the context:
66
Pulse.Lib.SpinLock.lock_alive my_lock
77
(exists* (v: Prims.int). Pulse.Lib.Reference.pts_to r v)

test/bug-reports/Bug266.fst.output.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
- Current context:
1212
emp
1313
- In typing environment:
14-
_#60 : Prims.squash (_ == Bug266.my_intro Prims.l_False),
15-
_#59 :
14+
__#60 : Prims.squash (__ == Bug266.my_intro Prims.l_False),
15+
__#59 :
1616
Pulse.Lib.Core.stt_ghost Prims.unit
1717
Pulse.Lib.Core.emp_inames
1818
(Pulse.Lib.Core.pure Prims.l_False)

test/bug-reports/ExistsErasedAndPureEqualities.fst.output.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
- Current context:
1414
ExistsErasedAndPureEqualities.some_pred x v
1515
- In typing environment:
16-
_#586 : Prims.squash (v_ == v),
16+
__#586 : Prims.squash (v_ == v),
1717
v_#585 : FStar.Ghost.erased Prims.int,
18-
_#451 : Prims.squash (v == v),
18+
__#451 : Prims.squash (v == v),
1919
v#267 : FStar.Ghost.erased Prims.int,
2020
x#262 : Pulse.Lib.Reference.ref Prims.int
2121

0 commit comments

Comments
 (0)