From 7bf884b7c525092db74ac2effcf1091bd3c3d46c Mon Sep 17 00:00:00 2001 From: Emilio Jesus Gallego Arias Date: Mon, 14 Sep 2020 18:23:55 +0200 Subject: [zarith] [micromega] Bump to 1.10 and remove some hacks In particular, behavior of `Z.gcd` and `Z.lcm` has been fixed in 1.10, see https://github.com/ocaml/Zarith/issues/58 --- .gitlab-ci.yml | 2 +- INSTALL.md | 2 +- azure-pipelines.yml | 2 +- coq.opam | 2 +- coq.opam.docker | 2 +- dev/build/windows/makecoq_mingw.sh | 2 +- dev/ci/docker/bionic_coq/Dockerfile | 6 +++--- plugins/micromega/numCompat.ml | 13 +++++-------- plugins/micromega/numCompat.mli | 7 +++++++ 9 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cfa6f84147..22658cc9b8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,7 +19,7 @@ stages: variables: # Format: $IMAGE-V$DATE [Cache is not used as of today but kept here # for reference] - CACHEKEY: "bionic_coq-V2020-09-07-V22" + CACHEKEY: "bionic_coq-V2020-09-16-V38" IMAGE: "$CI_REGISTRY_IMAGE:$CACHEKEY" # By default, jobs run in the base switch; override to select another switch OPAM_SWITCH: "base" diff --git a/INSTALL.md b/INSTALL.md index 05a92ca005..adc0f557ac 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -18,7 +18,7 @@ To compile Coq yourself, you need: - The [num](https://github.com/ocaml/num) library; note that it is included in the OCaml distribution for OCaml versions < 4.06.0 -- The [ZArith library](https://github.com/ocaml/Zarith) >= 1.8 +- The [ZArith library](https://github.com/ocaml/Zarith) >= 1.10 - The [findlib](http://projects.camlcity.org/projects/findlib.html) library (version >= 1.8.0) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 17228bda8a..be9e774381 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -80,7 +80,7 @@ jobs: opam switch set ocaml-base-compiler.$COMPILER eval $(opam env) opam update - opam install -j "$NJOBS" num ocamlfind${FINDLIB_VER} ounit lablgtk3-sourceview3 zarith.1.9.1 + opam install -j "$NJOBS" num ocamlfind${FINDLIB_VER} ounit lablgtk3-sourceview3 zarith.1.10 opam list displayName: 'Install OCaml dependencies' env: diff --git a/coq.opam b/coq.opam index f44223052d..342adee1f4 100644 --- a/coq.opam +++ b/coq.opam @@ -25,7 +25,7 @@ depends: [ "dune" { >= "2.5.0" } "ocamlfind" { build } "num" - "zarith" { >= "1.9.1" } + "zarith" { >= "1.10" } ] build: [ diff --git a/coq.opam.docker b/coq.opam.docker index ac1869f344..09065fdffd 100644 --- a/coq.opam.docker +++ b/coq.opam.docker @@ -24,7 +24,7 @@ depends: [ "ocaml" { >= "4.05.0" } "ocamlfind" { build } "num" - "zarith" { >= "1.9.1" } + "zarith" { >= "1.10" } "conf-findutils" {build} ] diff --git a/dev/build/windows/makecoq_mingw.sh b/dev/build/windows/makecoq_mingw.sh index cde1d798a0..fcc585117b 100755 --- a/dev/build/windows/makecoq_mingw.sh +++ b/dev/build/windows/makecoq_mingw.sh @@ -1026,7 +1026,7 @@ function make_num { function make_zarith { make_ocaml - if build_prep https://github.com/ocaml/Zarith/archive release-1.9.1 tar.gz 1 zarith-1.9.1; then + if build_prep https://github.com/ocaml/Zarith/archive release-1.10 tar.gz 1 zarith-1.10; then logn configure ./configure log1 make log2 make install diff --git a/dev/ci/docker/bionic_coq/Dockerfile b/dev/ci/docker/bionic_coq/Dockerfile index ee50d25318..2fcd69e130 100644 --- a/dev/ci/docker/bionic_coq/Dockerfile +++ b/dev/ci/docker/bionic_coq/Dockerfile @@ -1,4 +1,4 @@ -# CACHEKEY: "bionic_coq-V2020-09-07-V22" +# CACHEKEY: "bionic_coq-V2020-09-16-V38" # ^^ Update when modifying this file. FROM ubuntu:bionic @@ -43,7 +43,7 @@ ENV COMPILER="4.05.0" # Common OPAM packages, num to be removed once the migration to # micromega is complete, `num` also does not have a version number as # the right version to install varies with the compiler version. -ENV BASE_OPAM="num zarith.1.9.1 ocamlfind.1.8.1 ounit2.2.2.3 odoc.1.5.1" \ +ENV BASE_OPAM="num zarith.1.10 ocamlfind.1.8.1 ounit2.2.2.3 odoc.1.5.1" \ CI_OPAM="menhir.20190626 ocamlgraph.1.8.8" \ BASE_ONLY_OPAM="elpi.1.11.0" @@ -59,7 +59,7 @@ RUN opam init -a --disable-sandboxing --compiler="$COMPILER" default https://opa # base+32bit switch, note the zarith hack RUN opam switch create "${COMPILER}+32bit" && eval $(opam env) && \ - i386 env CC='gcc -m32' opam install zarith.1.9.1 && \ + i386 env CC='gcc -m32' opam install zarith.1.10 && \ opam install $BASE_OPAM # EDGE switch diff --git a/plugins/micromega/numCompat.ml b/plugins/micromega/numCompat.ml index 62f05685aa..8cfda32543 100644 --- a/plugins/micromega/numCompat.ml +++ b/plugins/micromega/numCompat.ml @@ -31,6 +31,8 @@ module type ZArith = sig end module Z = struct + (* Beware this only works fine in ZArith >= 1.10 due to + https://github.com/ocaml/Zarith/issues/58 *) include Z (* Constants *) @@ -39,13 +41,8 @@ module Z = struct let power_int = Big_int_Z.power_big_int_positive_int let quomod = Big_int_Z.quomod_big_int - (* Workaround https://github.com/ocaml/Zarith/issues/58 , remove - the abs when zarith 1.9.2 is released *) - let gcd x y = Z.abs (Z.gcd x y) - - (* zarith fails with division by zero if x && y == 0 *) - let lcm x y = - if Z.equal x zero && Z.equal y zero then zero else Z.abs (Z.lcm x y) + (* zarith fails with division by zero if x == 0 && y == 0 *) + let lcm x y = if Z.equal x zero && Z.equal y zero then zero else Z.lcm x y let ppcm x y = let g = gcd x y in @@ -144,7 +141,7 @@ module Q : QArith with module Z = Z = struct let ceiling q : t = Z.cdiv (Q.num q) (Q.den q) |> Q.of_bigint let half = Q.make Z.one Z.two - (* Num round is to the nearest *) + (* We imitate Num's round which is to the nearest *) let round q = floor (Q.add half q) (* XXX: review / improve *) diff --git a/plugins/micromega/numCompat.mli b/plugins/micromega/numCompat.mli index acc6be6ce0..fe0a6e7660 100644 --- a/plugins/micromega/numCompat.mli +++ b/plugins/micromega/numCompat.mli @@ -25,8 +25,15 @@ module type ZArith = sig val power_int : t -> int -> t val quomod : t -> t -> t * t val ppcm : t -> t -> t + + (** [gcd x y] Greatest Common Divisor. Must always return a + positive number *) val gcd : t -> t -> t + + (** [lcm x y] Least Common Multiplier. Must always return a + positive number *) val lcm : t -> t -> t + val to_string : t -> string end -- cgit v1.2.3