Fix `Export` order for `length`. Remove `length` hack in strings.
The notation in strings
was a hack to shadow the length
function on strings with those on lists.
@msammler and I figured out how to change the imports to fix this problem without the hack. Basically, stdpp.base
exports Coq.Strings
and Coq.List
in the right order, so the shadowing is done right. As a consequence Coq.Strings
should never be exported by hand.
This approach seems to work among all supported Coq versions.
We also added a test.
Merge request reports
Activity
I looked again at the problem and found out the following: If you do
From stdpp Require Import strings. Goal length [1] = 1%nat.
or
From stdpp Require Import prelude. From stdpp Require Import strings. Goal length [1] = 1%nat.
length
is printed aslength
(as it should be). However, if you doFrom stdpp Require Import strings. From stdpp Require Import prelude. Goal length [1] = 1%nat.
length
is printed asstrings.length
. The problem is thatstdpp.prelude
exportsstdpp.base
, which exportsCoq.List
. In this case the pretty printer tries to print the notation (now available asstrings.length
sincelength
refers to the definition on lists) instead of the definition, which in this case is uglier. The problem is that many filesRequire Export stdpp.prelude
since it is part ofiris.algebra.base
, thus addingFrom stdpp Require Import strings.
to the beginning of files would not work. One would need to add it after all other imports. One other work around could be to addstrings
tostdpp.prelude
(I have not tried this).See !139 (closed) where I tried the change to stdpp and it seems to work. No change to Iris seems to be necessary. Importing
strings
directly should be fine, there is only a problem if you importstdpp.base
afterstdpp.strings
.added 29 commits
-
7f59be76...4b0c93cb - 28 commits from branch
master
- 7d981af6 - Fix `Export` order for `length`. Remove `length` hack in strings. Add a test.
-
7f59be76...4b0c93cb - 28 commits from branch
mentioned in merge request !139 (closed)
added 1 commit
- f3842eb3 - Use `Check` instead of `About` to hopefully have stable test output among Coq versions.
added 2 commits
added 2 commits
3 3 abstract interfaces for ordered structures, sets, and various other data 4 4 structures. *) 5 5 6 From Coq Require Export Morphisms RelationClasses List Bool Utf8 Setoid. 6 (** The order of this [Require Export] is important: The definition of [length] 7 in [List] should shadow the definition of [length] in [String]. We also need 8 to export [Datatypes] because [List] contains a [parsing only] notation for 9 [length], not the actual definition of [length], which is in [Datatypes]. *) 10 From Coq Require Export String Datatypes List. It seems rather excessive and potentially problematic to export
String
to every single user of std++. (I am not sure whatDatatype
contains.)Edited by Ralf JungDatatypes contain all the basic data types like
bool
,list
,unit
, and some basic functions on those, likelength
.It seems rather excessive and potentially problematic to export
String
to every single user of std++.If things are properly shadowed it should not hurt. Note that we already export tons of stuff like Utf8, Setoids, Program stuff, etc.
Anyway, to assess if it causes any problems, could we run the CI on all Iris reverse dependencies?
If things are properly shadowed it should not hurt.
Well this is still a gross misuse of the Coq module system. Just because we in Iris are not very careful about what we import, and rely on "C-style namespacing" to disambiguation, that does not mean we should force this on all Iris users.
could we run the CI on all Iris reverse dependencies?
I can do that. (I can also tell you how to do it so you don't have to wait for me each time, and I don#' have to forward the results each time.^^)
The CI run found two failures, lambda-rust master and weak_mem:
Edited by Ralf JungMy guess what is going wrong with the
The term "bool" has type "Set" while it is expected to have type "type".
failure in lambda-rust (https://gitlab.mpi-sws.org/iris/lambda-rust/-/jobs/64059#L230): There is a lambda-rusttype
calledbool
in lambda rust and there is a CoqSet
calledbool
inDatatypes
. This is a violation of the usual c-style namespacing we do and this is why this MR break this code. Note that the failure is inint.v
which first importsbool
and then (ordering is important) importsprograms
. https://gitlab.mpi-sws.org/iris/lambda-rust/-/blob/master/theories/typing/int.v#L3[rograms
transitively exportsstdpp.base
which with this MR exports the Coqbool
due to the export ofDatatypes
. Thus with this MRbool
inint.v
refers to the Coqbool
, while without this MR it refers to the lambda rustbool
. Note that my other MR !139 (closed) would probably also run into this problem as it would also makeprograms
exportDatatypes
.This is all very messy and I don't know what the best solution is. I see the following options:
- accept this MR (or !139 (closed)) and accept the breakage
- I thought there was a version which works on all Coq versions and does not rely on exporting
Datatypes
but printsDatatypes.length
on Coq versions before 8.11. (Was it making the notation in strings.v parsing only?) This would make the problem for users of 8.11 go away and changestrings.length
toDatatypes.length
for users for older Coq versions. - do nothing (please not)
Edited by Michael Sammleraccept this MR (or !139 (closed)) and accept the breakage
s/accept/fix/
I'm afraid that's the most pragmatic choice. I would be in favor of this.
I thought there was a version which works on all Coq versions and does not rely on exporting
Datatypes
but printsDatatypes.length
on Coq versions before 8.11. (Was it making the notation in strings.v parsing only?) This would make the problem for users of 8.11 go away and changestrings.length
toDatatypes.length
for users for older Coq versions.That's removing the
Notation length
inbase.v
. I don't think that affects the lambdarust problem.In another thread you wrote:
Well this is still a gross misuse of the Coq module system. Just because we in Iris are not very careful about what we import [..]
I don't think there is a way to use Coq's module system properly, i.e., to not abuse it. As far as I am concerned it's broken beyond repair.
When this issue came up on coq-club, a few people reported that they did use it, and seemed somewhat surprised by our issues with it.
You don't have to
Import
everything, doingRequire
most of the time gets you a long way. You can also split a file likeDefinition auth := ... Module auth. (* Auth lemmas, without `auth_` prefix. *)
If I understand correctly that this is a problem only for old Coq versions, then honestly I think it is better to leave it unfixed for them than to add this reexport.
Edited by Ralf JungNow we have !144 (merged), so let's see how well that works.
What I meant is otherwise I think a reasonable solution would fix the problem on Coq 8.11 only, and leave Coq 8.10 broken, without adding the reexport. I am not sure if one of the candidates that @msammler considered satisfies this.
Oh, right, the discussion is a bit defused (since it's in many issues/MRs), so that's yet another alternative. @msammler could you test that !144 (merged) indeed works with Iris and RefinedC?
mentioned in merge request !144 (merged)
There is another option which I tried here and which seems to work without adding new exports: !144 (merged)
Wait @robbertkrebbers why did you merge this? Please revert, this is the one I did not agree to.
Ah I didn't realize @msammler based his MR on this. I think we should have squashed that to avoid noise in the history. Oh well, too late now.^^