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

JIT Infrastructure for continuation serialization #5152

Merged
merged 9 commits into from
Jun 28, 2024
Merged

Conversation

dolio
Copy link
Contributor

@dolio dolio commented Jun 27, 2024

This PR includes work that goes part of the way toward having serializable continuations on the JIT.

One of the main changes is a rework of the define-unison macro. It now has additional features and expands to different code.

  • The definition with the primary name is now a macro, so static occurrences of ref-whatever have the following behavior
    • Occurrences in a non-function context just build a closure
    • Under-applications also expand to building a closure
    • Exactly saturated applications expand to the fast path
    • Over-applications split the argument list
  • The above means that occurrences of a unison function are never raw scheme procedures. Saturated applications directly call the procedure, and under-applications are always a closure structure. This means the 'slow path' was able to be moved into a procedure property of the closure struct. When you use a closure as a function, it is the slow path.
  • The macro now takes 'hints' that control its behavior.
    • 'force-pure makes the macro generate code under the assumption that the continuation will never be captured and serialized, so annotations do not have to be manipulated. This performs better.
    • 'gen-link makes the macro generate a builtin termlink for the definition
    • 'no-link-decl tells the macro to not declare the association between the generated function and the termlink. Otherwise the macro automatically handles this, and it is no longer necessary to do by hand
    • 'internal bundles together some of the above options as appropriate for internal, builtin definitions
  • A helper macro define-unison-builtin has been made for defining builtin definitions. It picks hints that are appropriate for such definitions.
  • The generated code also has some features for detecting when it's in an ability context that would not involve serializing a continuation (like, just IO and Exception), allowing it to skip annotating the continuation there, too. This works via a runtime test, but as with arithmetic on small numbers, this seems to have negligible cost when you are actually in a context that is supposed to be fast.

The checked in files have been modified with this in mind, and the bumped share code generates appropriate output. Right now, 'force-pure defaults to #t, because reflecting the continuation isn't actually implemented yet. So there should be no performance impact at the moment (it's equivalent to the old code).

This also declares some structures for continuation management. There is a structure for wrapping a racket continuation, and another for a representation in terms of (de)serialized frames. Conversion between the two is as needed; for instance, it doesn't make sense to immediately reflect the continuation into serializable frames if it's just going to be used locally. Code for deserializing into the frame representation has been implemented in the two repositories, but some of the cases for actually applying a continuation are missing, pending some supporting work from the code generator.

- The define-unison macro has been reworked in various ways. It can
  now accept some hint flags that influence its behavior. It also,
  by default, generates definitions that will annotate the
  continuation with procedure arguments so that they can later be
  recovered and reflected for continuation serialization.
- A helper macro define-unison-builtin has been added and made use of
  in the builtin files. This uses hints that turn off the continuation
  management, because they'll never occur in a captured continuation.
  The macro also auto-generates termlink information for builtins, so
  it's no longer necessary to separately define/declare those
  (required porting some files to racket language).
- The unison-continuation struct now acts as the slow path. Static
  calls to a unison procedure are now macros that either build a
  closure or call directly into the fast path.
- One thing to note: the auto-generation features of the macro are
  based on the name that occurs in the definition. So declaring
  abbreviated names and using `prefix-out` is not an option with them.
  I think this seems like a decent trade off.
- #:by-name annotations were inconsistent and eating arguments
- Auto-generated builtin links were including "builtin-" in the termlink text
unison/data needs to have some of the continuation functions to
allow using the struct wrappers like procedures.

Includes some infrastructure for deserializing continuations.
@dolio dolio requested a review from a team as a code owner June 27, 2024 18:58
@dolio dolio requested a review from aryairani June 27, 2024 21:34
Copy link
Contributor

@aryairani aryairani left a comment

Choose a reason for hiding this comment

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

Awesome!
What's the slow path? The one that supports restoring a serialized continuation?

@aryairani aryairani merged commit 570db9b into trunk Jun 28, 2024
35 checks passed
@aryairani aryairani deleted the topic/jit-cont branch June 28, 2024 04:48
@dolio
Copy link
Contributor Author

dolio commented Jun 28, 2024

No, the slow path is what happens when you call a function that gets passed as an argument. Since that could be anything, you need to inspect it and look at how many arguments it takes vs. how many you're applying and so on. For statically known functions you can figure that out at compile time so all you have to do at runtime is jump to the code (or whatever).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants