Skip to content

ltac2: operations to manipulate transparent states#21558

Merged
coqbot-app[bot] merged 1 commit intorocq-prover:masterfrom
MathisBD:ltac2-transparent-state
Feb 3, 2026
Merged

ltac2: operations to manipulate transparent states#21558
coqbot-app[bot] merged 1 commit intorocq-prover:masterfrom
MathisBD:ltac2-transparent-state

Conversation

@MathisBD
Copy link
Contributor

Adds low-level operations to manipulate transparent states in Ltac2.

  1. I wrote small wrappers around TransparentState in the file ltac2/tac2stdlib.ml. I'm not sure this is the right place for this code.
  2. The API exposed in TransparentState.v is quite redundant because many functions are mirrored for constants, projections, and variables. Would it be cleaner to create a small Ltac2 type like:
Ltac2 Type entry := [
| Variable (ident)
| Constant (constant)
| Projection (projection)
].

And have the functions in TransparentState.v take as input an entry instead?

@MathisBD MathisBD requested a review from a team as a code owner January 29, 2026 10:26
@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 Jan 29, 2026
@ppedrot
Copy link
Member

ppedrot commented Jan 29, 2026

Would it be cleaner to create a small Ltac2 type like

No, this would expose too much internal details and not be future-proof whenever we want to add data there. ADTs should only be in the FFI whenever we want to expose a view type, not when we take arguments across distinct domains. (IMO some of the Ltac2 APIs are already too fragile in this regard, but that doesn't prevent from trying to make the situation worse.)

@ppedrot
Copy link
Member

ppedrot commented Jan 29, 2026

(The more reasonable alternative to an ADT is an opaque type with injection functions.)

@SkySkimmer SkySkimmer self-assigned this Jan 29, 2026
@MathisBD MathisBD force-pushed the ltac2-transparent-state branch from f706258 to 1ebf3fb Compare January 29, 2026 11:58
@MathisBD MathisBD force-pushed the ltac2-transparent-state branch from 1ebf3fb to 7c29a67 Compare January 29, 2026 15:00
@MathisBD
Copy link
Contributor Author

@coqbot run full ci

@coqbot-app coqbot-app bot removed 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 Jan 30, 2026
@thomas-lamiaux
Copy link
Contributor

@SkySkimmer looks good to me, should the milestones be 9.2 for @andres-erbsen ?

@ppedrot
Copy link
Member

ppedrot commented Jan 30, 2026

should the milestones be 9.2

What's not clear about the concept of a release here?

@thomas-lamiaux
Copy link
Contributor

Was the freeze done now ? I don't get it

@ppedrot
Copy link
Member

ppedrot commented Jan 30, 2026

We've branched a while ago, yes.

@thomas-lamiaux
Copy link
Contributor

This was not merged #21541 so we can still put 9.2+rc1 right ?

@ppedrot
Copy link
Member

ppedrot commented Jan 30, 2026

we can still put 9.2+rc1 right ?

The RM (@tabareau) is sovereign, but the very concept of the branch is to put a hold on the 9.2 development. Only fix PRs should be backported (when reasonable) and in theory we collectively agree for some feature PRs on the verge of being ready to be backported before the branch. This is a feature PR that was written after the branch, ergo it's not backportable.

@thomas-lamiaux thomas-lamiaux added this to the 9.3+rc1 milestone Jan 30, 2026
@thomas-lamiaux
Copy link
Contributor

This is a feature PR that was written after the branch, ergo it's not backportable.

In the case of pure extensions like this one, that do not create overlays, I personally disagree since we have only a release every 6 months, and consequently it gets the feature to most people which do not work with master with 6 months delay. But it is up to the developers doing the releases to choose.

@tabareau
Copy link
Contributor

The PR #21541 is just a "working PR" to test the CI before backporting and is not supposed to be merged.

That said, the problem of providing an untested extension just before the release is that it prevents from modifying it in few weeks if you realize it should be done differently.

So 9.3.

@MathisBD MathisBD force-pushed the ltac2-transparent-state branch from 7c29a67 to 9d82c1b Compare January 30, 2026 20:49
@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 Jan 30, 2026
Comment on lines +30 to +43
(** [union t1 t2] builds a transparency state containing all the variables,
constants, and primitive projections which are either in [t1] or in [t2]. *)
Ltac2 @ external union : t -> t -> t :=
"rocq-runtime.plugins.ltac2" "union_transparent_state".

(** [inter t1 t2] builds a transparency state containing all the variables,
constants, and primitive projections which are both in [t1] and in [t2]. *)
Ltac2 @ external inter : t -> t -> t :=
"rocq-runtime.plugins.ltac2" "inter_transparent_state".

(** [diff t1 t2] builds a transparency state containing all the variables,
constants, and primitive projections which are in [t1] but not in [t2]. *)
Ltac2 @ external diff : t -> t -> t :=
"rocq-runtime.plugins.ltac2" "diff_transparent_state".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should expose these operations. In #19117 there is some discussion about changing Hint Constants Opaque to set a default but not change constants which were explicitly set transparent, I'm not sure how well that would work with combining transparent states.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This low-level API are useful to a small minority of users that want a very fine control.
I would imagine, they would be interested in recovering the transparency state for some hint databases, and take the union or sth like that ? @andres-erbsen would you have such a need ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SkySkimmer this would typically be done at the HintDB API level, not the transparent state one AFAIU. I'm envisioning a system where we keep two different TS for each hintdb and switch one with the other with a flag. So I don't think exposing this kind of operations is problematic.

@SkySkimmer SkySkimmer added kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. part: ltac2 Issues and PRs related to the (in development) Ltac2 tactic langauge. needs: changelog entry This should be documented in doc/changelog. labels Jan 31, 2026
@SkySkimmer
Copy link
Contributor

needs changelog

@MathisBD MathisBD force-pushed the ltac2-transparent-state branch from 9d82c1b to b1221ca Compare February 2, 2026 09:55
@Janno
Copy link
Contributor

Janno commented Feb 2, 2026

  1. The API exposed in TransparentState.v is quite redundant because many functions are mirrored for constants, projections, and variables. Would it be cleaner to create a small Ltac2 type like:
Ltac2 Type entry := [
| Variable (ident)
| Constant (constant)
| Projection (projection)
].

A different way to go would be to (abstractly) expose the structure of OCaml's TransparentState.t. We could then use the tag infrastructure in FSet.v to provide operations on the individual parts. We do need a new Pred.v file with an FSet-like interface that accounts for the difference between Set and Predicate. But at least that we only have to write once and it might even come in handy in other places.

It's a bit more work up-front but it does make the interface to TransparentState.t a whole lot nicer. It would look like this, I think:

Module TransparentState.
Ltac2 Type t.
Ltac2 @ external empty : t := .. (* unchanged *)
Ltac2 @ external full : t := .. (* unchanged *)
Ltac2 @ external get_constants : constant_tag Pred.t := .. (* same for variables, projections *)
Ltac2 @ set_constants : constant_tag Pred.t -> t -> t := .. (* same for variables, projections *)

@ppedrot
Copy link
Member

ppedrot commented Feb 2, 2026

@Janno This is adding more coupling with the implementation, I think this is a bad idea. We should be as abstract as possible, especially when it comes to collections as it could be very inefficient to convert back and from different representations.

@SkySkimmer SkySkimmer removed the needs: changelog entry This should be documented in doc/changelog. label Feb 2, 2026
@SkySkimmer
Copy link
Contributor

@coqbot run full ci

@coqbot-app coqbot-app bot removed 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 Feb 2, 2026
@SkySkimmer
Copy link
Contributor

@coqbot merge now

@coqbot-app coqbot-app bot merged commit d6fda2f into rocq-prover:master Feb 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. part: ltac2 Issues and PRs related to the (in development) Ltac2 tactic langauge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants