Skip to content

Commit

Permalink
Fix states attributes calculation (history and children)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsvgit committed Dec 22, 2023
1 parent a5efef2 commit 5e7da8a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion VSharp.Explorer/AISearcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ type internal AISearcher(coverageToSwitchToAI: uint, oracle:Oracle, serialize:bo
edges.AddRange delta.Map
let activeStates = vertices |> Seq.collect (fun v -> v.States) |> HashSet
let states =
s.States |> Array.filter (fun s -> activeStates.Contains s.Id && (not <| updatedStates.Contains s.Id))
s.States
|> Array.filter (fun s -> activeStates.Contains s.Id && (not <| updatedStates.Contains s.Id))
|> Array.map (fun s -> State(s.Id
, s.Position
, s.PredictedUsefulness
Expand Down
4 changes: 2 additions & 2 deletions VSharp.Explorer/Explorer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ type private SVMExplorer(explorationOptions: ExplorationOptions, statistics: SVM
goodStates @ iieStates @ errors
| _ ->
sIsStopped <- true
goodStates @ iieStates @ errors
Application.moveState loc s (Seq.cast<_> newStates)
goodStates @ iieStates @ errors
for newState in newStates do
let historyCopy = System.Collections.Generic.Dictionary<_,_>()
for kvp in s._history do historyCopy.Add(kvp.Key, kvp.Value)
newState._history <- historyCopy
s.children <- s.children @ newStates
Application.moveState loc s (Seq.cast<_> newStates)
statistics.TrackFork s newStates
searcher.UpdateStates s newStates
if sIsStopped then
Expand Down
2 changes: 2 additions & 0 deletions VSharp.IL/CFG.fs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,8 @@ module Application =
let terminateState (state: IGraphTrackableState) =
// TODO: gsv: propagate this into application graph
let removed = state.CodeLocation.BasicBlock.AssociatedStates.Remove state
let added = applicationGraphDelta.TouchedBasicBlocks.Add state.CodeLocation.BasicBlock
let added = applicationGraphDelta.TouchedStates.Add state
visualizer.TerminateState state

let addCallEdge = graph.AddCallEdge
Expand Down
2 changes: 1 addition & 1 deletion VSharp.IL/Serializer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ let collectGameState (basicBlocks:ResizeArray<BasicBlock>) (serialize: bool) =
s.VisitedNotCoveredVerticesInZone,
s.VisitedNotCoveredVerticesOutOfZone,
s.History |> Seq.map (fun kvp -> StateHistoryElem(kvp.Key.Id, kvp.Value)) |> Array.ofSeq,
s.Children |> Array.map (fun s -> s.Id) |> Array.filter activeStates.Contains
s.Children |> Array.map (fun s -> s.Id) // |> Array.filter activeStates.Contains
)
|> allStates.Add
|> ignore
Expand Down
8 changes: 3 additions & 5 deletions VSharp.SILI/CILState.fs
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,8 @@ module CilState =
let clone = { x with state = x.state }
let mkCilState state' =
if LanguagePrimitives.PhysicalEquality state' x.state then x
else
let s = clone.Copy(state')
s.internalId <- getNextStateId()
s
else clone.Copy(state')

StatedConditionalExecution x.state conditionInvocation
(fun state k -> thenBranch (mkCilState state) k)
(fun state k -> elseBranch (mkCilState state) k)
Expand Down Expand Up @@ -486,7 +484,7 @@ module CilState =
// -------------------- Changing inner state --------------------

member x.Copy(state : state) =
{ x with state = state }
{ x with state = state ;internalId = getNextStateId(); children = [] }

// This function copies cilState, instead of mutation
member x.ChangeState state' : cilState =
Expand Down

0 comments on commit 5e7da8a

Please sign in to comment.