anchor.diff:              ,   firstTrial  = true
               )
   
  -
  -    match step (Step(conflictState,None)) startingStep stackpack flags  with
  +    match step (Step(diveConflict,None)) (startingStep,None) stackpack currentRequirement  Seq.empty flags  with
       | { Status = Resolution.Conflict _ } as conflict ->
           if conflict.TryRelaxed then
               stackpack.KnownConflicts.Clear()
               stackpack.ConflictHistory.Clear()
  -            (step (Step(conflict,None)) { startingStep with Relax = true } stackpack flags ).Status
  +            (step   (Step(conflict,None)) 
  +                    ({startingStep with Relax=true},None) 
  +                    stackpack currentRequirement Seq.empty flags).Status
           else
               conflict.Status
       | x -> x.Status
  
positive.code:         |> dict
  
      if Set.isEmpty rootDependencies then Resolution.Ok Map.empty 
      //      ----------- TERMINATE --------------
      else
  
  
  
  
  
      let keepLooping (flags:StepFlags) (conflictState:ConflictState) =
          if flags.ForceBreak then false else
          if conflictState.Status.IsDone || Seq.isEmpty conflictState.VersionsToExplore then false else
          flags.FirstTrial || Set.isEmpty conflictState.Conflicts
          
  
  
      // we need a conflict state option that can store data while looping down to
      // to the end of a package resolution
  
  
      let rec stepLoop    (stage:Stage) (currentStep:ResolverStep) (stackpack:StackPack) 
                          (currentRequirement:PackageRequirement)  compatibleVersions (flags:StepFlags) =
          match stage with            
          | Step  (conflictState, diver)
          | Outer (conflictState, diver) ->
              if flags.Ready then 
                  conflictState 
              //------------EXIT STEPLOOP----------------    
              else
              let flags = StepFlags(flags.Ready,flags.UseUnlisted,flags.HasUnlisted,false,true)
  
              let conflictState = {
                  conflictState with
                      VersionsToExplore = compatibleVersions
              }
  
              stepLoop    (Inner (conflictState, diver))(currentStep:ResolverStep)  (stackpack:StackPack) 
                          (currentRequirement:PackageRequirement) compatibleVersions  flags 
              //------------STEPLOOP AGAIN----------------    
  
          | Inner (conflictState,diver )->
  
  //                let conflictState, flags =
  //                    match conflictState.Status with
  //                    | Resolution.Conflict (_,conflicts,_,_)
  //                        when
  //                            (Set.isEmpty conflicts |> not)
  //                            && nextStep.CurrentResolution.Count > 1
  //                            && not (conflicts |> Set.exists (fun r ->
  //                                r = currentRequirement
  //                                || r.Graph |> List.contains currentRequirement)) ->
  //                        let flags = StepFlags(flags.Ready,flags.UseUnlisted,flags.HasUnlisted,true,flags.FirstTrial)
  //                        conflictState, flags 
  //                    | _ ->
  //                        conflictState, flags 
  //
  
  
  
              if not (keepLooping flags conflictState) then
                  let flags =
                      if not flags.UseUnlisted && flags.HasUnlisted && not conflictState.Status.IsDone then
                          StepFlags(flags.Ready,true,flags.HasUnlisted,flags.ForceBreak,flags.FirstTrial)
                      else
                          StepFlags(true,flags.UseUnlisted,flags.HasUnlisted,flags.ForceBreak,flags.FirstTrial)
  
                  stepLoop (Outer(conflictState,diver)) (currentStep:ResolverStep)  (stackpack:StackPack) 
                           (currentRequirement:PackageRequirement) compatibleVersions  flags 
                  //------------STEPLOOP AGAIN----------------    
              else
              let flags = StepFlags(flags.Ready,flags.UseUnlisted,flags.HasUnlisted,flags.ForceBreak,false)
              let (version,sources) & versionToExplore = Seq.head conflictState.VersionsToExplore
  
              let conflictState = {
                  conflictState with
                      VersionsToExplore = Seq.tail conflictState.VersionsToExplore
              }
              let packageDetails = {
                  GroupName          = groupName
                  Dependency         = currentRequirement
                  GlobalRestrictions = globalFrameworkRestrictions
                  RootSettings       = rootSettings
                  Version            = version
                  Sources            = sources
                  UpdateMode         = updateMode
              }
  
  
              match getExploredPackage packageDetails getPackageDetailsF stackpack.ExploredPackages with
              | None ->
                  stepLoop (Inner(conflictState,diver)) (currentStep:ResolverStep) (stackpack:StackPack) 
                           (currentRequirement:PackageRequirement) compatibleVersions  flags
                  //------------STEPLOOP AGAIN----------------    
  
              | Some exploredPackage ->
                  let hasUnlisted = exploredPackage.Unlisted || flags.HasUnlisted
  
                  let flags = StepFlags(flags.Ready,flags.UseUnlisted,hasUnlisted,flags.ForceBreak,flags.FirstTrial)
                  if exploredPackage.Unlisted && not flags.UseUnlisted then
                      tracefn "     unlisted"
                      stepLoop (Inner (conflictState,diver)) (currentStep:ResolverStep) (stackpack:StackPack) 
                               (currentRequirement:PackageRequirement) compatibleVersions  flags 
                      //------------STEPLOOP AGAIN----------------    
                  else
                      
                  let nextStep =
                      {   Relax              = currentStep.Relax
                          FilteredVersions   = Map.add currentRequirement.Name ([versionToExplore],conflictState.GlobalOverride) currentStep.FilteredVersions
                          CurrentResolution  = Map.add exploredPackage.Name exploredPackage currentStep.CurrentResolution
                          ClosedRequirements = Set.add currentRequirement currentStep.ClosedRequirements
                          OpenRequirements   = calcOpenRequirements(exploredPackage,globalFrameworkRestrictions,versionToExplore,currentRequirement,currentStep)
                      }
  
                  if nextStep.OpenRequirements = currentStep.OpenRequirements then
                      failwithf "The resolver confused itself. The new open requirements are the same as the old ones. This will result in an endless loop.%sCurrent Requirement: %A%sRequirements: %A" Environment.NewLine currentRequirement Environment.NewLine nextStep.OpenRequirements
  
  //                    let versionsToExplore = conflictState.VersionsToExplore
                      
                  // takes the next step and dives to update internal conflicts
                  // explore more versions, and accumulate more compatible packages for the requirement
                  let diveConflict = step (Step(conflictState,diver)) nextStep stackpack flags : ConflictState
  
  
                  // we take the updated state from the diveconflct, but we need to continue 
                  // searching the versions we halted to allow the diveConflict to evaluate
                  let continueConflict = {
                      diveConflict with
                          VersionsToExplore = conflictState.VersionsToExplore
                  }
  // !!!!! disabled temporarily !!!!!
  //                    match conflictState.Status with
  //                    | Resolution.Conflict (_,conflicts,_,_)
  //                        when
  //                            (Set.isEmpty conflicts |> not)
  //                            && nextStep.CurrentResolution.Count > 1
  //                            && not (conflicts |> Set.exists (fun r ->
  //                                r = currentRequirement
  //                                || r.Graph |> List.contains currentRequirement)) ->
  //                        let flags = StepFlags(flags.Ready,flags.UseUnlisted,flags.HasUnlisted,true,flags.FirstTrial)
  //                        stepLoop (Inner conflictState) flags
  //                    | _ ->
  //                        stepLoop flags (Inner conflictState)
                  stepLoop (Inner(continueConflict,diver)) (currentStep:ResolverStep) (stackpack:StackPack) 
                           (currentRequirement:PackageRequirement) compatibleVersions  flags 
                  //------------STEPLOOP AGAIN----------------    
      //--------END-OF-STEPLOOP---------------------
  
  
  
      and step (stage:Stage) (currentStep:ResolverStep) (stackpack:StackPack)(flags:StepFlags) =
          match stage with
          | Step  (conflictState, diver)
          | Inner (conflictState, diver) 
          | Outer (conflictState, diver) ->
  
          // if there are no outstanding package requirements we can return successfully
          if Set.isEmpty currentStep.OpenRequirements then
              { conflictState with
                 Status = Resolution.Ok (cleanupNames currentStep.CurrentResolution)
              }
          // ----------- TERMINATE --------------
          //    NEED TO HANDLE DIVER HERE - loop with INNER STAGE
          //-------------------------------------
          else
          verbosefn "  %d packages in resolution. %d requirements left" 
              currentStep.CurrentResolution.Count currentStep.OpenRequirements.Count
  
          let currentRequirement = 
              getCurrentRequirement packageFilter currentStep.OpenRequirements stackpack.ConflictHistory
  
          let conflicts = 
              getConflicts currentStep currentRequirement stackpack.KnownConflicts
  
          let conflictState =
              if Set.isEmpty conflicts then
                  let getVersionsF = getVersionsF currentRequirement.Sources ResolverStrategy.Max groupName
                  { conflictState with
                      Status = Resolution.Conflict(currentStep,Set.empty,currentRequirement,getVersionsF)}
              else
                  let getVersionsF = getVersionsF currentRequirement.Sources ResolverStrategy.Max groupName
                  { conflictState with
                      Status = Resolution.Conflict(currentStep,conflicts,Seq.head conflicts,getVersionsF)}
  
  
          if not (Set.isEmpty conflicts) then
              conflictState
          // ----------- TERMINATE --------------
          //    NEED TO HANDLE DIVER HERE - loop with INNER STAGE
          //-------------------------------------
          else
          let compatibleVersions,globalOverride,tryRelaxed =
              getCompatibleVersions currentStep groupName currentRequirement getVersionsF
                      conflictState.GlobalOverride
                      globalStrategyForDirectDependencies
                      globalStrategyForTransitives
  
          let conflictState = {
              conflictState with
                  Conflicts           = conflicts
                  TryRelaxed          = tryRelaxed
                  GlobalOverride      = globalOverride
          }
  
          let conflictState, stackpack =
              if Seq.isEmpty compatibleVersions then
                  boostConflicts currentStep.FilteredVersions currentRequirement stackpack conflictState
              else
                  conflictState, stackpack
  
          let flags =
              StepFlags
                  (   ready       = false
                  ,   useUnlisted = false
                  ,   hasUnlisted = false
                  ,   forceBreak  = flags.ForceBreak
                  ,   firstTrial  = flags.FirstTrial
                  )
  
  
  
          stepLoop (Outer (conflictState,diver)) (currentStep:ResolverStep) (stackpack:StackPack) 
                   currentRequirement compatibleVersions  flags 
          // ----------- TERMINATE --------------
      
      //--------END-OF-STEP---------------------
  
  
  
      let startingStep = {
  
negative.code: }
  
  
  let private getExploredPackage (pkgConfig:PackageConfig) getPackageDetailsF (stackpack:StackPack) =
      let key = (pkgConfig.Dependency.Name, pkgConfig.Version)
  
      match stackpack.ExploredPackages.TryGetValue key with
      | true, package ->
          let package = updateRestrictions pkgConfig package
          stackpack.ExploredPackages.[key] <- package
          stackpack, Some package
      | false,_ ->
          match explorePackageConfig getPackageDetailsF pkgConfig with
          | Some explored ->
              stackpack.ExploredPackages.Add(key,explored)
              stackpack, Some explored
          | None ->
              stackpack, None
  
  
  
  