Skip to content

Commit

Permalink
Improve compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
mht208 committed Jun 15, 2022
1 parent 8d5ee86 commit 17f9da5
Show file tree
Hide file tree
Showing 6 changed files with 1,155 additions and 987 deletions.
81 changes: 67 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## # GNU Lesser General Public License Version 2.1 ##
## # (see LICENSE file for the text of the license) ##
##########################################################################
## GNUMakefile for Coq 8.13.2
## GNUMakefile for Coq 8.14.1

# For debugging purposes (must stay here, don't move below)
INITIAL_VARS := $(.VARIABLES)
Expand All @@ -29,14 +29,14 @@ MLLIBFILES := $(COQMF_MLLIBFILES)
CMDLINE_VFILES := $(COQMF_CMDLINE_VFILES)
INSTALLCOQDOCROOT := $(COQMF_INSTALLCOQDOCROOT)
OTHERFLAGS := $(COQMF_OTHERFLAGS)
COQ_SRC_SUBDIRS := $(COQMF_COQ_SRC_SUBDIRS)
COQCORE_SRC_SUBDIRS := $(COQMF_COQ_SRC_SUBDIRS)
OCAMLLIBS := $(COQMF_OCAMLLIBS)
SRC_SUBDIRS := $(COQMF_SRC_SUBDIRS)
COQLIBS := $(COQMF_COQLIBS)
COQLIBS_NOML := $(COQMF_COQLIBS_NOML)
CMDLINE_COQLIBS := $(COQMF_CMDLINE_COQLIBS)
LOCAL := $(COQMF_LOCAL)
COQLIB := $(COQMF_COQLIB)
COQCORELIB := $(COQMF_COQCORELIB)
DOCDIR := $(COQMF_DOCDIR)
OCAMLFIND := $(COQMF_OCAMLFIND)
CAMLFLAGS := $(COQMF_CAMLFLAGS)
Expand All @@ -59,6 +59,15 @@ Makefile.conf: _CoqProject
# practice is discouraged since _CoqProject better not contain make specific
# code (be nice to user interfaces).

# set KEEP_ERROR to prevent make from deleting files produced by failing rules.
# For instance if coqc creates a .vo but then fails to native compile,
# the .vo will be deleted unless KEEP_ERROR is nonempty.
# May confuse make so use only for debugging.
KEEP_ERROR?=
ifneq (,$(KEEP_ERROR))
.DELETE_ON_ERROR:
endif

# Print shell commands (set to non empty)
VERBOSE ?=

Expand Down Expand Up @@ -90,16 +99,17 @@ endif
COQC ?= "$(COQBIN)coqc"
COQTOP ?= "$(COQBIN)coqtop"
COQCHK ?= "$(COQBIN)coqchk"
COQNATIVE ?= "$(COQBIN)coqnative"
COQDEP ?= "$(COQBIN)coqdep"
COQDOC ?= "$(COQBIN)coqdoc"
COQPP ?= "$(COQBIN)coqpp"
COQMKFILE ?= "$(COQBIN)coq_makefile"
OCAMLLIBDEP ?= "$(COQBIN)ocamllibdep"

# Timing scripts
COQMAKE_ONE_TIME_FILE ?= "$(COQLIB)/tools/make-one-time-file.py"
COQMAKE_BOTH_TIME_FILES ?= "$(COQLIB)/tools/make-both-time-files.py"
COQMAKE_BOTH_SINGLE_TIMING_FILES ?= "$(COQLIB)/tools/make-both-single-timing-files.py"
COQMAKE_ONE_TIME_FILE ?= "$(COQCORELIB)/tools/make-one-time-file.py"
COQMAKE_BOTH_TIME_FILES ?= "$(COQCORELIB)/tools/make-both-time-files.py"
COQMAKE_BOTH_SINGLE_TIMING_FILES ?= "$(COQCORELIB)/tools/make-both-single-timing-files.py"
BEFORE ?=
AFTER ?=

Expand Down Expand Up @@ -208,8 +218,36 @@ COQEXTRAFLAGS?=
COQCHKEXTRAFLAGS?=
COQDOCEXTRAFLAGS?=

# Find the last argument of the form "-native-compiler FLAG"
COQUSERNATIVEFLAG:=$(strip \
$(subst -native-compiler-,,\
$(lastword \
$(filter -native-compiler-%,\
$(subst -native-compiler ,-native-compiler-,\
$(strip $(COQEXTRAFLAGS)))))))

COQFILTEREDEXTRAFLAGS:=$(strip \
$(filter-out -native-compiler-%,\
$(subst -native-compiler ,-native-compiler-,\
$(strip $(COQEXTRAFLAGS)))))

COQACTUALNATIVEFLAG:=$(lastword $(COQMF_COQ_NATIVE_COMPILER_DEFAULT) $(COQMF_COQPROJECTNATIVEFLAG) $(COQUSERNATIVEFLAG))

ifeq '$(COQACTUALNATIVEFLAG)' 'yes'
COQNATIVEFLAG="-w" "-deprecated-native-compiler-option" "-native-compiler" "ondemand"
COQDONATIVE="yes"
else
ifeq '$(COQACTUALNATIVEFLAG)' 'ondemand'
COQNATIVEFLAG="-w" "-deprecated-native-compiler-option" "-native-compiler" "ondemand"
COQDONATIVE="no"
else
COQNATIVEFLAG="-w" "-deprecated-native-compiler-option" "-native-compiler" "no"
COQDONATIVE="no"
endif
endif

# these flags do NOT contain the libraries, to make them easier to overwrite
COQFLAGS?=-q $(OTHERFLAGS) $(COQEXTRAFLAGS)
COQFLAGS?=-q $(OTHERFLAGS) $(COQFILTEREDEXTRAFLAGS) $(COQNATIVEFLAG)
COQCHKFLAGS?=-silent -o $(COQCHKEXTRAFLAGS)
COQDOCFLAGS?=-interpolate -utf8 $(COQDOCEXTRAFLAGS)

Expand All @@ -218,9 +256,14 @@ COQDOCLIBS?=$(COQLIBS_NOML)
# The version of Coq being run and the version of coq_makefile that
# generated this makefile
COQ_VERSION:=$(shell $(COQC) --print-version | cut -d " " -f 1)
COQMAKEFILE_VERSION:=8.13.2
COQMAKEFILE_VERSION:=8.14.1

COQSRCLIBS?= $(foreach d,$(COQ_SRC_SUBDIRS), -I "$(COQLIB)/$(d)")
# COQ_SRC_SUBDIRS is for user-overriding, usually to add
# `user-contrib/Foo` to the includes, we keep COQCORE_SRC_SUBDIRS for
# Coq's own core libraries, which should be replaced by ocamlfind
# options at some point.
COQ_SRC_SUBDIRS?=
COQSRCLIBS?= $(foreach d,$(COQCORE_SRC_SUBDIRS), -I "$(COQCORELIB)/$(d)") $(foreach d,$(COQ_SRC_SUBDIRS), -I "$(COQLIB)/$(d)")

CAMLFLAGS+=$(OCAMLLIBS) $(COQSRCLIBS)
# ocamldoc fails with unknown argument otherwise
Expand Down Expand Up @@ -718,6 +761,10 @@ endif
$(VOFILES): %.vo: %.v
$(SHOW)COQC $<
$(HIDE)$(TIMER) $(COQC) $(COQDEBUG) $(TIMING_ARG) $(COQFLAGS) $(COQLIBS) $< $(TIMING_EXTRA)
ifeq ($(COQDONATIVE), "yes")
$(SHOW)COQNATIVE $@
$(HIDE)$(COQNATIVE) $(COQLIBS) $@
endif

# FIXME ?merge with .vo / .vio ?
$(GLOBFILES): %.glob: %.v
Expand Down Expand Up @@ -820,13 +867,14 @@ opt:
printenv::
$(warning printenv is deprecated)
$(warning write extensions in Makefile.local or include Makefile.conf)
@echo 'LOCAL = $(LOCAL)'
@echo 'COQLIB = $(COQLIB)'
@echo 'COQCORELIB = $(COQCORELIB)'
@echo 'DOCDIR = $(DOCDIR)'
@echo 'OCAMLFIND = $(OCAMLFIND)'
@echo 'HASNATDYNLINK = $(HASNATDYNLINK)'
@echo 'SRC_SUBDIRS = $(SRC_SUBDIRS)'
@echo 'COQ_SRC_SUBDIRS = $(COQ_SRC_SUBDIRS)'
@echo 'COQCORE_SRC_SUBDIRS = $(COQCORE_SRC_SUBDIRS)'
@echo 'OCAMLFIND = $(OCAMLFIND)'
@echo 'PP = $(PP)'
@echo 'COQFLAGS = $(COQFLAGS)'
Expand All @@ -840,10 +888,10 @@ printenv::
.merlin:
$(SHOW)'FILL .merlin'
$(HIDE)echo 'FLG $(COQMF_CAMLFLAGS)' > .merlin
$(HIDE)echo 'B $(COQLIB)' >> .merlin
$(HIDE)echo 'S $(COQLIB)' >> .merlin
$(HIDE)$(foreach d,$(COQ_SRC_SUBDIRS), \
echo 'B $(COQLIB)$(d)' >> .merlin;)
$(HIDE)echo 'B $(COQCORELIB)' >> .merlin
$(HIDE)echo 'S $(COQCORELIB)' >> .merlin
$(HIDE)$(foreach d,$(COQCORE_SRC_SUBDIRS), \
echo 'B $(COQCORELIB)$(d)' >> .merlin;)
$(HIDE)$(foreach d,$(COQ_SRC_SUBDIRS), \
echo 'S $(COQLIB)$(d)' >> .merlin;)
$(HIDE)$(foreach d,$(SRC_SUBDIRS), echo 'B $(d)' >> .merlin;)
Expand All @@ -865,6 +913,11 @@ debug:

.DEFAULT_GOAL := all

# Users can create Makefile.local-late to hook into double-colon rules
# or add other needed Makefile code, using defined
# variables if necessary.
-include Makefile.local-late

# Local Variables:
# mode: makefile-gmake
# End:
1 change: 1 addition & 0 deletions _CoqProject
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-R src nbits
src/Compatibility.v
src/AuxLemmas.v
src/NBitsDef.v
src/NBitsOp.v
Expand Down
66 changes: 66 additions & 0 deletions build-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

SWITCHES=" \
ocaml4.08.1-coq8.11.0-ssr1.10.0 \
ocaml4.11.2-coq8.12.2-ssr1.11.0 \
ocaml4.12.1-coq8.13.2-ssr1.12.0 \
ocaml4.13.1-coq8.14.1-ssr1.13.0 \
ocaml4.14.0-coq8.15.2-ssr1.14.0 \
"

BUILD_DIR=_build

if [[ "$1" == "clean" ]]; then
rm -rf ${BUILD_DIR}
exit
fi

CURRENT=`opam switch show`

for s in ${SWITCHES}; do
echo "Building with ${s}"

echo -n " * Running 'opam switch' "
opam switch ${s} &> /dev/null
status=$?
if [[ ${status} == 0 ]]; then
echo "[DONE]"
else
echo "[FAIL]"
continue
fi
eval $(opam env)

echo -n " * Copying files "
mkdir -p ${BUILD_DIR}/${s}
tar -c --exclude ${BUILD_DIR} --exclude "*.vo" --exclude "*.vok" --exclude "*.vos" --exclude "*.glob" * | tar -x --keep-newer-files -C ${BUILD_DIR}/${s} &> /dev/null
echo "[DONE]"

echo -n " * Building Coq code "
make -C ${BUILD_DIR}/${s} all >${BUILD_DIR}/${s}.log 2>&1
status=$?
if [[ $status == 0 ]]; then
echo "[DONE]"
echo -n " * Building OCaml code "
pushd ${BUILD_DIR}/${s}/src/ocaml &> /dev/null
dune build &> /dev/null
status=$?
if [[ $status == 0 ]]; then
echo "[DONE]"
else
echo "[FAIL]"
fi
popd &> /dev/null
else
echo "[FAIL]"
fi
done

echo
echo "See the following log files for compilation details."
for s in ${SWITCHES}; do
echo " * ${BUILD_DIR}/${s}.log"
done

opam switch ${CURRENT}
eval $(opam env)
30 changes: 30 additions & 0 deletions src/Compatibility.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

From Coq Require Import ZArith.
From mathcomp Require Import ssreflect.

(*
* Before Coq 8.14, this lemma is:
* Lemma Z_div_nz_opp_full : forall a b:Z, a mod b <> 0 -> (-a)/b = -(a/b)-1.
*)
Lemma Z_div_nz_opp_full (a b : Z) :
b <> 0%Z -> (a mod b)%Z <> 0%Z -> (- a / b)%Z = (- (a / b) - 1)%Z.
Proof. move=> *; by apply: Z_div_nz_opp_full. Qed.

(*
* Before Coq 8.14, this lemma is:
* Lemma Z_div_nz_opp_r : forall a b:Z, a mod b <> 0 -> a/(-b) = -(a/b)-1.
*)
Lemma Z_div_nz_opp_r (a b : Z):
b <> 0%Z -> (a mod b)%Z <> 0%Z -> (a / - b)%Z = (- (a / b) - 1)%Z.
Proof. move=> *; by apply: Z_div_nz_opp_r. Qed.

(*
* After Coq 8.14, this lemma (in the module Z2N) is:
* Lemma inj_mod n m : 0<=n -> 0<=m -> Z.to_N (n mod m) = ((Z.to_N n) mod (Z.to_N m))%N.
*)
Lemma Z2N_inj_mod (n m : Z) :
(0<=n)%Z -> (0<m)%Z -> Z.to_N (n mod m) = ((Z.to_N n) mod (Z.to_N m))%N.
Proof.
move=> H0n H0m. move: (Z.lt_le_incl _ _ H0m) => H0m'.
by apply: Z2N.inj_mod.
Qed.
Loading

0 comments on commit 17f9da5

Please sign in to comment.