Skip to content

Work around DMD 2.105–2.112 quicksort inlining failures - #502

Open
jmh530 wants to merge 1 commit into
libmir:masterfrom
jmh530:codex/dmd-sorting-inlining
Open

jmh530 wants to merge 1 commit into
libmir:masterfrom
jmh530:codex/dmd-sorting-inlining

Conversation

@jmh530

@jmh530 jmh530 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #501.

Sorting arrays of structs can trigger a bounds assertion when compiled with DMD 2.105–2.112 and optimization/inlining. Construct quicksort’s tail partition directly and shorten the head in place on those releases, avoiding the returned range views that trigger the failure. Other compilers retain the existing implementation.

The reproducer starts passing at dlang/dmd#22189, released in DMD 2.113. The workaround is therefore restricted to DigitalMars with 2105 <= __VERSION__ < 2113. It preserves the sorting algorithm, comparator behavior, public API, and allocation behavior.

Strengthen the existing struct regression with an independently sorted reference. Add ascending and descending tests around quicksort’s size thresholds, checking ordering and preservation of every record and its payload.

Validation

  • All 30 standalone compiler/optimization combinations passed across DMD 2.104.2, 2.105.0, 2.106.0, 2.107.0, 2.108.0, 2.109.0, 2.110.0, 2.111.0, 2.112.1, and 2.113.0.
  • All 19 imported ndslice test modules passed with optimized inlining on Linux DMD 2.105.0, 2.112.1, and 2.113.0; Linux LDC 1.36; and Windows x64 DMD 2.112.0.
  • Additional optimized checks for strided, zipped, and reference-counted views passed on those Linux compilers.
  • Disabling the workaround while retaining the strengthened tests reproduces the original bounds assertion on Linux DMD 2.112.1.
  • The original standalone failure did not reproduce on Windows DMD 2.112.0; both baseline and workaround passed there.

No 32-bit runtime testing, full-package test run, or performance benchmarking was performed.

AI-Assisted-By: Codex (GPT-6 Astra Medium)

Avoid returned range views when splitting quicksort partitions on
affected DMD releases. Construct the tail directly and shorten the
head in place, preserving the original slicing path on other compilers.

Strengthen struct-sorting coverage with an independent reference and
checks for ordering and record preservation around quicksort thresholds.

AI-Assisted-By: Codex (GPT-6 Astra Medium)
@jmh530
jmh530 force-pushed the codex/dmd-sorting-inlining branch from a901cdc to d1eb1cc Compare November 2, 2026 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sorting structs triggers a bounds assertion with DMD 2.105–2.112 and inlining

1 participant