-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception filters handling in WebAssembly AOT #46927
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsUnfortunately, CLR supports exception filters that don’t unwind the stack. This is something that is not supported by WASM. We'll have to mitigate this somehow as exception filters are C# feature that is generally used nowadays. This is problematic for other targets that generate intermediate representations like is WASM. We have a few options on how to handle this for WebAssembly. Implement basic blocks transformation inside MonoVMThis is an interesting option from a tooling perspective as it would allow us to target only methods that are AOT-ed and don't complicate build process. We would have to do a similar transformation for an interpreter to keep the behaviour consistent. Unfortunately, it's the most expensive option as Mono does not have a place where we could do the transformation and the exception logic is scattered everywhere. Write a new build taskWe could write a tool that rewrites IL as part of the build process. We have a prototype of that work and it's a non-trivial amount of code which we'd need to re-process during every build unless we add some extra caching. Rewrite IL code as part of ILLink runThis is the same as the option above but we would run it as part of the trimming process which would mean running linker possibly inside faster inner-dev loop. Rewrite original C# codeThis alternative is interesting as it would give the developers and end-users exactly same behaviour in hot-reload and publish-ed output. Although without aggressive analyzers and code-fixes it's quite unlikely we'll succeed in changing developers habits on using this C# feature.
|
This issue targets WebAssembly but any intermediate representation can be affected (#47197) |
An alternative approach might be to run these methods with the interpreter. Since interpreter frames are linked together, it might be possible to execute the filters in the first pass before 'throwing' the exception. Will experiment. |
With the above PR merged, filter clauses seem to work in aot+interp mode for simple tests. |
This test still fails: |
#52883 mitigated this issue by doing all exception handling in the interpreter. Should we resolve this or keep it open to continue to explore other options? |
I think the current approach is good enough. |
Unfortunately, CLR supports exception filters that don’t unwind the stack. This is something that is not supported by WASM. We'll have to mitigate this somehow as exception filters are C# feature that is generally used nowadays. This is problematic for other targets that generate intermediate representations like is WASM. We have a few options on how to handle this for WebAssembly.
Implement basic blocks transformation inside MonoVM
This is an interesting option from a tooling perspective as it would allow us to target only methods that are AOT-ed and don't complicate build process. We would have to do a similar transformation for an interpreter to keep the behaviour consistent.
Unfortunately, it's the most expensive option as Mono does not have a place where we could do the transformation and the exception logic is scattered everywhere.
Write a new build task
We could write a tool that rewrites IL as part of the build process. We have a prototype of that work and it's a non-trivial amount of code which we'd need to re-process during every build unless we add some extra caching.
Rewrite IL code as part of ILLink run
This is the same as the option above but we would run it as part of the trimming process which would mean running linker possibly inside faster inner-dev loop.
Rewrite original C# code
This alternative is interesting as it would give the developers and end-users exactly same behaviour in hot-reload and publish-ed output. Although without aggressive analyzers and code-fixes it's quite unlikely we'll succeed in changing developers habits on using this C# feature.
@vargaz @lewing
The text was updated successfully, but these errors were encountered: