Skip to content

Preserve equality attributes for annotated algebraic values - #504

Open
jmh530 wants to merge 1 commit into
libmir:masterfrom
jmh530:fix/annotated-equality-inference
Open

jmh530 wants to merge 1 commit into
libmir:masterfrom
jmh530:fix/annotated-equality-inference

Conversation

@jmh530

@jmh530 jmh530 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Problem

Compiling recursive algebraic values containing Annotated or AnnotatedOnce can fail attribute checking depending on compiler source-file order. This surfaced during a Redub build of mir-algorithm; replaying the compiler command independently reproduced the failure.

The underlying DMD frontend issue is tracked in dlang/dmd#24202. This PR provides a library workaround.

Changes

Explicitly declare pure nothrow @nogc on Annotated and AnnotatedOnce equality when isVariant!T is true. Mir algebraic equality already guarantees these attributes, so stating them on the wrappers breaks the recursive inference cycle.

Other wrapped types retain the existing inferred attributes. The equality expressions remain unchanged.

Add regression tests for both wrappers covering nested values, matching and differing annotations and payloads, mutable and const receivers, and equality calls requiring all three attributes. Additional checks verify that wrappers around a custom type whose equality allocates, throws, and modifies shared state do not incorrectly acquire these attributes.

Validation

Using mir-core 1.7.4:

  • Full Windows package tests passed with DMD 2.113.0 and LDC 1.43.0: 75 modules each.
  • Focused tests compiled and ran in both source-file orders on Windows with DMD 2.113.0 and LDC 1.43.0, and on Linux with DMD 2.112.0 and LDC 1.43.0.
  • Focused DMD tests passed with DIP1000 and with mir_test enabled.
  • The Windows DMD unittest-ci configuration passed.
  • The original equality methods fail the new regression tests with recursive attribute diagnostics.
  • git diff --check passed.

Remote CI, macOS tests, and the complete Linux package suite remain to be verified. This workaround addresses Mir algebraic types; it does not resolve attribute inference for arbitrary user-defined recursive wrappers.

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

Recursive equality attribute inference can fail depending on compiler
source-file order, as reported in dlang/dmd#24202. This affects algebraic
variants containing Annotated or AnnotatedOnce alternatives.

Explicitly declare pure, nothrow, and @nogc on both wrappers' equality
methods when the wrapped type is a Mir algebraic variant, whose equality
already guarantees those attributes. Preserve attribute inference for
other wrapped types.

Add regression coverage for nested equality, differing annotations and
values, const receivers, and calls requiring all three attributes.
Verify that wrappers around effectful custom types retain their original
attribute restrictions.

AI-Assisted-By: Codex (GPT-6 Astra Medium)
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.

1 participant