src/rules/imports.bend checks
raw source on the hub · import bolt@1.62.0.0/src/rules/imports.bend as Imports
src/rules/imports: paths and relative imports, as the project rules see
them. A path is normalized (no ./, .. applied), an import resolves
against the importing file's directory, and a file's closure is every file
the linter read that it reaches by relative imports (import ./m.bend as M,
import ../x/y.bend as Y). Imports of files that were not read are dropped:
nothing is known of them.
4 imports
import Base import ../syntax/outline.bend as Outline import ../lazy/lazy.bend as Lazy import ../syntax/bind.bend as Bind
Types
type Edge source · line 59 · raw
Data
a file (normalized) and the files it imports relatively (normalized)
Edge@path:String -> @deps:List<&2, String> -> Edge
type EIx source · line 163 · raw
Data
The walk's indexes. Each step asks what a file imports, then whether each import was seen and was read, and scanning the edges, the files seen and the files read for each is the files squared: on a project of 4,062 files, 9.5 s of a 24 s run, three walks a role computation and two of those. So the edges are put in a trie on the low bits of each path's number, the binder index's shape (src/syntax/bind.bend), and the files seen and read in the binder's index itself, the seen ones put in as the walk finds them. A lookup off each is the scan (proofs/lemmas/WalkIndex.bend).
ENoneEIx
ELeaf@es:List<&2, Edge> -> EIx
ENode@lo:EIx -> @hi:EIx -> EIx
Definitions
def norm.put source · line 16 · raw
@+s:String -> @acc:List<&2, String> -> List<&2, String>
a segment onto the reversed path: . and empty are dropped, .. pops
def norm.go source · line 25 · raw
@segs:List<&2, String> -> @acc:List<&2, String> -> List<&2, String>
def norm source · line 33 · raw
@path:String -> String
a path without ./, ../ and doubled slashes, so two spellings compare
def init source · line 37 · raw
@segs:List<&2, String> -> List<&2, String>
the segments but the last
def dir_of source · line 47 · raw
@path:String -> String
a path's directory, with its slash (src/lsp/; `` at the root)
def resolve source · line 52 · raw
@+from:String -> @rel:String -> String
a path imported from a file, normalized
def targets source · line 63 · raw
@items:List<&2, 0x6d68cd62cf70fccf6858a2f9885ddbe4/src/syntax/outline.Item> -> @+from:String -> List<&2, String>
the relative imports among a file's items, resolved against it
def has source · line 74 · raw
@ps:List<&2, String> -> @+p:String -> Bool
is the path among them?
def deps.spec source · line 79 · raw
@es:List<&2, Edge> -> @+p:String -> List<&2, String>
what the file at p imports (nothing when it was not read): the spec deps.first is proven against (src/rules/PROOF.bend imp.deps)
def fresh.spec source · line 89 · raw
@ds:List<&2, String> -> @+seen:List<&2, String> -> @+read:List<&2, String> -> List<&2, String>
the files of ds that were read and are not yet seen, each once: the spec fresh.fast is proven against (imp.fresh)
def paths source · line 99 · raw
@es:List<&2, Edge> -> List<&2, String>
the paths of the files
def walk.spec source · line 110 · raw
@fuel:Nat -> @todo:List<&2, String> -> @+seen:List<&2, String> -> @+es:List<&2, Edge> -> @+read:List<&2, String> -> List<&2, String>
a worklist walk; each read file enters todo once, and a start that was
not read imports nothing, so fuel as many as the files never runs out
(src/rules/LAWS.bend unsafe_shut). The spec walk is proven against
(imp.walk), and what the laws' proofs reason over
def seek source · line 128 · raw
@ps:List<&2, String> -> @+pp:String -> Bool
has, stopping at the first hit
def deps.first source · line 136 · raw
@es:List<&2, Edge> -> @+p:String -> List<&2, String>
deps.spec, stopping at the first file of that path
def fresh.fast source · line 145 · raw
@ds:List<&2, String> -> @+seen:List<&2, String> -> @+read:List<&2, String> -> List<&2, String>
fresh.spec, asking the short lists first and each only while the answer is
open: a target already found or seen is never looked for among every file
def edges.ix.es source · line 169 · raw
@ix:EIx -> List<&2, Edge>
the edges at a leaf, none elsewhere
def edges.ix.pick source · line 179 · raw
@b:Bool -> @lo:EIx -> @hi:EIx -> EIx
the half a bit picks: an even bit the low half
def edges.ix.near source · line 187 · raw
@b:Bool -> @ix:EIx -> EIx
the half of a node a bit picks; none below anything else
def edges.ix.join source · line 195 · raw
@b:Bool -> @sub:EIx -> @far:EIx -> EIx
a node from the half a bit picks and the other half
def edges.ix.put source · line 203 · raw
@d:Nat -> @+k:U32 -> @+ix:EIx -> @e:Edge -> EIx
an edge put at the front of the leaf its path's number leads to
def edges.ix.at source · line 212 · raw
@d:Nat -> @+k:U32 -> @ix:EIx -> List<&2, Edge>
the edges at the leaf a number's low bits lead to
def edges.ix.of source · line 220 · raw
@es:List<&2, Edge> -> EIx
the index of these edges, each leaf in their order
def deps.ix source · line 228 · raw
@ex:EIx -> @+p:String -> List<&2, String>
what the file at p imports, read off the index: deps.first's
def seen.onto source · line 233 · raw
@xs:List<&2, String> -> @ix:0x6d68cd62cf70fccf6858a2f9885ddbe4/src/syntax/bind.Index -> 0x6d68cd62cf70fccf6858a2f9885ddbe4/src/syntax/bind.Index
these paths put in an index, the first nearest the top: the index of them followed by the ones it held
def fresh.ix source · line 241 · raw
@ds:List<&2, String> -> @+sx:0x6d68cd62cf70fccf6858a2f9885ddbe4/src/syntax/bind.Index -> @+rx:0x6d68cd62cf70fccf6858a2f9885ddbe4/src/syntax/bind.Index -> List<&2, String>
fresh.fast, the files seen and read asked of their indexes
def walk.ix source · line 254 · raw
@fuel:Nat -> @todo:List<&2, String> -> @+seen:List<&2, String> -> @+sx:0x6d68cd62cf70fccf6858a2f9885ddbe4/src/syntax/bind.Index -> @+ex:EIx -> @+rx:0x6d68cd62cf70fccf6858a2f9885ddbe4/src/syntax/bind.Index -> List<&2, String>
walk.spec, step for step, through the indexes: sx the files seen, ex the
edges, rx the files read
def walk source · line 273 · raw
@fuel:Nat -> @todo:List<&2, String> -> @+seen:List<&2, String> -> @+es:List<&2, Edge> -> @+read:List<&2, String> -> List<&2, String>
the walk: walk.spec, through the indexes above
def closure.go source · line 283 · raw
@es:List<&2, Edge> -> @+read:List<&2, String> -> @+fuel:Nat -> @+from:String -> List<&2, String>
the closure of the file at from, a path normalized already, over the graph