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

Denotation of open cfgs in presence of function calls #166

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

YaZko
Copy link
Collaborator

@YaZko YaZko commented Mar 30, 2020

This PR describes the ongoing work to denote open control flow graphs, such as in the asm language used in the tutorial, in presence of functional calls and return statements. The motivation for this PR comes from Vellvm.

Currently, we only extend asm with return statements, a Bret case in the Branch data-type, so that we do not have to bother with call-stacks. We quickly describe why this extension is already problematic.

A natural denotation for Bret r is to return the value stored in the register r. However, this impacts the type of the denotation of a block: from itree E label, we now may return a value, i.e. we now work with an itree E (label + value).

This simple modification however completely jeopardize the denotation of open programs: by relying on a loop operator over the ktree category, we rely on the uniformity of the entry and return types. Intuitively, the issue is that returning acts as an exception, so that the loop combinator do not know what to do when fed such a value.

The natural answer is naturally "since it acts as an effect, it should be an event"! However, this cannot work either. Indeed, if the event is simply parametized by the register and returning a value, then our type has not changes. To avoid carrying a value, it would have to be parameterized by the continuation, i.e. the continuation at call-site, which would require some higher-order trickery that itrees do not support.

We therefore are exploring a more blasphemous path: stranding away from the beautiful land of the freer monad and denote (before interpretation!) our programs directly into eitherT value (itree E). By doing so, the exception behavior is internalize by the eitherT monad transformers, and we recover the right type for our loop combinator.

As far as denotation is concerned, it is fairly straightforward: it only requires a slight generalization of the finite type manipulated, as well as of course lifting the Kleisli structure via the EitherT transformer (see Basics/MonadEither.v).

Things get a bit more troublesome from there. We now need a new interpreter, and as far as I can see it cannot be simply expressed in terms of the current interp. The file InterEither therefore define two such, where the hesitation comes from whether the handlers themselves should live in the either monad.

This path will likely lead to the duplication of all the code related to interpreters. Alternatively, we could try defining a type class of "Interpretable" monads in order to factor things out.

If anyone sees a simpler way to tackle this issue, suggestions are welcome :)

@YaZko YaZko requested a review from Zdancewic March 30, 2020 17:55
@YaZko YaZko self-assigned this Mar 30, 2020
@YaZko YaZko added enhancement New feature or request itrees Particular to theory and implementation of itrees wip Work in Progress labels Mar 30, 2020
…therT monad

transformer, clean up/ think a bit more about the monad infrastructure we are
building and draft an Interpretable type class
@gmalecha
Copy link
Collaborator

gmalecha commented Apr 8, 2020

I didn't follow your explanation above as to why changing the semantics of basic blocks to itree Call (label + val) doesn't work. Naively, this would result in something akin to:

denote_block : block -> itree Call (label + val)
denote_function : function -> itree Call val
denote_program : closed_program -> itree Call val

denote_function uses loop to tie a knot, and denote_program uses something like mrec (now defined using loop?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request itrees Particular to theory and implementation of itrees wip Work in Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants