code wiki / (root) / nx_quality_grade.nx

nx_quality_grade.nx

buildroot/runtime/nx_quality_grade.nx

79013 B2008 linesdepth 3pulls 4 transitivereach 5 importersview sourcekind librarytopic quality
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_runtime.nx nx_types.nx nx_tier.nx nx_quality_grade.nx nx_quality_grade_daemon.nx nx_quality_grade_quad.nx nx_quality_grade_self.nx nx_quality_grade_septagon.nx nx_quality_grade_test.nx

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

181struct GradeProfile
569struct CategoryReport
588struct GradeCard
1520struct TriangulatedReport
1537struct GradeTriangulation
1768struct CardSet

consts

73const NX_SEV_INFO: nx_int = 0
74const NX_SEV_WARN: nx_int = 1
75const NX_SEV_ERROR: nx_int = 2
76const NX_SEV_SECURITY: nx_int = 3
77const NX_SEV_N: nx_int = 4
81const NX_KIND_COMPLEXITY: nx_int = 0
82const NX_KIND_DEADCODE: nx_int = 1
83const NX_KIND_RELIABILITY: nx_int = 2
84const NX_KIND_SECURITY: nx_int = 3
85const NX_KIND_MAINTAIN: nx_int = 4
86const NX_KIND_PORTABILITY: nx_int = 5
87const NX_KIND_PERFORMANCE: nx_int = 6
88const NX_KIND_API_MISUSE: nx_int = 7
89const NX_KIND_N: nx_int = 8
93const NX_QV_UNMEASURED: nx_int = 0
94const NX_QV_LOSE: nx_int = 1
95const NX_QV_TIE: nx_int = 2
96const NX_QV_WIN: nx_int = 3
97const NX_QV_N: nx_int = 4
103const NX_GRADE_F: nx_int = 0
104const NX_GRADE_D: nx_int = 1
105const NX_GRADE_C: nx_int = 2
106const NX_GRADE_B: nx_int = 3
107const NX_GRADE_A: nx_int = 4
108const NX_GRADE_S: nx_int = 5
109const NX_GRADE_N: nx_int = 6
118const NX_GRADE_CCN_WARN: nx_int = 15
119const NX_GRADE_CCN_ERROR: nx_int = 25
120const NX_GRADE_CCN_WIN_P99: nx_int = 14 // WIN if p99 < 15 - 1
125const NX_GRADE_FNLEN_WARN: nx_int = 80
126const NX_GRADE_FNLEN_ERROR: nx_int = 150
127const NX_GRADE_FNLEN_WIN_P99: nx_int = 79
130const NX_GRADE_DEAD_WIN_MAX: nx_int = 0
165const NX_GRADE_PROV_SONARQUBE: nx_int = 0
166const NX_GRADE_PROV_CLIPPY: nx_int = 1
167const NX_GRADE_PROV_ELM: nx_int = 2
168const NX_GRADE_PROV_JPL: nx_int = 3
169const NX_GRADE_PROV_CERT: nx_int = 4
170const NX_GRADE_PROV_LINUS: nx_int = 5
171const NX_GRADE_PROV_IDRIS: nx_int = 6
172const NX_GRADE_PROV_N: nx_int = 7
623const NX_GRADE_CAT_STRIDE: nx_int = 96
624const NX_GRADE_N_CATS: nx_int = 8
655const NX_GRADE_CARD_BYTES: nx_size = 1024
700const NX_GRADE_FUNCTION_STRIDE: nx_int = 176
701const NX_GRADE_INSTR_STRIDE: nx_int = 128
705const NX_GRADE_TRI_STRIDE: nx_int = 80
836const NX_GRADE_TIER0_EMIT_FACTOR: nx_int = 16
1566const NX_GRADE_TRI_VERDICT_OFFSET: nx_int = 24
1571const NX_TRIANGULATION_BYTES: nx_size = 1024

functions

236func nx_grade_profile_sonarqube(p: *GradeProfile) -> nx_int
273func nx_grade_profile_clippy(p: *GradeProfile) -> nx_int
321func nx_grade_profile_elm(p: *GradeProfile) -> nx_int
376func nx_grade_profile_jpl(p: *GradeProfile) -> nx_int
428func nx_grade_profile_cert(p: *GradeProfile) -> nx_int
called by 1: _setup_cardset_7
470func nx_grade_profile_linus(p: *GradeProfile) -> nx_int
called by 1: _setup_cardset_7
515func nx_grade_profile_idris(p: *GradeProfile) -> nx_int
called by 1: _setup_cardset_7
550func nx_grade_provenance_is_valid(p: nx_int) -> nx_int
626func _grade_cat_at(card: *GradeCard, idx: nx_int) -> *CategoryReport
644func _inc_by_idx(base: *nx_int, idx: nx_int) -> nx_int
657func nx_grade_card_alloc() -> *GradeCard
662func _cat_zero(c: *CategoryReport, kind: nx_int) -> nx_int
called by 1: nx_grade_card_init
678func nx_grade_card_init(card: *GradeCard) -> nx_int
707func _function_at(m: *Module, idx: nx_int) -> *Function
712func _instr_at(f: *Function, idx: nx_int) -> *Instr
725func _count_ccn(f: *Function) -> nx_int
called by 1: _rule_complexity calls 1: _instr_at
741func _classify_severity(c: *CategoryReport, value: nx_int,
754func _rule_complexity(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
768func _rule_function_length(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
786func _count_returns(f: *Function) -> nx_int
called by 1: _rule_explicit_return calls 1: _instr_at
797func _rule_explicit_return(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
called by 1: _run_layer0_rules calls 1: _count_returns
811func _verdict_reliability(c: *CategoryReport, p: *GradeProfile) -> nx_int
838func _rule_tier_zero_fits(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
846func _verdict_portability(c: *CategoryReport, p: *GradeProfile) -> nx_int
866func _count_calls(f: *Function) -> nx_int
called by 1: _rule_fanout calls 1: _instr_at
877func _rule_fanout(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
885func _verdict_performance(c: *CategoryReport, p: *GradeProfile) -> nx_int
907func _is_syscall_wrapper(f: *Function) -> nx_int
called by 1: _rule_syscall_leak
920func _count_syscalls(f: *Function) -> nx_int
called by 1: _rule_syscall_leak calls 1: _instr_at
931func _rule_syscall_leak(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
946func _verdict_security(c: *CategoryReport, p: *GradeProfile) -> nx_int
960func _name_starts_with(f: *Function, prefix: *u8, plen: nx_int) -> nx_int
called by 1: _count_fd_balance
971func _name_equals(f: *Function, target: *u8, tlen: nx_int) -> nx_int
called by 1: _count_fd_balance
982func _count_fd_balance(f: *Function) -> nx_int
1006func _rule_fd_leak(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
called by 1: _run_layer2_rules calls 1: _count_fd_balance
1028func _rule_wide_signature(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
1035func _verdict_api_misuse(c: *CategoryReport, p: *GradeProfile) -> nx_int
1053func _count_self_calls(f: *Function) -> nx_int
called by 1: _rule_no_recursion calls 1: _instr_at
1066func _rule_no_recursion(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
called by 1: _run_layer2_rules calls 1: _count_self_calls
1086func _is_main(f: *Function) -> nx_int
1108func _is_public_export(f: *Function) -> nx_int
1117func _function_is_called(m: *Module, target: *Function) -> nx_int
1134func _rule_dead_functions(card: *GradeCard, m: *Module, p: *GradeProfile) -> nx_int
1169func _verdict_complexity(c: *CategoryReport, p: *GradeProfile) -> nx_int
1178func _verdict_fn_length(c: *CategoryReport, p: *GradeProfile) -> nx_int
1187func _verdict_deadcode(c: *CategoryReport, p: *GradeProfile) -> nx_int
1210func _run_layer0_rules(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
1218func _run_layer2_rules(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
1228func _run_per_fn_rules(card: *GradeCard, f: *Function, p: *GradeProfile) -> nx_int
1234func nx_grade_card_scan(card: *GradeCard, m: *Module, p: *GradeProfile) -> nx_int
1257func _grade_card_count_security(card: *GradeCard) -> nx_int
called by 1: nx_grade_card_compute calls 1: _grade_cat_at
1272func _bump_counts(card: *GradeCard, verdict: nx_int) -> nx_int
called by 1: _compute_aggregates calls 1: _inc_by_idx
1299func _grade_letter(wins: nx_int, losses: nx_int) -> nx_int
1320func _compute_verdicts_layer0(card: *GradeCard, p: *GradeProfile) -> nx_int
1328func _compute_verdicts_layer2(card: *GradeCard, p: *GradeProfile) -> nx_int
1336func _compute_verdicts(card: *GradeCard, p: *GradeProfile) -> nx_int
1343func _compute_aggregates(card: *GradeCard) -> nx_int
1359func nx_grade_card_compute(card: *GradeCard, p: *GradeProfile) -> nx_int
1376func nx_grade_severity_is_valid(s: nx_int) -> nx_int
called by 1: main
1382func nx_grade_kind_is_valid(k: nx_int) -> nx_int
called by 1: main
1388func nx_grade_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
1394func nx_grade_letter_is_valid(g: nx_int) -> nx_int
called by 1: main
1416func _grade_letter_str(g: nx_int) -> *u8
1425func _verdict_str(v: nx_int) -> *u8
1432func _kind_str(k: nx_int) -> *u8
1446func _named_improvement(kind: nx_int) -> *u8
called by 1: _emit_category
1457func _emit_category(c: *CategoryReport) -> nx_int
1485func _emit_card_header(card: *GradeCard) -> nx_int
1502func nx_grade_card_emit(card: *GradeCard) -> nx_int
1576func _grade_tri_at(tr: *GradeTriangulation, idx: nx_int) -> *TriangulatedReport
1581func nx_grade_triangulation_alloc() -> *GradeTriangulation
called by 5: mainmainmainmainmain calls 1: sys_mmap
1603func _count_votes(a: nx_int, b: nx_int, c: nx_int, d: nx_int, target: nx_int) -> nx_int
called by 1: _vote4
1614func _count_buckets_with_n(n_win: nx_int, n_tie: nx_int,
called by 2: _vote4_vote_n
1625func _vote4(a: nx_int, b: nx_int, c: nx_int, d: nx_int,
1653func _count_in_array(verdicts: *nx_int, n: nx_int, target: nx_int) -> nx_int
called by 1: _vote_n
1663func _vote_n(verdicts: *nx_int, n: nx_int, out_disagreement: *nx_int) -> nx_int
1686func _vote(a: nx_int, b: nx_int, c: nx_int, out_disagreement: *nx_int) -> nx_int
called by 1: _triangulate_one
1702func _zero_higher_slots(t: *TriangulatedReport) -> nx_int
1709func _triangulate_one(t: *TriangulatedReport, kind: nx_int,
1728func _polyangulate_one(t: *TriangulatedReport, kind: nx_int,
1755func _bump_tri(tr: *GradeTriangulation, verdict: nx_int, disagreement: nx_int) -> nx_int
1779func _zero_poly_counters(tr: *GradeTriangulation) -> nx_int
1791func _gather_verdicts(verdicts: *nx_int, cs: *CardSet, i: nx_int) -> nx_int
called by 1: nx_grade_polyangulate calls 1: _grade_cat_at
1804func nx_grade_polyangulate(tr: *GradeTriangulation,
1835func _gather_verdicts_7(verdicts: *nx_int, cs: *CardSet, i: nx_int) -> nx_int
called by 1: nx_grade_heptagulate calls 1: _grade_cat_at
1853func _heptagulate_one(t: *TriangulatedReport, kind: nx_int,
1874func nx_grade_heptagulate(tr: *GradeTriangulation, cs: *CardSet) -> nx_int
1894func _triangulate_one_cat(tr: *GradeTriangulation, cs: *CardSet,
1914func _build_3cardset(sq: *GradeCard, cl: *GradeCard,
called by 1: nx_grade_triangulate calls 1: sys_mmap
1929func nx_grade_triangulate(tr: *GradeTriangulation,
1947func _emit_graders_0_3(t: *TriangulatedReport) -> nx_int
1959func _emit_graders_4_6(t: *TriangulatedReport) -> nx_int
1969func _emit_tri_category(t: *TriangulatedReport) -> nx_int
1983func _emit_tri_header(tr: *GradeTriangulation) -> nx_int
2000func nx_grade_triangulation_emit(tr: *GradeTriangulation) -> nx_int