Skip to content

Experiment the addition of sealed/defined attributes - #19029

Closed
herbelin wants to merge 21 commits into
rocq-prover:masterfrom
herbelin:master+sealed-attribute
Closed

Experiment the addition of sealed/defined attributes#19029
herbelin wants to merge 21 commits into
rocq-prover:masterfrom
herbelin:master+sealed-attribute

Conversation

@herbelin

@herbelin herbelin commented May 15, 2024

Copy link
Copy Markdown
Member

The PR experiments the implementation of a proposal related to rocq-prover/rfcs#42. It adds attributes sealed and defined that allow to indicate the opacity of a definition defined non-interactively.

When used in an interactive proof, sealed and defined take precedence over Qedand Defined. Consequently, using an attribute in interactive mode allows to match Definition with Defined and Theorem with Qed without impacting the opacity (since it is the attribute which takes precedence).

In non-interactive mode, a Definition is declared defined in the absence of an atttribute while Theorem mandatorily requires an attribute (however, the syntax Theorem :=itself is eventually provided only in #19301).

The main technical change is that the "opaque" value is now part of the Declare.CInfo.t while it was before passed as a standalone argument or stored in the program obligation state.

Here are some examples:

#[sealed] Definition c := 0.
#[defined] Theorem t : nat. exact 0. Defined.
Fixpoint #[sealed] f n := match n with 0 => 0 | S n => g n end
with #[defined] g n := match n with 0 => 0 | S n => f n end.
  • Added / updated test-suite.
  • Added changelog.
  • Added / updated documentation.

Pending questions:

Depends on:

@herbelin herbelin added kind: feature New user-facing feature request or implementation. part: attributes #[attributes] modify the behaviour of vernac sentences. part: gallina The gallina commands labels May 15, 2024
@herbelin herbelin added this to the 8.20+rc1 milestone May 15, 2024
@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 May 15, 2024
@github-actions github-actions Bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label May 16, 2024
@herbelin
herbelin force-pushed the master+sealed-attribute branch from b5d663f to e3c91ca Compare May 17, 2024 15:57
@coqbot-app coqbot-app Bot removed the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label May 17, 2024
@herbelin
herbelin force-pushed the master+sealed-attribute branch from e3c91ca to 3e40fa2 Compare May 17, 2024 16:01
@github-actions github-actions Bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label May 24, 2024
@proux01

proux01 commented May 31, 2024

Copy link
Copy Markdown
Contributor

Draft PR, removing the milestone.

@proux01 proux01 removed this from the 8.20+rc1 milestone May 31, 2024
@herbelin herbelin added the request: full CI Use this label when you want your next push to trigger a full CI. label Jun 18, 2024
@herbelin
herbelin force-pushed the master+sealed-attribute branch from 3e40fa2 to f881a75 Compare June 18, 2024 19:27
@coqbot-app coqbot-app Bot removed request: full CI Use this label when you want your next push to trigger a full CI. needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. labels Jun 18, 2024
@herbelin
herbelin marked this pull request as ready for review June 18, 2024 19:27
@herbelin
herbelin requested review from a team as code owners June 18, 2024 19:27
@github-actions github-actions Bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Jun 21, 2024
@herbelin
herbelin force-pushed the master+sealed-attribute branch from f881a75 to 6b63e32 Compare June 22, 2024 10:12
@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 Jun 22, 2024

@herbelin herbelin left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the comments

This can be used to define a term incrementally, in particular by relying on the :tacn:`refine` tactic.
In this case, the proof should be terminated with :cmd:`Defined` in order to define a :term:`constant`
for which the computational behavior is relevant. See :ref:`proof-editing-mode`.
In this case, the proof should normally be terminated with :cmd:`Defined`. See :ref:`proof-editing-mode`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, but we are talking here about definitions and Qed is unusual both in mathematical practice and in Coq scripts.

---------------------------

Definitions and theorems associate terms of some type to a name. In
the case of a definition (or assimilated, like :cmd:`Fixpoint` or

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OK, done.

Comment on lines +233 to +236
Definitions and theorems associate terms of some type to a name. In
the case of a definition (or assimilated, like :cmd:`Fixpoint` or
:cmd:`CoFixpoint`), the term is the body of the definition and the
type is the type of the body. In the case of a theorem (or
assimilated), the term is the proof and the type is the statement.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I moved the paragraph at the beginning of the section. Tell me what you think about it.

I did not rephrase it though because it is important I think to let open the idea that a definition can be build by tactics and a proof as a term.

This attribute tells to prevent the unfoldability of a definition,
so that the definition behaves like an abstract definition.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't know what happend in my mind when I wrote the comment.

What I want to say is that it is more than preventing unfolding (which Opaque does in some sense). In the absence of a better choice, I reused "prevents the unfoldability of a definition".

Comment thread doc/sphinx/language/core/inductive.rst Outdated
Comment on lines +476 to +479
This command accepts the :attr:`program`,
:attr:`bypass_check(universes)`, and :attr:`bypass_check(guard)` attributes.
It also accepts the :attr:`sealed` attribute placed just before the
name (or names) defined by the fixpoint.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines +1510 to +1511
| REPLACE quoted_attributes ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations
| WITH quoted_attributes ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines 1519 to 1517
fix_definition: [
| REPLACE ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations
| WITH ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations
| REPLACE quoted_attributes ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations
| WITH quoted_attributes ident_decl binders_fixannot type_cstr OPT [ ":=" lconstr ] decl_notations
]

cofix_definition: [
| REPLACE ident_decl binders type_cstr OPT [ ":=" lconstr ] decl_notations
| WITH ident_decl binders type_cstr OPT [ ":=" lconstr ] decl_notations
| REPLACE quoted_attributes ident_decl binders type_cstr OPT [ ":=" lconstr ] decl_notations
| WITH quoted_attributes ident_decl binders type_cstr OPT [ ":=" lconstr ] decl_notations
]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

herbelin and others added 21 commits October 27, 2024 09:47
…int.

Also adding some missing supported attributes.
…transparent.

The main changes are:
- "opaque" is now part of the Declare.CInfo.t (one per component of the proof)
- at Qed/Defined time, a check is done to determine if there is an
  attribute which takes precedence over the Qed/Defined keyword;
- for non-interactive declaration, Definition is transparent by
  default and (assuming the syntax provided as in rocq-prover#19301) Theorem
  requires an explicit attribute.
- the attribute can be set both globally (before the command name) and
  locally (just before the names declared by the command)
Co-Authored-By: Jim Fehrle <jim.fehrle@gmail.com>
Co-Authored-By: Zimmi48 <Zimmi48@users.noreply.github.com>
@herbelin

Copy link
Copy Markdown
Member Author

In answer to your remaining todo, yes, I think it makes sense to support the attribute both before the command itself or before the constant names. In case it is before the command, the same sealedness should apply to all defined constants. If it is in front of the name of the constant, it allows being more fine-grained. Obviously, we should error if these are inconsistent.

Done.

Either, we want to have two separate notions: transparent vs opaque / defined vs sealed. Or we think that this is a continuum worth presenting as such. Then no need for the word defined, the attributes could be named transparent, opaque and sealed.

I added a commit experimenting this (to be eventually squashed if we adopt it).

Comment on lines +3 to +6
New attributes :attr:`sealed` and :attr:`defined` allow to change
the default opacity (now called sealing to prevent the confusion
with the notion of opacity implemented by the command :cmd:`Opaque`)
of a definition or theorem

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
New attributes :attr:`sealed` and :attr:`defined` allow to change
the default opacity (now called sealing to prevent the confusion
with the notion of opacity implemented by the command :cmd:`Opaque`)
of a definition or theorem
Attributes :attr:`sealed` and :attr:`defined` to set
the opacity of a definition or theorem. :attr:`sealed` makes the object
immutably opaque, unlike the :cmd:`Opaque` command, which makes
an object mutably opaque

Some of the wording was not idiomatic
Also "the confusion with the notion of opacity" doesn't tell you what the difference in notions is, so vague

@coqbot-app

coqbot-app Bot commented Nov 28, 2024

Copy link
Copy Markdown
Contributor

The "needs: rebase" label was set more than 30 days ago. If the PR is not rebased in 30 days, it will be automatically closed.

@coqbot-app

coqbot-app Bot commented Dec 30, 2024

Copy link
Copy Markdown
Contributor

This PR was not rebased after 30 days despite the warning, it is now closed.

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

Labels

kind: feature New user-facing feature request or implementation. needs: merge of dependency This PR depends on another PR being merged first. needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. part: attributes #[attributes] modify the behaviour of vernac sentences. part: gallina The gallina commands stale This PR will be closed unless it is rebased.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants