code wiki / _hdl_build / nx_dupfunc.nx
nx_dupfunc.nx
buildroot/runtime/_hdl_build/nx_dupfunc.nx
about
nx_dupfunc.nx -- WHICH FUNCTION BODIES ARE WRITTEN MORE THAN ONCE?
===== WHY THIS EXISTS ============================================
The tree already has nx_dup_source_check, and it is a good tool, but it
answers a different question: it detects the SAME FILE existing in two
source trees. It is file-level and cross-tree by construction, so it
cannot see two files in the same directory that happen to contain the same
function written twice.
That gap is not theoretical. Building nx_gatescan and nx_gatequality I
duplicated NINE functions between them -- the tree walk, file read, path
join, the file-type predicates, the attribution rule -- while holding two
tools designed to find exactly this class of problem. Nothing in the
ecosystem could have told me. This organ closes that.
===== THE DESIGN DECISION THAT MAKES IT WORK =====================
★NAMES ARE IGNORED. My nine duplicates were called gs_len and gq_len,
gs_walk and gq_walk -- identical bodies behind different prefixes, which is
what copying into a new file naturally produces. A detector keyed on names
would have found none of them. So a function is reduced to its BODY, and
the body alone decides identity.
Normalisation before comparison, each for a reason:
- comments stripped : a copied function usually keeps the code and
rewrites the comment, or vice versa
- whitespace collapsed : re-indentation is not a difference
- the signature line dropped: that is where the name lives
===== RANKED BY COST, NOT BY COUNT ===============================
Two copies of a 60-line walk are a different problem from two copies of a
one-line helper. Severity is therefore (copies - 1) x body size: what you
would actually save, and what is actually at risk of drifting apart.
⚠WHAT IT DOES NOT MEAN. Identical bodies are not automatically a defect.
This tree deliberately keeps independent re-derivations of a rule inside
gates, because a test that calls the code under test can only confirm
self-consistency -- and that decision is what caught a dead primitive
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_eco_graph.nxnx_gatelib.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 52 | const DF_MAGIC_1469598103934665603: i64 = 1469598103934665603 |
| 53 | const DF_MAGIC_1099511628211: i64 = 1099511628211 |
| 54 | const DF_MAGIC_4096: i64 = 4096 |
| 55 | const DF_MAGIC_262144: i64 = 262144 |
| 57 | const DF_MAXNODE: i64 = 24000 |
| 58 | const DF_ARENA: i64 = 4194304 |
| 59 | const DF_HASH: i64 = 65536 |
| 60 | const DF_PATHARENA: i64 = 4194304 |
| 61 | const DF_MAXFUNCS: i64 = 64 |
| 63 | const DF_MAXTOTAL: i64 = 120000 |
functions
| 65 | func dw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 66 | func dn(v: i64) -> i64 { let b: *u8 = sys_mmap(24); var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } let t: *u8 = sys_mmap(24); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; while i < k { b[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, b, k); return 0 } |
| 73 | func df_hash(buf: *u8, n: i64) -> i64 called by 1: main |
| 84 | func main(argc: i64, argv: *i64) -> i64 |