Skip to content

Comments

dynamic dispatch: add test for nested existentials in composite types (#9839)#10116

Open
NV-xiaoyongs wants to merge 1 commit intomasterfrom
xsun/dynamic-dispatch.9839.2026-02-20
Open

dynamic dispatch: add test for nested existentials in composite types (#9839)#10116
NV-xiaoyongs wants to merge 1 commit intomasterfrom
xsun/dynamic-dispatch.9839.2026-02-20

Conversation

@NV-xiaoyongs
Copy link
Collaborator

Fixes #9839

Test existential values crossing dynamic dispatch boundaries when nested inside structs and arrays. Covers 6 patterns with 12 scenarios: single container, array container, dual containers, mixed-interface container, triple dispatch (processor + nested IFoo + IBar param), and chained processors. Verified on vk, cuda, cpu, llvm backends with REPORT checks.

…#9839)

Test existential values crossing dynamic dispatch boundaries when nested
inside structs and arrays. Covers 6 patterns with 12 scenarios: single
container, array container, dual containers, mixed-interface container,
triple dispatch (processor + nested IFoo + IBar param), and chained
processors. Verified on vk, cuda, cpu, llvm backends with REPORT checks.
@NV-xiaoyongs NV-xiaoyongs requested a review from a team as a code owner February 20, 2026 23:43
@NV-xiaoyongs NV-xiaoyongs requested review from bmillsNV and Copilot and removed request for a team and Copilot February 20, 2026 23:43
@NV-xiaoyongs NV-xiaoyongs added the pr: non-breaking PRs without breaking changes label Feb 20, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2026

📝 Walkthrough

Walkthrough

Introduces a new Slang test file for nested existential values within composite types across dynamic dispatch patterns. Defines interfaces, concrete structs, containers with existential fields, and multiple dispatch processors. Includes 12 test cases validating existential propagation through dispatch boundaries and buffer operations.

Changes

Cohort / File(s) Summary
New Nested Existential Test Suite
tests/language-feature/dynamic-dispatch/nested-existential-dynamic-dispatch.slang
New comprehensive test file covering existential values nested in composite types (structs and arrays) across five dispatch patterns: single container, array container, dual containers, mixed containers with multiple existentials, and weighted dispatch with IBar parameters. Includes factory helpers, dispatch wrappers, and 12 test cases with embedded CHECK expectations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Existentials dance in nested arrays,
Through dispatch patterns, they find their ways,
In containers deep, they hold their grace,
Weighted, mixed, in each test case—
Twelve adventures proved, the truth remains:
Nested values flow through dispatch lanes!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'dynamic dispatch: add test for nested existentials in composite types' clearly and concisely describes the main change: adding a test for nested existentials in dynamic dispatch scenarios.
Description check ✅ Passed The description accurately relates to the changeset, detailing that it adds a comprehensive test for existential values crossing dynamic dispatch boundaries when nested in structs and arrays, covering 6 patterns with 12 scenarios.
Linked Issues check ✅ Passed The pull request fully addresses the requirements from issue #9839 by implementing comprehensive tests covering struct fields containing existentials, arrays of existentials, buffer loading, and dynamic dispatch across multiple patterns.
Out of Scope Changes check ✅ Passed All changes are scoped to adding a single test file focused on nested existentials in dynamic dispatch, with no extraneous modifications outside the stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch xsun/dynamic-dispatch.9839.2026-02-20

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

@claude
Copy link

claude bot commented Feb 20, 2026

Claude finished @NV-xiaoyongs's task in 8m 24s —— View job


Review complete

  • Fetch and analyze PR diff
  • Read the full test file for context
  • Check for correctness, test patterns, and consistency
  • Submit review

Result: Submitted a review comment. This is a well-structured, test-only PR adding comprehensive regression tests for nested existentials in composite types crossing dynamic dispatch boundaries (issue #9839). I manually verified all 12 expected computation values — all are correct. The test covers 6 dispatch patterns across 4 backends with both runtime (CHECK) and compile-time dispatch-site (REPORT-DAG) verification. No bugs or issues found.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/language-feature/dynamic-dispatch/nested-existential-dynamic-dispatch.slang (1)

7-13: Minor documentation inconsistency in pattern descriptions.

Lines 9-10 mention "through IProcessor dispatch" but the actual implementations use different interfaces:

  • Pattern 2 uses IArrayProcessor (not IProcessor)
  • Pattern 3 uses IDualProcessor (not IProcessor)
📝 Suggested fix
 // Patterns tested:
 //   1. Single Container (IFoo field) through IProcessor dispatch
-//   2. ArrayContainer (IFoo[4]) through IProcessor dispatch
-//   3. Two Containers through IProcessor dispatch (multiple nested existentials)
+//   2. ArrayContainer (IFoo[4]) through IArrayProcessor dispatch
+//   3. Two Containers through IDualProcessor dispatch (multiple nested existentials)
 //   4. Container with two different interface fields (IFoo + IBar) through dispatch
 //   5. Chained processors: output of one dispatched call feeds another
 //   6. IProcessor taking Container + additional IBar parameter (triple dispatch)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@tests/language-feature/dynamic-dispatch/nested-existential-dynamic-dispatch.slang`
around lines 7 - 13, Update the top comment patterns to accurately name the
interfaces used: change pattern 2's "through IProcessor dispatch" to "through
IArrayProcessor dispatch" and change pattern 3's "through IProcessor dispatch"
to "through IDualProcessor dispatch" so the descriptions match the
implementations (refer to IArrayProcessor and IDualProcessor symbols in the test
file).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@tests/language-feature/dynamic-dispatch/nested-existential-dynamic-dispatch.slang`:
- Around line 7-13: Update the top comment patterns to accurately name the
interfaces used: change pattern 2's "through IProcessor dispatch" to "through
IArrayProcessor dispatch" and change pattern 3's "through IProcessor dispatch"
to "through IDualProcessor dispatch" so the descriptions match the
implementations (refer to IArrayProcessor and IDualProcessor symbols in the test
file).

Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR adds a comprehensive test file (tests/language-feature/dynamic-dispatch/nested-existential-dynamic-dispatch.slang) targeting issue #9839. It tests existential values nested inside composite types (structs and arrays) crossing dynamic dispatch boundaries. No compiler source changes—test only.

What the test covers

The test exercises 6 dispatch patterns across 12 scenarios:

  1. Single Container (struct with IFoo field) through IProcessor dispatch
  2. ArrayContainer (IFoo[4]) through IArrayProcessor dispatch (sum and max)
  3. Dual Containers (two Container params) through IDualProcessor dispatch
  4. MixedContainer (IFoo + IBar fields) through IMixedProcessor dispatch
  5. Triple dispatchIWeightedProcessor dispatching on processor type, nested IFoo, and a separate IBar parameter
  6. Chained processors — output of one dispatched call feeding into another

Backends tested: -slang, -vk, -cuda, -cpu.

Verification

I manually traced all 12 expected values through the dispatch logic (with id=0 from numthreads(1,1,1)):

Test Processor Input Expected
1 ScaleProcessor(3.0) FooA(5.0), meta=7 5×3+7=22.0
2 OffsetProcessor(10.0) FooB(4.0), meta=3 8+10+3=21.0
3 ArraySumProcessor [1,4,3,8] 16.0
4 ArrayMaxProcessor [1,4,3,8] 8.0
5 DualScaleProcessor FooA(3)×FooB(2) 3×4=12.0
6 DualAddProcessor FooB(5)+FooA(7) 10+7=17.0
7 MixedScaleProcessor FooA(6)×BarX(3) 18.0
8 MixedSumProcessor FooB(3)+BarY(10) 6+5=11.0
9 WeightedProcessor FooB(4)×BarX(2) 8×2=16.0
10 BiasedProcessor FooA(3)+BarY(8)+1 3+4+1=8.0
11 Chained Scale→Offset FooA(5)→FooA(10) 20.0
12 MixedScale swapped FooB(2)×BarY(6) 4×3=12.0

All values are correct. Buffer size (12 floats) matches the output indices [0..11]. REPORT-DAG line offsets all reference the correct dispatch site lines.

Key findings

No bugs or correctness issues found. The test is clean.

Positive aspects

  • Excellent documentation: Each test block has clear comments explaining the expected computation, making the test self-documenting and easy to maintain.
  • Comprehensive dispatch coverage: 6 patterns covering single, array, dual, mixed, triple, and chained dispatch—good breadth for a regression test.
  • REPORT checks: The SIMPLE(filecheck=REPORT) test with -report-dynamic-dispatch-sites verifies not just runtime correctness but also that the compiler correctly identifies all dispatch sites. This is valuable for catching regressions in the dispatch analysis itself.
  • Clean structure: Separation of interfaces → composites → processors → helpers → entry point makes the 469-line file easy to follow.
  • Multi-backend: Testing across -slang, -vk, -cuda, -cpu provides good backend coverage.

Minor observations (non-blocking)

  • Issue #9839 also mentions loading existentials from StructuredBuffer<Container> (buffer-loaded existentials). This test covers the "passed between dynamically dispatched functions" aspect but not the buffer-loading scenario. That could be a follow-up.
  • The PR description mentions "llvm" backend but the test uses -slang (which may use LLVM internally). Not an issue, just a note.

Verdict

Looks good. This is a well-structured, comprehensive regression test with correct expected values. No inline comments needed—the code is solid.

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

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Existential Values Nested in Composite Types

1 participant