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

Some assorted fixes #2998

Merged
merged 3 commits into from Mar 28, 2022
Merged

Some assorted fixes #2998

merged 3 commits into from Mar 28, 2022

Conversation

dolio
Copy link
Contributor

@dolio dolio commented Mar 24, 2022

This PR fixes some minor things I encountered when working on Scheme stuff.

  1. When we started leaving signatures around longer, I missed a case in the lambda lifting that caused us to float lambdas out of signatures. So if you had:

    f : T -> U -> V
    f x y = ...
    

    it would turn into something like:

    f = 
      g x y = ...
      g : T -> U -> V
    

    which is silly.

  2. Serialization for binders was wrong. Variables are serialized as de Bruijn indices, so the serializer threads a backwards context around. But multi-variable bindings were pushing the variables on in the forwards order. I think it was technically broken in both directions, which might have made the serializer actually work. But it's better if the indices are numbered the standard way, because it allows simple arithmetic for certain things, rather than having to keep track of a list to figure out the weird permutations in certain cases.

    I guess I could revert this change if we want to not declare that the format was broken, since it might have been technically working (although I'm unsure about that, too). But it'd be nicer to just switch to the intended format.

  3. I extended the format to enable serializing builtins that are implemented with foreign ops. This doesn't make sense to use for sending code to a remote machine, since they might not have the foreign operation, but it's useful for getting access to the builtins via binary until I figure out an API that doesn't go through the serializer.

  4. I allowed the Code lookup function to look up builtins. This is again useful for a compiler, and not very useful for remote evaluation (since the remote should already have any builtins if we want it to work properly).

Due to a missing case in the floating logic, definitions like:

    f : ...
    f x y z = ...

were being turned into:

    f : ...
    f =
      g x y z = ...
      g

Because the compiler thought the lambda needed to be floated out of the
signature ascription, as the original `f` is the same as:

    f = (x y z -> ...) : ...

This is obviously not necessary, as the signature will be erased anyway,
and just results in extra indirection.
1. Allow for serializing `Code` with builtin foreign references to
   binary, using a mapping to the builtin name used. This is useful for
   parsing the binary and emitting scheme within unison.
2. Fixed an encoding error where variable indexing was wrong. The
   context maintained for serialization is stored backwards, but
   simultaneous bindings of multiple variables were being pushed on in
   order, which resulted in reversing the order of variables in some
   cases.
@pchiusano pchiusano merged commit d9c339c into trunk Mar 28, 2022
@pchiusano pchiusano deleted the fix/assorted branch March 28, 2022 18:15
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