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

[CEP] Proposal for libobject API refactoring #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ejgallego
Copy link
Member

@ejgallego ejgallego commented Sep 12, 2022

Rendered version here

Comment on lines +147 to +158
categories, names, locations. For now we implement a reverse map for
names, but more options could be desirable after more experimentation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this refer to a branch somewhere or is more like "for now we propose to start with a reverse map for names"?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is implemented in the prototype branch, cleaning it up to submit as we speak.

Copy link
Member Author

Choose a reason for hiding this comment

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

PR done, you can use (hack hack) Print Graph to print the reverse map


In particular, we can distinguish a few common behaviors:

- `Kernel` : objects with this trait provide a function to register with a `safe_env`
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that currently I believe the only part of libobject which modifies the safe_env is the Require replay after closing section/module (in_require in library.ml).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, that's correct. Tho the trait is meant to capture objects that call the diverse Global.* functions, so at some point the env can be owned by declaremods.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've clarified this a bit in an update.

In particular, we can distinguish a few common behaviors:

- `Kernel` : objects with this trait provide a function to register with a `safe_env`
- `Named` : objects with this trait can register with the `Nametab`, in a uniform way
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that currently nametab itself is not uniform (there are separate tables for globref, modules, ltacs, some other stuff) so this may require a nametab redesign first.

Copy link
Member

Choose a reason for hiding this comment

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

FTR I think that unifying the various nametabs is gong the wrong way. It's a feature that each plugin can define its own set of names, so the design critically needs to account for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the idea is that when an object declares a nametab trait, it does so with their own nametab. Refactoring is indeed needed, you can see current progress here, but need to advance more https://github.com/ejgallego/coq/blob/f059e5a57e95c5c80a3c9026e91ba91936d90db5/library/nametab.mli

Ideally, if we think this is a good idea we would do such a change in two steps:

  • we would first define the trait, which takes a module as a parameter and performs the imperative state
  • we would then push the trait to be functional, and have Declaremods own the nametab.

Copy link
Member Author

Choose a reason for hiding this comment

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

Clarified a bit.

@gares
Copy link
Member

gares commented Sep 12, 2022

Can you explain how the proposed approach solves/improves-on the downsides of the current approach, in particular:

  • there is no possibility to systematically explore the list of objects currently in scope (other than hoping the ad-hoc internal structures are somehow exposed)
  • in some cases (such as printing), we need to perform a costly (and messy) global imperative state update as to simulate that a module has been opened, due to the imperative nature of the module system implementation

@ejgallego
Copy link
Member Author

  • there is no possibility to systematically explore the list of objects currently in scope (other than hoping the ad-hoc internal structures are somehow exposed)

For this see for example coq/coq#16261 , and how the API with the reverse map introduced here is used in Search and Locate. If we move Category.t in that PR to the data, one could have a reverse map on categories too. What metadata to add is a bit open, for now I was thinking of documentation as sketched in the proposal for liberabaci.

  • in some cases (such as printing), we need to perform a costly (and messy) global imperative state update as to simulate that a module has been opened, due to the imperative nature of the module system implementation

Hopefully the Named trait could be used to avoid the global state update for the Nametab in printmod.ml

# Part II: behavior specification

The second part of this CEP, not yet implemented, is to phase out the
`declare_object` API in favor a set of `Behavior.t` traits that an
Copy link
Member

Choose a reason for hiding this comment

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

Is there a description of the Behavior API?

Copy link
Member Author

@ejgallego ejgallego Sep 13, 2022

Choose a reason for hiding this comment

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

I don't have a too precise view on how to implement it, there are several options so here we can use some feedback.

I guess for the first prototype I'd try to have a list of traits, indeed due to the existential nature of traits that would mean turning the declaration of objects into a module, but I think I'm fine with that (as in the case for the proposal about errors in coq/coq#12602)

ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 2, 2022
This is both a cleanup and a step towards pushing the state upwards,
and handling the nametabs functionally.

Related to coq#16746 and
coq/ceps#65
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 2, 2022
This is both a cleanup and a step towards pushing the state upwards,
and handling the nametabs functionally.

Related to coq#16746 and
coq/ceps#65
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 2, 2022
This is both a cleanup and a step towards pushing the state upwards,
and handling the nametabs functionally.

Related to coq#16746 and
coq/ceps#65
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 3, 2022
This is both a cleanup and a step towards pushing the state upwards,
and handling the nametabs functionally.

Related to coq#16746 and
coq/ceps#65
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 3, 2022
This is both a cleanup and a step towards pushing the state upwards,
and handling the nametabs functionally.

Related to coq#16746 and
coq/ceps#65
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 14, 2022
This is both a cleanup and a step towards pushing the state upwards,
and handling the nametabs functionally.

Related to coq#16746 and
coq/ceps#65
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 16, 2022
This is both a cleanup and a step towards pushing the state upwards,
and handling the nametabs functionally.

Related to coq#16746 and
coq/ceps#65
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 17, 2022
This is a first implementation of CEP coq/ceps#65

We add a common metadata object to atomic libobjects, so we can store
documentation, location, names, and other interesting attributes that
are needed by clients to implement functionality.

As we allow storing names of the objects, we can index them by name to
provide efficient reverse lookup.

We export an experimental API for clients to consume this metadata.

PR coq#16261 is implemented on top of this one.
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 18, 2022
This is a first implementation of CEP coq/ceps#65

We add a common metadata object to atomic libobjects, so we can store
documentation, location, names, and other interesting attributes that
are needed by clients to implement functionality.

As we allow storing names of the objects, we can index them by name to
provide efficient reverse lookup.

We export an experimental API for clients to consume this metadata.

PR coq#16261 is implemented on top of this one.
ejgallego added a commit to ejgallego/coq that referenced this pull request Nov 18, 2022
This is a first implementation of CEP coq/ceps#65

We add a common metadata object to atomic libobjects, so we can store
documentation, location, names, and other interesting attributes that
are needed by clients to implement functionality.

As we allow storing names of the objects, we can index them by name to
provide efficient reverse lookup.

We export an experimental API for clients to consume this metadata.

PR coq#16261 is implemented on top of this one.
ejgallego added a commit to ejgallego/coq that referenced this pull request Jan 23, 2023
This is a first implementation of CEP coq/ceps#65

We add a common metadata object to atomic libobjects, so we can store
documentation, location, names, and other interesting attributes that
are needed by clients to implement functionality.

As we allow storing names of the objects, we can index them by name to
provide efficient reverse lookup.

We export an experimental API for clients to consume this metadata.

PR coq#16261 is implemented on top of this one.
ejgallego added a commit to ejgallego/coq that referenced this pull request Jan 25, 2023
This is both a cleanup and a step towards pushing the state upwards,
and handling the nametabs functionally.

Related to coq#16746 and
coq/ceps#65
ejgallego added a commit to ejgallego/coq that referenced this pull request Mar 3, 2023
This is both a cleanup and a step towards pushing the state upwards,
and handling the nametabs functionally.

Related to coq#16746 and
coq/ceps#65
ejgallego added a commit to ejgallego/coq that referenced this pull request Apr 13, 2023
This is both a cleanup and a step towards pushing the state upwards,
and handling the nametabs functionally.

Related to coq#16746 and
coq/ceps#65
ejgallego added a commit to ejgallego/coq that referenced this pull request Jun 23, 2023
This is both a cleanup and a step towards pushing the state upwards,
and handling the nametabs functionally.

Related to coq#16746 and
coq/ceps#65
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.

5 participants