Crocq
A VS Code extension for developing functionally correct C code with the
Verified Software Toolchain,
following the workflows in
Software Foundations Volume 5: Verifiable C.
Annotate C programs with /*@ ... */ specifications, jump between code and
proof, and generate Rocq models with CompCert's clightgen.
See examples/ for small verified C programs with Crocq annotations demonstrating the features of the extension.
Crocq is under active development. Windows is not supported in this
release; macOS on Apple Silicon, Linux x64 and Linux arm64 are supported.
Report bugs
Report issues and suggested features at our public issue tracker.
Features
Annotate C code with special comments that link to the corresponding
specification and proof:

Generate the Rocq model
Generate the model with clightgen; Crocq tracks whether it is up to date and
warns when the C program changes.

Scaffold specifications and proofs
Create the boilerplate verif_<file>.v next to each annotated C file, so you
can focus on the proofs. Existing files are not overwritten unless you use the
overwrite variant.

Inline specifications and invariants
Keep VST assertions and funspecs close to their implementations: a SPEC or
INV clause may carry its body inline, e.g. SPEC path.v:name <{ ... }>.
Diagnostics from VsRocq are forwarded into the annotation where the model is
written.

Rename Rocq files safely
Renaming a .v file or folder in VS Code rewrites the annotation links that
point into it in the open C files, and re-checks them so their diagnostics stay
in sync. Renames made outside VS Code (for example with git mv) are not
observed. The annotations keep resolving when a folder and a file inside it are
renamed in one operation.
Coming soon: Proof status
Crocq is being extended to show whether a function's proof is complete, admitted
or failing, next to its PROOF clause.

Also included: diagnostics and syntax highlighting for annotations, navigation
in both directions, dependency checks with status views, annotation formatting,
and model-staleness tracking.
0.3.0 ships native parser binaries for:
- macOS (Apple Silicon)
- Linux (x64/arm)
Windows is not supported yet. Intel Macs are not supported yet either. The extension refuses to activate with an
explanation on any other platform.
Requirements
- VS Code 1.104 or later.
- Rocq 9.1 or later.
- CompCert 3.17 or later, including the
clightgen
tool. With opam: opam install coq-compcert.
- VsRocq
2.5.0 or later.
If a dependency is missing or outdated, Crocq shows a notification and links to
the installation guide in
Software Foundations volume 5, Verifiable C — Practicalities.
The same link is available from the Dependencies view.
Install
From the VS Code Marketplace, search for Crocq (publisher code2rocq), or
install the VSIX attached to the
latest release:
code --install-extension crocq-0.3.0.vsix
Reload the window after installing. VsRocq must be installed and enabled; Crocq
checks for it and offers a link instead of failing silently.
Annotations
A function annotation links the C function to a Rocq specification and proof:
/*@
SPEC verif_sumarray_linked.v:sumarray_spec
PROOF verif_sumarray_linked.v:body_sumarray
*/
unsigned sumarray(unsigned a[], int n)
{
/*@
INV verif_sumarray_linked.v:loop_invariant
*/
while (i < n)
{
/* ... */
}
}
An annotation starts with /*@ and is made of clauses: an uppercase keyword
followed by its contents. Clauses that link to a Rocq document use the path to
the file, a colon, and the target name. Annotations are
currently valid above function definitions and loops.
| Clause |
Applies to |
Meaning |
PROOF path.v:name |
function |
Links to the theorem/lemma that proves the function. |
SPEC path.v:name |
function |
Links to the VST specification (funspec). |
INV path.v:name |
loop |
Links to the loop invariant. |
ℹ️ Links are relative to the C file.
A SPEC or INV clause may also carry its body inline, after the link:
/*@
SPEC verif_sumarray_inline.v:sumarray_spec <{
WITH a: val, sh : share, contents : list Z, size: Z
PRE [ tptr tuint, tint ]
PROP (...) PARAMS (a; Vint (Int.repr size)) SEP (...)
POST [ tuint ]
PROP () RETURN (Vint (Int.repr (sum_Z contents))) SEP (...)
}>
PROOF verif_sumarray_inline.v:body_sumarray
*/
Saving the C file replaces the body of the linked definition in the .v file
(the wrapper is removed) and saves the proof document, so the C annotation is
the source of truth for that definition.
Inline body rules:
- the linked target must be a Rocq definition with a body (
:=); its statement
is kept and only the body is replaced;
- a linked clause may have at most one inline body;
- a
SPEC body may omit DECLARE _<function>; Crocq adds it from the C
function name;
- edits made to that definition body in the proof document are overwritten the
next time the C file is saved;
- the wrapper is found by the grammar's scanner, so a body may contain
}
(including one ending in } right before the wrapper, <{ ... }}>), and a
}> inside a Rocq comment or string. A missing or unterminated wrapper is
reported on the clause without disabling the rest of the annotation;
- diagnostics inside the linked definition are mirrored onto the inline body,
so proof errors are visible where the model is written;
- if Rocq has not loaded the proof document yet, Crocq waits up to about
three seconds for the language server before reporting that the definition
could not be updated.
Commands
| Command |
What it does |
Crocq: Create Rocq model of opened file |
Runs clightgen -normalize on the active C file. |
Crocq: Toggle auto-generation of Rocq model on save |
Turns automatic model generation on or off for the workspace. |
Crocq: Check Dependencies |
Re-runs the Rocq/CompCert/VsRocq dependency check. |
Crocq: Show Status |
Reveals the Rocq model and Dependencies views. |
Crocq: Create proof files for project |
Scaffolds verif_<file>.v for every annotated C file; never overwrites. |
Crocq: Create proof files for project (Overwrite existing) |
Same, but overwrites existing generated proof files. |
Crocq: Format annotations |
Formats annotation blocks without touching C. |
Settings
| Setting |
Default |
Description |
crocq.clightgen.path |
clightgen |
Path to the clightgen executable from CompCert. Use the bare name to look it up on PATH. |
crocq.formatAnnotationsOnSave |
follow |
Format annotations on save. follow uses editor.formatOnSave; yes always formats; no never does. |
As with editor.formatOnSave, an auto-save after a delay does not format; an
explicit save does, even when files.autoSave is afterDelay. Formatting is
applied as a will-save edit, so a C formatter still runs afterwards.
Known limitations
- Windows is not supported in 0.3.0. It is planned for a later release. The
extension blocks installation on Windows and refuses to activate on
unsupported architectures (for example Intel macOS).
- Generated proof documents contain placeholder specifications and invariants
and do not compile until you fill them in.
- Inline bodies are authoritative. If you edit the linked definition in the
.v file, saving the C file overwrites that edit.
- Proof status (solved/admitted) is not shown in the editor yet.
- Code completions for clause targets and Rocq definitions are not implemented
yet.
- Opening some Rocq documents can surface VsRocq/Rocq errors; this is tracked in
#93.
See https://git.marfavi.com/code2rocq/crocq/issues for all tracked issues.
Troubleshooting
clightgen not found — set crocq.clightgen.path to the executable, or
install CompCert with opam install coq-compcert.
- VsRocq missing or too old — install VsRocq 2.5.0 or later and reload the
window.
- A command does nothing — run Crocq: Show Status and check the
Dependencies view. Errors and command output are written to the Crocq
output channel (
View → Output → Crocq).
- Model looks stale — regenerate it with Crocq: Create Rocq model of
opened file. The status view shows the
clightgen command that was run.
Repository layout
| Path |
Contents |
extension/ |
The VS Code extension (TypeScript). |
tree-sitter-crocq/ |
The tree-sitter grammar for Crocq annotations. |
examples/ |
Small verified C projects used for demos and manual testing. |
.forgejo/ |
CI workflows, runner configuration and container images. |
License
MIT.