Skip to content

C11 _Generic selects by the controlling type; M*LIB's upstream B+tree test runs under With (Phase 4 done) - #2579

Merged
ehartford merged 3 commits into
mainfrom
mlib-lane
Oct 23, 2026
Merged

ehartford merged 3 commits into
mainfrom
mlib-lane

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Two layers, one battery.

C11 _Generic selects by the controlling expression's type. libclang's GenericSelectionExpr (kind 122) was grouped with the transparent wrappers and peeled to its last child, the default arm: M*LIB's m_string_init_set(s, "text") called the string_t overload with a C string, and the upstream B+tree test faulted at its first emplace. The selection follows C11 6.5.1.1 from the expression's preprocessed text (libclang names association types only as TypeRefs for typedef names): the controlling type after lvalue conversion, one spelling per integer synonym, typedef names resolved through the translation unit's typedef declarations, the first matching arm, else default, else refused loudly. The text expander now substitutes function-like macro invocations (refusing #/## bodies) and the last definition of a redefined macro wins, as in the preprocessor. <stdbool.h>'s true/false lower as literals. Fixture generic_selection; WITH_MIGRATE_TRACE_GENERIC=1 traces each selection.

The mlib test lane (the Phase 4 gate). Upstream's tests/test-mbptree.c (eleven B+tree instantiations; int, double, string_t, testobj_t keys and values; multimaps and multisets; I/O round trips) is migrated whole in upstream's test configuration (M_USE_STDIO=1), checked in under test/corpora/mlib/programs/test_mbptree, compiled by the release binary with the prelude off and run; its exit code is the verdict, as STC's lane does. Targets mlib-migrate-tests, mlib-promote-tests, mlib-test-programs (run by mlib-test, so :test has it) and mlib-test-programs-fresh (in corpus-migrator-gate). The library corpus is untouched (D112): the test programs carry their own UPSTREAM pin.

Evidence: all thirteen upstream tests run to exit 0; c-migrator-basic-tests green; the four lane targets green; gate and battery green on the top commit (posted below).

Battery GREEN on 82d7b32 (334 s, seed-driven, this host).

Eric Hartford added 3 commits October 23, 2026 05:03
libclang's GenericSelectionExpr (kind 122) was grouped with the
transparent wrappers and peeled to its last child, the default arm:
M*LIB's `m_string_init_set(s, "text")` (`_Generic((b)+0, char*:
m_string_init_set_cstr, const char *: m_string_init_set_cstr, default:
m_string_init_set)`) called the string_t overload with a C string, and
the upstream B+tree test faulted in its string contract at the first
emplace.

The selection follows C11 6.5.1.1. libclang names an association's type
only as a TypeRef child for a typedef name and not at all for a builtin
spelling, so the association list is read from the expression's text
through the macros that spell it (ci_preprocessed_text_for_cursor): the
controlling expression's canonical type after lvalue conversion, each
association's type name under one spelling for the integer synonyms
(`signed int` is `int`, `long int` is `long`), a typedef name resolved
through its TypeRef, the first match's expression, else the default's,
else refused loudly. M*LIB's hash dispatch, `_Generic(((void)0,(x)),
int32_t: (x), default: (int32_t){0})`, selects by type where the arms'
expressions share one. Fixture: generic_selection.

The text expander (ci_expand_macros_in_text, the pure-With stand-in for
a `cc -E` slice) refused a function-like macro invocation; it now
substitutes the invocation's arguments into the macro session's body for
that macro and expands the result, refusing a body that pastes or
stringifies, so a dispatch spelled through M*LIB's macros
(`M_STR1NG_SELECT2`, the hash selectors) reaches its association list.
With it, `<stdbool.h>`'s `true`/`false` lower as the literals they are,
not as D90 library constants (`SetDouble_in_str` returned `true`).

Three further facts the upstream test's selections needed. An
association typed by a typedef name whose TypeRef libclang does not
produce (M*LIB's `m_str1ng_t`) is resolved by scanning the translation
unit's typedef declarations once per session (ci_typedef_canonical_key).
An arm whose expression is spelled by a macro parameter, `type: (x),
default: (type) {0}`, is read from its parenthesized expression. Two
definitions of one function-like macro (`M_PRINTF_FORMAT_EXTEND()` is
defined empty in m-core.h and redefined in m-string.h) resolve to the
last one in both macro lookups, as the preprocessor does; the printf
format selections (`btree_get_str`, `SetDouble_out_str`) read their full
association lists. The goto-CFG assignment site keeps its inner bail
reason instead of the generic one. WITH_MIGRATE_TRACE_GENERIC=1 prints
each selection's expressions, segments, keys and the chosen arm.
… Phase 4 gate)

`tests/test-mbptree.c` (eleven B+tree instantiations over int, double,
string_t and testobj_t keys and values, multimaps and multisets) is
migrated whole with m-core.h, m-string.h, m-bptree.h, tests/test-obj.h
and tests/coverage.h beside it, in upstream's test configuration
(`M_USE_STDIO=1`: tests/test-obj.h parses with fscanf outside any
M_USE_STDIO guard; coverage.h keeps M_ASSERT without BUILD_COVERAGE),
checked in under test/corpora/mlib/programs/test_mbptree, compiled by the
release binary with the prelude off and run; its exit code is the
verdict, as build/stc.w's lane does for STC's tests. Targets:
mlib-migrate-tests, mlib-promote-tests, mlib-test-programs and the
`-fresh` twin from the fresh migration (D112's migrator gate).
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