dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.4k stars 196 forks source link

[NativeAOT-LLVM] Invalid Release code generation for `wasi-wasm` #2671

Closed dicej closed 2 weeks ago

dicej commented 2 weeks ago

I've been developing an AspNetCore example based on wasi-http. One of the URI handlers in that example uses System.Text.Json.Serialization and source generation to deserialize request bodies. When built using -c Debug, it all works fine. However, the -c Release build is incorrect, having replaced the code for deserializing a custom class with an infinite loop.

I've tried to reduce the issue to a minimal reproduction, e.g. as a CLI app with a Main method, but so far I've only managed to reproduce this issue in an AspNetCore web server. To reproduce:

Apologies for the complicated steps to reproduce this. Let me know if you have any trouble following them.

dicej commented 2 weeks ago

NB: I left out an important step above when I first opened the issue and just edited it in: "Comment out this line in the example source code."

dicej commented 2 weeks ago

@SingleAccretion helped narrow this down and find a solution. Turns out some of the warnings I was ignoring were important, and I needed <EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>, which I had read about, but ignored because it's supposedly implied by <PublishTrimmed>true</PublishTrimmed>. Turns out that's not always the case. See the discussion following https://discord.com/channels/143867839282020352/1141126727028985877/1278474370842628116 for details.