fix: fingerprint Solidity functions in ctx duplicates (AGE-2)#30
Merged
saldestechnology merged 1 commit intoJul 11, 2026
Conversation
ctx duplicates silently skipped all Solidity functions: the MinHash detector tokenizes each function via tree-sitter, and Solidity has no tree-sitter grammar in this build (it uses solang-parser), so .sol functions never got fingerprints. On a Solidity-heavy repo that made `ctx duplicates` blind to the largest part of the codebase. Tokenize Solidity with the solang-parser lexer (already a dependency) in `tokenize`, mapping identifiers -> ID, string/hex/address/number literals -> LIT, and keeping keywords/punctuation verbatim -- the same normalization the tree-sitter path uses. Solidity functions now get MinHash fingerprints at index time and participate in near-duplicate detection. Removes the now-false "skipped" messaging from `duplicates` output and help; inverts the index-level test and adds tokenizer + end-to-end duplicate tests for .sol. Note: `ctx audit`'s Duplication score is a separate name-based heuristic that does not consult MinHash, so its score is unaffected by this change; rewiring audit to use fingerprints is a possible follow-up. Refs AGE-2
saldestechnology
force-pushed
the
johan/age-2-duplicates-solidity-functions-are-skipped-no-tree-sitter
branch
from
July 11, 2026 14:19
ee43493 to
a906e78
Compare
saldestechnology
deleted the
johan/age-2-duplicates-solidity-functions-are-skipped-no-tree-sitter
branch
July 11, 2026 15:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ctx duplicatessilently skipped all Solidity functions. The MinHash near-duplicate detector normalizes each function into token shingles via tree-sitter, and Solidity has no tree-sitter grammar in this build (it's parsed withsolang-parser), so.solfunctions never got fingerprints at index time. On a Solidity-heavy repo this made the detector — and the perception of coverage — blind to the largest part of the codebase.Approach
Rather than add
tree-sitter-solidity(which conflicts with the pinnedtree-sitter ~0.20.10— the documented reason the project chose solang in the first place), tokenize Solidity with thesolang-parserlexer already in the dependency tree.tokenize_solidityinsrc/fingerprint.rs: lexes withsolang_parser::lexer::Lexerand maps tokens with the same normalization as the tree-sitter path (normalize_leaf): identifiers →ID; string/hex/address/number literals →LIT; keywords and punctuation kept verbatim; comments dropped (the lexer excludes them). Each token's 1-indexed line is derived from its byte offset sofile_fingerprintsslices by symbol line range exactly as for other languages.tokenizeshort-circuits to this path forLanguage::Solidity;ts_languagestill returnsNonefor it.skipped_languagesinduplicates --jsonno longer lists solidity, the human-readable skip note is gone, and theduplicates/module docs are updated.Scope note
ctx audit's Duplication score is a separate name-based heuristic that never consults MinHash, so this change fixesctx duplicatesbut does not by itself move the audit score. Rewiring audit's duplication category onto fingerprints is a possible follow-up, not included here.Tests
New
test_tokenize_solidity_normalization(identifiers→ID, literals→LIT, renamed identifiers produce an identical stream).Inverted
test_solidity_files_produce_no_fingerprints→test_solidity_files_produce_fingerprints.Updated
tests/duplicates_cli.rsskip-list expectation and added an end-to-end test asserting two structurally-identical.solfunctions are detected as a near-duplicate pair.cargo fmt --all -- --check✅cargo clippy --all-targets -- -D warnings✅ (0 warnings)cargo test✅ (304 lib + all integration suites, 0 failures)Refs AGE-2. Sibling of AGE-4 (modifier edges) and AGE-5 (qualified-call resolution).