Allow accumulating Dbs (and other things) into Dbs #890
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change turns databases into "libraries" (see #Elpi users & devs > Calling `derive` from other elpi commands @ 💬). They can now accumulate anything that commands and programs can accumulate.
This is largely achieved by removing differences and, if that's not easily possible, copying code. The most difficult part that needed re-engineering is probably the compilation and especially caching. The current implementation is very slightly buggy and required a single re-ordering change in
Accumulates in bluerock code before it would build everything. I could probably use help here.Fixes: #889
Depends on: LPCIC/elpi#372
TODO:
Noteworthy changes
Duplicates are Pruned
The new code prunes duplicates within a database/program/command, even transitively. That's how libraries should work. It also doesn't hurt to do it for commands and programs, I think. Pruning only happens for accumulated databases and full units. Signatures currently have no useful identity so I opted to simply accumulate those multiple times.
Databases accumulate the Command Template
Some derive extensions graft clauses into predicates from coq-lib.elpi (look for
before "subst:fail"). To make this work, thederivedatabase must accumulate not just the signature but the entirety ofcoq-lib.elpi. Unfortunately, doing this just forderiveand with justcoq-lib.elpiruns into limitations of the aforementioned pruning:coq-lib.elpiis contained inelpi-command-template.elpiwhich is always accumulated intoCommands. However, my code does not (and perhaps cannot?) see thatelpi-command-template.elpiis made up of smaller files. So the two files are treated as unrelated and accumulatingderiveinto a command (which always accumulates the template) runs into problems with duplicate clauses fromcoq-lib.elpi.I opted to accumulate the entire command template into every database. This way, the files are recognized as duplicates and accumulating databases into commands works without any problem.
Everything in Dbs is SuperGlobal
To make the semantics for transitive dependencies work out,
Accumulatewith a database target is alwayssuperglobal. I do not understand why this is necessary. Using anything butsupergloballeads to changes (Accumulates) to the DB being invisible to clients that import the module containing the changes. This might be a self-inflicted problem due to my changes. Perhaps it is also because I am still confused by #721.Example:
deriveas a DatabaseThe change also includes a change to
derivewhich can now be first and foremost a database and just a smallmainshim around that database. We make use of the fact that Commands can be exported under different names to have both a vernacular commandderive(actually calledderive_cmd) and a databasederive.