nx_quality_grade.nx
buildroot/runtime/nx_quality_grade.nx
about
nx_quality_grade.nx -- substrate self-grader with triangulation.
license_tier: INDEPENDENT_REDERIVE
genealogy_id: code-grader-perspectives-research/{sonarqube,clippy,elm,jpl,cert,linus,idris}
genealogy_id: international-research-sources/nasa_contractor/holzmann_2006_power_of_10
Answers the user's 2026-05-15 question: "is NishiLang a favela of
shit or the greatest building in the world?" Encodes the rules the
world's best static analyzers apply (SonarQube, clippy, Elm) and
runs them on NishiLang's own IR. Emits sealed-verdict per category
+ an overall A/B/C/D/F grade letter PER GRADER, plus a triangulated
verdict across all three so a single grader can't pat its own back.
TRIANGULATION (per the user's 2026-05-15 followup): one grader
alone is fart-smelling. Three independent graders, each encoding
a different industry tool's published thresholds, give us
triangulation -- a category counts as WIN only when 2+ graders
agree. Disagreements surface as CONTROVERSIAL signals worth
investigating.
AI-DRIFT GUARDRAILS (per the user's 2026-05-15 followup): AI tends
to produce sprawl + hacks + obtuse code + magic numbers + multiple
ways to do the same thing. Elm is the gold standard contrast:
handcrafted, one-way-to-do-X, every error message reads like a
teacher's note. Specific guardrails enforced in this file:
- One scan entry point (`nx_grade_card_scan`). No "convenience"
wrappers that duplicate the API surface.
- Every threshold has a `provenance:` citation in its comment;
no magic numbers.
- Triangulation lives in this file (not a separate
nx_grade_triangulate.nx) because splitting it would create
sprawl with no compensating benefit.
- Elm is the third grader specifically because Elm code is the
strictest published-style target -- if Elm says LOSE, that's a
real signal even if SonarQube says WIN.
PHILOSOPHY: before linting OTHER languages, grade yourself. Grade
with the toughest judges. Triangulate so no single judge can flatter
you. Fix what fails. Repeat until the substrate scores A
dependencies 4 imports · 5 importers
imports: nx_syscalls.nxnx_runtime.nxnx_types.nxnx_tier.nx
imported by: nx_quality_grade_daemon.nxnx_quality_grade_quad.nxnx_quality_grade_self.nxnx_quality_grade_septagon.nxnx_quality_grade_test.nx
structs
| 181 | struct GradeProfile |
| 569 | struct CategoryReport |
| 588 | struct GradeCard |
| 1520 | struct TriangulatedReport |
| 1537 | struct GradeTriangulation |
| 1768 | struct CardSet |
consts
| 73 | const NX_SEV_INFO: nx_int = 0 |
| 74 | const NX_SEV_WARN: nx_int = 1 |
| 75 | const NX_SEV_ERROR: nx_int = 2 |
| 76 | const NX_SEV_SECURITY: nx_int = 3 |
| 77 | const NX_SEV_N: nx_int = 4 |
| 81 | const NX_KIND_COMPLEXITY: nx_int = 0 |
| 82 | const NX_KIND_DEADCODE: nx_int = 1 |
| 83 | const NX_KIND_RELIABILITY: nx_int = 2 |
| 84 | const NX_KIND_SECURITY: nx_int = 3 |
| 85 | const NX_KIND_MAINTAIN: nx_int = 4 |
| 86 | const NX_KIND_PORTABILITY: nx_int = 5 |
| 87 | const NX_KIND_PERFORMANCE: nx_int = 6 |
| 88 | const NX_KIND_API_MISUSE: nx_int = 7 |
| 89 | const NX_KIND_N: nx_int = 8 |
| 93 | const NX_QV_UNMEASURED: nx_int = 0 |
| 94 | const NX_QV_LOSE: nx_int = 1 |
| 95 | const NX_QV_TIE: nx_int = 2 |
| 96 | const NX_QV_WIN: nx_int = 3 |
| 97 | const NX_QV_N: nx_int = 4 |
| 103 | const NX_GRADE_F: nx_int = 0 |
| 104 | const NX_GRADE_D: nx_int = 1 |
| 105 | const NX_GRADE_C: nx_int = 2 |
| 106 | const NX_GRADE_B: nx_int = 3 |
| 107 | const NX_GRADE_A: nx_int = 4 |
| 108 | const NX_GRADE_S: nx_int = 5 |
| 109 | const NX_GRADE_N: nx_int = 6 |
| 118 | const NX_GRADE_CCN_WARN: nx_int = 15 |
| 119 | const NX_GRADE_CCN_ERROR: nx_int = 25 |
| 120 | const NX_GRADE_CCN_WIN_P99: nx_int = 14 // WIN if p99 < 15 - 1 |
| 125 | const NX_GRADE_FNLEN_WARN: nx_int = 80 |
| 126 | const NX_GRADE_FNLEN_ERROR: nx_int = 150 |
| 127 | const NX_GRADE_FNLEN_WIN_P99: nx_int = 79 |
| 130 | const NX_GRADE_DEAD_WIN_MAX: nx_int = 0 |
| 165 | const NX_GRADE_PROV_SONARQUBE: nx_int = 0 |
| 166 | const NX_GRADE_PROV_CLIPPY: nx_int = 1 |
| 167 | const NX_GRADE_PROV_ELM: nx_int = 2 |
| 168 | const NX_GRADE_PROV_JPL: nx_int = 3 |
| 169 | const NX_GRADE_PROV_CERT: nx_int = 4 |
| 170 | const NX_GRADE_PROV_LINUS: nx_int = 5 |
| 171 | const NX_GRADE_PROV_IDRIS: nx_int = 6 |
| 172 | const NX_GRADE_PROV_N: nx_int = 7 |
| 623 | const NX_GRADE_CAT_STRIDE: nx_int = 96 |
| 624 | const NX_GRADE_N_CATS: nx_int = 8 |
| 655 | const NX_GRADE_CARD_BYTES: nx_size = 1024 |
| 700 | const NX_GRADE_FUNCTION_STRIDE: nx_int = 176 |
| 701 | const NX_GRADE_INSTR_STRIDE: nx_int = 128 |
| 705 | const NX_GRADE_TRI_STRIDE: nx_int = 80 |
| 836 | const NX_GRADE_TIER0_EMIT_FACTOR: nx_int = 16 |
| 1566 | const NX_GRADE_TRI_VERDICT_OFFSET: nx_int = 24 |
| 1571 | const NX_TRIANGULATION_BYTES: nx_size = 1024 |
functions
| 236 | func nx_grade_profile_sonarqube(p: *GradeProfile) -> nx_int |
| 273 | func nx_grade_profile_clippy(p: *GradeProfile) -> nx_int |
| 321 | func nx_grade_profile_elm(p: *GradeProfile) -> nx_int |
| 376 | func nx_grade_profile_jpl(p: *GradeProfile) -> nx_int |
| 428 | func nx_grade_profile_cert(p: *GradeProfile) -> nx_int called by 1: _setup_cardset_7 |
| 470 | func nx_grade_profile_linus(p: *GradeProfile) -> nx_int called by 1: _setup_cardset_7 |
| 515 | func nx_grade_profile_idris(p: *GradeProfile) -> nx_int called by 1: _setup_cardset_7 |
| 550 | func nx_grade_provenance_is_valid(p: nx_int) -> nx_int |
| 626 | func _grade_cat_at(card: *GradeCard, idx: nx_int) -> *CategoryReport |
| 644 | func _inc_by_idx(base: *nx_int, idx: nx_int) -> nx_int |
| 657 | func nx_grade_card_alloc() -> *GradeCard |
| 662 | func _cat_zero(c: *CategoryReport, kind: nx_int) -> nx_int called by 1: nx_grade_card_init |
| 678 | func nx_grade_card_init(card: *GradeCard) -> nx_int |
| 707 | func _function_at(m: *Module, idx: nx_int) -> *Function |
| 712 | func _instr_at(f: *Function, idx: nx_int) -> *Instr |
| 725 | func _count_ccn(f: *Function) -> nx_int |
| 741 | func _classify_severity(c: *CategoryReport, value: nx_int, |
| 754 | func _rule_complexity(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 768 | func _rule_function_length(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 786 | func _count_returns(f: *Function) -> nx_int |
| 797 | func _rule_explicit_return(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 811 | func _verdict_reliability(c: *CategoryReport, p: *GradeProfile) -> nx_int called by 1: _compute_verdicts_layer0 |
| 838 | func _rule_tier_zero_fits(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 846 | func _verdict_portability(c: *CategoryReport, p: *GradeProfile) -> nx_int called by 1: _compute_verdicts_layer2 |
| 866 | func _count_calls(f: *Function) -> nx_int |
| 877 | func _rule_fanout(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 885 | func _verdict_performance(c: *CategoryReport, p: *GradeProfile) -> nx_int called by 1: _compute_verdicts_layer2 |
| 907 | func _is_syscall_wrapper(f: *Function) -> nx_int called by 1: _rule_syscall_leak |
| 920 | func _count_syscalls(f: *Function) -> nx_int |
| 931 | func _rule_syscall_leak(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 946 | func _verdict_security(c: *CategoryReport, p: *GradeProfile) -> nx_int called by 1: _compute_verdicts_layer2 |
| 960 | func _name_starts_with(f: *Function, prefix: *u8, plen: nx_int) -> nx_int called by 1: _count_fd_balance |
| 971 | func _name_equals(f: *Function, target: *u8, tlen: nx_int) -> nx_int called by 1: _count_fd_balance |
| 982 | func _count_fd_balance(f: *Function) -> nx_int |
| 1006 | func _rule_fd_leak(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 1028 | func _rule_wide_signature(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 1035 | func _verdict_api_misuse(c: *CategoryReport, p: *GradeProfile) -> nx_int called by 1: _compute_verdicts_layer2 |
| 1053 | func _count_self_calls(f: *Function) -> nx_int |
| 1066 | func _rule_no_recursion(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 1086 | func _is_main(f: *Function) -> nx_int called by 1: _rule_dead_functions |
| 1108 | func _is_public_export(f: *Function) -> nx_int called by 1: _rule_dead_functions |
| 1117 | func _function_is_called(m: *Module, target: *Function) -> nx_int |
| 1134 | func _rule_dead_functions(card: *GradeCard, m: *Module, p: *GradeProfile) -> nx_int |
| 1169 | func _verdict_complexity(c: *CategoryReport, p: *GradeProfile) -> nx_int called by 1: _compute_verdicts_layer0 |
| 1178 | func _verdict_fn_length(c: *CategoryReport, p: *GradeProfile) -> nx_int called by 1: _compute_verdicts_layer0 |
| 1187 | func _verdict_deadcode(c: *CategoryReport, p: *GradeProfile) -> nx_int called by 1: _compute_verdicts_layer0 |
| 1210 | func _run_layer0_rules(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 1218 | func _run_layer2_rules(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 1228 | func _run_per_fn_rules(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int |
| 1234 | func nx_grade_card_scan(card: *GradeCard, m: *Module, p: *GradeProfile) -> nx_int called by 5: mainmainmain_grade_card_formain calls 3: _run_per_fn_rules_function_at_rule_dead_functions |
| 1257 | func _grade_card_count_security(card: *GradeCard) -> nx_int |
| 1272 | func _bump_counts(card: *GradeCard, verdict: nx_int) -> nx_int |
| 1299 | func _grade_letter(wins: nx_int, losses: nx_int) -> nx_int |
| 1320 | func _compute_verdicts_layer0(card: *GradeCard, p: *GradeProfile) -> nx_int called by 1: _compute_verdicts calls 4: _verdict_complexity_verdict_fn_length_verdict_deadcode_verdict_reliability |
| 1328 | func _compute_verdicts_layer2(card: *GradeCard, p: *GradeProfile) -> nx_int |
| 1336 | func _compute_verdicts(card: *GradeCard, p: *GradeProfile) -> nx_int |
| 1343 | func _compute_aggregates(card: *GradeCard) -> nx_int |
| 1359 | func nx_grade_card_compute(card: *GradeCard, p: *GradeProfile) -> nx_int |
| 1376 | func nx_grade_severity_is_valid(s: nx_int) -> nx_int called by 1: main |
| 1382 | func nx_grade_kind_is_valid(k: nx_int) -> nx_int called by 1: main |
| 1388 | func nx_grade_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 1394 | func nx_grade_letter_is_valid(g: nx_int) -> nx_int called by 1: main |
| 1416 | func _grade_letter_str(g: nx_int) -> *u8 |
| 1425 | func _verdict_str(v: nx_int) -> *u8 |
| 1432 | func _kind_str(k: nx_int) -> *u8 |
| 1446 | func _named_improvement(kind: nx_int) -> *u8 called by 1: _emit_category |
| 1457 | func _emit_category(c: *CategoryReport) -> nx_int called by 1: nx_grade_card_emit calls 7: print_kind_str_verdict_strprint_i64sys_write_named_improvement+1 |
| 1485 | func _emit_card_header(card: *GradeCard) -> nx_int |
| 1502 | func nx_grade_card_emit(card: *GradeCard) -> nx_int |
| 1576 | func _grade_tri_at(tr: *GradeTriangulation, idx: nx_int) -> *TriangulatedReport |
| 1581 | func nx_grade_triangulation_alloc() -> *GradeTriangulation |
| 1603 | func _count_votes(a: nx_int, b: nx_int, c: nx_int, d: nx_int, target: nx_int) -> nx_int called by 1: _vote4 |
| 1614 | func _count_buckets_with_n(n_win: nx_int, n_tie: nx_int, |
| 1625 | func _vote4(a: nx_int, b: nx_int, c: nx_int, d: nx_int, |
| 1653 | func _count_in_array(verdicts: *nx_int, n: nx_int, target: nx_int) -> nx_int called by 1: _vote_n |
| 1663 | func _vote_n(verdicts: *nx_int, n: nx_int, out_disagreement: *nx_int) -> nx_int |
| 1686 | func _vote(a: nx_int, b: nx_int, c: nx_int, out_disagreement: *nx_int) -> nx_int called by 1: _triangulate_one |
| 1702 | func _zero_higher_slots(t: *TriangulatedReport) -> nx_int |
| 1709 | func _triangulate_one(t: *TriangulatedReport, kind: nx_int, |
| 1728 | func _polyangulate_one(t: *TriangulatedReport, kind: nx_int, |
| 1755 | func _bump_tri(tr: *GradeTriangulation, verdict: nx_int, disagreement: nx_int) -> nx_int |
| 1779 | func _zero_poly_counters(tr: *GradeTriangulation) -> nx_int |
| 1791 | func _gather_verdicts(verdicts: *nx_int, cs: *CardSet, i: nx_int) -> nx_int |
| 1804 | func nx_grade_polyangulate(tr: *GradeTriangulation, called by 1: main calls 7: _zero_poly_counterssys_mmap_gather_verdicts_grade_tri_at_polyangulate_one_bump_tri+1 |
| 1835 | func _gather_verdicts_7(verdicts: *nx_int, cs: *CardSet, i: nx_int) -> nx_int |
| 1853 | func _heptagulate_one(t: *TriangulatedReport, kind: nx_int, |
| 1874 | func nx_grade_heptagulate(tr: *GradeTriangulation, cs: *CardSet) -> nx_int called by 1: main calls 7: _zero_poly_counterssys_mmap_gather_verdicts_7_grade_tri_at_heptagulate_one_bump_tri+1 |
| 1894 | func _triangulate_one_cat(tr: *GradeTriangulation, cs: *CardSet, |
| 1914 | func _build_3cardset(sq: *GradeCard, cl: *GradeCard, |
| 1929 | func nx_grade_triangulate(tr: *GradeTriangulation, called by 3: mainmainmain calls 5: _zero_poly_counters_build_3cardsetsys_mmap_triangulate_one_cat_grade_letter |
| 1947 | func _emit_graders_0_3(t: *TriangulatedReport) -> nx_int |
| 1959 | func _emit_graders_4_6(t: *TriangulatedReport) -> nx_int |
| 1969 | func _emit_tri_category(t: *TriangulatedReport) -> nx_int called by 1: nx_grade_triangulation_emit calls 7: print_kind_str_verdict_str_emit_graders_0_3_emit_graders_4_6print_i64+1 |
| 1983 | func _emit_tri_header(tr: *GradeTriangulation) -> nx_int |
| 2000 | func nx_grade_triangulation_emit(tr: *GradeTriangulation) -> nx_int |