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

Section.t is never empty #10829

Merged
merged 1 commit into from Dec 9, 2019
Merged

Section.t is never empty #10829

merged 1 commit into from Dec 9, 2019

Conversation

SkySkimmer
Copy link
Contributor

This approach using type t = { sec_prev: t option; sec_... } makes
it easy to update sections using the record update syntax, but
impossible to statically ensure that an operation only affects the
current section.

We may instead consider using type t = section * section list which
needs some boilerplate to update.

@@ -404,7 +408,7 @@ let check_current_library dir senv = match senv.modvariant with
(** When operating on modules, we're normally outside sections *)

let check_empty_context senv =
assert (Environ.empty_context senv.env && Section.is_empty senv.sections)
assert (Environ.empty_context senv.env && senv.sections = None)
Copy link
Member

Choose a reason for hiding this comment

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

Use Option.is_empty.

let c, r, typ = Term_typing.translate_local_def senv.env id de in
let x = Context.make_annot id r in
let env'' = safe_push_named (LocalDef (x, c, typ)) senv.env in
{ senv with sections; env = env'' }
{ senv with sections=Some sections; env = env'' }
Copy link
Member

Choose a reason for hiding this comment

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

Spaces are not a threatened species, please put a pair between equality, as well as everywhere below. Even better, reuse the punning and leave that line unchanged, writing above instead let sections = Some (Section.push_local sections) in.

@@ -20,7 +20,9 @@ type section_entry =

type 'a entry_map = 'a Cmap.t * 'a Mindmap.t

type 'a section = {
type 'a t = {
sec_prev : 'a t option;
Copy link
Member

Choose a reason for hiding this comment

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

Really not pretty, I'd prefer a list and ensuring everywhere that it's not empty.

Copy link
Member

Choose a reason for hiding this comment

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

We use non-empty lists in a few places already so indeed we could add a generic NEList data structure to the libraries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH I don't see a need to use nonempty lists here, having the outer section be a member of the current one seems to work fine.

Comment on lines +331 to +328
let get_section = function
| None -> CErrors.user_err Pp.(str "No open section.")
| Some s -> s
Copy link
Member

Choose a reason for hiding this comment

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

[nit] It seems that the users below follow the same pattern to an extent that it could be worth to make this into a combinator with_open_section and refactor a bit more.

@ejgallego ejgallego added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Oct 13, 2019
@coqbot coqbot removed the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Oct 14, 2019
@ejgallego ejgallego added kind: cleanup Code removal, deprecation, refactorings, etc. needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. labels Oct 24, 2019
@ejgallego
Copy link
Member

This PR got stuck, but it seems like a nice one to me, what should be done?

@silene silene removed their request for review November 20, 2019 15:26
@coqbot coqbot removed the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Dec 4, 2019
@ppedrot ppedrot self-assigned this Dec 4, 2019
val sections_of_safe_env : safe_environment -> section_data Section.t
val sections_of_safe_env : safe_environment -> section_data Section.t option

val force_sections_of_safe_env : safe_environment -> section_data Section.t
Copy link
Member

Choose a reason for hiding this comment

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

Why export this if there are no users? I don't think it's the job of the kernel to display nice messages when there is a programming error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a user in lib

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yes, sorry. (Still seems strange to export, but fine.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could move it to lib and make it internal

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer so if possible. Not to mention the fact that this is quite ill-named...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

This approach using `type t = { sec_prev: t option; sec_... }` makes
it easy to update sections using the record update syntax, but
impossible to statically ensure that an operation only affects the
current section.

We may instead consider using `type t = section * section list` which
needs some boilerplate to update.
@ppedrot ppedrot added this to the 8.12+beta1 milestone Dec 9, 2019
ppedrot added a commit that referenced this pull request Dec 9, 2019
Ack-by: ejgallego
Reviewed-by: ppedrot
@ppedrot ppedrot merged commit 88dfc41 into coq:master Dec 9, 2019
@SkySkimmer SkySkimmer deleted the section-nonempty branch December 9, 2019 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: cleanup Code removal, deprecation, refactorings, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants