Skip to content

IOSimPOR: racyByLabel - #274

Merged
coot merged 4 commits into
mainfrom
coot/racy-by-label
Nov 20, 2026
Merged

coot merged 4 commits into
mainfrom
coot/racy-by-label

Conversation

@coot

@coot coot commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

This PR adds a more control over which threads are part of schedule exploration. It relies on two API changes:

  • explorationRaceByLabel callback field for ExplorationOptions (with two helpers withRacyMainThread and withRaceByLabel
  • new forkLabelledIO, asyncLabelled, withAsyncLabelled & friends, which must be used so the label is available when forked thread is created rather than altered when the forked read is being executed.

An alternative design where IOSimThreadId is no longer a type with two constructors RacyThreadId and ThreadId is possilbe. It wouldn't require speciall forkLabelledIO API, but it is significant change to the IOSimPOR internals, and thus I decided to not pursue it. The advantage of the implemented design is simplicity of IOSimPOR changes (Fork carries ThreadLabel field), all other changes are peripheral to IOSimPOR race discovery logic, plus changes to MonadFork and MonadAsync.

@coot
coot requested a review from a team as a code owner November 13, 2026 16:14
@coot
coot force-pushed the coot/racy-by-label branch 2 times, most recently from 1c9bc01 to 553d462 Compare November 14, 2026 21:13
@coot coot added IOSimPOR Issues / PRs related to IOSimPOR leios Issues, PRs related to leios labels Nov 14, 2026
@coot coot self-assigned this Nov 14, 2026
@github-project-automation github-project-automation Bot moved this to In Progress in Ouroboros Network Nov 14, 2026
@coot

coot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Subsumes #273

@jasagredo jasagredo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some minor clarifications requested

Comment thread io-sim/src/Control/Monad/IOSim/Types.hs Resolved
Comment thread io-sim/src/Control/Monad/IOSim/Types.hs Resolved
explorationStepTimelimit,
explorationReplay,
explorationDebugLevel,
explorationRacyByLabel = _

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why destructure it if you are discarding the value?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to be explicit that it is not shown.

coot added 4 commits November 20, 2026 13:37
The default implementation of `withAsyncWithUnmask` (used by IOSim, but
not IO), didn't restore masking state the same way `async` and `base`
packages do.  This only matters if the `withAsyncWithUnmask` is
called when exception are `Unmasked`.   The correct implementation
(below) uses `restore` in
```hs
 withAsyncWithUnmask action inner = mask $ \restore -> do
                                      a <- asyncWithUnmask (\unmask -> restore (action unmask))
                                      restore (inner a)
                                        `finally` uninterruptibleCancel a
```
to restores the original `Unmasked` state.

The buggy implementation:
```hs
 withAsyncWithUnmask action inner = mask $ \restore -> do
                                      a <- asyncWithUnmask action
                                      restore (inner a)
                                        `finally` uninterruptibleCancel a
```
when called with exceptions `Unmasked`, will run `action` in
`InterruptibleMasked` state instead.

There's not difference between the two implementations when the function
is called when exceptions are masked or uninterruptibly masked.

The commit includes tests for `IO` and `IOSim` instances.
IOSimPOR can now select the threads which take par ti in race discovery
by their label with the following rules:

* threads must be started by one of `forkLabelledIO` or `asyncLabelled`,
  `withAsyncLabelled` and friends - this makes sure the thread label is
  available in `IOSim` when a thread is created rather than set by
  `labelThisThread` when it is scheduled
* racy flag is sticky, e.g. threads started by a thread that are part of
  race discovery are part of the race discovery.

You need to set the new `explorationRacyByLabel` field of
`ExplorationOptions`, either directly or by using one of the two
combinators:
* `withRacyMainThread` - IOSimPOR will make all threads part of schedule
  exploration (this wasn't possible before)
* `withRacyByLabel` - by passing a callback the simulation can select
  which threads will be part race exploration

The test-suite is using now internal API, and thus depends on `io-sim`
sources directly.  This way we can keep internal API unexposed to the
user.  Almost all `IOSimPOR` tests are using now `withRacyMainThread`
- for that reason we had to drop `withNumTests 1000` from two tests.

New tests are included for labelled functions.
@coot
coot force-pushed the coot/racy-by-label branch from f1338ba to 7e838de Compare November 20, 2026 12:46
@coot
coot enabled auto-merge November 20, 2026 12:46
@coot
coot added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit b730c3d Nov 20, 2026
17 checks passed
@coot
coot deleted the coot/racy-by-label branch November 20, 2026 13:11
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Ouroboros Network Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

IOSimPOR Issues / PRs related to IOSimPOR leios Issues, PRs related to leios

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants