Skip to content

Commit 2c8f703

Browse files
Make ident an abstract type
AST.ident values can now only be created through Ident.of_string, and can only be used through Ident.to_string. This guarantees that the concrete positive <-> string mapping used is immaterial and that ident values can never be communicated with the outside world. This discipline is enforced both in the Coq and Ocaml code: the Camlcoq functions intern_string and extern_atom now use the sealed Ident module (and type) as extracted from Coq. Independently, the FastIdent Ocaml module provides the string interning backend necessary for Symbols.v, but it cannot be used to bypass abstraction. The new structure also makes it easy to switch out the implementation of the Ident module in the future, or provide an alternative one, for instance if we want to implement a version of Ident where of_string and to_string can compute within Coq, sacrificing performance.
1 parent c75619d commit 2c8f703

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1104
-996
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ FLOCQ=\
5858
VLIB=Axioms.v Coqlib.v Intv.v Maps.v Heaps.v Lattice.v Ordered.v \
5959
Iteration.v Integers.v Archi.v Fappli_IEEE_extra.v Floats.v \
6060
Parmov.v UnionFind.v Wfsimpl.v \
61-
Postorder.v FSetAVLplus.v IntvSets.v Decidableplus.v BoolEqual.v
61+
Postorder.v FSetAVLplus.v IntvSets.v Decidableplus.v BoolEqual.v \
62+
Symbols.v
6263

6364
# Parts common to the front-ends and the back-end (in common/)
6465

Makefile.extr

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ INCLUDES=$(patsubst %,-I %, $(DIRS))
5050
# Control of warnings:
5151

5252
WARNINGS=-w +a-4-9-27 -strict-sequence -safe-string -warn-error +a #Deprication returns with ocaml 4.03
53+
extraction/%.cmi: WARNINGS +=-w -20-27-32..34-39-41-44..45
5354
extraction/%.cmx: WARNINGS +=-w -20-27-32..34-39-41-44..45
5455
extraction/%.cmo: WARNINGS +=-w -20-27-32..34-39-41-44..45
5556
cparser/pre_parser.cmx: WARNINGS += -w -41

arm/AsmToJSON.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let mnemonic_names = [ "Padc"; "Padd"; "Padds"; "Pand";"Pannot"; "Pasr"; "Pb"; "
3737

3838
type instruction_arg =
3939
| ALabel of positive
40-
| Atom of positive
40+
| Atom of ident
4141
| Data32 of Integers.Int.int
4242
| Data64 of Integers.Int64.int
4343
| DFreg of freg

backend/Asmexpandaux.mli

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
open Asm
1515
open AST
16-
open BinNums
1716

1817
(** Auxiliary functions for builtin expansion *)
1918

@@ -31,6 +30,6 @@ val set_current_function: coq_function -> unit
3130
(* Set the current function *)
3231
val get_current_function: unit -> coq_function
3332
(* Get the current function *)
34-
val expand_debug: positive -> int -> (preg -> int) -> (instruction -> unit) -> instruction list -> unit
33+
val expand_debug: ident -> int -> (preg -> int) -> (instruction -> unit) -> instruction list -> unit
3534
(* Expand builtin debug function. Takes the function id, the register number of the stackpointer, a
3635
function to get the dwarf mapping of varibale names and for the expansion of simple instructions *)

backend/Cminor.v

+10-10
Original file line numberDiff line numberDiff line change
@@ -185,29 +185,29 @@ Definition funsig (fd: fundef) :=
185185
*)
186186

187187
Definition genv := Genv.t fundef unit.
188-
Definition env := PTree.t val.
188+
Definition env := ATree.t val.
189189

190190
(** The following functions build the initial local environment at
191191
function entry, binding parameters to the provided arguments and
192192
initializing local variables to [Vundef]. *)
193193

194194
Fixpoint set_params (vl: list val) (il: list ident) {struct il} : env :=
195195
match il, vl with
196-
| i1 :: is, v1 :: vs => PTree.set i1 v1 (set_params vs is)
197-
| i1 :: is, nil => PTree.set i1 Vundef (set_params nil is)
198-
| _, _ => PTree.empty val
196+
| i1 :: is, v1 :: vs => ATree.set i1 v1 (set_params vs is)
197+
| i1 :: is, nil => ATree.set i1 Vundef (set_params nil is)
198+
| _, _ => ATree.empty val
199199
end.
200200

201201
Fixpoint set_locals (il: list ident) (e: env) {struct il} : env :=
202202
match il with
203203
| nil => e
204-
| i1 :: is => PTree.set i1 Vundef (set_locals is e)
204+
| i1 :: is => ATree.set i1 Vundef (set_locals is e)
205205
end.
206206

207207
Definition set_optvar (optid: option ident) (v: val) (e: env) : env :=
208208
match optid with
209209
| None => e
210-
| Some id => PTree.set id v e
210+
| Some id => ATree.set id v e
211211
end.
212212

213213
(** Continuations *)
@@ -359,7 +359,7 @@ Variable m: mem.
359359

360360
Inductive eval_expr: expr -> val -> Prop :=
361361
| eval_Evar: forall id v,
362-
PTree.get id e = Some v ->
362+
ATree.get id e = Some v ->
363363
eval_expr (Evar id) v
364364
| eval_Econst: forall cst v,
365365
eval_constant sp cst = Some v ->
@@ -447,7 +447,7 @@ Inductive step: state -> trace -> state -> Prop :=
447447
| step_assign: forall f id a k sp e m v,
448448
eval_expr sp e m a v ->
449449
step (State f (Sassign id a) k sp e m)
450-
E0 (State f Sskip k sp (PTree.set id v e) m)
450+
E0 (State f Sskip k sp (ATree.set id v e) m)
451451

452452
| step_store: forall f chunk addr a k sp e m vaddr v m',
453453
eval_expr sp e m addr vaddr ->
@@ -673,7 +673,7 @@ with exec_stmt:
673673
| exec_Sassign:
674674
forall f sp e m id a v,
675675
eval_expr ge sp e m a v ->
676-
exec_stmt f sp e m (Sassign id a) E0 (PTree.set id v e) m Out_normal
676+
exec_stmt f sp e m (Sassign id a) E0 (ATree.set id v e) m Out_normal
677677
| exec_Sstore:
678678
forall f sp e m chunk addr a vaddr v m',
679679
eval_expr ge sp e m addr vaddr ->
@@ -948,7 +948,7 @@ Proof.
948948
constructor.
949949

950950
(* assign *)
951-
exists (State f Sskip k sp (PTree.set id v e) m); split.
951+
exists (State f Sskip k sp (ATree.set id v e) m); split.
952952
apply star_one. constructor. auto.
953953
constructor.
954954

backend/CminorSel.v

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Variable m: mem.
165165

166166
Inductive eval_expr: letenv -> expr -> val -> Prop :=
167167
| eval_Evar: forall le id v,
168-
PTree.get id e = Some v ->
168+
ATree.get id e = Some v ->
169169
eval_expr le (Evar id) v
170170
| eval_Eop: forall le op al vl v,
171171
eval_exprlist le al vl ->
@@ -284,7 +284,7 @@ End EVAL_EXPR.
284284

285285
Definition set_builtin_res (res: builtin_res ident) (v: val) (e: env) : env :=
286286
match res with
287-
| BR id => PTree.set id v e
287+
| BR id => ATree.set id v e
288288
| _ => e
289289
end.
290290

@@ -348,7 +348,7 @@ Inductive step: state -> trace -> state -> Prop :=
348348
| step_assign: forall f id a k sp e m v,
349349
eval_expr sp e m nil a v ->
350350
step (State f (Sassign id a) k sp e m)
351-
E0 (State f Sskip k sp (PTree.set id v e) m)
351+
E0 (State f Sskip k sp (ATree.set id v e) m)
352352

353353
| step_store: forall f chunk addr al b k sp e m vl v vaddr m',
354354
eval_exprlist sp e m nil al vl ->

backend/Debugvar.v

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Fixpoint set_state (v: ident) (i: debuginfo) (s: avail) : avail :=
7474
match s with
7575
| nil => (v, i) :: nil
7676
| (v', i') as vi' :: s' =>
77-
match Pos.compare v v' with
77+
match Ident.compare v v' with
7878
| Eq => (v, i) :: s'
7979
| Lt => (v, i) :: s
8080
| Gt => vi' :: set_state v i s'
@@ -85,7 +85,7 @@ Fixpoint remove_state (v: ident) (s: avail) : avail :=
8585
match s with
8686
| nil => nil
8787
| (v', i') as vi' :: s' =>
88-
match Pos.compare v v' with
88+
match Ident.compare v v' with
8989
| Eq => s'
9090
| Lt => s
9191
| Gt => vi' :: remove_state v s'
@@ -157,7 +157,7 @@ Fixpoint join (s1: avail) (s2: avail) {struct s1} : avail :=
157157
match s2 with
158158
| nil => nil
159159
| (v2, i2) as vi2 :: s2' =>
160-
match Pos.compare v1 v2 with
160+
match Ident.compare v1 v2 with
161161
| Eq => if eq_debuginfo i1 i2 then vi1 :: join s1' s2' else join s1' s2'
162162
| Lt => join s1' s2
163163
| Gt => join2 s2'
@@ -296,7 +296,7 @@ Fixpoint diff (s1 s2: avail) {struct s1} : avail :=
296296
match s2 with
297297
| nil => s1
298298
| (v2, i2) :: s2' =>
299-
match Pos.compare v1 v2 with
299+
match Ident.compare v1 v2 with
300300
| Eq => if eq_debuginfo i1 i2 then diff s1' s2' else vi1 :: diff s1' s2'
301301
| Lt => vi1 :: diff s1' s2
302302
| Gt => diff2 s2'

backend/Debugvarproof.v

+40-29
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ Remark diff_same:
4141
Proof.
4242
induction s as [ | [v i] s]; simpl.
4343
auto.
44-
rewrite Pos.compare_refl. rewrite dec_eq_true. auto.
44+
destruct (Ident.compare_spec v v); try solve [eelim Ident.lt_not_eq; eauto].
45+
rewrite dec_eq_true. auto.
4546
Qed.
4647

4748
Remark delta_state_same:
@@ -117,7 +118,7 @@ Qed.
117118
but establish some confidence in the availability analysis. *)
118119

119120
Definition avail_above (v: ident) (s: avail) : Prop :=
120-
forall v' i', In (v', i') s -> Plt v v'.
121+
forall v' i', In (v', i') s -> Ident.lt v v'.
121122

122123
Inductive wf_avail: avail -> Prop :=
123124
| wf_avail_nil:
@@ -132,7 +133,7 @@ Lemma set_state_1:
132133
Proof.
133134
induction s as [ | [v' i'] s]; simpl.
134135
- auto.
135-
- destruct (Pos.compare v v'); simpl; auto.
136+
- destruct (Ident.compare v v'); simpl; auto.
136137
Qed.
137138

138139
Lemma set_state_2:
@@ -141,7 +142,7 @@ Lemma set_state_2:
141142
Proof.
142143
induction s as [ | [v1 i1] s]; simpl; intros.
143144
- contradiction.
144-
- destruct (Pos.compare_spec v v1); simpl.
145+
- destruct (Ident.compare_spec v v1); simpl.
145146
+ subst v1. destruct H0. congruence. auto.
146147
+ auto.
147148
+ destruct H0; auto.
@@ -155,14 +156,14 @@ Lemma set_state_3:
155156
Proof.
156157
induction 1; simpl; intros.
157158
- intuition congruence.
158-
- destruct (Pos.compare_spec v v0); simpl in H1.
159+
- destruct (Ident.compare_spec v v0); simpl in H1.
159160
+ subst v0. destruct H1. inv H1; auto. right; split.
160-
apply not_eq_sym. apply Plt_ne. eapply H; eauto.
161+
apply not_eq_sym. apply Ident.lt_not_eq. eapply H; eauto.
161162
auto.
162163
+ destruct H1. inv H1; auto.
163-
destruct H1. inv H1. right; split; auto. apply not_eq_sym. apply Plt_ne. auto.
164-
right; split; auto. apply not_eq_sym. apply Plt_ne. apply Plt_trans with v0; eauto.
165-
+ destruct H1. inv H1. right; split; auto. apply Plt_ne. auto.
164+
destruct H1. inv H1. right; split; auto. apply not_eq_sym. apply Ident.lt_not_eq. auto.
165+
right; split; auto. apply not_eq_sym. apply Ident.lt_not_eq. apply Ident.lt_trans with v0; eauto.
166+
+ destruct H1. inv H1. right; split; auto. apply Ident.lt_not_eq. auto.
166167
destruct IHwf_avail as [A | [A B]]; auto.
167168
Qed.
168169

@@ -171,11 +172,11 @@ Lemma wf_set_state:
171172
Proof.
172173
induction 1; simpl.
173174
- constructor. red; simpl; tauto. constructor.
174-
- destruct (Pos.compare_spec v v0).
175+
- destruct (Ident.compare_spec v v0).
175176
+ subst v0. constructor; auto.
176177
+ constructor.
177178
red; simpl; intros. destruct H2.
178-
inv H2. auto. apply Plt_trans with v0; eauto.
179+
inv H2. auto. apply Ident.lt_trans with v0; eauto.
179180
constructor; auto.
180181
+ constructor.
181182
red; intros. exploit set_state_3. eexact H0. eauto. intros [[A B] | [A B]]; subst; eauto.
@@ -187,19 +188,19 @@ Lemma remove_state_1:
187188
Proof.
188189
induction 1; simpl; red; intros.
189190
- auto.
190-
- destruct (Pos.compare_spec v v0); simpl in *.
191-
+ subst v0. elim (Plt_strict v); eauto.
192-
+ destruct H1. inv H1. elim (Plt_strict v); eauto.
193-
elim (Plt_strict v). apply Plt_trans with v0; eauto.
194-
+ destruct H1. inv H1. elim (Plt_strict v); eauto. tauto.
191+
- destruct (Ident.compare_spec v v0); simpl in *.
192+
+ subst v0. elim (Ident.lt_not_eq v v); eauto.
193+
+ destruct H1. inv H1. elim (Ident.lt_not_eq v v); eauto.
194+
elim (Ident.lt_not_eq v v); eauto. apply Ident.lt_trans with v0; eauto.
195+
+ destruct H1. inv H1. elim (Ident.lt_not_eq v v); eauto. tauto.
195196
Qed.
196197

197198
Lemma remove_state_2:
198199
forall v v' i' s, v' <> v -> In (v', i') s -> In (v', i') (remove_state v s).
199200
Proof.
200201
induction s as [ | [v1 i1] s]; simpl; intros.
201202
- auto.
202-
- destruct (Pos.compare_spec v v1); simpl.
203+
- destruct (Ident.compare_spec v v1); simpl.
203204
+ subst v1. destruct H0. congruence. auto.
204205
+ auto.
205206
+ destruct H0; auto.
@@ -210,11 +211,11 @@ Lemma remove_state_3:
210211
Proof.
211212
induction 1; simpl; intros.
212213
- contradiction.
213-
- destruct (Pos.compare_spec v v0); simpl in H1.
214-
+ subst v0. split; auto. apply not_eq_sym; apply Plt_ne; eauto.
215-
+ destruct H1. inv H1. split; auto. apply not_eq_sym; apply Plt_ne; eauto.
216-
split; auto. apply not_eq_sym; apply Plt_ne. apply Plt_trans with v0; eauto.
217-
+ destruct H1. inv H1. split; auto. apply Plt_ne; auto.
214+
- destruct (Ident.compare_spec v v0); simpl in H1.
215+
+ subst v0. split; auto. apply not_eq_sym; apply Ident.lt_not_eq; eauto.
216+
+ destruct H1. inv H1. split; auto. apply not_eq_sym; apply Ident.lt_not_eq; eauto.
217+
split; auto. apply not_eq_sym; apply Ident.lt_not_eq. apply Ident.lt_trans with v0; eauto.
218+
+ destruct H1. inv H1. split; auto. apply Ident.lt_not_eq; auto.
218219
destruct IHwf_avail as [A B] ; auto.
219220
Qed.
220221

@@ -223,7 +224,7 @@ Lemma wf_remove_state:
223224
Proof.
224225
induction 1; simpl.
225226
- constructor.
226-
- destruct (Pos.compare_spec v v0).
227+
- destruct (Ident.compare_spec v v0).
227228
+ auto.
228229
+ constructor; auto.
229230
+ constructor; auto. red; intros.
@@ -246,12 +247,22 @@ Lemma join_1:
246247
Proof.
247248
induction 1; simpl; try tauto; induction 1; simpl; intros I1 I2; auto.
248249
destruct I1, I2.
249-
- inv H3; inv H4. rewrite Pos.compare_refl. rewrite dec_eq_true; auto with coqlib.
250+
- inv H3; inv H4.
251+
destruct (Ident.compare_spec v v); try solve [eelim Ident.lt_not_eq; eauto].
252+
rewrite dec_eq_true; auto with coqlib.
250253
- inv H3.
251-
assert (L: Plt v1 v) by eauto. apply Pos.compare_gt_iff in L. rewrite L. auto.
254+
assert (L: Ident.lt v1 v) by eauto.
255+
destruct (Ident.compare_spec v v1).
256+
+ eelim Ident.lt_not_eq; eauto.
257+
+ elim (Ident.lt_not_eq v v); eauto using Ident.lt_trans.
258+
+ auto.
252259
- inv H4.
253-
assert (L: Plt v0 v) by eauto. apply Pos.compare_lt_iff in L. rewrite L. apply IHwf_avail. constructor; auto. auto. auto with coqlib.
254-
- destruct (Pos.compare v0 v1).
260+
assert (L: Ident.lt v0 v) by eauto.
261+
destruct (Ident.compare_spec v0 v).
262+
+ eelim Ident.lt_not_eq; eauto.
263+
+ apply IHwf_avail. constructor; auto. auto. auto with coqlib.
264+
+ elim (Ident.lt_not_eq v v); eauto using Ident.lt_trans.
265+
- destruct (Ident.compare v0 v1).
255266
+ destruct (eq_debuginfo i0 i1); auto with coqlib.
256267
+ apply IHwf_avail; auto with coqlib. constructor; auto.
257268
+ eauto.
@@ -262,7 +273,7 @@ Lemma join_2:
262273
In (v, i) (join s1 s2) -> In (v, i) s1 /\ In (v, i) s2.
263274
Proof.
264275
induction 1; simpl; try tauto; induction 1; simpl; intros I; try tauto.
265-
destruct (Pos.compare_spec v0 v1).
276+
destruct (Ident.compare_spec v0 v1).
266277
- subst v1. destruct (eq_debuginfo i0 i1).
267278
+ subst i1. destruct I. auto. exploit IHwf_avail; eauto. tauto.
268279
+ exploit IHwf_avail; eauto. tauto.
@@ -275,7 +286,7 @@ Lemma wf_join:
275286
forall s1, wf_avail s1 -> forall s2, wf_avail s2 -> wf_avail (join s1 s2).
276287
Proof.
277288
induction 1; simpl; induction 1; simpl; try constructor.
278-
destruct (Pos.compare_spec v v0).
289+
destruct (Ident.compare_spec v v0).
279290
- subst v0. destruct (eq_debuginfo i i0); auto. constructor; auto.
280291
red; intros. apply join_2 in H3; auto. destruct H3. eauto.
281292
- apply IHwf_avail. constructor; auto.

0 commit comments

Comments
 (0)