Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Oct 1, 2024
1 parent e59e3aa commit 6f2c371
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
17 changes: 8 additions & 9 deletions src/Draco.Compiler.Fuzzer/TuiTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ namespace Draco.Compiler.Fuzzer;

internal sealed class TuiTracer : Window, ITracer<SyntaxTree>
{
private sealed class InputQueueItem(SyntaxTree input, int index)
private sealed class InputQueueItem(InputWithId<SyntaxTree> input)
{
public SyntaxTree Input { get; } = input;
public int Index { get; } = index;
public SyntaxTree Input => input.Input;
public int Id => input.Id;

private readonly string labelString = $"Input {index}";
private readonly string labelString = $"Input {input.Id}";

public override string ToString() => this.labelString;
}

private sealed class FaultItem(SyntaxTree input, FaultResult fault)
private sealed class FaultItem(InputWithId<SyntaxTree> input, FaultResult fault)
{
public SyntaxTree Input { get; } = input;
public SyntaxTree Input { get; } = input.Input;
public FaultResult Fault { get; } = fault;

public override string ToString()
Expand Down Expand Up @@ -75,7 +75,6 @@ public override string ToString()
private readonly StatusItem seedStatusItem;

// Counters
private int inputQueueItemCounter = 0;
private int fuzzedInputCounter = 0;
private int minimizedInputCounter = 0;
private int mutatedInputCounter = 0;
Expand Down Expand Up @@ -329,7 +328,7 @@ public void SetFuzzer(Fuzzer<SyntaxTree, string, int> fuzzer)

public void InputsEnqueued(IEnumerable<InputWithId<SyntaxTree>> inputs)
{
foreach (var item in inputs) this.inputQueueList.Add(new(item, this.inputQueueItemCounter++));
foreach (var item in inputs) this.inputQueueList.Add(new(item));

this.inputQueueFrameView.Title = GetInputQueueFrameTitle(this.inputQueueList.Count);
}
Expand All @@ -339,7 +338,7 @@ public void InputDequeued(InputWithId<SyntaxTree> input)
this.minimizedInputCounter = 0;
this.mutatedInputCounter = 0;

var itemIndex = this.inputQueueList.FindIndex(item => item.Input == input);
var itemIndex = this.inputQueueList.FindIndex(item => item.Id == input.Id);
if (itemIndex >= 0) this.inputQueueList.RemoveAt(itemIndex);

this.currentInputFrameView.Title = GetCurrentInputFrameTitle();
Expand Down
12 changes: 6 additions & 6 deletions src/Draco.Fuzzing/Fuzzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ private QueueEntry Minimize(QueueEntry entry)
var entryInput = entry.GetInputWithId(this);
foreach (var minimizedInput in this.InputMinimizer.Minimize(this.Random, entryInput.Input))
{
var (minimizedResult, _) = this.Execute(minimizedInput);
var (minimizedResult, _, id) = this.Execute(minimizedInput);
if (AreEqualExecutions(referenceResult, minimizedResult))
{
// We found an equivalent execution, replace entry
lock (this.tracerSync) this.Tracer.MinimizationFound(entryInput, minimizedInput);
lock (this.tracerSync) this.Tracer.MinimizationFound(entryInput, new(id, minimizedInput));
entry = this.MakeQueueEntry(minimizedInput, minimizedResult);
goto found;
}
Expand All @@ -239,15 +239,15 @@ private void Mutate(QueueEntry entry)
var entryInput = entry.GetInputWithId(this);
foreach (var mutatedInput in this.InputMutator.Mutate(this.Random, entryInput.Input))
{
var (_, isInteresting) = this.Execute(mutatedInput);
var (_, isInteresting, id) = this.Execute(mutatedInput);
if (isInteresting)
{
lock (this.tracerSync) this.Tracer.MutationFound(entryInput, mutatedInput);
lock (this.tracerSync) this.Tracer.MutationFound(entryInput, new(id, mutatedInput));
}
}
}

private (ExecutionResult Result, bool IsInteresting) Execute(TInput input, int existingId = -1)
private (ExecutionResult Result, bool IsInteresting, int Id) Execute(TInput input, int existingId = -1)
{
var targetInfo = this.TargetExecutor.Initialize(input);
this.CoverageReader.Clear(targetInfo);
Expand All @@ -271,7 +271,7 @@ private void Mutate(QueueEntry entry)
this.inputQueue.Add(entry);
lock (this.tracerSync) this.Tracer.InputsEnqueued([entry.GetInputWithId(this)]);
}
return (executionResult, isInteresting);
return (executionResult, isInteresting, inputId);
}

private QueueEntry MakeQueueEntry(TInput input, ExecutionResult? executionResult = null, int id = -1)
Expand Down

0 comments on commit 6f2c371

Please sign in to comment.