Skip to content

Add special casing for string constructors for WebAssembly#130104

Open
davidwrighton wants to merge 3 commits into
dotnet:mainfrom
davidwrighton:SpecialCaseStringCtors
Open

Add special casing for string constructors for WebAssembly#130104
davidwrighton wants to merge 3 commits into
dotnet:mainfrom
davidwrighton:SpecialCaseStringCtors

Conversation

@davidwrighton

Copy link
Copy Markdown
Member
  • String constructors are special. Notably, they are implemented by static functions with a slightly different calling convention
  • Add logic to tweak the JIT to notify crossgen2 that its working with one of them
  • Add logic to let the stubs generated be the correct ones
  • Add logic to find the right thunks

- String constructors are special. Notably, they are implemented by static functions with a slightly different calling convention
- Add logic to tweak the JIT to notify crossgen2 that its working with one of them
- Add logic to let the stubs generated be the correct ones
- Add logic to find the right thunks
Copilot AI review requested due to automatic review settings July 1, 2026 23:54
@davidwrighton davidwrighton requested a review from AndyAyersMS July 1, 2026 23:54
@github-actions github-actions Bot added the area-crossgen2-coreclr only use for closed issues label Jul 1, 2026
@davidwrighton

Copy link
Copy Markdown
Member Author

@AndyAyersMS We probably also need the interpreter to R2R variant handling for this, but I'll tackle that when I work on bringup of using the compiled System.Private.CoreLib.dll

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 adjusts the WebAssembly JIT/EE and crossgen2 wasm signature plumbing to special-case string constructors, which are treated as “constructor-like” entrypoints but implemented via static helpers with a different effective calling convention/signature for thunk generation and lookup.

Changes:

  • Adds a shared helper (WasmLowering.GetStringCtorActualSignature) to reinterpret string ctor signatures as static methods returning string.
  • Updates crossgen2 wasm signature handling to apply the adjusted signature for thunk generation in relevant paths.
  • Updates the wasm VM thunk lookup path to select special portable-entrypoint-to-interpreter thunk keys for string constructors.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/coreclr/vm/wasm/helpers.cpp Adds string-ctor-specific portable entrypoint thunk key selection.
src/coreclr/tools/Common/JitInterface/WasmLowering.cs Adds helper to rewrite string ctor signatures to their effective wasm signature.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs Adds detection/rewriting for the string-ctor special-case when recording wasm managed call signatures.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/WasmImportThunkPortableEntrypoint.cs Uses rewritten signature for string ctor internal calls when computing wasm import thunk signatures.
src/coreclr/jit/codegenwasm.cpp Adjusts the signature reported to crossgen2 for special-cased ctor calls (intended for string ctors).

Comment thread src/coreclr/vm/wasm/helpers.cpp
Comment thread src/coreclr/jit/codegenwasm.cpp Outdated

@AndyAyersMS AndyAyersMS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

You will need to fix formatting so ping me and I'll approve after that goes through.

Comment thread src/coreclr/tools/Common/JitInterface/WasmLowering.cs
Copilot AI review requested due to automatic review settings July 2, 2026 21:09

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment on lines +1446 to +1449
default:
PORTABILITY_ASSERT("GetPortableEntryPointToInterpreterThunk: unknown thunk for string constructor");
break;
}
Comment on lines +2875 to +2881
if (callRetType == TYP_REF && sigInfoCall->retType == CORINFO_TYPE_VOID &&
sigInfoCall->callConv == CORINFO_CALLCONV_HASTHIS)
{
// Adjust sigInfoCall for string ctor case
sigInfoCall->retType = CORINFO_TYPE_CLASS;
sigInfoCall->callConv = CORINFO_CALLCONV_DEFAULT;
}
Comment on lines +3615 to +3622
if (callSig->callConv == CorInfoCallConv.CORINFO_CALLCONV_DEFAULT &&
callSig->retType == CorInfoType.CORINFO_TYPE_CLASS &&
!sig.IsStatic &&
sig.ReturnType == sig.Context.GetWellKnownType(WellKnownType.Void))
{
// Detect special case for string ctors
sig = WasmLowering.GetStringCtorActualSignature(sig);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-crossgen2-coreclr only use for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants