Add package conflicts
Rolling Release / build (push) Successful in 1m41s
Rolling Release / publish (push) Successful in 9s

Packages can declare conflicts in orbit.json. The solver keeps them apart,
and a global install offers to replace the installed ones in the way.
Rollback now checks for clashes before it unlinks anything.

Planning: 8m9kt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-12-01 05:29:25 -08:00
1 parent 6d35f207fd
commit cc47acb3e2
9 files changed
+831 -28

No files matched your search

+85 -3
View File
@@ -1,7 +1,7 @@
// Lazy Resolvo-style CDCL SAT solver for package dependency resolution.
//
// Translates package version selection, dependency implications, channel pins,
// and binary-name ownership conflicts into Boolean clauses lazily as candidate
// declared conflicts and binary-name ownership into Boolean clauses lazily as candidate
// manifests are demanded.
///|
@@ -44,6 +44,7 @@ struct SolverProvider {
details : async (CandidateInfo) -> CandidateDetail
extra_reqs : (String) -> Array[SolveReq]
locked_bins : Map[String, String]
locked : Map[String, LockedInfo]
}
///|
@@ -53,6 +54,8 @@ enum ClauseOrigin {
AtMostOne(String)
BinConflict(String, Int32, Int32)
LockedBinConflict(String, Int32, String)
Conflict(Int32, Int32)
LockedConflict(Int32, String, String)
Learned(Array[Int32])
}
@@ -89,6 +92,7 @@ struct SatSolver {
expanded : Array[Bool]
details : Array[CandidateDetail?]
bin_providers : Map[String, Array[Int32]]
conflict_declarers : Map[String, Array[Int32]] // by the name conflicted with
pending_reqs : Array[SolveReq]
}
@@ -242,6 +246,7 @@ fn new_solver(provider : SolverProvider) -> SatSolver {
expanded: [],
details: [],
bin_providers: Map([]),
conflict_declarers: Map([]),
pending_reqs: [],
}
}
@@ -751,7 +756,67 @@ async fn expand_next(s : SatSolver) -> (Bool, Int32) raise OrbitError {
record_confl(c)
}
// 2. Check binary-name collisions against locked global packages (skipped if
// 2. Declared conflicts, with installed packages outside this solve and with
// active candidates. Each pair is seen when its second package is expanded.
// Before binaries, so that an explanation names the declared conflict.
let conflict_clause = fn(declarer : Int32, target : Int32) {
let c = add_clause_dynamic(
s,
[@kernel.neg_lit(declarer), @kernel.neg_lit(target)],
Conflict(declarer, target),
)
record_confl(c)
}
for owner, info in s.provider.locked {
if owner != cand.name &&
!s.pkg_index.contains(owner) &&
(
declares_conflict(det.manifest.conflicts, owner, info.version) ||
declares_conflict(info.conflicts, cand.name, det.manifest.version)
) {
let c = add_clause_dynamic(
s,
[@kernel.neg_lit(v)],
LockedConflict(v, owner, info.version),
)
record_confl(c)
}
}
for target, con in det.manifest.conflicts {
s.conflict_declarers.get_or_init(target, fn() { [] }).push(v)
match s.pkg_index.get(target) {
Some(pid) =>
for u in s.pkgs[pid].all_vars {
match s.details[u] {
Some(d) =>
if conflict_covers(con, d.manifest.version) {
conflict_clause(v, u)
}
None => ()
}
}
None => ()
}
}
match s.conflict_declarers.get(cand.name) {
Some(declarers) =>
for u in declarers {
match s.details[u] {
Some(d) =>
if declares_conflict(
d.manifest.conflicts,
cand.name,
det.manifest.version,
) {
conflict_clause(u, v)
}
None => ()
}
}
None => ()
}
// 3. Check binary-name collisions against locked global packages (skipped if
// that package is part of this solve) and against active candidates.
for b in det.manifest.bins {
let bn = basename(b)
@@ -788,7 +853,7 @@ async fn expand_next(s : SatSolver) -> (Bool, Int32) raise OrbitError {
provs.push(v)
}
// 3. Flush any extra requirements discovered when dependencies first loaded.
// 4. Flush any extra requirements discovered when dependencies first loaded.
while s.pending_reqs.length() > 0 {
let req = s.pending_reqs.remove(0)
let c = add_req_clause(s, req)
@@ -900,6 +965,19 @@ fn explain_unsat(s : SatSolver, confl : Int32) -> String {
" - \{c.name} \{c.version} provides binary '\{bin}', already provided by installed \{owner}",
)
}
Conflict(v1, v2) => {
let c1 = s.vars[v1]
let c2 = s.vars[v2]
push_line(
" - \{c1.name} \{c1.version} conflicts with \{c2.name} \{c2.version}",
)
}
LockedConflict(vid, owner, owner_version) => {
let c = s.vars[vid]
push_line(
" - \{c.name} \{c.version} conflicts with installed \{owner} \{owner_version}",
)
}
}
for l in cl.lits {
let v = @kernel.lit_var(l)
@@ -1052,6 +1130,7 @@ fn mock_manifest(
version : String,
depends : Map[String, String],
bins? : Array[String] = [],
conflicts? : Map[String, String] = Map([]),
) -> Manifest {
Manifest::{
name,
@@ -1059,6 +1138,7 @@ fn mock_manifest(
description: "",
documentation: "",
depends,
conflicts,
bins,
}
}
@@ -1069,6 +1149,7 @@ fn make_mock_provider(
detail_fetches? : Ref[Int32] = Ref(0),
extra_reqs_map? : Map[String, Array[SolveReq]] = Map([]),
locked_bins? : Map[String, String] = Map([]),
locked? : Map[String, LockedInfo] = Map([]),
) -> SolverProvider {
let by_id : Map[String, Manifest] = Map([])
for _, entries in repo {
@@ -1131,6 +1212,7 @@ fn make_mock_provider(
}
},
locked_bins,
locked,
}
}