Algebra of an import hierarchy #
This file provides algebraic/compositional relationships between module system dependencies in an import hierarchy.
Notably, we provide transitive closure operators relative to an import hierarchy, which relies on the nontrivial composition of module system imports.
Future work #
- Document this more thoroughly.
- Consider making the
HierarchyAPI more featureful.
Equations
- ImportGraph.Shake.«term_≫_» = Lean.ParserDescr.trailingNode `ImportGraph.Shake.«term_≫_» 80 80 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ≫ ") (Lean.ParserDescr.cat `term 81))
Instances For
𝓘⟦n⟧ is the transitive closure of n with respect to the hierarchy 𝓘.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Given an abstract NeedsKind [kImp⟩ and a collection of prearrows j [k⟩ · (Provides),
add to base the composed prearrows j [k⟩[imp⟩ · where composition is possible. Does not account
for public ⊆ private on the codomain side (see linearize).
Note that this does not add the original collection of prearrows to base.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- ImportGraph.Shake.instHPostcompNeedsNeedsKind = { hpostcomp := fun (n : ImportGraph.Shake.Needs) (k : ImportGraph.Shake.NeedsKind) => n.andThen k }
Instances For
Given an abstract Import [kImp⟩ and a collection of prearrows j [k⟩ · (Provides), add
to base the composed prearrows j [k⟩[imp⟩ · where composition is possible.
Note that this does not add the original collection of prearrows to base.
Equations
- ImportGraph.Shake.Lean.Import.addAndThen impTransDeps imp base = Id.run (impTransDeps.addAndThen (ImportGraph.Shake.NeedsKind.ofImport imp) base)
Instances For
Given an abstract import [k⟩ and a collection of prearrows j [k⟩ · (Needs), forms
the composed prearrows j [k'⟩[k⟩ · where composition is possible.
Equations
- ImportGraph.Shake.Lean.Import.andThen impTransDeps imp = ImportGraph.Shake.Lean.Import.addAndThen impTransDeps imp ImportGraph.Shake.Needs.empty
Instances For
Equations
- ImportGraph.Shake.instHPostcompNeedsImport = { hpostcomp := fun (n : ImportGraph.Shake.Needs) (imp : Lean.Import) => ImportGraph.Shake.Lean.Import.andThen n imp }
Instances For
Given an import hierarchy of arrows j' [_⟩ j and a preimport i [imp⟩ ·, forms the set of
prearrows obtained by transitively closing i [imp⟩ · with respect to the import hierarchy. This
is i [imp⟩ · together with compositions j [_⟩ i [imp⟩ ·. transDeps is assumed to be
reflexified.
Equations
- ImportGraph.Shake.NeedsKind.transitiveClosureSingle i k transDeps = ImportGraph.Shake.HPostcomp.hpostcomp transDeps[i]! k
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given an import hierarchy of arrows j' [_⟩ j and a preimport i [imp⟩ ·, forms the set of
prearrows obtained by transitively closing i [imp⟩ · with respect to the import hierarchy. This
is i [imp⟩ · together with compositions j [_⟩ i [imp⟩ ·. transDeps is assumed to be
reflexified.
Equations
- ImportGraph.Shake.Lean.Import.transitiveClosureSingle i imp transDeps = ImportGraph.Shake.HPostcomp.hpostcomp transDeps[i]! imp
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a set of prearrows i [k⟩ · and an import hierarchy, includes in base the compositions
of arrows j [k'⟩ i [k⟩ · where composition is possible. Assumes every index is valid.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a set of prearrows i [k⟩ · and an import hierarchy, forms the compositions of arrows
j [k'⟩ i [k⟩ · where composition is possible.
Equations
- ImportGraph.Shake.Hierarchy.andThen transDeps n = ImportGraph.Shake.Hierarchy.addAndThen transDeps n
Instances For
Equations
- ImportGraph.Shake.instHPostcompNeedsOfHierarchy = { hpostcomp := fun (transDeps : H) (n : ImportGraph.Shake.Needs) => ImportGraph.Shake.Hierarchy.andThen transDeps n }
Instances For
Equations
- base.addTransitiveClosure n transDeps = ImportGraph.Shake.Hierarchy.addAndThen transDeps n (base ∪ n)
Instances For
n ∪ (transDeps ≫ n)
Equations
- n.transitiveClosure transDeps = ImportGraph.Shake.Hierarchy.addAndThen transDeps n n
Instances For
Equations
- ImportGraph.Shake.instHTransClosureNeedsOfHierarchy = { htransClosure := fun (transDeps : H) (n : ImportGraph.Shake.Needs) => n.transitiveClosure transDeps }
Instances For
Includes the public visibilities in the corresponding private visibilities, to represent a
"provides" relationship. A k : Needs is "linear" iff it accounts for public ⊆ private (and
likewise for both being meta). Accounting for this on the target side means that k.pub ⊆ k.priv
(public imports are available privately) and accounting for it on the source side means that
k.privOfPriv ⊆ k.priv (importing the private scope privately implies importing the public scope
privately).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Removes private needs which can be inferred by accounting for public ⊆ private on both the
source and target side. See Needs.linearize for details.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A Provides providing to a module the aspects of that module which it provides to itself. Note
that a module does not provide its own non-meta scopes as meta dependencies to itself.
Linearized.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Adds in the reflexive availabilities of a given module, which are just the public and private
availabilities and not the meta lifted versions. This matches what is available within a given
module. Equivalent to a ∪ .reflOf i.
Note that this operation does not necessarily commute with transitive closure.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Clears all dependencies at the given index.
Equations
- ImportGraph.Shake.Needs.clearAt i a = a.map fun (x : ImportGraph.Shake.Bitset) => x \ {i}
Instances For
Checks if the Provides hierarchy transDeps provides arrows j [k⟩ i for all
(j [k⟩ ·) ∈ needs. Assumes transDeps is well-formed as a Provides hierarchy (i.e. linearized
and reflexified).
Instances For
Checks if the prearrows j [k⟩ · in n₁ are included in the arrows provided by the transitive
closure of n₂ with respect to the import hierarchy. Linearizes n₂ first, which ensures n₁ is
not penalized for itself being linearized and respecting public ⊆ private. Assumes transDeps
is a well-formed Provides hierarchy, i.e. linearized and reflexified.
Equations
- n₁.subsumedBy n₂ transDeps = n₁.directLe (ImportGraph.Shake.HTransClosure.htransClosure transDeps n₂.linearize)
Instances For
Returns an antilinearized reduced : Needs such that
a ≤ transDeps⟦reduced.linearize⟧
and reduced is minimal (perhaps non-uniquely) among such Needs.
The returned reduced is antilinearized, and thus suitable for converting to imports.
Does not assume a is linearized.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Attempts to insert a among the set as of minimal elements as a new minimal element
according to lt. Clears elements of as that are above a, and ignores a if we already have
an element lower than a.
Equations
- One or more equations did not get rendered due to their size.
Instances For
At k, attempts to insert a among the set as of minimal elements as a new minimal element
according to lt. Clears elements of as that are above a, and ignores a if we already have
an element lower than a.
Equations
Instances For
The minimal values of xs under val according to lt, organized and compared per key
value. See minimalsPer for a version without val; val is essentially an optimization.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The minimal elements of xs according to lt, organized and compared per key value.
Equations
- ImportGraph.Shake.Array.minimalsPer xs key lt = ImportGraph.Shake.Array.minimalValuesPer xs key id lt