src/rules/links.bend checks
raw source on the hub · import bolt@1.67.0.0/src/rules/links.bend as Links
src/rules/links: what a file's imports are to it, read once for the
project rule spare (rules/suspicious/spare.bend) and kept in the file's
digest (rules/digest.bend). Two things: the imports whose alias the file
never names, and whether importing the file does something besides making
its names available.
An import is named by its alias (import ./ops.bend as O); the file names
the alias when a dotted name outside an import line starts with it and a
dot (O.add, O.Shape{..}, def O.lemma(..)). A comment or a string is
no name, and an import line's own path is none either (./O.bend).
A file loads when it states a law, holds a def that is a proof (one that
returns -> {..}, or has no type: rules/calls.bend's proof), or holds a
foreign def (one whose body opens with import). bend checks a law and
a proof with whatever imports their file, and links a foreign def only
when the entry reaches its file, so an import of such a file has a use
though nothing names its alias. Pure.
8 imports
import Base import ../syntax/lex.bend as Lex import ../syntax/tree.bend as Tree import ../syntax/outline.bend as Outline import ../lazy/lazy.bend as Lazy import ./imports.bend as Imports import ./calls.bend as Calls import ./suspicious/unused.bend as Unused
Types
type Spare source · line 29 · raw
Data
an import the file never names: its alias, the file it names (resolved against the importer and normalized) and the line it is on
Spare@alias:String -> @path:String -> @line:U32 -> Spare
type Links source · line 33 · raw
Data
a file's links: whether it loads, and its spare imports
Links@loads:Bool -> @spare:List<&2, Spare> -> Links
Definitions
def dotted source · line 38 · raw
@k:0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/lex.TokKind -> @t:String -> @prefix:String -> Bool
is the token a dotted name that starts with the prefix (an alias and a dot)?
def opens source · line 46 · raw
@k:0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/lex.TokKind -> @t:String -> Bool
is the token the keyword import?
def skips source · line 55 · raw
@+k:0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/lex.TokKind -> @t:String -> @skip:Bool -> Bool
is the walk still on an import line past this token: one it was on that has not ended, or one this token opens?
def names.go source · line 61 · raw
@toks:List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/lex.Tok> -> @+prefix:String -> @skip:Bool -> @hit:Bool -> Bool
does a dotted name among the tokens, outside every import line, start with the prefix? skip: the walk is on an import line; hit: a token before these was such a name, so the answer is known
def names source · line 73 · raw
@toks:List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/lex.Tok> -> @alias:String -> Bool
does the file name the alias: a dotted name outside its import lines that starts with the alias and a dot?
def local source · line 79 · raw
@name:String -> @+path:String -> Bool
is an import one of a file by a relative path, under an alias of its own
(import Base is named by its path, and a hub package's path is not
relative)?
def spares source · line 84 · raw
@items:List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/outline.Item> -> @+toks:List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/lex.Tok> -> @+from:String -> List<&2, Spare>
the imports of files by relative paths whose alias the tokens never name, in order
def uses source · line 96 · raw
@items:List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/outline.Item> -> @+toks:List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/lex.Tok> -> Bool
does the file name the alias of any import of its own?
def spare source · line 108 · raw
@+items:List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/outline.Item> -> @+toks:List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/lex.Tok> -> @from:String -> List<&2, Spare>
a file's spare imports: those it never names, when it names another. A file that names none of its imports loads them (an entry, a harness, a list of what a package publishes); it has no leftover among them
def loads.def source · line 112 · raw
@+kids:0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/tree.Node -> @+body:0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/tree.Node -> Bool
does a def load: is it a proof, or foreign?
def loads source · line 117 · raw
@root:0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/tree.Node -> Bool
does the file load: a law, a def that is a proof, or a foreign def among its top-level statements?
def of source · line 129 · raw
@items:List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/outline.Item> -> @toks:List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/lex.Tok> -> @tree:0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/tree.Node -> @from:String -> Links
a parsed file's links, its path normalized already