-
Notifications
You must be signed in to change notification settings - Fork 272
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
Change interpreter calling conventions to be more direct #5542
Conversation
The new conventions are not aimed to encode structure on the stack, but to instead directly produce corresponding unison values. This should allow the raw foreign operations to be called directly in most cases, without the wrapper having to mediate between the convention encoding and the unison value. This both allows for more efficient direct calls, and avoiding what might be considerable overhead of building up the unison values via multiple iterations through the interpreter loop. The one portion where a 'flattened' encoding is retained is for tuples, but this is just for supporting multi-argument functions, not for actually encoding tuples on the stack.
…tions Most wrappers became obselete for foreigns, and we can just specify how many arguments they take. The foreign functions now have an option for indicating an exceptional result, in which case the returned value is a `Failure`, and the machine will directly call the `Exception` handler using that value. This allows e.g. array operations to have less interpreter overhead.
All base tests pass
Transcripts now pass
I'll run the cloud integration tests against this today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't reviewed the code, but I have verified that the Unison Cloud test suite passes with this change.
Here are some benchmark numbers:
I think most of them are fake, though, because they don't actually use anything that I changed. The real one is I also wrote a bubble sort on byte arrays test, and it is about twice as fast on the new branch (that was the sort of builtin I would expect to be most improved). |
I think this should be good to go. I fiddled around with inlining/strictness on some of the new stuff related to the sorting test case I wrote, but none of it seemed to make any difference. |
This change set reworks the calling conventions of foreign functions to avoid various encoding methodologies that were just wasting time by causing more passes through the interpreter loop. Instead, the
ForeignConvention
class has turned into a way of specifying how unison values are parsed into their Haskell equivalents, and each foreign operation is expected to just take a number of unison values that are parsed this way. Similarly, single results are written back directly, rather than encoding them on the stack. The result is that most wrappers are now just trivial (and should be subject to inlining).One additional thing I did was add support for foreign functions that raise an
Exception
in the unison sense. The convention for these is that foreign functions return booleans indicating whether the result on the stack is valid or exceptional. In the latter case the stack will have aFailure
value, and the interpreter will call the currentException
handler. This means that e.g. the array operations are also just trivial wrappers, and don't need to return their results wrapped inEither
.Haven't gotten to benchmarks yet, but the tests I've run are working (@unison/base tests, unison-runtime tests, transcripts and interpreter-tests). I haven't run any cloud tests; if Cody could arrange for that that'd be helpful.
Also haven't compared performance with any of our benchmarks yet.
Making this draft because it seems to indicate I need to merge in trunk or something.