-
Notifications
You must be signed in to change notification settings - Fork 11
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
lib/dfa/jvm: Support for effect.finally
#3784
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is still work-in-progress and missing interpreter and C backend support completely. Two main new features: - effect.instate0 is now implemented in Instrinsix with less help from jvm.Runtime - the `def` function passed to `instate` now receives the final instance of the effect as an argument, so it can use the data form the last effect instance to produce a result - new feature `effect.finally` will be called when an effect is removed from the environment, either because the code passed to `instate` returns normally, or because the effect was aborted, or a surrounding effect was aborted. - `effect.finally` is called after the execution of the code has returned or was aborted and after the effect was removed from tne environment, but before the function `def` is run, which t determines the result of `instate` in case of an abort. - the JVM backend now supported exception simple exception tables in the code. - a test was added that checks nested resource tracking effects and that `finally` is called when expected.
Managed to remove `if (3%%4) e.static_finally` by adding the feature dependance in `MiddleEnd.martInternallyUsed`. Remove unused code.
Support for `finally` still incomplete, no cleanup if surrounding effect is aborted.
…instate` Renamed `Runtime.effect_pop_and_get` as `Runtime.effect_pop`.
…orts For this, there is no longer a thread local jump buffer for each effect clazz, but only one jump buffer for any effect abort. The value passed to longjump and returned by setjmp is the effect id. On an instate, the id returned from setjump is then used to decide if this is a local abort, such that instate woudl return the result of call_def, or we have an abort of a surrounding effect, i.e., we have to longjump further to the next instate.
This was ingored by the C backend, we can handle the effect replacing in Fuzion code instead.
Also restructured the code not to use `finally`, which would otherwise be executed also in case of, e.g., an `OutOfMemoryError`.
Added and improved comments. Use `instate` instead of `install` for effects. Remove debug code, unused code, unused method arguments. Add constants fields for inline Strings like `"dev/flang/be/jvm/runtime/Runtime$Abort"`. Optimization: Added `JVM.effectId()` to create a small id 0,1,2,... to use instead of the clazz id for effects. This reduces the size of the list `FuzionThread._installedEffects`.
The effect environment now has a flag `isAborted` that tracks if a given effect is ever aborted.
…er called This happens if an effect is found never to be aborted, so no code will be generated for call_def.
maxteufel
approved these changes
Sep 16, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Semantic additions to effect are
effect.finally
will be called when an effect is removed from the environment, either because the code passed toinstate
returns normally, or because the effect was aborted, or a surrounding effect was aborted. This can be used as a resource cleanup mechanismdef
function passed toinstate
now receives the final instance of the effect as an argument, so it can use the data form the last effect instance to produce a resulteffect.finally
is called after the execution of the code has returned or was aborted and after the effect was removed from the environment, but before the functiondef
is run, which determines the result ofinstate
in case of an abort.Implementation changes
finally
is called when expected.