swiftlang / swiftlang/swift-corelibs-libdispatch

[SR-9631] Extend `dispatchPrecondition` with context parameters.

Open
#626 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Improvement libdispatch
Dominant language
C
Stars
2.6k
Forks
496
Avg merge
2d 6h
Merged PRs (30d)
3

Description

Previous ID SR-9631
Radar None
Original Reporter @DevAndArtist
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s libdispatch
Labels Improvement
Assignee None
Priority Medium

md5: e24006469dbf42660effda4f02808744

Issue Description:

public func dispatchPrecondition(condition: @autoclosure () -> DispatchPredicate)

Is a great function to prove correct scheduling behavior, but it completely lacks of context. In my particular case I have to nest that function into an operator for an `Observable` type which works asynchronously. Whenever the precondition triggers I have no information where the issue was raised because as already mentioned `dispatchPrecondition` must be nested.

In local development I can manually print `#function` and similar before calling `dispatchPrecondition` which will give me the right context, but this solution is far from ideal and cannot be captured in a real crash on a released application.

I would like to propose an addition of context parameters for `dispatchPrecondition` which will be printed when the execution traps.

public func dispatchPrecondition(
  condition: @autoclosure () -> DispatchPredicate,
  message: @autoclosure () -> String = "",
  function: StaticString = #function,
  file: StaticString = #file,
  line: UInt = #line
)

That new context should be passed to the internal `_dispatch_client_assert_fail` function.

As already mentioned, it's impossible to workaround this problem for a released application and when nested it's impossible to obtain the context information from a crash report.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the dispatchPrecondition API and the internal _dispatch_client_assert_fail entry point mentioned in the issue, then trace how precondition failures are reported. Determine how the proposed message, function, file, and line context should reach the trap output; the work is done when nested calls expose that context in released crash reports.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, swift
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.