Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[coqdoc] Fix #18516 (handling of Context) #18527

Merged
merged 1 commit into from Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/changelog/09-cli-tools/18527-hack_18516.rst
@@ -0,0 +1,5 @@
- **Fixed:**
coqdoc links to section variables introduced with :cmd:`Context`
(`#18527 <https://github.com/coq/coq/pull/18527>`_,
fixes `#18516 <https://github.com/coq/coq/issues/18516>`_,
by Pierre Roux).
7 changes: 4 additions & 3 deletions interp/dumpglob.mli
Expand Up @@ -49,8 +49,9 @@
[%kind %bc:%ec %secpath %name]

where [%kind] is one of
[{def,coe,subclass,canonstruc,ex,scheme,proj,inst,meth,defax,prfax,thm,prim,class,var,indrec,rec,corec,ind,variant,coind,constr,not,binder,lib,mod,modtype}],
[{ax,def,coe,subclass,canonstruc,ex,scheme,proj,inst,meth,defax,prfax,thm,prim,class,var,indrec,rec,corec,ind,variant,coind,constr,not,binder,lib,mod,modtype}],
meaning:
+ [ax] Axiom, Parameter or Variable(s), Hypothes{i,e}s, Context outside any section
+ [def] Definition
+ [coe] Coertion
+ [thm] Theorem
Expand All @@ -65,7 +66,7 @@
+ [defax] Definitional assumption
+ [prfax] Logical assumption
+ [prim] Primitive
+ [var] Variable reference
+ [var] section Variable reference (Variable{,s}, Hypothes{i,e}s, Context)
+ [indrec] Inductive
+ [rec] Inductive (variant)
+ [corec] Coinductive
Expand All @@ -79,7 +80,7 @@
+ [mod] Module Reference (Import, Module start / end)
+ [modtype] Module Type

[%bc] and [%ec] are respectively the start and end byte locations in the file (0-indexed)
[%bc] and [%ec] are respectively the start and end byte locations in the file (0-indexed), multiple entries can share the same [%bc] and [%ec]
[%secpath] the section path (or [<>] if no section path) and [%name] the name of the
defined object, or also [<>] in where no name applies.

Expand Down
36 changes: 36 additions & 0 deletions test-suite/coqdoc/Context.html.out
@@ -0,0 +1,36 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="coqdoc.css" rel="stylesheet" type="text/css" />
<title>Coqdoc.Context</title>
</head>

<body>

<div id="page">

<div id="header">
</div>

<div id="main">

<h1 class="libtitle">Library Coqdoc.Context</h1>

<div class="code">
<span class="id" title="keyword">Section</span> <a id="Sec" class="idref" href="#Sec"><span class="id" title="section">Sec</span></a>.<br/>
<span class="id" title="keyword">Context</span> (<a id="Sec.foo" class="idref" href="#Sec.foo"><span class="id" title="binder, variable"><span id="foo:1" class="id">foo</span></span></a> : <a class="idref" href="http://coq.inria.fr/stdlib/Coq.Init.Datatypes.html#nat"><span class="id" title="inductive">nat</span></a>).<br/>
<span class="id" title="keyword">Check</span> <a class="idref" href="Coqdoc.Context.html#Sec.foo"><span class="id" title="variable">foo</span></a>.<br/>
<span class="id" title="keyword">End</span> <a class="idref" href="Coqdoc.Context.html#Sec"><span class="id" title="section">Sec</span></a>.<br/>
</div>
</div>

<div id="footer">
<hr/><a href="index.html">Index</a><hr/>This page has been generated by <a href="http://coq.inria.fr/">coqdoc</a>
</div>

</div>

</body>
</html>
31 changes: 31 additions & 0 deletions test-suite/coqdoc/Context.tex.out
@@ -0,0 +1,31 @@
\documentclass[12pt]{report}
\usepackage[utf8x]{inputenc}

%Warning: tipa declares many non-standard macros used by utf8x to
%interpret utf8 characters but extra packages might have to be added
%such as "textgreek" for Greek letters not already in tipa
%or "stmaryrd" for mathematical symbols.
%Utf8 codes missing a LaTeX interpretation can be defined by using
%\DeclareUnicodeCharacter{code}{interpretation}.
%Use coqdoc's option -p to add new packages or declarations.
\usepackage{tipa}

\usepackage[T1]{fontenc}
\usepackage{fullpage}
\usepackage{coqdoc}
\usepackage{amsmath,amssymb}
\usepackage{url}
\begin{document}
\coqlibrary{Coqdoc.Context}{Library }{Coqdoc.Context}

\begin{coqdoccode}
\coqdocnoindent
\coqdockw{Section} \coqdef{Coqdoc.Context.Sec}{Sec}{\coqdocsection{Sec}}.\coqdoceol
\coqdocnoindent
\coqdockw{Context} (\coqdef{Coqdoc.Context.Sec.foo}{foo}{\coqdocvariable{foo}} : \coqexternalref{nat}{http://coq.inria.fr/stdlib/Coq.Init.Datatypes}{\coqdocinductive{nat}}).\coqdoceol
\coqdocnoindent
\coqdockw{Check} \coqref{Coqdoc.Context.Sec.foo}{\coqdocvariable{foo}}.\coqdoceol
\coqdocnoindent
\coqdockw{End} \coqref{Coqdoc.Context.Sec}{\coqdocsection{Sec}}.\coqdoceol
\end{coqdoccode}
\end{document}
4 changes: 4 additions & 0 deletions test-suite/coqdoc/Context.v
@@ -0,0 +1,4 @@
Section Sec.
Context (foo : nat).
Check foo.
End Sec.
16 changes: 15 additions & 1 deletion vernac/comAssumption.ml
Expand Up @@ -261,9 +261,23 @@ let interp_context env sigma l =
sigma, ctx

let do_context ~poly l =
let sec = Lib.sections_are_opened () in
if Dumpglob.dump () then begin
let l = List.map (function
| Constrexpr.CLocalAssum (l, _, _, _) ->
let ty = if sec then "var "else "ax" in List.map (fun n -> ty, n) l
| Constrexpr.CLocalDef (n, _, _, _) ->
let ty = if sec then "var "else "def" in [ty, n]
| Constrexpr.CLocalPattern _ -> [])
l in
List.iter (function
| ty, {CAst.v = Names.Name.Anonymous; _} -> ()
| ty, {CAst.v = Names.Name.Name id; loc} ->
Dumpglob.dump_definition (CAst.make ?loc id) sec ty)
(List.flatten l) end;
Copy link
Member

Choose a reason for hiding this comment

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

Looking at it further, what is done for other declarations (in vernacentries.ml) is the following:

  • Variable/Hypothesis: "var"
  • Axiom/Parameter: "ax"
  • Definition/Theorem: "def"
  • Let: "var"

So, "def" would also be an option for LocalDef outside a section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense but I'd rather keep it as "var" for now since the references (lines starting with R in the glob file) mention it as such.

Copy link
Member

Choose a reason for hiding this comment

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

I'm now confused. Shouldn't Context (a:=0) outside a section be considered the same as Definition a:=0 (and thus with "def") or are we rather talking about Let?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I did forgot that outside-section case. Should be fixed.

Copy link
Member

Choose a reason for hiding this comment

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

Did you push?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, here it is.

let env = Global.env() in
let sigma = Evd.from_env env in
let sigma, ctx = interp_context env sigma l in
if Lib.sections_are_opened ()
if sec
then context_insection sigma ~poly ctx
else context_nosection sigma ~poly ctx