Skip to content

Chained array === with array_unique/array_map is false only in a larger program (semantic suite) #516

Closed

Description

@blacktrs

Summary

A chained && comparison of arrays inside a ternary evaluates to false natively, but only when the program also contains other code. Whole-program dependent miscompile; no single-file repro found yet.

Failing check (tests/semantic/name_index.php, dynamic_member_is_uncertain)

$s = $i->uncertainSites('anything');
$lines = array_map(fn($x) => $x->line, $s);
sort($lines);
$reasons = array_unique(array_map(fn($x) => $x->reason, $s));
return $lines === [2, 3, 4] && array_unique(array_map(fn($x) => $x->col, $s)) === [1] && $reasons === ['dynamic-member'] ? true : 'got ' . json_encode($s);

Native output: FAIL dynamic_member_is_uncertain: got [... 3 correct sites ...]. Zend: PASS. Each comparison evaluated into its own variable (or via string-concatenated var_export) is TRUE; only the combined && chain inside the ternary is false.

Reproduce

On the semantic-core P2c tree (bin/manticore freshly built):
bash tests/semantic/run.sh -k name_index,tolerant,variables,workspace (~90 s)

PASSES with -k name_index alone and with name_index + any ONE of tolerant/variables/workspace. Needs >= 2 of them.

Reduction so far (all native builds, each ~90 s)

Keeping only some top-level check(...) blocks of the other scripts (name_index.php untouched) still fails with:

Dropping half of workspace's checks flips the result either way (first half alone: pass; second half alone: pass; both: fail), so the trigger looks like a whole-program count/ordering effect (type-inference/monomorphization/fused-closure counters), not one construct. A standalone file with the same expression plus 300 extra array_map(fn)/array_unique functions does NOT reproduce.

Related, already fixed: #514 (array === hinted cell elems), #512 (prelude fn specialised too late after fused array_map).

Suggested next step: diff bin/manticore dump-mir --prelude of the failing vs passing combined program around the array_unique(...) call and the cmp === operands (which array_unique$mono$... clone / repr is used).

Activity

  1. added
    bug
    wrong-answer
    on Oct 28, 2026
  2. blacktrs commented on Oct 28, 2026

    @blacktrs
    ContributorAuthor

    Narrowing (compiler at semantic-core-p2c 9d33ff5):

    • The wrong value is the result of array_unique, not the comparison. In the failing combined program, array_unique(array_map(fn($x) => $x->col, $s)) where every col is int returns ["1"]: gettype($c[0]) is string, json_encode prints ["1"], == with [1] is true and === false. The array_map result itself is int.
    • It is sensitive to the number of array_unique call sites: adding three more calls (literal list, loop-built list, a second array_map result) to the same closure makes all results int and the test pass.
    • In the failing build the user-code calls do not reach manticore_array_unique by name; its only callers in the IR are __mir_dynft_* trampolines. The closure carries the array_unique work inline (__mir_array_live_len / __mir_array_alloc / __mir_array_value_at / __mir_array_key_cell_at loops).
    • Repro needs name_index + two or more of tolerant_analysis / variables / workspace: bash tests/semantic/run.sh -k name_index,tolerant,variables,workspace (tests/semantic/run.sh is on branch semantic-core-p2c).
    • Next step: see which pass decides the specialisation of the prelude array_unique per call site (Monomorphize call keys / SPEC_CAP / the cell-elem dimension) and why the int-element site gets a string-element body when the program has few sites.
  3. added
    needs-info
    on Nov 2, 2026
  4. blacktrs commented on Nov 15, 2026

    @blacktrs
    ContributorAuthor

    No longer reproduces on main 8c817ed + fix/lsp-followups: bash tests/semantic/run.sh -k name_index,tolerant,variables,workspace → 93 PASS / 0 FAIL (dynamic_member_is_uncertain passes); full tests/semantic 744/0. Program-composition dependent, so not proven fixed by a specific change.

  5. blacktrs commented on Nov 15, 2026

    @blacktrs
    ContributorAuthor

    Closing: does not reproduce (evidence above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-infowrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions