+
    2j;O                    V   R t ^ RIHt ^ RIHtHt ^RIHt ^RIH	t	 ^RI
Ht ^RIHtHt ^RIHt ^RIHtHt ]'       d   ^R	I
Ht ^R
IHt ^RIHt . R%Ot^t^t^t^t^ tR R ltR R ltR R lt R R lt!R R lt"R R lt#R R lt$R R lt%R R lt&R R lt'R  R! lt(R" R# lt)R$# )&aL  Conflict resolution and backtracking for the PubGrub resolver.

Owns the conflict-resolution loop, the most-recent-satisfier
search, the always-learn force-resolution gate, the targeted
backtrack queue, and the catastrophic restart handler.

Reference: https://github.com/dart-lang/pub/blob/master/doc/solver.md#conflict-resolution
)annotations)TYPE_CHECKINGAny)ResolutionError)add_incompatibility)PartialSolution)format_errorprior_cause)ROOT)IncompatibilityIncompatibilityCause)
Assignment)Resolver)Termc               $    V ^8  d   QhRRRRRR/# )   resolverResolver[Any, Any]conflicting_incompatibilityIncompatibility[Any, Any]return )formats   "`/home/user/billing-ledger-validation/.venv/lib/python3.14/site-packages/nab_resolver/conflict.py__annotate__r   >   s0     MT MT MT!:MT MT    c           
        TpRp\        \        V P                  P                  \        ,          4      p\        V4       EF  p\        V4      '       d8   \        \        VV P                  P                  V P                  R7      VR7      h\        W4      pV^ ,          pV^,          pV^,          p	VP                  ;'       g    WP                  8g  p
V
'       d    \        V VVVV	4      w  pppp	pV'       d   RpV P                   P#                  VVP$                  VP                  VP                  V	V
R7       V
'       Ed   V'       dJ   \'        W4       V P(                  ;P*                  ^,          un        V P                   P-                  V4       T	pVP                  '       d$   WP                  8  d   VP                  ^,
          p\/        WP                  P                  4      p\        V^ 4      pV^ 8X  d8   \        \        VV P                  P                  V P                  R7      VR7      hV P                  P                  pV P                  P1                  V4       V P(                  ;P2                  ^,          un        V P                   P5                  W4       VP$                  pV P(                  P6                  \9        V4      ;;,          ^,          uu&   \;        V VVV4       Vu # VP<                  f   Q hVf   Q hRp\?        VVP<                  VP$                  4      p\A        V\B        PD                  VVP<                  R7      pEK  	  RV RV: 2p\        VVR7      h)	a1  Learn a new incompatibility and backjump to the appropriate level.

Implements PubGrub's conflict resolution algorithm: resolve
backwards through the assignment trail combining incompatibilities
until the learned clause has at most one term at the current
decision level.

Raises ``ResolutionError`` when the conflict proves the requirements
unsatisfiable, and also when the loop exceeds its step budget, which
signals a resolver bug rather than an unsatisfiable input.

Reference: https://github.com/dart-lang/pub/blob/master/doc/solver.md#conflict-resolution
F)narrowformat_rangeincompatibilityT)satisfier_packagesatisfier_is_decisionsatisfier_levelprevious_levelcan_backjumpcause
cause_leftcause_rightz(Conflict resolution made no progress in zT steps; this is a resolver bug rather than an unsatisfiable requirement. Stalled on )#max_MIN_CONFLICT_STEPSsolutiontrail_length_STEPS_PER_TRAIL_ENTRYrangeis_terminal_incompatibilityr   r   providernarrow_for_displayr   find_most_recent_satisfieris_decisiondecision_leveliterate_force_resolutionobserveron_conflict_steppackager   statsincompatibilities_learned
on_learnedmin	backtrack	backjumpson_backjumppackage_conflict_countsconflict_credit_targetupdate_culprit_countsr'   r	   r   r   DERIVED)r   r   current_incompatibility
is_derivedstep_budget_satisfier_resultmost_recent_satisfiermost_recent_satisfier_termprevious_satisfier_levelr%   
forced_anybackjump_target
from_levelaffected_packageresolved_termsstalled_messages   &&               r   conflict_resolutionrS   >   sY   " :J&&)??K
 ;&'>??!+#,,??!)!6!6
 !8  6hX 0 3%5a%8"#3A#6  "-- P P'+O+OO 	
  )'%*('%*( !
**#3;;"7"C"C1@@3% 	+ 	
 <#HF88A=8!!,,-DE6O%111#'K'KK"7"F"F"J!/3D3D3S3STO!/15O!#% /'00CC%-%:%:
 %<  "**99J''8NN$$)$))*F  5<<NN22&'<=  "' %	 +* %**666)555
$#!''&..
 #2&...-33	#
S  b 3;- @O"
%	' 
 /;R
SSr   c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r   r   r   r    r   rP   r   	satisfierAssignment[Any, Any]r   Noner   )r   s   "r   r   r      sA     (@ (@ (@.(@ (@ $	(@
 
(@r   c                   / pVP                    F%  pVP                  pV\        J g   Wb8X  d   K!  RWF&   K'  	  \        VP                   4      ^8X  dN   VP                  e@   VP                  P                    F%  pVP                  pV\        J g   Wb8X  d   K!  RWF&   K'  	  V P
                  pV F  pV P                  P                  V;;,          ^,          uu&   V P                  P                  V,          pW8  g   KQ  W,          ^ 8X  g   K`  W`P                  9  g   Kr  V P                  P                  V4       K  	  R# )aT  Credit non-affected packages in a learned clause as culprits.

Modelled on uv's ConflictTracker (PR #9843).  Every non-affected,
non-root package in the clause is a culprit; for single-term NO_VERSIONS
clauses we walk the satisfier's cause chain instead.  When a culprit
crosses ``CULPRIT_THRESHOLD`` it gets queued for targeted backtrack.
N)
termsr9   r
   lenr'   CULPRIT_THRESHOLDr:   package_culprit_countspending_targeted_backtrackappend)	r   r    rP   rU   culprit_packagestermr9   	thresholdcounts	   &&&&     r   rC   rC      s    )+%%,,d?g9$(!	 & ?  !Q&9??+FOO))DllG$'"=(,%	 * **I#--g6!;655g>!Q&BBB//66w? $r   c                    V ^8  d   QhRRRR/# )r   rU   rV   r   r   r   )r   s   "r   r   r      s      &: s r   c                L   V P                   '       g   V P                  f   V P                  # V P                  P                  \        P                  Jd   V P                  # V P                  P
                  ^ ,          P                  pWP                  8X  d   V P                  # V# )a?  Return the package whose decision receives the conflict credit.

A positive term over a decided package used to be satisfied only by the
decision itself, so the credit landed on the package whose decision
triggered the conflict.  A widened parent term is often already
satisfied by the earlier derivation propagated from its dependency
clause; crediting the derivation's own package then starves the
promotion heuristics, while crediting both packages over-promotes the
whole cluster past the backjump horizon.  The clause's depending parent
receives the one credit instead.
)r4   r'   r9   r   
DEPENDENCYrY   )rU   parents   & r   rB   rB      s     	 7   $8$C$CC   __""1%--F"""   Mr   c               0    V ^8  d   QhRRRRRRRRR	R
RR/# )r   r   r   r    r   rU   rV   satisfier_termTerm[Any, Any]rL   intr   zQtuple[Incompatibility[Any, Any], Assignment[Any, Any], Term[Any, Any], int, bool]r   )r   s   "r   r   r     sD     * * *.* $* #	*
 "**r   c                b    Rp \        WW#4      pVf   MRpTp\        W4      w  pppK'  VVVVV3# )aI  Iterate :func:`try_force_resolution_step` while it succeeds.

Returns the (possibly-resolved) incompatibility, refreshed satisfier,
satisfier term, previous-satisfier level, and a ``forced_any`` flag
indicating whether at least one resolution step happened.  Stops when
``try_force_resolution_step`` declines (returns ``None``).
FT)try_force_resolution_stepr3   )r   r    rU   rh   rL   rM   forceds   &&&&&  r   r6   r6     sb    ( J
*y
 >
 
 'x8		
$ 	  r   c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r   r   r   r    r   rU   rV   rh   ri   r   z Incompatibility[Any, Any] | Noner   )r   s   "r   r   r   <  s:     + + +.+ $+ #	+
 &+r   c                   VP                   '       g-   \        VP                  4      \        8w  g   VP                  f   R# \        WP                  VP                  4      p\        V4      \        8  d   R# \        V\        P                  VVP                  R7      p\        W4      w  rgpVP                   ;'       g    WP                  8g  p	V	'       g   R# V# )a  Resolve a single-term NO_VERSIONS clause once with a soundness gate.

Standard PubGrub backjumps to root for single-term clauses, losing the
supporting decisions; resolving once with the satisfier's cause exposes
them so later propagation can skip the bad decision.

Returns ``None`` when the resolved clause collapses to <2 terms (the
eliminated package's conditioning would be lost) or when it is not
assert-eligible.
Nr&   )r4   rZ   rY   _SINGLE_TERMr'   r	   r9   _MIN_RESOLVED_TERMSr   r   rD   r3   r5   )
r   r    rU   rh   rQ   rm   forced_recentrH   forced_prev_levelforced_can_backjumps
   &&&&      r   rl   rl   <  s    " 	$$%5??" .*@*@N >00"**"OO	F +EX*V'M'!!VV%6:V:V%V  Mr   c               $    V ^8  d   QhRRRRRR/# )r   r   r   r    r   r   z0tuple[Assignment[Any, Any], Term[Any, Any], int]r   )r   s   "r   r   r   j  s$     '9 '9 '93L'95'9r   c                   RpRp^pVP                    F  pV P                  P                  V4      pVf   RV: R2p\        V4      hVP                  pVe   WP                  8  d    Ve   \        WBP                  4      pTpTpKs  \        WFP                  4      pK  	  Vf   Rp\        V4      hVf   Q h\        WW44      pW#V3# )a9  Find the most recently assigned satisfier across all terms.

Returns ``(satisfier, term, previous_satisfier_level)``.  The previous
level is the highest among the other terms' satisfiers and bounds how
far back the resolver can jump.  Refined when the satisfier is partial
(earlier assignments also contributed).
NzBug: no satisfier for z in a satisfied incompatibilityz1Bug: no satisfiers in a satisfied incompatibility)rY   r,   rU   RuntimeErrortrail_indexr*   r5   recompute_previous_level)	r   r    most_recentmost_recent_termr$   r`   rU   unreachablesatisfier_indexs	   &&       r   r3   r3   j  s     04K.2N%%%%//5	(0OP  {++#//?5L5L#L&!$^5O5O!P#K# 1I1IJN &  I;'''''-/N .88r   c          
     ,    V ^8  d   QhRRRRRRRRR	R/# )
r   r   r   rU   rV   rh   ri   current_previous_levelrj   r   r   )r   s   "r   r   r     s:     !" !" !"#!" #!"  	!"
 	!"r   c                   VP                   f   V# RpVP                   P                   F"  pVP                  VP                  8X  g   K   Tp M	  Vf   V# VP                  4       pVP	                  VP                  4       4      pVf   Q hVP
                  P                  '       d   V# V P                  P                  VP                  4       4      pVe   \        W8P                  4      # V# )a  Refine previous_level when the satisfier is partial.

The satisfier's own assertion (the negated cause term) may cover only
part of the term; the trail must then also exclude the difference
``own & ~term``, so the level of the earliest assignment that does is
folded in.
N)r'   rY   r9   negate	intersect
constraintis_emptyr,   rU   r*   r5   )	r   rU   rh   r   
cause_termr`   own_term
differencedifference_satisfiers	   &&&&     r   ry   ry     s     %%J%%<<>111J & %%  "H##N$9$9$;<J!!!%%%%%#,,66z7H7H7JK')+N+NOO!!r   c                    V ^8  d   QhRRRR/# )r   r    r   r   boolr   )r   s   "r   r   r     s     G G1J Gt Gr   c                    V P                   '       g   R# \        ;QJ d&    R V P                    4       F  '       d   K   R# 	  R# ! R V P                    4       4      # )zCCheck whether this incompatibility proves resolution is impossible.Tc              3  D   "   T F  qP                   \        J x  K  	  R # 5i)N)r9   r
   ).0r`   s   & r   	<genexpr>.is_terminal_incompatibility.<locals>.<genexpr>  s     F0E||t#0Es    F)rY   allr   s   &r   r0   r0     sF       3F0E0EF33F3F3F0E0EFFFr   c                    V ^8  d   QhRRRR/# r   r   r   r   
Any | Noner   )r   s   "r   r   r     s      '9 j r   c                    V P                   '       d1   V P                  P                  V P                  8  d   \	        V 4      # R# )zRun :func:`apply_targeted_backtrack` if the gate is open.

Gate: pending non-empty AND total conflicts past
``TARGETED_BT_MIN_CONFLICTS``.  Pending culprits are kept across rounds.
N)r]   r:   	conflictsTARGETED_BT_MIN_CONFLICTSapply_targeted_backtrack)r   s   &r   maybe_targeted_backtrackr     s6     	+++NN$$(J(JJ'11r   c               (    V ^8  d   QhRRRRRRRR/# )r   r   r   restart_thresholdrj   restarts_remainingr   ztuple[int, int, bool]r   )r   s   "r   r   r     s0     ? ? ?? ? 	?r   c                   V^ 8:  d   WR3# \        V P                  P                  P                  4       ^ R7      pW18  d   WR3# V P                  ;P                  ^,          un        \        V P                  R7      V n        V P                  P                  \        V P                  4       V P                  P                  4        ^ V P                  n        V^,          V^,
          R3# )zRestart the solver if any package crossed ``restart_threshold``.

Returns ``(new_threshold, new_remaining, restarted)``.  Preserves
``incompatibilities`` and ``package_conflict_counts`` across restart.
F)default)
range_typeT)r*   r:   rA   valuesrestartsr   r   r,   decider
   root_versionr]   cleartargeted_backtracks)r   r   r   	max_counts   &&& r   maybe_restartr     s     Q e;;HNN::AACQOI$ e;;NNq '83F3FGHT8#8#89''--/)*HNN&q "4q"8$>>r   c               $    V ^8  d   QhRRRRRR/# )r   r   r   packagesz	list[Any]r   r   r   )r   s   "r   r   r     s$     . . .,5..r   c                &   V'       g   R# V P                   pV Fk  pV P                  P                  V,          pWB8  d   W P                  P                  V&   W0P                  9  g   KP  V P                  P	                  V4       Km  	  \        V 4      # )ae  Apply a targeted back-track without waiting for the normal gate.

Used when the provider supplies direct evidence that the named
packages are culprits. Bumps each package's culprit count past the
dominant-culprit threshold, queues it, and applies immediately.

Returns the back-jumped package, or ``None`` if the back-track did
not move the decision level.
N)r[   r:   r\   r]   r^   r   )r   r   ra   r9   currents   &&   r   force_targeted_backtrackr     sx     **I..77@=FNN11':===//66w?  $H--r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r     s     $ $'9 $j $r   c                   V P                   P                  V P                  8  d   V P                  P	                  4        R# V P
                  P                  pRpV P                   F\  pV P
                  P                  V4      pV F8  pVP                  \        8  d   K  VP                  ^,
          pWa8  d   TpTp KZ  	  K^  	  V P                  P	                  4        Ve   WP
                  P                  8  d   R# V P
                  P                  V4       V P                   ;P                  ^,          un        V# )a  Backtrack to before the earliest pending-culprit assignment.

Picks the smallest decision-level among queued culprits' first assignments
(decision OR derivation; derivations count too so propagated culprits in
cluster conflicts still trigger a backtrack) and jumps to one before it.
Capped at ``MAX_TARGETED_BACKTRACKS`` per restart segment.

Level-1 assignments are skipped to preserve ROOT.
N)
r:   r   MAX_TARGETED_BACKTRACKSr]   r   r,   r5   assignments_for_TARGETED_BT_MIN_LEVELr>   )r   target_leveltriggering_packager9   package_entries
assignment	candidates   &      r   r   r     s    ~~))X-M-MM++113$$33L%)66"++;;GD *J((+AA"11A5I'(%," *	 7 ''--/!\5F5F5U5U%U-NN&&!+&r   N)r   rB   rS   r3   r   r0   r6   r   r   ry   rl   rC   )*__doc__
__future__r   typingr   r   errorsr   incompat_indexr   partial_solutionr   reportr   r	   rootr
   typesr   r   r   r   r   r   __all__rp   rq   r   r.   r+   rS   rC   rB   r6   rl   r3   ry   r0   r   r   r   r   r   r   r   <module>r      s    # % # / - -  8,"&       MT`(@V,*Z+\'9T!"HG?4.4$r   