Skip to content

Speed up rusi's compiler backend and build it on current nightly - #166

Merged
prabhu merged 5 commits into
mainfrom
perf/rusi-span-flow-models
Nov 5, 2026
Merged

prabhu merged 5 commits into
mainfrom
perf/rusi-span-flow-models

Conversation

@prabhu

@prabhu prabhu commented Nov 5, 2026

Copy link
Copy Markdown
Member

This pull request speeds up rusi's compiler backend, keeps the wrapper building on current nightly, and makes the report name the toolchain that produced its evidence.

The rustc wrapper repeated two kinds of work that depend only on their input. Recording a call, signal or crypto finding asked the source map for the same span up to four times, so span_site now resolves both ends of a callsite once and BodyVisitor keeps the last span it resolved, since one call is usually recorded as a usage, a crypto component and a signal in turn. matching_flow_models compared each symbol with all 185 built-in flow models, re-normalizing the symbol and every pattern on each comparison, several times per MIR call and again in each data-flow iteration. The patterns are now normalized once, each distinct symbol is matched once per wrapper process, and the fallback loop in sink_matches reads cached pattern normalizations. On mini-redis (aarch64-macos, wrapper prebuilt, rustc 1.101.0-nightly 2026-10-15) a run with --dataflow security went from 21.5-22.0s to 4.4-4.7s, and one with --deps --dataflow security-deps from 974s to 581s. Max RSS is unchanged and both reports are byte-identical to those of the previous wrapper.

rust-lang/rust#165079 (first nightly 2026-11-01) removed ty::GenericArgsRef and made ty::GenericArgs a Copy handle, which broke the wrapper build on nightly. A new rusi_rustc_generic_args_handle probe in build.rs selects the right type, as the existing probes do for the earlier API changes, and the README table lists it. cargo update also moves libc to 0.2.191; every direct dependency is already on its latest release.

runtime.rustc_version and runtime.cargo_version came from the rustc and cargo first on PATH, so a run with --toolchain beta, nightly or auto (which picks nightly when one is installed) reported stable 1.99.1, and cdxgen copied that into cdx:rusi:rustcVersion. The driver already queries the resolved toolchain, so CompilerBackendPayload now carries those versions and the runtime info uses them, falling back to the PATH tools for the stable backend.

The changes were made by AI agents. On macOS arm64 and on Windows 11 ARM64 (MSVC), cargo test --locked, the compiler-backend tests (RUSTC_BOOTSTRAP=1 cargo test -- --ignored --test-threads=1, 18 tests), cargo clippy --all-targets -- -D warnings and cargo fmt --check pass on stable 1.99.1, and the wrapper's tests and clippy pass on 1.100.0-beta.10 and 1.101.0-nightly (2026-11-04). A compiler-backend run of fixtures/vulnerable-web-app on each of the three toolchains completes on both platforms with matching counts and reports its own rustc and cargo versions. Linux was not run locally.

Two hot paths in the compiler-backend wrapper repeated work that only
depends on their input.

Recording a call, signal, crypto component or crypto material asked the
source map for the same span up to four times: once for the file path,
once for the position and twice for the id key. span_site now resolves
both ends of the callsite once and returns all three, and BodyVisitor
keeps the last span it resolved, because one call is usually recorded
as a usage, a crypto component and a signal in turn.

matching_flow_models compared a symbol against all 185 built-in flow
models, re-normalizing both the symbol and each model pattern on every
comparison, and it is called several times per MIR call (source, sink,
passthrough, tags, properties) and again in every data-flow iteration.
The model patterns are now normalized once, the symbol once per match,
the result is kept per distinct symbol for the life of the wrapper
process, and the path-suffix checks no longer format a string. The
fallback loop in sink_matches reads normalized pattern symbols from a
cache instead of normalizing each one per call.

On mini-redis, with the wrapper prebuilt on aarch64-macos and rusi's
default toolchain choice (rustc 1.101.0-nightly 2026-10-15), a
compiler-backend run with --dataflow security went from 21.5-22.0s to
4.4-4.7s wall time (three runs each), and with --deps --dataflow
security-deps from 974s to 581s (one run each). Max RSS is unchanged
and both reports are byte-identical to the previous wrapper's output.

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
rust-lang/rust#165079 (first nightly 2026-11-01, 1.101) made
ty::GenericArgs a Copy handle to the interned argument list and removed
the ty::GenericArgsRef alias, so the compiler-backend wrapper no longer
built on current nightly: the FnDefArgs shim names GenericArgsRef in
five places.

build.rs gains a rusi_rustc_generic_args_handle probe, which compiles
only where GenericArgs can be taken by value, and main.rs maps a local
GenericArgsRef alias to whichever type the toolchain has. The README
table of probed API changes lists the new cfg.

The wrapper builds, passes its tests and is clippy-clean on stable
1.99.1, beta 1.100.0-beta.10 and nightly 1.101.0 (2026-11-04), and a
compiler-backend run on mini-redis completes on each of them.

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
cargo update moves the one dependency that had a newer compatible
release; every direct dependency is already on its latest version.

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
The report's runtime.rustc_version and runtime.cargo_version came from
a bare `rustc --version` and `cargo --version`, so they named whichever
toolchain was first on PATH. With --toolchain beta or nightly, or with
auto (which picks the rolling nightly when one is installed), the report
named stable 1.99.1 while a different compiler had produced its
evidence, and cdxgen copied that into cdx:rusi:rustcVersion.

The driver already reads the resolved toolchain's versions to decide
whether the backend is supported. CompilerBackendPayload now carries
their first lines, and the runtime info uses them when present, falling
back to the PATH tools for the stable backend or when the toolchain
could not be queried. JSON_ATTRIBUTE_REFERENCE.md describes the fields
as they are now; it previously said rustc -Vv, which the report never
contained.

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
@prabhu prabhu added bug Something isn't working enhancement New feature or request ai-auto A person set the task, and AI agents carried it through to completion rusi labels Nov 5, 2026
@prabhu
prabhu enabled auto-merge November 5, 2026 05:57
@prabhu
prabhu added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit dbc6949 Nov 5, 2026
@prabhu
prabhu deleted the perf/rusi-span-flow-models branch November 5, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-auto A person set the task, and AI agents carried it through to completion bug Something isn't working enhancement New feature or request rusi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant