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

[Cleanup] Remove state machine factory, runtime factory, and name resolver #774

Merged
Merged
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
24 changes: 15 additions & 9 deletions Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@
/// </remarks>
private static readonly AsyncLocal<ControlledRuntime> AsyncLocalInstance = new AsyncLocal<ControlledRuntime>();

internal static ControlledRuntime InstalledRuntime { get; private set; } = CreateWithConfiguration(default);

private static ControlledRuntime CreateWithConfiguration(CheckerConfiguration checkerConfiguration)
{
if (checkerConfiguration is null)
{
checkerConfiguration = CheckerConfiguration.Create();
}

var valueGenerator = new RandomValueGenerator(checkerConfiguration);
return new ControlledRuntime(checkerConfiguration, valueGenerator);
}

/// <summary>
/// The currently executing runtime.
/// </summary>
Expand All @@ -61,28 +74,28 @@
"state machine handlers or controlled tasks. If you are using external libraries that are executing concurrently, " +
"you will need to mock them during testing.",
Task.CurrentId.HasValue ? Task.CurrentId.Value.ToString() : "<unknown>")) :
RuntimeFactory.InstalledRuntime);
InstalledRuntime);

/// <summary>
/// If true, the program execution is controlled by the runtime to
/// explore interleavings and sources of nondeterminism, else false.
/// </summary>
internal static bool IsExecutionControlled { get; private protected set; } = false;

Check warning on line 83 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.IsExecutionControlled.set': new protected member declared in sealed type

Check warning on line 83 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.IsExecutionControlled.set': new protected member declared in sealed type

Check warning on line 83 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.IsExecutionControlled.set': new protected member declared in sealed type

Check warning on line 83 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.IsExecutionControlled.set': new protected member declared in sealed type

Check warning on line 83 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.IsExecutionControlled.set': new protected member declared in sealed type

Check warning on line 83 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.IsExecutionControlled.set': new protected member declared in sealed type

/// <summary>
/// The checkerConfiguration used by the runtime.
/// </summary>
protected internal readonly CheckerConfiguration CheckerConfiguration;

Check warning on line 88 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.CheckerConfiguration': new protected member declared in sealed type

Check warning on line 88 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.CheckerConfiguration': new protected member declared in sealed type

Check warning on line 88 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.CheckerConfiguration': new protected member declared in sealed type

Check warning on line 88 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.CheckerConfiguration': new protected member declared in sealed type

Check warning on line 88 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.CheckerConfiguration': new protected member declared in sealed type

Check warning on line 88 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.CheckerConfiguration': new protected member declared in sealed type

/// <summary>
/// List of monitors in the program.
/// </summary>
protected readonly List<Monitor> Monitors;

Check warning on line 93 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.Monitors': new protected member declared in sealed type

Check warning on line 93 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.Monitors': new protected member declared in sealed type

Check warning on line 93 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.Monitors': new protected member declared in sealed type

Check warning on line 93 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.Monitors': new protected member declared in sealed type

Check warning on line 93 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.Monitors': new protected member declared in sealed type

Check warning on line 93 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.Monitors': new protected member declared in sealed type

/// <summary>
/// Responsible for generating random values.
/// </summary>
protected readonly IRandomValueGenerator ValueGenerator;

Check warning on line 98 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.ValueGenerator': new protected member declared in sealed type

Check warning on line 98 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.ValueGenerator': new protected member declared in sealed type

Check warning on line 98 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.ValueGenerator': new protected member declared in sealed type

Check warning on line 98 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.ValueGenerator': new protected member declared in sealed type

Check warning on line 98 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.ValueGenerator': new protected member declared in sealed type

Check warning on line 98 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.ValueGenerator': new protected member declared in sealed type

/// <summary>
/// Monotonically increasing operation id counter.
Expand All @@ -92,7 +105,7 @@
/// <summary>
/// Records if the runtime is running.
/// </summary>
protected internal volatile bool IsRunning;

Check warning on line 108 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.IsRunning': new protected member declared in sealed type

Check warning on line 108 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.IsRunning': new protected member declared in sealed type

Check warning on line 108 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.IsRunning': new protected member declared in sealed type

Check warning on line 108 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.IsRunning': new protected member declared in sealed type

Check warning on line 108 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.IsRunning': new protected member declared in sealed type

Check warning on line 108 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.IsRunning': new protected member declared in sealed type

/// <summary>
/// Callback that is fired when the program throws an exception which includes failed assertions.
Expand Down Expand Up @@ -514,13 +527,6 @@
{
id = new StateMachineId(type, name, this);
}
else
{
Assert(id.Runtime is null || id.Runtime == this, "Unbound state machine id '{0}' was created by another runtime.", id.Value);
Assert(id.Type == type.FullName, "Cannot bind state machine id '{0}' of type '{1}' to an state machine of type '{2}'.",
id.Value, id.Type, type.FullName);
id.Bind(this);
}

var stateMachine = Create(type);
IStateMachineManager stateMachineManager = new StateMachineManager(this, stateMachine);
Expand Down Expand Up @@ -664,7 +670,7 @@
{
// Directly use sender as a StateMachine
var originInfo = new EventOriginInfo(sender.Id, sender.GetType().FullName,
NameResolver.GetStateNameForLogging(sender.CurrentState.GetType()));
sender.CurrentState.GetType().Name);

var eventInfo = new EventInfo(e, originInfo);

Expand Down Expand Up @@ -1440,7 +1446,7 @@
/// <summary>
/// Raises the <see cref="OnFailure"/> event with the specified <see cref="Exception"/>.
/// </summary>
protected internal void RaiseOnFailureEvent(Exception exception)

Check warning on line 1449 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.RaiseOnFailureEvent(Exception)': new protected member declared in sealed type

Check warning on line 1449 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.RaiseOnFailureEvent(Exception)': new protected member declared in sealed type

Check warning on line 1449 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.RaiseOnFailureEvent(Exception)': new protected member declared in sealed type

Check warning on line 1449 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-MacOS

'ControlledRuntime.RaiseOnFailureEvent(Exception)': new protected member declared in sealed type

Check warning on line 1449 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Windows

'ControlledRuntime.RaiseOnFailureEvent(Exception)': new protected member declared in sealed type

Check warning on line 1449 in Src/PChecker/CheckerCore/PRuntime/Runtime/ControlledRuntime.cs

View workflow job for this annotation

GitHub Actions / Build-And-Test-Ubuntu

'ControlledRuntime.RaiseOnFailureEvent(Exception)': new protected member declared in sealed type
{
if (exception is ExecutionCanceledException ||
(exception is ActionExceptionFilterException ae && ae.InnerException is ExecutionCanceledException))
Expand Down
74 changes: 0 additions & 74 deletions Src/PChecker/CheckerCore/PRuntime/Runtime/RuntimeFactory.cs

This file was deleted.

6 changes: 3 additions & 3 deletions Src/PChecker/CheckerCore/PRuntime/Specifications/Monitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected internal Type CurrentState
/// </summary>
internal string CurrentStateName
{
get => NameResolver.GetQualifiedStateName(CurrentState);
get => CurrentState.Name;
}

/// <summary>
Expand Down Expand Up @@ -985,7 +985,7 @@ internal HashSet<string> GetAllStates()
var allStates = new HashSet<string>();
foreach (var state in StateMap[GetType()])
{
allStates.Add(NameResolver.GetQualifiedStateName(state.GetType()));
allStates.Add(state.GetType().Name);
}

return allStates;
Expand All @@ -1003,7 +1003,7 @@ internal HashSet<Tuple<string, string>> GetAllStateEventPairs()
{
foreach (var binding in state.EventHandlers)
{
pairs.Add(Tuple.Create(NameResolver.GetQualifiedStateName(state.GetType()), binding.Key.FullName));
pairs.Add(Tuple.Create(state.GetType().Name, binding.Key.FullName));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public EnqueueStatus Enqueue(Event e, EventInfo info)

// TODO: check op-id of default event.
// A default event handler exists.
var stateName = NameResolver.GetStateNameForLogging(StateMachine.CurrentState.GetType());
var stateName = StateMachine.CurrentState.GetType().Name;
var eventOrigin = new EventOriginInfo(StateMachine.Id, StateMachine.GetType().FullName, stateName);
return (DequeueStatus.Default, DefaultEvent.Instance, new EventInfo(DefaultEvent.Instance, eventOrigin));
}
Expand Down Expand Up @@ -208,7 +208,7 @@ public EnqueueStatus Enqueue(Event e, EventInfo info)
/// <inheritdoc/>
public void RaiseEvent(Event e)
{
var stateName = NameResolver.GetStateNameForLogging(StateMachine.CurrentState.GetType());
var stateName = StateMachine.CurrentState.GetType().Name;
var eventOrigin = new EventOriginInfo(StateMachine.Id, StateMachine.GetType().FullName, stateName);
var info = new EventInfo(e, eventOrigin);
RaisedEvent = (e, info);
Expand Down
54 changes: 0 additions & 54 deletions Src/PChecker/CheckerCore/PRuntime/StateMachines/NameResolver.cs

This file was deleted.

12 changes: 6 additions & 6 deletions Src/PChecker/CheckerCore/PRuntime/StateMachines/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ private protected async Task HandleEventAsync(Event e)
break;
}

var currentStateName = NameResolver.GetQualifiedStateName(currentState.GetType());
var currentStateName = currentState.GetType().Name;
await InvokeUserCallbackAsync(UserCallbackType.OnEventUnhandled, e, currentStateName);
if (CurrentStatus is Status.Active)
{
Expand Down Expand Up @@ -1112,7 +1112,7 @@ private bool TryGetHandler(Type e, out EventHandlerDeclaration o)

private async Task HandleEventAsync(Event e, State declaringState, EventHandlerDeclaration eventHandler)
{
var handlingStateName = NameResolver.GetQualifiedStateName(declaringState.GetType());
var handlingStateName = declaringState.GetType().Name;
if (eventHandler is ActionEventHandlerDeclaration actionEventHandler)
{
var cachedAction = StateMachineActionMap[actionEventHandler.Name];
Expand Down Expand Up @@ -1265,7 +1265,7 @@ private void CheckDanglingTransition()
private async Task GotoStateAsync(Type s, string onExitActionName, Event e)
{
Runtime.LogWriter.LogGotoState(Id, CurrentStateName,
$"{s.DeclaringType}.{NameResolver.GetStateNameForLogging(s)}");
$"{s.DeclaringType}.{s.Name}");

// The state machine performs the on exit action of the current state.
await ExecuteCurrentStateOnExitAsync(onExitActionName, e);
Expand Down Expand Up @@ -1300,7 +1300,7 @@ private void DoStateTransition(State state)
{
EventHandlerMap = state.EventHandlers; // non-inheritable handlers.
CurrentState = state;
CurrentStateName = NameResolver.GetQualifiedStateName(CurrentState.GetType());
CurrentStateName = CurrentState.GetType().Name;
}


Expand Down Expand Up @@ -1542,7 +1542,7 @@ internal HashSet<string> GetAllStates()
var allStates = new HashSet<string>();
foreach (var state in StateInstanceCache[GetType()])
{
allStates.Add(NameResolver.GetQualifiedStateName(state.GetType()));
allStates.Add(state.GetType().Name);
}

return allStates;
Expand Down Expand Up @@ -1573,7 +1573,7 @@ internal HashSet<Tuple<string, string>> GetAllStateEventPairs()
where IncludeInCoverage(b.Value)
select b)
{
pairs.Add(Tuple.Create(NameResolver.GetQualifiedStateName(state.GetType()), binding.Key.FullName));
pairs.Add(Tuple.Create(state.GetType().Name, binding.Key.FullName));
}
}

Expand Down

This file was deleted.

Loading
Loading