~/bend-docscommunity

src/rules/style/transcong.bend checks

raw source on the hub · import bolt@1.52.0.0/src/rules/style/transcong.bend as Transcong

rule transcong (opt-in): an Equal.trans that an Equal.cong feeds (the name is the two calls, as in fromrev), which a rewrite says shorter. Equal.trans(T, a, b, c, Equal.cong(S, T, x => F(x), u, v, e), r) proves {F(u) == c : T} from r : {F(v) == c : T}, and spells F(u) and F(v) out once more each, as a and b; the rewrite %Equal.sym(S, u, v, e) : {F(_) == c : T}, then r on the next line, names the motive once and drops the middle term (%e alone when e is itself an Equal.sym). With the cong last, Equal.trans(T, a, b, c, r, Equal.cong(S, T, x => F(x), u, v, e)) is %e : {a == F(_) : T}, then r. The rewrite is a statement: in an argument it goes in parentheses, (%e : P; r). A let has no type to check it against, so in one (+q = Equal.trans(..)) the rewrite needs an annotation and is left alone. Exactly: a leaf of a name kind whose text is Equal.trans, then, next in its chain, a group opened by ( whose kids, split at their comma leaves, are six arguments (five comma leaves among the kids' own nodes), the fifth or the sixth of which is exactly a leaf of a name kind whose text is Equal.cong and a group opened by ( (the kids end right after the group or go on with a comma); not among the own nodes of a let statement (a = or <- among its tokens, as src/syntax/tree.bend reads it) and not after a = or <- leaf earlier in its own chain (a let inside a group, as in a lambda's body written in an argument, which the tree keeps as one chain rather than statements: the rest of that chain is the let's value, or code after it the rule leaves alone), and found at any depth otherwise, under statements and inside groups. One finding for each, on the Equal.trans leaf. The rule reads the shape, not the types: a motive that _ cannot mark (a cong under a binder of the lambda's own, or a chain whose middle term is not the cong's) is still reported. Laws and proofs are where it looks, so nothing is exempt.

5 imports
import Base
import ../../src.bend as Src
import ../../finding.bend as F
import ../../syntax/lex.bend as Lex
import ../../syntax/tree.bend as Tree

Definitions

def named source · line 36 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+tt:String -> Bool

is the node a leaf of a name kind with this text?

def paren source · line 44 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Bool

is the node a group opened by (?

def comma source · line 52 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Bool

is the node a comma leaf?

def ends source · line 60 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Bool

does the chain end here, or go on with a comma?

def cong.call source · line 68 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Bool

past the Equal.cong leaf: a ( group, then the argument's end

def cong source · line 76 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Bool

does the chain open an argument that is exactly an Equal.cong call?

def commas source · line 84 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Nat

the comma leaves among a chain's own nodes

def late source · line 92 · raw

@+nc:Nat -> Bool

is an argument with nc commas before it the fifth or the sixth?

def fed source · line 98 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+nc:Nat -> @+fresh:Bool -> @+seen:Bool -> Bool

from here on in a group's kids, does the fifth or sixth argument open with an Equal.cong call? nc: the commas so far; fresh: an argument opens here; seen: one did already

def shape source · line 108 · raw

@+kids:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Bool

are a call's kids six arguments, the fifth or the sixth an Equal.cong?

def args source · line 112 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Bool

past the Equal.trans leaf: a ( group of that shape

def cite source · line 120 · raw

@+ll:U32 -> @+cc:U32 -> @+path:String -> 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding

the finding at the Equal.trans leaf

def site source · line 125 · raw

@hh:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @rest:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+path:String -> List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding>

the finding when a node and the chain after it open the shape

def binds source · line 134 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Bool

is the node a = or <- leaf, a let's?

def is_let source · line 144 · raw

@sk:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.StmtKind -> Bool

is the statement a let?

def walk source · line 153 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+top:Bool -> @+path:String -> List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding>

every site under the node, at any depth; top: the node is not among a let's own nodes, nor after a = or <- leaf in its chain

def check source · line 167 · raw

@ss:0xfb394c8f685b7b3a6abb1443099643d8/src/src.Src -> List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding>

the rule