Skip to content

feat(rpl): add item-pattern matching and Send/Sync variance predicates - #125

Draft
jellllly420 wants to merge 11 commits into
RPL-Toolchain:masterfrom
jellllly420:codex/send-sync-items-pr1
Draft

jellllly420 wants to merge 11 commits into
RPL-Toolchain:masterfrom
jellllly420:codex/send-sync-items-pr1

Conversation

@jellllly420

Copy link
Copy Markdown
Contributor

Summary

Add a framework-level foundation for Rudra-inspired Send/Sync bug detection using composable predicates over Rust program properties, rather than a dedicated Rudra checker.

  • Parse, validate, lower, and document struct/impl item patterns, ADT/access metavariables, wildcard generics/fields/where clauses, impl bindings, and bundle-level predicate guards.
  • Match explicit positive unsafe trait impls at HIR/type level using resolved trait identities and explicit paths/imports, including custom traits and local reexports.
  • Evaluate Send ownership/bound predicates and Sync resource-access predicates as correlated relational rows. Preserve the access witness so a bound on one method cannot justify a different method.
  • Keep upstream's function/ADT MatchSession path alongside the item matcher. Register upstream's has_attr predicate for the stricter where-clause validation and cover the integration with a regression test.
  • Add focused parser, metadata, documentation, and UI coverage, including all 12 pinned Rudra Send/Sync fixtures.

The example detection patterns currently live in UI fixtures; this does not enable new default built-in lints. The work is split into eleven commits and rebased onto master at 6fb8514.

Example enabled by this change

pattern send-variance

patt {
    use core::marker::Send;

    send_variance[
        $Wrapper: adt,
        $Parameter: type,
        $MappedType: type,
    ] = {
        struct $Wrapper<..> { .. }

        $marker:
        unsafe impl<..> Send for $Wrapper<..>
        where ..
        {}
    } where {
        has_type_parameters($Wrapper)
        && type_parameter_of($Parameter, $Wrapper)
        && type_parameter_maps_to($Parameter, $MappedType, $marker)
        && owns_type($Wrapper, $Parameter)
        && !is_send_in($MappedType, $marker)
    }
}

The Sync examples separately check exclusive resource access requiring Send and concurrent resource access requiring Sync, correlating each trait query with its own access context.

Current precision / draft scope

The predicate evaluators are initial approximations, not a sound or complete Send/Sync analysis:

  • Ownership follows structural by-value fields, with special handling for Box, PhantomData, pointers/references, and unresolved aliases.
  • Shared-reference access is signature-based and recognizes direct safe inherent methods. Body-mediated, trait, guard, alias, and specialized access require further work; by-value signatures can over-report when the body never transfers the value.
  • Relational evaluation carries unknown/incomplete results, but the current trait-proof backends still map failed rustc proofs to false. Failure to prove a bound is not proof of a concrete non-Send/Sync counterexample.
  • Access-specific trait checks currently accept a proof from either the marker-impl environment or the correlated method environment; a fully combined instantiated environment is future work.

Rudra fixture expectations intentionally reflect these predicate semantics, not identical diagnostic output from Rudra.

Validation

On macOS/aarch64 after the rebase (subsequent changes only corrected commit attribution):

  • UI tests with embedded and external patterns: 261 passed, 19 ignored, including all 42 Send/Sync cases.
  • Workspace unit/integration tests and the new has_attr regression passed.
  • cargo clippy --workspace -- -D warnings and Clippy for the new regression test passed.
  • cargo fmt --all -- --check, python3 scripts/check_rpl_patterns.py, and git diff --check passed.
  • Documentation test invocation completed; the four available doctests are ignored.

Outstanding smoke-test caveat: lintcheck's third-party cc 1.0.67 run was stopped after 5m38s at approximately 100% CPU. A process sample located the time in unchanged upstream MIR interblock dependency-graph construction. That smoke check remains unverified; lintcheck's harness returns success even when a checked crate fails, so its exit status alone is not treated as a clean result. Cache-related failures were also observed during the initial smoke runs.


Earlier implementation commits are attributed to GPT-5.6; the rebase compatibility fix is attributed to GPT-6.

Generated by Codex (GPT-6) on behalf of @jellllly420

jellllly420 and others added 11 commits September 8, 2026 09:10
Parse and lower ADT metavariables, item wildcards, impl bindings, bundle guards, and explicit trait paths while preserving legacy function-pattern behavior.

Co-authored-by: GPT-5.6 <codex@openai.com>
Preserve and display trailing item-pattern where blocks in generated pattern documentation.

Co-authored-by: GPT-5.6 <codex@openai.com>
Match explicit positive unsafe trait impls by resolved DefId, evaluate temporary true/false guards, follow local reexports, and cover Send, Sync, and custom traits with focused UI fixtures.

Co-authored-by: GPT-5.6 <codex@openai.com>
Register the five generic-wrapper Send predicates with input/output signatures and statically validate item-guard arity, sorts, binding order, disjunctions, and closed negation.

Co-authored-by: GPT-5.6 <codex@openai.com>
Execute item guards as correlated relational rows, preserve incomplete results through closed negation, and provide initial implementations of the five generic-wrapper Send predicates with focused positive and negative UI coverage.

Co-authored-by: GPT-5.6 <codex@openai.com>
Co-authored-by: GPT-5.6 <codex@openai.com>
Co-authored-by: GPT-5.6 <codex@openai.com>
Co-authored-by: GPT-5.6 <codex@openai.com>
Co-authored-by: GPT-5.6 <codex@openai.com>
Co-authored-by: GPT-5.6 <codex@openai.com>
Register has_attr so stricter function where-clause validation accepts the predicate added on master. Cover the integration with a dedicated metadata regression test.

Co-authored-by: GPT-6 <codex@openai.com>
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.

1 participant