dotnet / dotnet/runtime

WasmLowering: Empty struct detection doesn't exist for ABI purposes, and should

Offen
#127,361 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
arch-wasm area-TypeSystem-coreclr
Vorherrschende Sprache
C#
Sterne
18.3k
Forks
5.6k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

The WebAssembly Basic C ABI (https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md) specifies that empty structs and unions are "ignored" for both parameters and returns. In WasmLowering.GetSignature, empty struct parameters are currently detected via
paramType.GetElementSize().AsInt == 0. However, .NET pads empty value types to a minimum size of 1 byte:

// MetadataFieldLayoutAlgorithm.cs:1177
// Pad the length of structs to be 1 if they are empty, so we have no zero-length structures
if (type.IsValueType && instanceSize == LayoutInt.Zero)
instanceSize = LayoutInt.One;

What needs to change

1. Detect empty structs by instance field count (0 non-static fields), no explicit layout.
2. Empty struct return/parameters should not contribute to the arguments of the function at the Wasm level.
3. This applies to all calling conventions (managed and unmanaged).

Location

src/coreclr/tools/Common/JitInterface/WasmLowering.cs — the GetSignature(MethodSignature, LoweringFlags) method.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.