Skip to content

Accept reordered neighbors in C graph clones - #376

Merged
jserv merged 2 commits into
sysprog21:mainfrom
jiawei110:fix-c-graph-neighbour-order
Oct 21, 2026
Merged

jserv merged 2 commits into
sysprog21:mainfrom
jiawei110:fix-c-graph-neighbour-order

Conversation

@jiawei110

@jiawei110 jiawei110 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Correct C graph clones could fail exact comparison when their neighbor arrays used a different order from the expected adjacency list. The C serializer now sorts temporary copies of neighbor IDs, preserving the candidate's graph and the original-node rejection check.

The regression tests cover original, reversed, partially reversed and rotated neighbor orders, including a node with three neighbors. They also compile and run a solution that returns the input graph and require rejection of every nonempty case.

Validation on Windows 11, over 4faffce:

  • node --test --test-name-pattern="C Clone Graph" tests/browser/compiler-explorer.test.js: 5 passed, 0 failed and 0 skipped on Windows using local cc, as confirmed by the contributor's output. This covers original, reversed, partially reversed and rotated neighbor orders, plus rejection of the original graph.
  • An earlier before/after comparison using a temporary local MSVC adapter showed that the three reordered-neighbor tests fail with the original serializer and all five graph tests pass with the fix. The adapter is not part of this PR.
  • git diff --check passes.
  • Manual validation reported by the contributor: C compilation and execution succeeded in the CodeTrial UI.

Additional local checks run by the contributor:

  • npx prettier --check web/compiler-explorer.js tests/browser/compiler-explorer.test.js
  • npx eslint web/compiler-explorer.js tests/browser/compiler-explorer.test.js
  • ./scripts/test.sh

./scripts/test.sh is not green on this Windows machine. Failing gate touch non of these files


Summary by cubic

Fixes the C Clone Graph judge rejecting valid deep copies when neighbor order differs, and now also rejects NULL neighbors in C and C++ graph clones so malformed answers get a diagnostic instead of crashing the harness.

The C serializer now sorts neighbor IDs before comparison, and both C and C++ graph serializers detect and reject NULL neighbors during traversal.

Tests:

  • Cover original, reversed, partially reversed, and rotated neighbor orders, including a degree-three node.
  • Verify every nonempty case is rejected when the input graph is returned unchanged, and that NULL neighbors are reported for root and non-root nodes.

Written for commit faa7c10. Summary will update on new commits.

View guided diff


Updated 20261022

Correct C graph clones could fail exact comparison when their neighbor arrays used a different order from the expected adjacency list. The C serializer now sorts temporary copies of neighbor IDs, preserving the candidate's graph and the original-node rejection check.

Both C and C++ graph serializers now reject NULL neighbor slots during traversal, before dereferencing them or generating adjacency rows. An incomplete clone receives a per-case diagnostic while subsequent cases continue to run.

The native regression tests cover original, reversed, partially reversed and rotated C neighbor orders, reversed C++ neighbors, and a node with three neighbors. They also reject returned original C nodes and exercise NULL slots on both root and reachable non-root nodes in C and C++.

Validation:

  • node --test --test-timeout=30000 --test-name-pattern="Clone Graph" tests/browser/compiler-explorer.test.js: 10 passed, 0 failed and 0 skipped on Windows using local cc and g++.
  • ./scripts/test.sh browser: 1,022 passed, 0 failed and 320 skipped because Chromium or Java was unavailable; the lane exited successfully.
  • Before/after native checks reproduced crashes for NULL slots on root and reachable non-root nodes in both C and C++; the guarded versions pass. An earlier MSVC comparison also confirmed that three reordered-neighbor tests fail before C neighbor normalization.
  • Prettier and ESLint pass for both changed files.
  • git diff --check passes.
  • Manual validation reported by the contributor: C++ compilation and execution succeeded in the CodeTrial UI.

Closes #360

cubic-dev-ai[bot]

This comment was marked as resolved.

Comment thread web/compiler-explorer.js Outdated
The graph contract ignores neighbor order, but C results depended on
it and rejected valid deep copies. Normalize neighbor IDs so equivalent
graphs receive the same verdict while retaining deep-copy validation.
Incomplete graph clones can leave NULL neighbor slots and crash the
harness. Reject them during traversal so malformed answers receive a
diagnostic and the remaining test cases can still run.
@jiawei110
jiawei110 force-pushed the fix-c-graph-neighbour-order branch from b18fcaf to faa7c10 Compare October 21, 2026 16:58
@jserv
jserv requested review from ColtenOuO and alanhc October 21, 2026 16:59
@jserv
jserv merged commit e335ae4 into sysprog21:main Oct 21, 2026
10 checks passed
@jserv

jserv commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Thank @jiawei110 for contributing!

@jiawei110
jiawei110 deleted the fix-c-graph-neighbour-order branch October 22, 2026 02:48
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.

C tests reject a correct graph clone with reordered neighbors

2 participants