Skip to content

Typeclass-based Ltac2 dispatch.#96

Open
gmalecha-at-skylabs wants to merge 2 commits intomainfrom
gmalecha/tc-based-ltac2-dispatch
Open

Typeclass-based Ltac2 dispatch.#96
gmalecha-at-skylabs wants to merge 2 commits intomainfrom
gmalecha/tc-based-ltac2-dispatch

Conversation

@gmalecha-at-skylabs
Copy link
Copy Markdown
Contributor

A sketch proposal for resolving an Ltac2 function using typeclasses.

@skylabs-ai-ci
Copy link
Copy Markdown

skylabs-ai-ci bot commented Mar 26, 2026

CI summary (Details)

Active Repos

Repo Job Branch Job Commit Base branch Base commit PR
fmdeps/BRiCk/ gmalecha/tc-based-ltac2-dispatch e59ba9e main 6464439 #96

Passive Repos

Repo Job Branch Job Commit
./ main 1a623c6
fmdeps/auto/ main 2193cc6
fmdeps/auto-docs/ main 9f57097
bluerock/NOVA/ skylabs-proof 996d600
bluerock/bhv/ skylabs-main 8030a8f
fmdeps/brick-libcpp/ main d30c178
fmdeps/ci/ main 9ecdef9
vendored/elpi/ skylabs-master aa4475f
fmdeps/fm-ci/ main 262fb04
fmdeps/fm-tools/ main e17f6db
psi/protos/ main 8fe3e7c
psi/backend/ main 99def76
psi/ide/ main 6b596cf
psi/data/ main 1c11c15
vendored/rocq/ skylabs-master 2ede3c9
fmdeps/rocq-agent-toolkit/ main 2ccdf85
vendored/rocq-elpi/ skylabs-master 103a742
vendored/rocq-equations/ skylabs-main a8c4832
vendored/rocq-ext-lib/ skylabs-master 94a6630
vendored/rocq-iris/ skylabs-master 3ad4ddd
vendored/rocq-lsp/ skylabs-main a8b7272
vendored/rocq-stdlib/ skylabs-master bc07423
vendored/rocq-stdpp/ skylabs-master e01d802
fmdeps/skylabs-fm/ main 7c3aae7
vendored/vsrocq/ skylabs-main 5b4527e

Performance

Relative Master MR Change Filename
+0.00% 123316.4 123317.6 +1.2 total
+0.00% - 1.2 +1.2 ├ newly appeared files (1)
-0.00% 123316.4 123316.4 -0.0 └ common files
-0.00% 22626.6 22626.6 -0.0 ├ translation units
+0.00% 100689.8 100689.8 +0.0 └ proofs and tests
Full Results
Relative Master MR Change Filename
+0.00% 123316.4 123317.6 +1.2 total
+0.00% - 1.2 +1.2 ├ newly appeared files (1)
-0.00% 123316.4 123316.4 -0.0 └ common files
-0.00% 22626.6 22626.6 -0.0 ├ translation units
+0.00% 100689.8 100689.8 +0.0 └ proofs and tests

@gmalecha-at-skylabs gmalecha-at-skylabs force-pushed the gmalecha/tc-based-ltac2-dispatch branch from d474fab to 4455298 Compare March 27, 2026 19:47
@skylabs-ai-ci
Copy link
Copy Markdown

skylabs-ai-ci bot commented Mar 27, 2026

CI summary (Details)

Active Repos

Repo Job Branch Job Commit Base branch Base commit PR
fmdeps/BRiCk/ gmalecha/tc-based-ltac2-dispatch 286433a main 238d10c #96

Passive Repos

Repo Job Branch Job Commit
./ main 655dc44
fmdeps/auto/ main 215fe77
fmdeps/auto-docs/ main 9f57097
bluerock/NOVA/ skylabs-proof 996d600
bluerock/bhv/ skylabs-main 8030a8f
fmdeps/brick-libcpp/ main d30c178
fmdeps/ci/ main 9ecdef9
vendored/elpi/ skylabs-master aa4475f
fmdeps/fm-ci/ main 262fb04
fmdeps/fm-tools/ main e17f6db
psi/protos/ main 8fe3e7c
psi/backend/ main 99def76
psi/ide/ main 6b596cf
psi/data/ main 1c11c15
vendored/rocq/ skylabs-master 2ede3c9
fmdeps/rocq-agent-toolkit/ main 6060926
vendored/rocq-elpi/ skylabs-master 103a742
vendored/rocq-equations/ skylabs-main a8c4832
vendored/rocq-ext-lib/ skylabs-master 94a6630
vendored/rocq-iris/ skylabs-master 3ad4ddd
vendored/rocq-lsp/ skylabs-main a8b7272
vendored/rocq-stdlib/ skylabs-master bc07423
vendored/rocq-stdpp/ skylabs-master e01d802
fmdeps/skylabs-fm/ main 7c3aae7
vendored/vsrocq/ skylabs-main 5b4527e

Performance

Relative Master MR Change Filename
+0.00% 123284.5 123290.6 +6.1 total
+0.00% - 6.1 +6.1 ├ newly appeared files (5)
+0.00% 123284.5 123284.5 +0.0 └ common files
+0.00% 22626.6 22626.6 +0.0 ├ translation units
+0.00% 100657.9 100657.9 +0.0 └ proofs and tests
Full Results
Relative Master MR Change Filename
+0.00% 123284.5 123290.6 +6.1 total
+0.00% - 6.1 +6.1 ├ newly appeared files (5)
+0.00% 123284.5 123284.5 +0.0 └ common files
+0.00% 22626.6 22626.6 +0.0 ├ translation units
+0.00% 100657.9 100657.9 +0.0 └ proofs and tests

let resolve_ltac2_safe (mp : string list) (id : string) : (unit -> unit Proofview.tactic) option =
let qualid = Libnames.make_qualid
(Names.DirPath.make (List.map Names.Id.of_string mp))
(Names.Id.of_string id)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not take a single string (containing .) and call qualid_of_string on it instead of taking string list + string and calling make_qualid?
That way conversion is simpler (no list_of_list_constr) and you don't have to remember which order the list needs to be in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This makes sense. Alternatively, I was thinking that we could get the module path from the constant of the type class instance. That makes it less fragile to move things around.

(Names.Id.of_string id)
in
let is_unit_typ (t : int Tac2expr.glb_typexpr) : bool =
(* TODO: why does Init.unit have two different representations? *)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

because you don't normalize it (cf what Tac2typing_env.kind does)

| Tac2expr.GTypArrow (t1, t2) -> is_unit_typ t1 && is_unit_typ t2
| _ -> false
in
match Tac2env.locate_ltac qualid with
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I guess we don't expose the full_path based API but if we did would you want to use it?
The difference with locate is that locate will resolve short names, so for instance locate on case will succeed when Control is imported but the full path based API would need Ltac2.Control.case regardless of importing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For this use case, I would want to use definite references. Resolution at this level seems very awkward.

then
let v = Tac2interp.eval_global kn in
Some (repr_to (fun1 unit unit) v)
else None
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

might want to return a result with some error message to distinguish between "could not resolve" "resolved to non constant (Abbreviation)" and "resolved to constant of incorrect type"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is a good idea, but I need to dig a bit more into the plugin API to figure out how to raise exceptions and such.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I said return result not raise though?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I actually need to figure out how to do that as well. This API is pretty foreign to me.

@gmalecha-at-skylabs gmalecha-at-skylabs force-pushed the gmalecha/tc-based-ltac2-dispatch branch from dffa510 to f1c41f8 Compare March 29, 2026 01:24
@skylabs-ai-ci
Copy link
Copy Markdown

skylabs-ai-ci bot commented Mar 29, 2026

CI summary (Details)

Active Repos

Repo Job Branch Job Commit Base branch Base commit PR
fmdeps/BRiCk/ gmalecha/tc-based-ltac2-dispatch 2eea27d main 238d10c #96

Passive Repos

Repo Job Branch Job Commit
./ main 655dc44
fmdeps/auto/ main fbd79d5
fmdeps/auto-docs/ main 9f57097
bluerock/NOVA/ skylabs-proof 996d600
bluerock/bhv/ skylabs-main 8030a8f
fmdeps/brick-libcpp/ main d30c178
fmdeps/ci/ main 9ecdef9
vendored/elpi/ skylabs-master aa4475f
fmdeps/fm-ci/ main 262fb04
fmdeps/fm-tools/ main e17f6db
psi/protos/ main 8fe3e7c
psi/backend/ main 99def76
psi/ide/ main 6b596cf
psi/data/ main 1c11c15
vendored/rocq/ skylabs-master 2ede3c9
fmdeps/rocq-agent-toolkit/ main 6060926
vendored/rocq-elpi/ skylabs-master 103a742
vendored/rocq-equations/ skylabs-main a8c4832
vendored/rocq-ext-lib/ skylabs-master 94a6630
vendored/rocq-iris/ skylabs-master 3ad4ddd
vendored/rocq-lsp/ skylabs-main a8b7272
vendored/rocq-stdlib/ skylabs-master bc07423
vendored/rocq-stdpp/ skylabs-master e01d802
fmdeps/skylabs-fm/ main 7c3aae7
vendored/vsrocq/ skylabs-main 5b4527e

Performance

Relative Master MR Change Filename
+0.00% 123290.5 123296.6 +6.1 total
+0.00% - 6.1 +6.1 ├ newly appeared files (5)
+0.00% 123290.5 123290.5 +0.0 └ common files
+0.00% 22626.6 22626.6 +0.0 ├ translation units
+0.00% 100663.9 100663.9 +0.0 └ proofs and tests
Full Results
Relative Master MR Change Filename
+0.00% 123290.5 123296.6 +6.1 total
+0.00% - 6.1 +6.1 ├ newly appeared files (5)
+0.00% 123290.5 123290.5 +0.0 └ common files
+0.00% 22626.6 22626.6 +0.0 ├ translation units
+0.00% 100663.9 100663.9 +0.0 └ proofs and tests

@skylabs-ai-ci
Copy link
Copy Markdown

skylabs-ai-ci bot commented Mar 29, 2026

CI summary (Details)

Active Repos

Repo Job Branch Job Commit Base branch Base commit PR
fmdeps/BRiCk/ gmalecha/tc-based-ltac2-dispatch 7878874 main 238d10c #96

Passive Repos

Repo Job Branch Job Commit
./ main 655dc44
fmdeps/auto/ main fbd79d5
fmdeps/auto-docs/ main 9f57097
bluerock/NOVA/ skylabs-proof 996d600
bluerock/bhv/ skylabs-main 8030a8f
fmdeps/brick-libcpp/ main d30c178
fmdeps/ci/ main 9ecdef9
vendored/elpi/ skylabs-master aa4475f
fmdeps/fm-ci/ main 262fb04
fmdeps/fm-tools/ main e17f6db
psi/protos/ main 8fe3e7c
psi/backend/ main 99def76
psi/ide/ main 6b596cf
psi/data/ main 1c11c15
vendored/rocq/ skylabs-master 2ede3c9
fmdeps/rocq-agent-toolkit/ main 6060926
vendored/rocq-elpi/ skylabs-master 103a742
vendored/rocq-equations/ skylabs-main a8c4832
vendored/rocq-ext-lib/ skylabs-master 94a6630
vendored/rocq-iris/ skylabs-master 3ad4ddd
vendored/rocq-lsp/ skylabs-main a8b7272
vendored/rocq-stdlib/ skylabs-master bc07423
vendored/rocq-stdpp/ skylabs-master e01d802
fmdeps/skylabs-fm/ main 7c3aae7
vendored/vsrocq/ skylabs-main 5b4527e

Performance

Relative Master MR Change Filename
+0.01% 123290.5 123297.8 +7.3 total
+0.01% - 7.3 +7.3 ├ newly appeared files (6)
+0.00% 123290.5 123290.5 +0.0 └ common files
+0.00% 22626.6 22626.6 +0.0 ├ translation units
+0.00% 100663.9 100663.9 +0.0 └ proofs and tests
Full Results
Relative Master MR Change Filename
+0.01% 123290.5 123297.8 +7.3 total
+0.01% - 7.3 +7.3 ├ newly appeared files (6)
+0.00% 123290.5 123290.5 +0.0 └ common files
+0.00% 22626.6 22626.6 +0.0 ├ translation units
+0.00% 100663.9 100663.9 +0.0 └ proofs and tests

@gmalecha-at-skylabs gmalecha-at-skylabs force-pushed the gmalecha/tc-based-ltac2-dispatch branch from b071f71 to e721ac7 Compare March 29, 2026 18:35
@skylabs-ai-ci
Copy link
Copy Markdown

skylabs-ai-ci bot commented Mar 29, 2026

CI summary (Details)

Active Repos

Repo Job Branch Job Commit Base branch Base commit PR
fmdeps/BRiCk/ gmalecha/tc-based-ltac2-dispatch 19f3f34 main 238d10c #96

Passive Repos

Repo Job Branch Job Commit
./ main 655dc44
fmdeps/auto/ main fbd79d5
fmdeps/auto-docs/ main 9f57097
bluerock/NOVA/ skylabs-proof 996d600
bluerock/bhv/ skylabs-main 8030a8f
fmdeps/brick-libcpp/ main d30c178
fmdeps/ci/ main 9ecdef9
vendored/elpi/ skylabs-master aa4475f
fmdeps/fm-ci/ main 262fb04
fmdeps/fm-tools/ main e17f6db
psi/protos/ main 8fe3e7c
psi/backend/ main 99def76
psi/ide/ main 6b596cf
psi/data/ main 1c11c15
vendored/rocq/ skylabs-master 2ede3c9
fmdeps/rocq-agent-toolkit/ main 6060926
vendored/rocq-elpi/ skylabs-master 103a742
vendored/rocq-equations/ skylabs-main a8c4832
vendored/rocq-ext-lib/ skylabs-master 94a6630
vendored/rocq-iris/ skylabs-master 3ad4ddd
vendored/rocq-lsp/ skylabs-main a8b7272
vendored/rocq-stdlib/ skylabs-master bc07423
vendored/rocq-stdpp/ skylabs-master e01d802
fmdeps/skylabs-fm/ main 7c3aae7
vendored/vsrocq/ skylabs-main 5b4527e

Performance

Relative Master MR Change Filename
+0.01% 123290.5 123297.8 +7.3 total
+0.01% - 7.3 +7.3 ├ newly appeared files (6)
-0.00% 123290.5 123290.5 -0.0 └ common files
-0.00% 22626.6 22626.6 -0.0 ├ translation units
+0.00% 100663.9 100663.9 +0.0 └ proofs and tests
Full Results
Relative Master MR Change Filename
+0.01% 123290.5 123297.8 +7.3 total
+0.01% - 7.3 +7.3 ├ newly appeared files (6)
-0.00% 123290.5 123290.5 -0.0 └ common files
-0.00% 22626.6 22626.6 -0.0 ├ translation units
+0.00% 100663.9 100663.9 +0.0 └ proofs and tests

(authors
"Gregory Malecha <gregory@skylabs-ai.com>")

(license MIT)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is there a LICENSE-LGPL file then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We should change to LGPL to encourage contributions over forking.

(library
(name ltac2_tc_dispatch)
(public_name ltac2-tc-dispatch.plugin)
(libraries coq-core.plugins.ltac2 rocq-extra stdlib-extra ltac2-extra.plugin))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
(libraries coq-core.plugins.ltac2 rocq-extra stdlib-extra ltac2-extra.plugin))
(libraries rocq-runtime.plugins.ltac2 rocq-extra stdlib-extra ltac2-extra.plugin))

Comment on lines +15 to +19
(* The typeclass: P is the goal/type, path is the module hierarchy, name is the tactic *)
Class Ltac2Lookup (P : Prop) := {
ltac2_path : list string;
ltac2_name : string;
}.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess we could add a new vernacular command for populating this class, and also checking the type of the given Ltac2 value.

@Janno
Copy link
Copy Markdown
Contributor

Janno commented Mar 30, 2026

I wonder if we should use dummy Rocq definitions to get the module paths automatically right. The simplest way would be to demand a definition of the same name as the tactic. That definition is used in the instance. No strings. At registration time, we check that a tactic of the same name exists. (And that it is not private.. we should check that anyway.)

This should allow us to not mention any module paths and Rocq will make sure that everything keeps working across module boundaries.

We could do the check in tactic-in-terms (or TC search) in the class constructor if we wanted to avoid a new vernacular command.

@gmalecha-at-skylabs
Copy link
Copy Markdown
Contributor Author

@Janno I mentioned a similar idea on the Rocq Zulip. I'm not completely certain how to implement this, but all the data should be there.

On a related note, I was thinking that we might be able to support:

  1. Calling regular Ltac tactics
  2. Passing arguments to tactics from the arguments of the typeclass, e.g. a constr for each argument.

Both seem optional, but could be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants