Skip to content
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

Closed
marek-safar opened this issue Jan 13, 2021 · 9 comments
Closed

Exception filters handling in WebAssembly AOT #46927

marek-safar opened this issue Jan 13, 2021 · 9 comments
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono
Milestone

Comments

@marek-safar
Copy link
Contributor

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jan 13, 2021
@dotnet-issue-labeler
Copy link

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.

@marek-safar marek-safar added arch-wasm WebAssembly architecture and removed untriaged New issue has not been triaged by the area owner labels Jan 13, 2021
@ghost
Copy link

ghost commented Jan 13, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

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

Author: marek-safar
Assignees: -
Labels:

arch-wasm

Milestone: -

@marek-safar
Copy link
Contributor Author

This issue targets WebAssembly but any intermediate representation can be affected (#47197)

@vargaz
Copy link
Contributor

vargaz commented Jan 26, 2021

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.

@vargaz
Copy link
Contributor

vargaz commented Jan 29, 2021

#47551

@vargaz
Copy link
Contributor

vargaz commented Jan 29, 2021

With the above PR merged, filter clauses seem to work in aot+interp mode for simple tests.

@vargaz
Copy link
Contributor

vargaz commented Jan 29, 2021

This test still fails:
dotnet/linker#1770 (comment)

@lewing
Copy link
Member

lewing commented Jun 17, 2021

#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?

@vargaz
Copy link
Contributor

vargaz commented Jun 17, 2021

I think the current approach is good enough.

@lewing lewing closed this as completed Jun 23, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jul 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono
Projects
None yet
Development

No branches or pull requests

3 participants