Skip to content

Reduce dependency graph variation attempts with conflict-directed backtracking #163

Open

Description

@NikolayPianikov

Problem

When several bindings have alternative dependency nodes, VariationalDependencyGraphBuilder explores their Cartesian product.

A failure caused by one unresolved dependency may therefore advance unrelated variants as well. For graphs containing several independent alternatives, this can cause a significant increase in repeated graph builds.

This behavior was observed while investigating #161: local constructor-resolution failures could result in a large number of graph-building attempts even though only a small subset of bindings affected each failure.

Expected behavior

  • A failed graph build should first advance variants related to the unresolved dependency path.
  • Unrelated bindings should keep their current variants.
  • Already tested variation states should not be rebuilt unnecessarily.
  • The existing exhaustive search must remain as a correctness fallback.
  • The first successfully resolved graph may be returned immediately.
  • Warnings should be produced from the final selected graph only. Failed intermediate variants do not need to contribute warnings.
  • If no variation resolves the graph, the existing graph error is sufficient; no additional warning about early termination is required.

Proposed solution

Introduce conflict-directed backtracking in VariationalDependencyGraphBuilder:

  1. Collect option sets associated with unresolved dependency targets and their consumer paths to composition roots.
  2. Advance only those prioritized option sets.
  3. Track visited variation states and skip duplicate graph builds.
  4. Fall back to the complete Cartesian search when directed search is exhausted.
  5. Invalidate visited states when new dynamic nodes are discovered, because previously invalid states may become resolvable.
  6. Expose the number of graph build attempts for regression and performance tests.

Also preserve deterministic constructor ordering:

  1. Explicit Ordinal
  2. OverloadResolutionPriority
  3. Required parameter count
  4. Accessibility
  5. Variation index

Acceptance criteria

  • User scenarios with fallback constructors continue to compile and run.
  • Directed search does not remove any combinations available to the exhaustive search.
  • Independent unresolved dependency paths do not cause combinatorial growth across unrelated bindings.
  • A regression scenario with two independent fallback bindings requires no more than four graph builds.
  • Successful graphs do not report warnings originating only from rejected variants.
  • Existing unit, usage, and integration tests pass for all supported Roslyn versions.

Activity

  1. added 2 commits that reference this issue on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions