Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interprocedural searcher #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion VSharp.API/VSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public enum SearchStrategy
/// </summary>
ShortestDistance,
/// <summary>
/// Picks the state closest to not covered locations (considering function calls).
/// </summary>
InterproceduralShortestDistance,
/// <summary>
/// With a high probability picks the state closest to not covered locations.
/// </summary>
RandomShortestDistance,
Expand Down Expand Up @@ -238,7 +242,8 @@ private static searchMode ToSiliMode(this SearchStrategy searchStrategy)
SearchStrategy.ShortestDistance => searchMode.ShortestDistanceBasedMode,
SearchStrategy.RandomShortestDistance => searchMode.RandomShortestDistanceBasedMode,
SearchStrategy.ContributedCoverage => searchMode.ContributedCoverageMode,
SearchStrategy.Interleaved => searchMode.NewInterleavedMode(searchMode.ShortestDistanceBasedMode, 1, searchMode.ContributedCoverageMode, 9)
SearchStrategy.Interleaved => searchMode.NewInterleavedMode(searchMode.ShortestDistanceBasedMode, 1, searchMode.ContributedCoverageMode, 9),
SearchStrategy.InterproceduralShortestDistance => searchMode.InterproceduralShortestDistanceMode
};
}

Expand Down
3 changes: 3 additions & 0 deletions VSharp.SILI/BidirectionalSearcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type BidirectionalSearcher(forward : IForwardSearcher, backward : IBackwardSearc
backward.Reset()
targeted.Reset()

override x.Refresh() = forward.Refresh()

override x.Remove cilState =
forward.Remove cilState
backward.Remove cilState
Expand All @@ -98,6 +100,7 @@ type OnlyForwardSearcher(searcher : IForwardSearcher) =
| Some s -> GoFront s
| None -> Stop
override x.States() = searcher.States()
override x.Refresh() = searcher.Refresh()
override x.Reset() = searcher.Reset()
override x.Remove cilState = searcher.Remove cilState
override x.StatesCount with get() = searcher.StatesCount
Expand Down
12 changes: 12 additions & 0 deletions VSharp.SILI/CILState.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
namespace VSharp.Interpreter.IL

open FSharpx.Collections
open VSharp
open System.Text
open System.Collections.Generic
open VSharp.Core
open VSharp.Interpreter.IL
open ipOperations

type CallStackEvent =
| Push of callFrom: codeLocation * callTo: codeLocation
| Pop

[<ReferenceEquality>]
type cilState =
{ mutable ipStack : ipStack
Expand All @@ -23,6 +28,7 @@ type cilState =
mutable suspended : bool
mutable targets : Set<codeLocation> option
mutable lastPushInfo : term option
mutable lastCallStackEvents : CallStackEvent FSharpx.Collections.Queue
/// <summary>
/// All basic blocks visited by the state.
/// </summary>
Expand Down Expand Up @@ -80,6 +86,7 @@ module internal CilStateOperations =
suspended = false
targets = None
lastPushInfo = None
lastCallStackEvents = Queue.empty
history = Set.empty
entryMethod = Some entryMethod
id = getNextStateId()
Expand Down Expand Up @@ -176,6 +183,7 @@ module internal CilStateOperations =
| Some loc' when loc'.method.HasBody ->
cilState.currentLoc <- loc'
Application.addCallEdge loc loc'
cilState.lastCallStackEvents <- Queue.conj (Push(loc, loc')) cilState.lastCallStackEvents
| _ -> ()
cilState.ipStack <- ip :: cilState.ipStack

Expand Down Expand Up @@ -223,6 +231,9 @@ module internal CilStateOperations =
| Some value when value > 0u -> cilState.level <- PersistentDict.add k (value - 1u) lvl
| _ -> ()

let clearLastCallStackEvents (cilState : cilState) =
cilState.lastCallStackEvents <- Queue.empty

let setBasicBlockIsVisited (cilState : cilState) (loc : codeLocation) =
cilState.history <- Set.add loc cilState.history

Expand All @@ -233,6 +244,7 @@ module internal CilStateOperations =
Memory.PopFrame cilState.state
let ip = List.tail cilState.ipStack
cilState.ipStack <- ip
cilState.lastCallStackEvents <- Queue.conj Pop cilState.lastCallStackEvents
match ip with
| ip::_ -> moveCodeLoc cilState ip
| [] -> ()
Expand Down
4 changes: 1 addition & 3 deletions VSharp.SILI/CombinedWeighter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ open VSharp.Interpreter.IL.TypeUtils
/// <summary>
/// Combines two weighters using the given combinator function.
/// </summary>
type internal CombinedWeighter(one : IWeighter, another : IWeighter, maxPriority : uint, combinator : uint option -> uint option -> uint option) =
type internal CombinedWeighter(one : IWeighter, another : IWeighter, combinator : uint option -> uint option -> uint option) =

interface IWeighter with
override x.Weight(state) =
let oneWeight = one.Weight state
let anotherWeight = another.Weight state
combinator oneWeight anotherWeight
override x.Next() = maxPriority

type internal AugmentedWeighter(baseWeighter : IWeighter, mapping : uint option -> uint option) =

interface IWeighter with
override x.Weight(state) = baseWeighter.Weight state |> mapping
override x.Next() = baseWeighter.Next()

module internal WeightOperations =

Expand Down
1 change: 1 addition & 0 deletions VSharp.SILI/ConcolicSearcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ type internal ConcolicSearcher(baseSearcher : IForwardSearcher) =
override x.Update(parent, newStates) = baseSearcher.Update(parent, newStates)
override x.States() = baseSearcher.States()
override x.Reset() = baseSearcher.Reset()
override x.Refresh() = baseSearcher.Refresh()
override x.Remove cilState = baseSearcher.Remove cilState
override x.StatesCount with get() = baseSearcher.StatesCount
3 changes: 0 additions & 3 deletions VSharp.SILI/ContributedCoverageSearcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type internal ContributedCoverageWeighter(statistics : SILIStatistics) =

interface IWeighter with
override x.Weight(state) = weight state
override x.Next() = UInt32.MaxValue

type internal ContributedCoverageSearcher(maxBound, statistics) =
inherit WeightedSearcher(maxBound, ContributedCoverageWeighter(statistics), BidictionaryPriorityQueue())
Expand All @@ -21,8 +20,6 @@ type internal ContributedCoverageWithDistanceAsFallbackWeighter(statistics) =
inherit CombinedWeighter(
ContributedCoverageWeighter(statistics),
IntraproceduralShortestDistanceToUncoveredWeighter(statistics),
UInt32.MaxValue,
WeightOperations.withInverseLinearFallback 100u)

type internal ContributedCoverageWithDistanceAsFallbackSearcher(maxBound, statistics) =
inherit WeightedSearcher(maxBound, ContributedCoverageWithDistanceAsFallbackWeighter(statistics), BidictionaryPriorityQueue())
4 changes: 1 addition & 3 deletions VSharp.SILI/DistanceWeighter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ type ShortestDistanceWeighter(target : codeLocation) =
return weight * logarithmicScale state.stepsNumber
| None -> return 1u
}
override x.Next() = 0u

type IntraproceduralShortestDistanceToUncoveredWeighter(statistics : SILIStatistics) =

Expand All @@ -107,6 +106,7 @@ type IntraproceduralShortestDistanceToUncoveredWeighter(statistics : SILIStatist
|> Seq.fold (fun min kvp ->
let loc = { offset = kvp.Key; method = method }
let distance = kvp.Value
// TODO: check all instructions of basic block for coverage
if distance < min && distance <> 0u && not <| statistics.IsCovered loc then distance
else min) infinity
Some minDistance
Expand All @@ -118,5 +118,3 @@ type IntraproceduralShortestDistanceToUncoveredWeighter(statistics : SILIStatist
| Some loc when loc.method.InCoverageZone -> minDistance loc.method loc.offset
| Some _ -> None
| None -> Some 1u)

override x.Next() = 0u
3 changes: 3 additions & 0 deletions VSharp.SILI/FairSearcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ type internal FairSearcher(baseSearcherFactory : unit -> IForwardSearcher, timeo

let remove cilState = baseSearcher.Remove cilState

let refresh() = baseSearcher.Refresh()

member x.BaseSearcher with get() = baseSearcher

interface IForwardSearcher with
Expand All @@ -141,4 +143,5 @@ type internal FairSearcher(baseSearcherFactory : unit -> IForwardSearcher, timeo
override x.States() = states()
override x.Reset() = reset()
override x.Remove cilState = remove cilState
override x.Refresh() = refresh()
override x.StatesCount with get() = baseSearcher.StatesCount
3 changes: 3 additions & 0 deletions VSharp.SILI/InterleavedSearcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type InterleavedSearcher(searchersWithStepCount: (IForwardSearcher * int) list)

let states() = searchersWithStepCount |> Seq.collect (fun (s, _) -> s.States()) |> Seq.distinct

let refresh() = for searcher, _ in searchersWithStepCount do searcher.Refresh()

let reset() = for searcher, _ in searchersWithStepCount do searcher.Reset()

let remove cilState = for searcher, _ in searchersWithStepCount do searcher.Remove cilState
Expand All @@ -42,6 +44,7 @@ type InterleavedSearcher(searchersWithStepCount: (IForwardSearcher * int) list)
override x.Pick selector = pick (Some selector)
override x.Update (parent, newStates) = update (parent, newStates)
override x.States() = states()
override x.Refresh() = refresh()
override x.Reset() = reset()
override x.Remove cilState = remove cilState
override x.StatesCount with get() = searchersEnumerator.Current.StatesCount
Loading