Skip to content

Draft: opt-in source-position-free library output (-position-free-library) - #22973

Draft
zitrono wants to merge 4 commits into
rocq-prover:masterfrom
zitrono:position-free-library
Draft

zitrono wants to merge 4 commits into
rocq-prover:masterfrom
zitrono:position-free-library

Conversation

@zitrono

@zitrono zitrono commented Dec 4, 2026

Copy link
Copy Markdown

Draft: opt-in source-position-free library output (-position-free-library)

Draft PR for discussing the shape. It follows #22826 and is not ready to merge: Ltac and hints are still in progress.

What this does

With rocq compile -position-free-library, we write the objects of the library without source positions, both in the .vo (and .vos) file and in the digest that importers record. For a library whose objects are all covered (see below), an edit that only moves positions, such as adding a comment or a blank line or reformatting, then leaves the whole .vo byte-identical. An edit inside an opaque proof still changes the opaque segment, as it should. Without the flag nothing changes.

The hook is an optional field of Libobject.object_declaration:

erase_function : 'a -> 'a;
(* identity by default; returns its argument physically when there is nothing to erase *)

Library.save_library_struct applies it, under the flag, to md_objects and md_syntax_objects, the record behind both the disk output and the digest. Declaremods.erase_library_objects traverses module, module type, include, keep and escape nodes the way subst_objects does. The file format and rocqchk are unchanged.

Covered in this PR

  • constants (cst_loc);
  • notations, syntax extensions and abbreviations;
  • inductive types and their constructors (the INDUCTIVE object keeps the locations of the names).

Still in progress (not in this PR)

  • Ltac definitions, Tactic Notation bodies and hints. These need an eraser for stored tactic syntax and for the terms inside it.
  • Ltac2 and objects of plugins that do not declare an eraser: their positions stay in the file. The documentation of the flag says so.

Until these are covered, a file that defines tactics or hints still contains positions, so its .vo can change on a comment-only edit.

Sharing

Each eraser returns its argument physically (==) when there is nothing to erase, and the traversals use List.Smart.map and the like, so the sharing of values is kept. The flag does not fix sharing that depends on the input: the one case reported in the issue, two equal values shared differently, still gives different files.

Cost

Imported declarations lose their source position, for example the "Declared in" line of About. Libraries compiled without the flag are unaffected.

Tests

  • test-suite/misc/position_free_library.sh compiles a file twice, editing only comments and layout, and compares the whole .vo with cmp, as well as the .vo of an importer. A control build without the flag must differ, rocqchk accepts the result, and About shows no "Declared in" for an imported constant. The file has constants, a functor instantiated in an importer, notations, an abbreviation and inductive types.
  • make success misc fails the same four tests with and without this patch in our environment (misc/bench-render, misc/rocqchk_vm_bytecode, misc/vm_structured_constants: missing camlzip and python3; misc/qed-time: timing).

The reference manual entry and a changelog entry are included. The changelog file is named XXXXX-position-free-library-Added.rst and we will rename it to the PR number.

Left for review

  • The flag is a global ref in Library, set from Coqcargs.
  • .vos output is position-free too, because save_library_struct feeds both.
  • We covered the objects we found holding a Loc.t (constants, notations, abbreviations, inductives). We will cover any others you point us to.

Questions that block the next commits

  1. Field or registry for the eraser. We used a new field of Libobject.object_declaration, identity by default like subst_function. Would you rather have a separate registry keyed by object name, leaving object_declaration unchanged?
  2. How Ltac gets erased. A stored tactic is a glob_tactic_expr, so erasing it needs a pass over the tactic syntax, with matching hooks beside Gensubst.register_subst0 and Gentactic.register_subst. Should that be its own pass (a new Tacerase of about 300 lines that mirrors Tacsubst, with no change to Tacsubst but a second traversal to keep in sync), or a traversal shared with Tacsubst (the subst argument becomes a record of leaf operations that substitution and erasure instantiate differently, which touches about 100 call sites of plugins/ltac/tacsubst.ml)? We have not written the refactor and would not before hearing from you.

…ry option

Libobject.object_declaration gets an optional erase_function (identity by
default) that removes source positions from an object, returning its argument
physically when there is nothing to erase.

With rocq compile -position-free-library, Library.save_library_struct applies
it to md_objects and md_syntax_objects, so to both the .vo and its digest.
Declaremods traverses module, module type, include, keep and escape nodes the
way substitution does. Constants get an eraser (cst_loc).

Test: compile a file twice changing only comments and layout and compare the
.vo, and the .vo of an importer.
…ions

Erasers for the NOTATION (notation_location), SYNTAX-EXTENSION
(synext_location) and ABBREVIATION (abbrev_src) objects. The test now has
notations, an abbreviation and a notation inside a functor, used through an
instantiation.
…he cost on About

The INDUCTIVE object keeps the locations of the type and constructor names.
The test also checks that About shows no "Declared in" for an imported
constant when the library was built with the option, and that it does without.
@coqbot-app coqbot-app Bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant