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

Major refactoring of cooking.ml #14727

Merged
merged 11 commits into from
Feb 14, 2022

Conversation

herbelin
Copy link
Member

@herbelin herbelin commented Jul 30, 2021

Kind: Refactoring

Depends on #14726 (merged).

In this PR, all technical code is concentrated in a few functions with the rest of the code simply calling the core functions compositionally.

These functions are:

  • expand_subst which itself includes:
    • expand_constr: expansion of global constants
    • subst_univs_level_constr: name-to-de-Bruijn universe renaming
    • subst_vars: name-to-de-Bruijn term renaming
  • abstract_as_type/abstract_as_body: actual generalization

It relies on the following data structures:

  • universe graph (abstr_uctx, or G)
  • term context (abstr_ctx, or Δ)
  • name-to-de-Bruijn universe substitution (abstr_usubst, or τ)
  • name-to-de-Bruijn term substitution (abstr_subst, or σ)
  • instance of universe graph (abstr_uinst, or |G|)
  • instance of term context (abstr_inst, or |Δ|)
  • expansion maps (expand_info, mapping a c generalized over G' and Δ' to c |G'| |Δ'|)

These data are enough to turn judgements of the form G, Δ ⊢ J into judgements of the form ⊢ ΠG.ΠΔ.(J[σ][τ]).

It includes:

  • lift_poly_univs: to absorb a universe context in the transformation, that is to reduce the admissibiliy of a rule going from G, Δ ⊢ ΠG'.J to ⊢ ΠG.ΠΔ.(ΠG'.J)[σ][τ]) to the admissibiliy of a rule going from G(G'[ττ']), Δ ⊢ J to ⊢ ΠG(G'[ττ']).ΠΔ.(J[σ][τ]) for a well-chosen τ'
  • abstract_context: to absorb a term context in the transformation, that is to reduce the admissibiliy of a rule going from G, Δ ⊢ ΠΩ.J to ⊢ ΠG.ΠΔ.((ΠΩ.J)[σ][τ]) to the admissibiliy of a rule going from G, Δ, Ω[σ][τ] ⊢ J to ⊢ ΠG.ΠΔ.Π(Ω[σ][τ]).(J[σ'][τ]) for a well-chosen σ'

Note that the new cooking is "incremental": the cooking data is not global to the section but attached to each declaration. So, in theory, it would be direct to precook all generalizations of a constant/inductive at the time of its declaration (and hence to use them in the section!).

  • Added / updated documentation of the code

Overlays (relative to the change in PrivatePolymorphic):

@herbelin herbelin added kind: cleanup Code removal, deprecation, refactorings, etc. part: kernel labels Jul 30, 2021
@herbelin herbelin added this to the 8.15+rc1 milestone Jul 30, 2021
@herbelin herbelin requested review from a team as code owners July 30, 2021 20:02
@herbelin herbelin added the needs: merge of dependency This PR depends on another PR being merged first. label Jul 30, 2021
@herbelin herbelin force-pushed the master+major-refactoring-cooking branch 2 times, most recently from 8f40105 to f2d4fce Compare July 31, 2021 07:30
Comment on lines 30 to 44
val cook_constant : recipe -> cooking_info Opaqueproof.opaque result
val cook_constr : cooking_info list ->
(constr * unit Opaqueproof.delayed_universes) -> (constr * unit Opaqueproof.delayed_universes)
val cook_opaque_proofterm : cooking_info list ->
Opaqueproof.opaque_proofterm -> Opaqueproof.opaque_proofterm

val cook_constant :
recipe -> cooking_info Opaqueproof.opaque result

val cook_inductive :
cooking_info -> mutual_inductive_body -> mutual_inductive_body

(** {6 Utility functions used in module [Discharge]. } *)
val make_cooking_info : expand_info -> named_context -> Univ.UContext.t -> cooking_info
(** Abstract a context assumed to be de-Bruijn free for terms and universes *)

val lift_poly_univs : cooking_info -> Univ.AbstractContext.t -> cooking_info * Univ.AbstractContext.t

val abstract_rel_context : cooking_info -> rel_context -> rel_context

val expmod_constr : work_list -> constr -> constr
val discharge_proj_repr : abstr_inst_info -> Names.Projection.Repr.t -> Names.Projection.Repr.t
Copy link
Member Author

Choose a reason for hiding this comment

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

The terminology, cook, or discharge, or abstract, or lift should probably be simplified.

  • lift_poly_univs and abstract_rel_context do morally the same: they traverse an already-quantified context, respectively a context of universe and a context of terms, updating the cooking info for the remainder of the judgement, and "cooking" this context at the same time.

Comment on lines 268 to 269
| Opaqueproof.PrivateMonomorphic () as priv ->
let () = assert (AbstractContext.is_empty info.abstr_info.abstr_uctx) in
let () = assert (is_empty_level_subst info.abstr_info.abstr_usubst) in
priv
Copy link
Member Author

Choose a reason for hiding this comment

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

Can't there be private universes also for monomorphic constants?

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't pass them to cook_constr (see drop_mono in opaqueproof)

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 don't understand well the story about PrivateMonomorphic. Is the apparentl loss of information in drop_mono to be related to the extraction of delayed_cst in Safe_typing.add_constant, so that the information is actually not lost?

Copy link
Member

Choose a reason for hiding this comment

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

This data is redundant for the kernel, and only used for vio computation. I have a series of patches that modify this area of the code but I've not submitted them yet because they break weird invariants in Declare that I need to fix first.

@herbelin herbelin force-pushed the master+major-refactoring-cooking branch from f2d4fce to a778cb2 Compare July 31, 2021 08:02
@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 Aug 18, 2021
@herbelin herbelin force-pushed the master+major-refactoring-cooking branch from a778cb2 to 810105a Compare August 18, 2021 15:33
@herbelin herbelin requested a review from a team as a code owner August 18, 2021 15:33
@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 Aug 18, 2021
@herbelin herbelin force-pushed the master+major-refactoring-cooking branch from 810105a to df00348 Compare August 18, 2021 16:09
@herbelin herbelin removed the needs: merge of dependency This PR depends on another PR being merged first. label Aug 28, 2021
@herbelin herbelin force-pushed the master+major-refactoring-cooking branch from df00348 to cc583bd Compare August 28, 2021 16:20
@herbelin
Copy link
Member Author

I added two further "cleaning" commits. We could do more cleaning, like completely bypassing the type Cooking.result for instance, or imposing more unity in naming.

@ppedrot: would you like to assign?

@ppedrot ppedrot self-assigned this Aug 30, 2021
Copy link
Contributor

@SkySkimmer SkySkimmer left a comment

Choose a reason for hiding this comment

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

Seems ok overall


type 'a entry_map = 'a Cmap.t * 'a Mindmap.t
type section_entry =
| SecDefinition of Constant.t * constant_body
| SecInductive of MutInd.t * mutual_inductive_body
Copy link
Contributor

@SkySkimmer SkySkimmer Sep 16, 2021

Choose a reason for hiding this comment

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

I'm not sure it makes sense to have the bodies here. It seems to be used to have access to them in close_section instead of getting them from the revstruct, but couldn't we just look them up in the env0?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need the hyps of the declaration in Section.segment_entry but not the full bodies. We could indeed use an access to the env instead. I can change it if you insist.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please change

Copy link
Member Author

Choose a reason for hiding this comment

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

Commit 9cfdd1e implements your suggestion. It looks a bit strange to recompute a data which we can have at hand for free, but I agree that it makes sense also to have the bodies stored in a unique place, even if there is a cost to get them back.

Copy link
Member Author

Choose a reason for hiding this comment

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

@SkySkimmer: I'm still a bit afraid of the extra time needed to find again the constant_body and mutual_inductive_body in the environment. Probably not more than a dozen of steps per definition for an environment of several thousands of declarations, so it is maybe a bit unjustified fear, especially considering how lax we are on factorizing the accesses to the environment in many parts of the code, but would you be ok if I would cache back the bodies in the section_entry?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am only OK if you can show an impact in the bench.

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 don't think I could. That would require a huge environment and short definitions so that the time for looking in the environment dominates.

Well, ok, this is globally non-significant, so I leave the PR without the "cache".

kernel/univ.mli Show resolved Hide resolved
@@ -484,6 +484,8 @@ val extend_in_context_set : 'a in_universe_context_set -> ContextSet.t ->

val empty_level_subst : universe_level_subst
val is_empty_level_subst : universe_level_subst -> bool
val lift_level_subst : int -> universe_level_subst -> universe_level_subst
val merge_level_subst : universe_level_subst -> universe_level_subst -> universe_level_subst
Copy link
Contributor

Choose a reason for hiding this comment

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

This should state the precondition (no common elements, even if they're mapped to the same value) explicitly.
I'm also not sure if it makes sense to have a function with such a precondition in the general API rather than having it defined near its (unique) user.

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 don't know. Both approaches are ok to me. In the meantime, I documented it.

kernel/names.ml Outdated
@@ -916,14 +916,15 @@ struct
module HashRepr = Hashcons.Make(Self_Hashcons)
let hcons = Hashcons.simple_hcons HashRepr.generate HashRepr.hcons (hcons_ind,Id.hcons)

let map_npars f p =
let map_ind_npars f p =
Copy link
Contributor

Choose a reason for hiding this comment

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

If this isn't exposed then it should be inlined in map_npars and map

Copy link
Member Author

Choose a reason for hiding this comment

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

But this would lead to a duplication. Is that what you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's really duplication

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 tried and I agree that this is clearer by splitting them.

(** Canonical renaming represented by its domain made of the
actual names of the abstracted term variables (e.g. [a,c]);
the codomain made of de Bruijn indices is implicit *)
abstr_usubst : Univ.universe_level_subst;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not always make_instance_subst abstr_uctx?

Copy link
Member Author

Choose a reason for hiding this comment

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

The name abstr_uctx is misleading. It is an AbstractContext and, if I'm correct, the orginal uctx levels have been lost. Maybe should it be renamed to abstr_auctx?

Copy link
Contributor

Choose a reason for hiding this comment

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

right

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -315,7 +315,7 @@ let cook_constant env info cb =
(********************************)
(* Discharging mutual inductive *)

let abstract_rel_context cache info ctx =
let cook_rel_context cache info ctx =
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO I prefer abstract to cook but it's not a strong preference.

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 like abstract also but cook is used many times already.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like abstract also but cook is used many times already.

Naming isn't a democracy, we can be tyrannical here

@SkySkimmer
Copy link
Contributor

The "adding" commits should be merged with the commits introducing the use of the new API imo

@herbelin
Copy link
Member Author

@SkySkimmer Thanks a lot for the comments. Next weeks are dense for me but I'll try to reply within a couple of days.

expand_info : expand_info;
abstr_info : abstr_info;
abstr_inst_info : abstr_inst_info; (* relevant for recursive types *)
names_info : Id.Set.t; (* set of generalized names *)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think that there is too much stuff exposed in this API. The datatypes used to live in Cooking and were moved here by @SkySkimmer IIRC but now that we're supposed to preserve more invariants I believe this should be move back under an opaque interface. How doable is this?

Copy link
Contributor

Choose a reason for hiding this comment

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

It was in opaqueproof, not cooking
b1675a6

Copy link
Member

Choose a reason for hiding this comment

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

Right, right. But now that Opaqueproof is parameterized by this data, it should be easier to put it in Cooking, shouldn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Dependency order goes opaqueproof <- declarations <- cooking so I guess no

Copy link
Member

Choose a reason for hiding this comment

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

This should still be tried nonetheless, I really don't like having all these internal bits exposed to everybody.

Copy link
Member Author

Choose a reason for hiding this comment

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

A possibility would be to split cooking.ml into two parts:

  • the low-level infrastructure up to subst_private_univs (and with an abstract export of cooking_info), coming before opaqueproof.ml
  • the high-level commands cook_constant and cook_inductive coming after declarations (with possible integration to term_typing.ml if we don't want creating an extra file)

At worst, in the higher levels (vernac, tactics, ...) only the field abstr_inst really needs to be visible (and it could as well be hidden behind an access function).

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 pushed a commit in this directon, providing a better abstraction of cooking_info. We could abstract even a bit further, depending on feedback.

@herbelin herbelin force-pushed the master+major-refactoring-cooking branch from 53f77e9 to fcee31c Compare September 20, 2021 15:21
@coqbot-app coqbot-app bot removed the stale This PR will be closed unless it is rebased. label Feb 6, 2022
@coqbot-app
Copy link
Contributor

coqbot-app bot commented Feb 7, 2022

🔴 CI failure at commit cb6d6fc without any failure in the test-suite

✔️ Corresponding job for the base commit 7c608fe succeeded

❔ Ask me to try to extract a minimal test case that can be added to the test-suite

🏃 @coqbot ci minimize will minimize the following target: ci-fcsl_pcm
  • You can also pass me a specific list of targets to minimize as arguments.

@herbelin herbelin force-pushed the master+major-refactoring-cooking branch from 1b4080e to 9c1aa5f Compare February 7, 2022 18:57
@herbelin
Copy link
Member Author

herbelin commented Feb 8, 2022

It seems that the slowdown due to vo size increase (presumably loss of sharing in files) has been magically solved (due to #14924 maybe??) and that the PR is now saving some cycles. Re-running a bench to be sure.

@herbelin
Copy link
Member Author

herbelin commented Feb 9, 2022

┌─────────────────────────────┬─────────────────────────┬───────────────────────────────────────┬───────────────────────────────────────┬──────────────────────────┬─────────────────┐
│                             │      user time [s]      │              CPU cycles               │           CPU instructions            │  max resident mem [KB]   │   mem faults    │
│                             │                         │                                       │                                       │                          │                 │
│                package_name │     NEW      OLD  PDIFF │            NEW             OLD  PDIFF │            NEW             OLD  PDIFF │     NEW      OLD   PDIFF │ NEW  OLD  PDIFF │
├─────────────────────────────┼─────────────────────────┼───────────────────────────────────────┼───────────────────────────────────────┼──────────────────────────┼─────────────────┤
│       coq-mathcomp-fingroup │   23.44    23.90  -1.92 │   106805940920    109030214819  -2.04 │   156617263857    156355281519   0.17 │  492776   483636    1.89 │   0    0    nan │
│              coq-coquelicot │   34.12    34.73  -1.76 │   153414999308    155205512585  -1.15 │   202802719577    202093224621   0.35 │  756360   746900    1.27 │   0    0    nan │
│           coq-iris-examples │  419.76   426.83  -1.66 │  1901963591861   1932779022537  -1.59 │  2912478866430   2907160631046   0.18 │ 1179768  1168668    0.95 │   0    0    nan │
│       coq-mathcomp-solvable │   87.39    88.80  -1.59 │   398917190747    404992118468  -1.50 │   612695822822    611691323579   0.16 │  665096   658220    1.04 │   0    0    nan │
│         coq-category-theory │ 1595.94  1615.87  -1.23 │  7289460792992   7381749753737  -1.25 │ 15272287002218  15265692532719   0.04 │ 1491856  1319056   13.10 │   0    0    nan │
│               coq-perennial │ 3951.51  4000.56  -1.23 │ 17915307138687  18139072891573  -1.23 │ 29814680824608  29800333829589   0.05 │ 2631012  2595764    1.36 │   0    0    nan │
│               coq-fiat-core │   55.26    55.83  -1.02 │   235149961848    237472562140  -0.98 │   331329293133    329126657680   0.67 │  481804   477624    0.88 │   0    0    nan │
│                   coq-verdi │   47.93    48.41  -0.99 │   216469840896    218962436658  -1.14 │   323187097116    322533677424   0.20 │  840088   834312    0.69 │   0    0    nan │
│                  coq-flocq3 │   76.36    77.12  -0.99 │   346941211462    349608014580  -0.76 │   456757482737    456073340914   0.15 │  990340   987092    0.33 │   0    0    nan │
│             coq-fiat-crypto │ 2801.57  2828.99  -0.97 │ 12623211416614  12748867114693  -0.99 │ 23285749144716  23305118307774  -0.08 │ 3851392  3851188    0.01 │   0    0    nan │
│                 coq-coqutil │   34.89    35.23  -0.97 │   155973351364    157473446404  -0.95 │   209805834695    208855730940   0.45 │  605640   602028    0.60 │   0    0    nan │
│            coq-fiat-parsers │  336.09   339.17  -0.91 │  1488162454735   1502441971027  -0.95 │  2456687826204   2457388572887  -0.03 │ 2695836  3443080  -21.70 │   0    0    nan │
│      coq-mathcomp-character │   76.48    77.14  -0.86 │   349040052934    352215332474  -0.90 │   530386229317    526227888337   0.79 │  846980   736600   14.99 │   0    0    nan │
│            coq-math-classes │   90.28    90.99  -0.78 │   407411393641    410150389584  -0.67 │   573189761727    572009403315   0.21 │  502944   496004    1.40 │   0    0    nan │
│                    coq-corn │  753.28   758.77  -0.72 │  3414052035393   3438305405424  -0.71 │  5290934018917   5283457995001   0.14 │  876408   874644    0.20 │   0    0    nan │
│      coq-mathcomp-ssreflect │   26.15    26.32  -0.65 │   118299168991    119298867398  -0.84 │   149535244969    149215647035   0.21 │  543648   531424    2.30 │   0    0    nan │
│              coq-verdi-raft │  557.62   561.13  -0.63 │  2538054990629   2553738330443  -0.61 │  3937497714163   3934797022564   0.07 │ 1238008  1230960    0.57 │   0    0    nan │
│       coq-engine-bench-lite │  178.54   179.48  -0.52 │   766529634499    770444905208  -0.51 │  1501005465141   1498003023517   0.20 │ 1304560  1174188   11.10 │   0    0    nan │
│          coq-mathcomp-field │  111.94   112.48  -0.48 │   510821493812    513849502285  -0.59 │   841983738897    837904153362   0.49 │  713016   653856    9.05 │   0    0    nan │
│      coq-mathcomp-odd-order │  552.37   554.77  -0.43 │  2526350741065   2537043994278  -0.42 │  4285944899933   4257070661209   0.68 │ 1216152   933208   30.32 │   0    0    nan │
│                coq-rewriter │  373.61   375.22  -0.43 │  1691198989236   1698620311956  -0.44 │  2775554411492   2776209799708  -0.02 │ 1060812  1060304    0.05 │   0    0    nan │
│                   coq-color │  210.65   211.31  -0.31 │   943988614189    946793583469  -0.30 │  1332544333095   1326284389908   0.47 │ 1113700  1145212   -2.75 │   0    0    nan │
│                  coq-stdlib │  403.56   404.66  -0.27 │  1635006877438   1632747098560   0.14 │  1417093712260   1413418374991   0.26 │  610900   604992    0.98 │   0    0    nan │
│                 coq-bignums │   27.83    27.88  -0.18 │   126333997430    126419819408  -0.07 │   173386626813    173042000047   0.20 │  468944   466460    0.53 │   0    0    nan │
│                     coq-vst │ 1054.79  1056.17  -0.13 │  4778893268602   4785190760743  -0.13 │  7815752108161   7797022841616   0.24 │ 2027156  2071936   -2.16 │   0    0    nan │
│                    coq-hott │  162.12   162.28  -0.10 │   728595888280    731518132588  -0.40 │  1148512666001   1150004602628  -0.13 │  576584   589884   -2.25 │   0    0    nan │
│        coq-mathcomp-algebra │   64.00    64.06  -0.09 │   291202174345    291335724354  -0.05 │   401077289288    398639226267   0.61 │  603284   556124    8.48 │   0    0    nan │
│                    coq-core │   98.70    98.63   0.07 │   394319518909    390056343365   1.09 │   440874824342    440975522738  -0.02 │  273400   274276   -0.32 │   0    0    nan │
│                coq-compcert │  282.14   281.84   0.11 │  1268668769850   1267114404524   0.12 │  1898238385466   1894609928141   0.19 │ 1106008  1097172    0.81 │   0    0    nan │
│                coq-coqprime │   59.94    59.87   0.12 │   271276783711    270596244556   0.25 │   445914237821    445209774748   0.16 │  765068   758036    0.93 │   0    0    nan │
│               coq-fourcolor │ 1497.60  1495.46   0.14 │  6609041479914   6611631136538  -0.04 │ 12116730950312  12087038324002   0.25 │  759664   706812    7.48 │   0    0    nan │
│  coq-performance-tests-lite │  783.51   781.57   0.25 │  3519196159594   3511137536724   0.23 │  5979272809534   5973814259925   0.09 │ 1824604  1825008   -0.02 │   0    0    nan │
│                 coq-unimath │ 3951.56  3940.02   0.29 │ 17966069978711  17920847020480   0.25 │ 35847011675268  35844603379789   0.01 │ 3102220  3322920   -6.64 │   0    0    nan │
│                  coq-geocoq │  692.29   689.91   0.34 │  3147352869258   3137697764730   0.31 │  4958179517993   4951178931605   0.14 │ 1077812  1077856   -0.00 │   0    0    nan │
│ coq-rewriter-perf-SuperFast │  937.12   932.52   0.49 │  4217783112423   4198587366524   0.46 │  7302050701082   7298336157057   0.05 │ 1145584  1148944   -0.29 │   0    0    nan │
└─────────────────────────────┴─────────────────────────┴───────────────────────────────────────┴───────────────────────────────────────┴──────────────────────────┴─────────────────┘
(bedrock2 and metacoq could not be tested)

@herbelin herbelin force-pushed the master+major-refactoring-cooking branch from 9c1aa5f to 4ef9d13 Compare February 10, 2022 09:17
@herbelin
Copy link
Member Author

There is still room for improvement. For instance, the cooking of the variance of universes is still treated separatedly. Also, one may probably want that there is a computation of the actual dependencies in the universe variables of the section, the same way as it is done for declarations of variables. But this can probably go in other PRs.

So, if nothing happens new on this PR by a fews days, I believe it can be considered ready.

kernel/opaqueproof.mli Outdated Show resolved Hide resolved
Includes a suggestion from Gaëtan Gilbert.
All technical code is now concentrated in a few functions with the
rest of the code simply calling the core functions compositionally.

The functions are:
- expand_subst =
  - expand_constr: expansion of global constants
  - subst_univs_level_constr: name-to-de-Bruijn universe renaming
  - subst_vars: name-to-de-Bruijn term renaming
- abstract_as_type/abstract_as_body: actual generalization

It relies on the following data structures:
- universe graph (abstr_auctx, or G)
- term context (abstr_ctx, or Δ)
- name-to-de-Bruijn universe substitution (abstr_ausubst, or τ)
- name-to-de-Bruijn term substitution (abstr_subst, or σ)
- instance of universe graph (abstr_uinst, or |G|)
- instance of term context (abstr_inst, or |Δ|)
- expansion maps (expand_info, mapping a c generalized over G' and Δ' to c |G'| |Δ'|)

These data are enough to turn judgements of the form
[G, Δ ⊢ J] into judgements of the form [⊢ ΠG.ΠΔ.(J[σ][τ])]

It includes:
- lift_poly_univs: to absorb a universe context in the transformation,
  that is to reduce the admissibiliy of a rule going from
  [G, Δ ⊢ ΠG'.J] to [⊢ ΠG.ΠΔ.(ΠG'.J)[σ][τ])] to the admissibiliy of a
  rule going from [G(G'[ττ']), Δ ⊢ J] to [⊢ ΠG(G'[ττ']).ΠΔ.(J[σ][τ])]
  for a well-chosen τ'
- abstract_context: to absorb a term context in the transformation,
  that is to reduce the admissibiliy of a rule going from
  [G, Δ ⊢ ΠΩ.J] to [⊢ ΠG.ΠΔ.((ΠΩ.J)[σ][τ])] to the admissibiliy of a
  rule going from [G, Δ, Ω[σ][τ] ⊢ J] to [⊢ ΠG.ΠΔ.Π(Ω[σ][τ]).(J[σ'][τ])]
  for a well-chosen σ'

Note: includes suggestions from Gaëtan Gilbert.
…oking_info.

New dependency chain:
cooking.ml <- opaqueproof.ml <- declarations.ml <- discharge.ml
@herbelin herbelin force-pushed the master+major-refactoring-cooking branch from 4ef9d13 to cb1b0ba Compare February 11, 2022 11:43
@ppedrot ppedrot added this to the 8.16+rc1 milestone Feb 12, 2022
@ppedrot
Copy link
Member

ppedrot commented Feb 13, 2022

Merging soon.

@ppedrot
Copy link
Member

ppedrot commented Feb 14, 2022

@coqbot merge now

@coqbot-app coqbot-app bot merged commit b356287 into coq:master Feb 14, 2022
@coqbot-app
Copy link
Contributor

coqbot-app bot commented Feb 14, 2022

@ppedrot: Please take care of the following overlays:

  • 14727-herbelin-master+major-refactoring-cooking.sh

LasseBlaauwbroek added a commit to coq-tactician/coq-tactician that referenced this pull request Sep 20, 2022
LasseBlaauwbroek added a commit to coq-tactician/coq-tactician that referenced this pull request Sep 20, 2022
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. part: kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants