Skip to content

Commit 873c621

Browse files
vbglxavierleroy
authored andcommitted
Make the checker happy (AbsInt#272)
Previously, the coqchk type- and proof-checker would take forever on some of CompCert's modules. This commit makes minimal changes to the problematic proofs so that all of CompCert can be checked with coqchk. Tested with Coq versions 8.8.2 and 8.9.0.
1 parent 0b3193b commit 873c621

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

Makefile

+1-5
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,8 @@ distclean:
279279
check-admitted: $(FILES)
280280
@grep -w 'admit\|Admitted\|ADMITTED' $^ || echo "Nothing admitted."
281281

282-
# Problems with coqchk (coq 8.6):
283-
# Integers.Int.Z_mod_modulus_range takes forever to check
284-
# compcert.backend.SelectDivproof.divs_mul_shift_2 takes forever to check
285-
286282
check-proof: $(FILES)
287-
$(COQCHK) -admit compcert.lib.Integers -admit compcert.backend.SelectDivproof compcert.driver.Complements
283+
$(COQCHK) compcert.driver.Complements
288284

289285
print-includes:
290286
@echo $(COQINCLUDES)

backend/SelectDivproof.v

+8-6
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,15 @@ Proof.
283283
intros (A & B & C). split. auto. rewrite C. f_equal. f_equal.
284284
rewrite Int.add_signed. unfold Int.mulhs. set (n := Int.signed x).
285285
transitivity (Int.repr (n * (m - Int.modulus) / Int.modulus + n)).
286-
f_equal.
286+
apply f_equal.
287287
replace (n * (m - Int.modulus)) with (n * m + (-n) * Int.modulus) by ring.
288288
rewrite Z_div_plus. ring. apply Int.modulus_pos.
289289
apply Int.eqm_samerepr. apply Int.eqm_add; auto with ints.
290290
apply Int.eqm_sym. eapply Int.eqm_trans. apply Int.eqm_signed_unsigned.
291-
apply Int.eqm_unsigned_repr_l. apply Int.eqm_refl2. f_equal. f_equal.
291+
apply Int.eqm_unsigned_repr_l. apply Int.eqm_refl2.
292+
apply (f_equal (fun x => n * x / Int.modulus)).
292293
rewrite Int.signed_repr_eq. rewrite Zmod_small by assumption.
293-
apply zlt_false. omega.
294+
apply zlt_false. assumption.
294295
Qed.
295296

296297
Theorem divu_mul_shift:
@@ -436,14 +437,15 @@ Proof.
436437
intros (A & B & C). split. auto. rewrite C. f_equal. f_equal.
437438
rewrite Int64.add_signed. unfold Int64.mulhs. set (n := Int64.signed x).
438439
transitivity (Int64.repr (n * (m - Int64.modulus) / Int64.modulus + n)).
439-
f_equal.
440+
apply f_equal.
440441
replace (n * (m - Int64.modulus)) with (n * m + (-n) * Int64.modulus) by ring.
441442
rewrite Z_div_plus. ring. apply Int64.modulus_pos.
442443
apply Int64.eqm_samerepr. apply Int64.eqm_add; auto with ints.
443444
apply Int64.eqm_sym. eapply Int64.eqm_trans. apply Int64.eqm_signed_unsigned.
444-
apply Int64.eqm_unsigned_repr_l. apply Int64.eqm_refl2. f_equal. f_equal.
445+
apply Int64.eqm_unsigned_repr_l. apply Int64.eqm_refl2.
446+
apply (f_equal (fun x => n * x / Int64.modulus)).
445447
rewrite Int64.signed_repr_eq. rewrite Zmod_small by assumption.
446-
apply zlt_false. omega.
448+
apply zlt_false. assumption.
447449
Qed.
448450

449451
Remark int64_shru'_div_two_p:

lib/Integers.v

+8-8
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,19 @@ Lemma Z_mod_modulus_range:
150150
Proof.
151151
intros; unfold Z_mod_modulus.
152152
destruct x.
153-
- generalize modulus_pos; omega.
153+
- generalize modulus_pos; intuition.
154154
- apply P_mod_two_p_range.
155155
- set (r := P_mod_two_p p wordsize).
156156
assert (0 <= r < modulus) by apply P_mod_two_p_range.
157157
destruct (zeq r 0).
158-
+ generalize modulus_pos; omega.
159-
+ omega.
158+
+ generalize modulus_pos; intuition.
159+
+ Psatz.lia.
160160
Qed.
161161

162162
Lemma Z_mod_modulus_range':
163163
forall x, -1 < Z_mod_modulus x < modulus.
164164
Proof.
165-
intros. generalize (Z_mod_modulus_range x); omega.
165+
intros. generalize (Z_mod_modulus_range x); intuition.
166166
Qed.
167167

168168
Lemma Z_mod_modulus_eq:
@@ -178,10 +178,10 @@ Proof.
178178
set (r := P_mod_two_p p wordsize) in *.
179179
rewrite <- B in C.
180180
change (Z.neg p) with (- (Z.pos p)). destruct (zeq r 0).
181-
+ symmetry. apply Zmod_unique with (-q). rewrite C; rewrite e. ring.
182-
generalize modulus_pos; omega.
183-
+ symmetry. apply Zmod_unique with (-q - 1). rewrite C. ring.
184-
omega.
181+
+ symmetry. apply Zmod_unique with (-q). rewrite C; rewrite e. Psatz.lia.
182+
intuition.
183+
+ symmetry. apply Zmod_unique with (-q - 1). rewrite C. Psatz.lia.
184+
intuition.
185185
Qed.
186186

187187
(** The [unsigned] and [signed] functions return the Coq integer corresponding

0 commit comments

Comments
 (0)