dotnet / dotnet/runtime

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

Ouverte
#127,361 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
arch-wasm area-TypeSystem-coreclr
Langage dominant
C#
Étoiles
18.3k
Forks
5.6k
Métriques de merge des PR
Métriques de PR en attente

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Start in src/coreclr/tools/Common/JitInterface/WasmLowering.cs at GetSignature(MethodSignature, LoweringFlags), then read the empty-value-type handling noted in MetadataFieldLayoutAlgorithm.cs:1177 and the linked Basic C ABI guidance. Done means empty structs with no non-static fields, including explicit-layout cases as specified, are omitted from WebAssembly parameters and returns for managed and unmanaged calling conventions.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
csharp, wasm
Domaine
compilers
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
68/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.