Skip to content

Import graph: build variants, symlinked headers, Dart conditional imports, exact Solidity relative paths - #3743

Merged
squid-protocol merged 2 commits into
mainfrom
claude/import-resolution-3665-3660
Sep 26, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
claude/import-resolution-3665-3660

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes #3665. Part of #3660: this covers its Dart, Objective-C and Solidity shapes, but not Kotlin (see below). Part of #3641.

Four import shapes where the resolver drew no edge, or the wrong one.

1. One file behind two paths, a symlink (#3665, #3660 objective-c). In SDWebImage, include/SDWebImage/X.h is a symlink to Core/X.h, so the scan sees both paths. #import "SDWebImageCompat.h" looked ambiguous and drew no edge.

  • Once the token's own path context has failed to pick a candidate, candidates that are one file on disk (realpath) collapse to the real file, not the link.
  • This needs the scan root, which galaxyscope now gives the sensor (network_sensor.root). Without a root nothing collapses.
  • <SDWebImage/X.h> still names the include/ path it spells: the collapse only runs after that path matching has failed.
  • A token that spells a directory no candidate has stays unmatched. For example, the umbrella header's <SDWebImage/MKAnnotationView+WebCache.h> names a file that only exists under SDWebImageMapKit/.

2. Build variants (#3665, import contract C8). circe has semiauto.scala under both scala-2/ and scala-3/. An importer in a scala-2 tree means the scala-2 copy.

  • Stage 2b applies only to parallel trees: the candidates have the same depth and differ in exactly one directory. Every candidate's name there must be a build variant (_BUILD_VARIANT_DIR):
    • versioned toolchain trees: scala-2, scala-2.13+, java11, py3;
    • platform trees: jvm, js, native, android, ios, …
  • The candidate whose variant directory is also in the importer's path is chosen. _resolve_path_tail (the Scala package-object path, and Dart's package:) narrows the same way.
  • The variant-name restriction came from the existing tests. Without it, the rule also picked service_a/utils.py for an importer in service_a/, and cobol_src/ over cobol_copy/. That's "nearest same-named file", which Dependency Attribution Error duplicate filenames #261 rejected. Sibling modules stay ambiguous, and those cases are now pinned as tests.
  • An importer in a shared tree (src/test/scala/) compiles against every variant and still draws no edge.

3. Solidity relative paths are exact (#3660). fv/harnesses/*.sol import ../patched/access/AccessControl.sol, which is generated at build time. The name search linked those imports to contracts/access/AccessControl.sol, a file the import doesn't name. Under the new top-level flag relative_imports_are_exact (solc's own rule), a relative import naming no scanned file draws no edge.

4. Dart conditional imports (#3660). In import 'stub.dart' if (dart.library.io) 'io_client.dart'; the alternatives are real, platform-selected imports. _dependency_capture gained a branch for each if (...) 'uri' that directly follows a closing quote. A collection-if in code (['a', if (c) 'b']) always has a comma there, so it never matches. The branch is bounded and uses one condition.

Not in this PR: Kotlin extension properties (#3660, 17 misses). import com.squareup.kotlinpoet.metadata.isPrimary names internal val KmConstructor.isPrimary. Declared-name resolution indexes functions and classes, but not properties, because nothing records a file's property names. That needs a new per-file declarations channel, persisted so incremental scans keep it, which is a separate change. #3660 stays open for it.

docs/import_rule_contract.md C8 records how it's implemented.

Type of change

  • Bug fix
  • New feature / language support
  • Parsing or engine logic (gitgalaxy/core/detector.py, language_standards.py, prism.py, or a per-language rule)
  • Docs, tooling, or CI only
  • Other (describe above)

CI checklist

  • python tests/tools/audit_check.py passes (bundles the ruff/mypy/dead-key baseline-gated audits + ruff format --check)
  • python -m pytest tests/ passes
  • Touches parsing/engine logic? python tests/tools/crucible_check.py passes: both fixtures re-blessed, 3 differences (below)
  • Touches parsing/engine logic? python tests/tools/tree_sitter_accuracy_audit.py --all --ci passes
  • Changes the CLI's output JSON schema? No.

Measurements

import_graph_accuracy.py, all 20 measured languages on the pinned corpus:

language repo before (precision / recall) after
objective-c SDWebImage 100.0 / 97.3 100.0 / 100.0
dart dart-lang/http 100.0 / 95.3 100.0 / 100.0
scala circe 98.8 / 93.5 98.8 / 94.8
solidity openzeppelin-contracts 97.1 / 99.8 100.0 / 99.8
kotlin kotlinpoet 100.0 / 95.2 unchanged (see above)

The other 15 languages are unchanged. The baseline is regenerated.

Nine Scala imports stay ambiguous, correctly: their importers sit in shared scala/ or scala-0/ trees that compile against both variants.

Golden masters: 3 differences, identical in both modes, all from dart/flutter/editable_text.dart. Its conditional import's web alternative is now an import. That file isn't in the crucible, so it adds one entry to "Extracted Dependencies" and one to "Direct Upstream", and raises the global firewall imports_unknown by one (10290 → 10291). No mass changes, so there are no layout coordinate changes.

keyword-rosetta: 51 languages, 0 regressions.

Differential Scan target

The import-graph corpus repos: circe/circe, SDWebImage/SDWebImage, dart-lang/http, OpenZeppelin/openzeppelin-contracts.

Verification

$ pytest tests/security_auditing tests/extraction/languages -k "import or network or dart or solidity or scala or objective"  -- 1257 passed
$ pytest tests/                                                           -- 11665 passed, 333 skipped
$ python tests/tools/audit_check.py                                       -- all clear
$ python tests/tools/import_graph_accuracy.py --ci                        -- OK, 20 languages
$ python tests/tools/tree_sitter_accuracy_audit.py --ci --all             -- all OK
$ python tests/tools/crucible_check.py --mode both --update --yes         -- both updated; 3 diffs, one dart file
$ python tests/tools/rosetta_audit.py --corpus ../keyword-rosetta         -- 51 languages, 0 regressions

New test file: tests/security_auditing/test_import_resolution_3665_3660.py. It covers:

🤖 Generated with Claude Code

https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr


Generated by Claude Code

…rts, solidity exact relatives (#3665, #3660)

- Stage 2b of the name search, once the token's own path context has failed:
  - two paths that are one file on disk (SDWebImage's include/X.h -> Core/X.h)
    collapse to the real file. Needs the scan root, which galaxyscope now
    gives the sensor; a token that spells a directory no candidate has stays
    unmatched.
  - parallel trees that differ in one directory whose names are all build
    variants (`scala-2`/`scala-3`, `jvm`/`js`, `scala-2.13+`) take the
    importer's variant (import contract C8). Sibling modules are not variants
    and stay ambiguous (#261). `_resolve_path_tail` narrows the same way.
- solidity `relative_imports_are_exact`: a `../x.sol` naming no scanned file
  (a build-generated patched/ tree) draws no edge instead of a basename match.
- dart: a conditional import's `if (dart.library.x) 'uri'` alternatives are
  imports.

import_graph_accuracy: objective-c recall 97.3 -> 100.0, dart 95.3 -> 100.0,
scala 93.5 -> 94.8, solidity precision 97.1 -> 100.0; no other language moved.
Kotlin extension-property imports (#3660) need a declared-property channel and
are not in this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
…-Ray entropy)

The single toolchain alternation literal scored 4.81 Shannon entropy, over the
binary anomaly detector's 4.8 threshold for a 64+ char string. Same compiled
pattern, assembled from two tuples.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit bc67c5b into main Sep 26, 2026
36 checks passed
@squid-protocol
squid-protocol deleted the claude/import-resolution-3665-3660 branch September 26, 2026 14:01
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.

Import resolver: a build-variant copy resolves to the importer's own variant (import contract C8)

2 participants