Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Improve handling of nested continuations #54

Merged
merged 19 commits into from
Aug 16, 2023

Conversation

frank-emrich
Copy link

This PR improves the handling of nested continuations (i.e., invoking continuations within continuations).

It fixes two bugs:

  1. In FuncEnvironment::typed_continuations_load_continuation_object, we were incorrectly setting the readonly flag, which meant that multiple loads to the continuation object slot in the VMContext were sometimes combined into one, even though the slot was overwritten in between.
  2. In continuation::resume, we were not updating the top of stack (TSP) pointer in the VMInstance after returning from a continuation.

This PR also adds debug printing to certain functions in continuation.rs. Printing only happens in debug builds AND if the variable ENABLE_DEBUG_PRINTING in the same file is manually set to true. The printing goes through a macro to ensure that there is no chance of it affecting performance in release builds.

This PR also adds various tests for nested uses of continuations, which also cover the two bugs mentioned earlier.

@frank-emrich frank-emrich requested a review from dhil August 16, 2023 12:52
Copy link

@dhil dhil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@@ -347,10 +368,24 @@ pub fn resume(
// entry of the payload store by virtue of using the array
// calling trampoline to execute it.

// Restore tsp pointer in instance
let _tsp = TopOfStackPointer::as_raw(instance.tsp());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this perform any side-effects? Can we remove it?

let parent = unsafe { (*(*contobj).fiber).stack().parent() };
instance.set_tsp(TopOfStackPointer::from_raw(parent));

debug_println!("Continuation @ {:p} returned normally, setting tsp from {:p} to {:p}", contobj, tsp, parent);
debug_println!("Continuation @ {:p} returned normally, setting tsp from {:p} to {:p}", contobj, _tsp, parent);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah it is used here...

@dhil dhil merged commit ec9a5af into effect-handlers:typed-continuations Aug 16, 2023
4 checks passed
@frank-emrich frank-emrich deleted the nested_testing branch August 16, 2023 16:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants