Skip to content

Add typed self-counting WASM sections - #131771

Open
jtschuster wants to merge 12 commits into
mainfrom
wasm-writer-typed-sections
Open

Add typed self-counting WASM sections#131771
jtschuster wants to merge 12 commits into
mainfrom
wasm-writer-typed-sections

Conversation

@jtschuster

@jtschuster jtschuster commented Aug 3, 2026

Copy link
Copy Markdown
Member

Summary

This is the second PR in the WASM object-writer stack and builds on #131770.

  • Replaces shared functionality in WasmSection and WebCilSection for emitting a SectionWriter's data to SectionDataEmitter.
  • Change WebCilSection's base class from WasmSection to SectionDataEmitter to clarify that it's not an actual custom Wasm section.
  • Add typed vector sections for imports, functions, globals, exports, and elements. Adding entries / data to these sections should be done through their respective methods that take an entry object and the corresponding SectionWriter. This allows them to accurately track the count of entries in the section.
  • Type and Code are externally counted since entries can be added to from the base ObjectWriter.
  • Remove the corresponding manual counters and count-prefix rewriting from the writer.

The emitted module structure and existing writer behavior are preserved while making section counts follow directly from successfully written rows.

Stack

  1. Extract WASM section model #131770 — Extract WASM section model
  2. Add typed self-counting WASM sections #131771 — Add typed self-counting WASM sections (this PR)
  3. Introduce WebCIL object writer type #131772 — Introduce WebCIL object writer type
  4. Move shared WASM logic to base writer #131778 — Move shared WASM logic to base writer

Note

This PR description was generated with GitHub Copilot assistance.

jtschuster and others added 2 commits August 3, 2026 10:46
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@jtschuster
jtschuster marked this pull request as ready for review August 3, 2026 21:03
Copilot AI review requested due to automatic review settings August 3, 2026 21:03
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors WASM section emission in the CoreCLR object writer to use typed, self-counting “vector” sections (imports/functions/globals/exports/elements), moving per-row encoding into section-specific WriteEntry implementations and eliminating manual counters / count-prefix patching in the writer.

Changes:

  • Introduces WasmVectorSection / WasmSection<TEntry> abstractions that prepend the vector length automatically and increment entry counts only after successful entry encoding.
  • Updates WasmObjectWriter to use Add* APIs that delegate row encoding/counting to typed section implementations, and finalizes Type/Code counts via an externally-counted section type.
  • Moves WasmExportKind to a shared location (WasmNative.cs) for reuse by section code.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs Switches writer logic to typed sections (Add* methods) and removes manual count handling; finalizes external counts for Type/Code.
src/coreclr/tools/Common/Compiler/ObjectWriter/WasmNative.cs Adds shared WasmExportKind enum for export section encoding.
src/coreclr/tools/Common/Compiler/ObjectWriter/Wasm/WasmSections.cs Adds typed GetSection<T> helpers to retrieve sections safely by name/index.
src/coreclr/tools/Common/Compiler/ObjectWriter/Wasm/WasmSection.cs Replaces PrependCount with a generalized content-prefix mechanism and adds self-counting vector section implementations for key WASM sections.

Copilot AI review requested due to automatic review settings August 6, 2026 18:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Note

This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.

Base automatically changed from wasm-writer-section-model to main August 6, 2026 19:08
Copilot AI review requested due to automatic review settings August 6, 2026 20:36
@jtschuster
jtschuster requested a review from agocke August 6, 2026 20:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Note

This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants