Skip to content

Add lizard cyclomatic complexity check to pre-commit#1221

Open
Hardcode84 wants to merge 1 commit intoiree-org:mainfrom
Hardcode84:lizard
Open

Add lizard cyclomatic complexity check to pre-commit#1221
Hardcode84 wants to merge 1 commit intoiree-org:mainfrom
Hardcode84:lizard

Conversation

@Hardcode84
Copy link
Copy Markdown
Contributor

Gate new code on CCN <= 50 and length <= 300. Existing violations are grandfathered via whitelizard.txt. Excludes vendored LLVM headers, generated code, tests, and examples.

Gate new code on CCN <= 50 and length <= 300. Existing violations
are grandfathered via whitelizard.txt. Excludes vendored LLVM
headers, generated code, tests, and examples.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Copy link
Copy Markdown
Contributor

@tgymnich tgymnich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CCN is a bad metric for code quality. What problem does this solve? Do we have serious intentions to fix all the exceptions?

@Hardcode84
Copy link
Copy Markdown
Contributor Author

Hardcode84 commented Apr 1, 2026

CCN is a bad metric for code quality. What problem does this solve? Do we have serious intentions to fix all the exceptions?

CCN 50 is extremely generous and all the whitelisted functions are legit candidates for refactoring. Even if we don't plan to fix them immediately, this will prevent us from creating the new ones.

@tgymnich
Copy link
Copy Markdown
Contributor

tgymnich commented Apr 1, 2026

That's 50 2 unvetted python dependencies running arbitrary code on my machine just to prevent nested if statements.
IMO the cost use benefit is not there for me. This can also be done using copilot reviews, which may or may not provide more value.

@tgymnich tgymnich modified the milestone: mmmmmmm Apr 1, 2026
@Hardcode84
Copy link
Copy Markdown
Contributor Author

Lizard Complexity Report

Generated: 2026-04-02
Thresholds: CCN > 50 or length > 300

Whitelisted Violations (sorted by CCN)

CCN NLOC Length Tokens File Function
96 577 658 5002 waveasm/lib/Transforms/AssemblyEmitter.cpp:342 KernelGenerator::generateOp
91 294 457 2538 waveasm/lib/Transforms/Liveness.cpp:265 computeLiveness
88 148 158 1573 waveasm/lib/Transforms/handlers/AMDGPUHandlers.cpp:86 handleAMDGPUMfma
82 377 459 2849 waveasm/lib/Transforms/handlers/AMDGPUHandlers.cpp:686 handleGatherToLds
75 561 666 3419 wave_lang/kernel/wave/perf/bench_mxfp4_comparison.py:1798 main
71 362 469 3086 waveasm/lib/Transforms/handlers/AffineHandlers.cpp:398 handleAffineApply
69 338 498 1860 wave_lang/kernel/wave/mlir_converter/water_emitter.py:592 _emit_ops_from_graph
66 215 348 1849 waveasm/lib/Transforms/LinearScanPass.cpp:144 LinearScanPass::processProgram
59 257 338 1883 waveasm/lib/Transforms/TranslateFromMLIR.cpp:1373 handleVectorStore
55 169 253 1360 waveasm/lib/Transforms/handlers/AMDGPUHandlers.cpp:430 handleFatRawBufferCast
51 222 272 1445 wave_lang/kernel/compiler/host_codegen.py:127 isolated_test_call
32 213 523 1716 wave_lang/kernel/compiler/wave_codegen/emitter.py:641 gen_sympy_index
26 200 306 1835 waveasm/lib/Transforms/TranslateFromMLIR.cpp:154 emitSRDPrologue
25 260 306 1227 wave_lang/kernel/wave/asm/scripts/compare_backends.py:1642 main
10 137 433 933 wave_lang/kernel/wave/templates/extend_attention.py:28 get_extend_attention_kernel
7 158 346 1204 wave_lang/kernel/wave/templates/extend_attention_rpe.py:28 get_extend_attention_rpe_kernel
6 139 447 833 wave_lang/kernel/wave/templates/paged_decode_attention.py:56 get_paged_decode_attention_kernels
4 179 420 1002 wave_lang/kernel/wave/templates/gemm.py:873 get_hybrid_streamk_gemm_kernel
3 169 407 929 wave_lang/kernel/wave/templates/gemm.py:464 get_streamk_gemm_kernel
3 318 401 1519 wave_lang/kernel/wave/schedules/gemm_mxfp4_double_buffer.py:1606 get_mxfp4_asymmetric_schedule.mxfp4_dbuf_schedule
2 270 344 1473 wave_lang/kernel/wave/schedules/gemm_mxfp4_double_buffer.py:917 get_mxfp4_dbuf_mixed_pingpong_schedule.mxfp4_dbuf_schedule
1 141 469 781 wave_lang/kernel/wave/templates/speculative_decoding.py:14 get_speculative_sampling_kernel
1 321 367 2521 waveasm/lib/Target/AMDGCN/InstructionInfo.cpp:19 InstructionRegistry::InstructionRegistry
1 7 434 33 wave_lang/kernel/wave/schedules/gemm_mxfp4_double_buffer.py:1575 get_mxfp4_asymmetric_schedule
1 7 367 41 wave_lang/kernel/wave/schedules/gemm_mxfp4_double_buffer.py:896 get_mxfp4_dbuf_mixed_pingpong_schedule
1 7 308 41 wave_lang/kernel/wave/schedules/gemm_mxfp4_double_buffer.py:1265 get_mxfp4_dbuf_mixed_pingpong_shuffle_schedule

Summary

Metric Count
Total whitelisted functions 26
CCN > 80 (critical) 4
CCN > 50 (high) 11
Length-only violations (CCN <= 50) 15
Worst offender CCN 96 (KernelGenerator::generateOp)
Worst offender length 666 (bench_mxfp4_comparison.py:main)

Breakdown by Component

Component Violations
waveasm C++ 12
wave_lang Python 14
water C++ 0

Notes

  • Templates and schedules trip the length threshold but have very low CCN (1-10). These are long declarative kernel definitions, not complex logic.
  • The waveasm handlers (handleAMDGPUMfma, handleGatherToLds, handleAffineApply) are type-dispatch switches -- inherently branchy but typical for code generators.
  • KernelGenerator::generateOp (CCN 96, 577 NLOC) is the single worst function and a strong refactoring candidate.

@ftynse
Copy link
Copy Markdown
Contributor

ftynse commented Apr 3, 2026

Breakdown by component shows that the more robust code review policy that I enacted in water works. Very basically, if people have to actually review your code, they will complain about cognitive complexity much sooner than tools.

I agree with Tim on the intent: if there is no intent to rearchitect this code beyond asking an LLM to refactor it which will just try to game an artificial metric, let's not bother. If somebody wants to run the tool, maybe we can have it as an optional CI?

@harsh-nod
Copy link
Copy Markdown
Collaborator

harsh-nod commented Apr 3, 2026

If this is a pre-commit hook, then we can catch this even before submitting the PR? Doesnt that help reduce the cognitive load on the reviewer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants