performance/repeated_call.bend checks
raw source on the hub · import bend-lint-rules@0.2.0.0/performance/repeated_call.bend as Repeated_call
performance/repeated_call: a call made again, with the same arguments, on one path of a definition: a
second call of a definition of the file that loops and returns a number, with its arguments written the
same way, in the same branch (the innermost case around both, or the definition's body).
Heuristics: clang does not merge two calls of a definition that loops: Bend runs each through its own
calls. Measured on the CPU, pow2(30) written Nat.add(pow2(q), pow2(q)) took 3.4 s; with the two calls
forked (a parallel let), 0.6 s; computed once (+h = pow2(q)), 0.1 s, the program's start. In
eldergrove-faire and in llama.bend's tokenizer, computing such calls once changed nothing measurable:
they walk short lists. Arguments are the same when written the same way: the same variables, literals,
and calls or constructions of them. Calls in a lambda, in a type, in a proof, or in the values of
Bool.pick, && or || (which performance/eager_branch judges) do not count, nor do the values of one
parallel let: copies made in parallel on purpose, as benchmarks do. A call that
performance/loop_invariant_call reports is left to it: computing it once before the loop also ends the
repeat. Only a number is sure to be shareable at no cost: data may be affine (an Array), so that it
must be built twice, and sharing it counts references; it is skipped. Numbers are those of
performance/gpu_fit, as the callee's return type is written.
8 imports
import Base import bend-lint-api@0.2.0.0/linter/lint.bend as Lint import bend-lint-api@0.2.0.0/shared/lists.bend as Lists import bend-lint-api@0.2.0.0/shared/names.bend as Names import ./deep_call_in_fork.bend as Deep import ./gpu_fit.bend as GpuFit import ./loop_invariant_call.bend as Invariant import ./missed_fork.bend as Fork
Types
type Call source · line 30 · raw
Data
A call of a definition that loops: the definition (as the check names it, and as written), its arguments, where it is written, and where its branch starts (0 for a definition's body).
Call@target:String -> @callee:String -> @args:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node> -> @span:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Span -> @branch:U32 -> Call
type Scope source · line 36 · raw
Data
What finding the calls of one definition reads: what performance/loop_invariant_call reads to judge them, with the definitions of the file that call themselves (as the check names them), and the program's definitions, by the name the check gives them.
Scope@owner:0x29a8624e9659aaa2c25b485f2135a43a/performance/loop_invariant_call.Owner -> @defs:Map<&2, Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def>> -> Scope
Definitions
def Call.target source · line 41 · raw
@c:Call -> String
Functions =========
def Call.callee source · line 46 · raw
@c:Call -> String
def Call.args source · line 51 · raw
@c:Call -> List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node>
def Call.span source · line 56 · raw
@c:Call -> 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Span
def Call.branch source · line 61 · raw
@c:Call -> U32
def message source · line 66 · raw
@callee:String -> @loop:String -> String
def is_guarded source · line 74 · raw
@path:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Above> -> @found:Bool -> Bool
Whether a node below path may not run on the path of its branch, or runs as a copy made on purpose: under a lambda,
a value of a choice (Bool.pick, Bool.and, Bool.or), or a value of a parallel let.
def first_beg source · line 90 · raw
@+fuel:Nat -> @nodes:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node> -> U32
Where the first of nodes, or a node under it, that has a place starts.
def branch.at source · line 102 · raw
@b:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node> -> U32
Where a branch starts (a case has no place of its own: its first node with one), or 0 for a definition's body.
def returns_number source · line 110 · raw
@info:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def> -> Bool
Whether a definition of the program says it returns a number.
def is_kept source · line 118 · raw
@ok:Bool -> @owner:0x29a8624e9659aaa2c25b485f2135a43a/performance/loop_invariant_call.Owner -> @path:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Above> -> @node:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node -> Bool
Whether a call that counts so far (if ok) still counts: not if performance/loop_invariant_call reports it.
def visit source · line 126 · raw
@+scope:Scope -> @+path:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Above> -> @+node:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node -> List<&2, Call>
The call of a definition that loops at an application below path, if it counts.
def is_shallow source · line 162 · raw
@x:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node -> @y:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node -> Bool
Whether two nodes, as written, are the same at their top: the same variable, literal or reference, or the same kind of application, annotation or construction (their nodes below are compared next).
def is_same source · line 180 · raw
@+fuel:Nat -> @xs:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node> -> @ys:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node> -> @ok:Bool -> Bool
Whether xs and ys are written the same way, node by node and below (if ok); fuel bounds the nodes compared.
def repeats source · line 199 · raw
@seen:List<&2, Call> -> @+c:Call -> @found:Bool -> Bool
Whether c repeats a call of seen: the same definition, in the same branch, with arguments written the same way.
def judged source · line 218 · raw
@calls:List<&2, Call> -> @+seen:List<&2, Call> -> @+loop:String -> @out:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding> -> List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding>
The findings about the calls of one definition (loop, as written) that repeat an earlier one, onto out.
def calls.of source · line 246 · raw
@proof:Bool -> @loops:List<&2, String> -> @defs:Map<&2, Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def>> -> @+node:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node -> List<&2, Call>
The calls of a definition (node) that count, unless it is a proof.
def defs source · line 258 · raw
@nodes:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node> -> @+loops:List<&2, String> -> @+program:Map<&2, Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def>> -> @out:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding> -> List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding>
def run source · line 287 · raw
@+here:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Here -> 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Ask(List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding>)
def rule source · line 298 · raw
0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Rule