dotnet / dotnet/runtime

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

未关闭
#127,361 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
arch-wasm area-TypeSystem-coreclr
主要语言
C#
星标
18.3k
派生
5.6k
PR 合并指标
PR 指标待抓取

描述

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.

贡献指南

打开贡献指南

调研方向

从 src/coreclr/tools/Common/JitInterface/WasmLowering.cs 中的 GetSignature(MethodSignature, LoweringFlags) 开始,然后阅读 MetadataFieldLayoutAlgorithm.cs:1177 中提到的空值类型处理以及链接的 Basic C ABI 指南。完成标准是:对于托管和非托管调用约定,不包含非静态字段的空结构体(包括指定的显式布局情况)会从 WebAssembly 参数和返回值中省略。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp, wasm
领域
compilers
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
68/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。