src/codes.bend
bolt@1.26.0.0 · 104 lines · 0 definitions
1# src/codes: the stable id of every rule. A bolt.bend still names the slug
2# (`wrap`); a diagnostic shows the code (`S003`) and, in an editor, the
3# source `bolt(group:slug)`. Numbers are assigned once, in the group order
4# of src/README.md: do not renumber a rule, and do not reuse a retired code
5# (L004 was `quantify`, now `closed` itself; C001 was `shadow` and U005 was
6# `nat`, whose failures bend 2.0.25 no longer has; U014 was `argv`, retired
7# before its first release, since every reader already drops the program;
8# U008 `table`, U009 `hoist`, U010 `ring`, U012 `unit` and U013 `scan` were
9# retired for want of real hits, and L003 `unsafe` since bend 2.0.32 reports
10# an unsafe def a proof reaches itself). A code names the rule, not its
11# group: a rule that moves keeps its code (`strings` and `chars` are `perf`,
12# `foreign` and the cost rules `fuel`, `index`, `strict` and `rewalk` are
13# `pedantic`).
14#
15# No law can say this, since it is about versions: a released code is never
16# renumbered or reused, which review of this table keeps.
17import Base
18import bolt@1.26.0.0/src/lazy/lazy.bend as Lazy
19
20# one rule: the slug bolt.bend names, its code, its group
21type Entry is Data:
22 Entry{slug: String, id: String, grp: String}
23
24# every rule, in group order
25def table() -> List<&2, Entry>:
26 [
27 Entry{"hole", "C002", "correctness"},
28 Entry{"pick", "C003", "correctness"},
29 Entry{"put", "C004", "correctness"},
30 Entry{"arms", "C005", "correctness"},
31 Entry{"escape", "C006", "correctness"},
32 Entry{"twice", "C007", "correctness"},
33 Entry{"setting", "C011", "correctness"},
34 Entry{"unused", "U001", "suspicious"},
35 Entry{"eager", "U003", "suspicious"},
36 Entry{"concat", "U004", "suspicious"},
37 Entry{"thunk", "U015", "suspicious"},
38 Entry{"fromrev", "U016", "suspicious"},
39 Entry{"prefix", "U017", "suspicious"},
40 Entry{"strings", "C008", "perf"},
41 Entry{"chars", "C009", "perf"},
42 Entry{"doc", "S001", "style"},
43 Entry{"space", "S002", "style"},
44 Entry{"wrap", "S003", "style"},
45 Entry{"param", "S004", "style"},
46 Entry{"noqa", "S005", "style"},
47 Entry{"transcong", "S006", "style"},
48 Entry{"coverage", "L001", "laws"},
49 Entry{"closed", "L002", "laws"},
50 Entry{"foreign", "C010", "pedantic"},
51 Entry{"strict", "U002", "pedantic"},
52 Entry{"fuel", "U006", "pedantic"},
53 Entry{"index", "U007", "pedantic"},
54 Entry{"rewalk", "U011", "pedantic"},
55 Entry{"tail", "P001", "pedantic"}]
56
57# this row is the slug
58def find.same(+row: Entry, +slug: String) -> Bool:
59 Entry{+s, _id, _grp} = row
60 String.eq(s, slug)
61
62# the row for a slug
63def find(rows: List<&2, Entry>, +slug: String) -> Maybe<&2, Entry>:
64 match rows:
65 case Nil{}:
66 None{}
67 case Con{+row, rest}:
68 Lazy.stop(Maybe<&2, Entry>, find.same(row, slug), Some{row}, _u => find(rest, slug))
69
70# the stable code; the slug itself when it is not a rule
71def code.at(mm: Maybe<&2, Entry>, +slug: String) -> String:
72 match mm:
73 case None{}:
74 slug
75 case Some{Entry{_s, +id, _grp}}:
76 id
77
78# the stable code; the slug itself when it is not a rule
79def code(+slug: String) -> String:
80 code.at(find(table(), slug), slug)
81
82# the group; empty when the slug is not a rule
83def group.at(mm: Maybe<&2, Entry>) -> String:
84 match mm:
85 case None{}:
86 ""
87 case Some{Entry{_s, _id, +grp}}:
88 grp
89
90# the group; empty when the slug is not a rule
91def group(+slug: String) -> String:
92 group.at(find(table(), slug))
93
94# `bolt(group:slug)`; `bolt` when the slug is not a rule
95def source.at(mm: Maybe<&2, Entry>) -> String:
96 match mm:
97 case None{}:
98 "bolt"
99 case Some{Entry{+s, _id, +grp}}:
100 "bolt(" ++ grp ++ ":" ++ s ++ ")"
101
102# `bolt(group:slug)`; `bolt` when the slug is not a rule
103def source(+slug: String) -> String:
104 source.at(find(table(), slug))