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

Allow void functions #13

Closed
JustusAdam opened this issue Sep 27, 2018 · 5 comments
Closed

Allow void functions #13

JustusAdam opened this issue Sep 27, 2018 · 5 comments
Labels

Comments

@JustusAdam
Copy link
Member

It has become apparent that it is necessary to support functions with no return. Perhaps we can abuse the unit hack again.

@sertel
Copy link
Contributor

sertel commented Sep 30, 2018

Here is the error report such that we can derive a test case:

This code has problems compiling:

ns some_ns;

use sf addition (produce, consume);

fn main() {
    let result = produce();
    consume(result)
}

It throws this error message:

[felix@Samaritan] $ ohuac build foobar.ohuac
[Debug] Lowering alang expr: AExpr {unAExpr = LetF "a" (AExpr {unAExpr = ApplyF (AExpr {unAExpr = VarF (Sf addition/consume Nothing)}) (AExpr {unAExpr = VarF (Sf addition/produce Nothing)})}) (AExpr {unAExpr = VarF (Local "a")})}
[Debug] Lowering Let -->
[Debug] Current state: []
[Error] Var must be local or env, was Sf addition/produce Nothing

The formatted version of the expression looks as follows:

AExpr {
  unAExpr = LetF "a" (AExpr { unAExpr = ApplyF (AExpr { unAExpr = VarF (Sf addition/consume Nothing)}) 
                                               (AExpr { unAExpr = VarF (Sf addition/produce Nothing)})}) 
                     (AExpr {unAExpr = VarF (Local "a")})}

According to this expression, the code actually looks as follows:

ns some_ns;

use sf addition (produce, consume);

fn main() {
    consume(produce());
}

In any case, the lowering pass seems to expect a Var as the second argument to Apply but finds Sf.
I already talked to @JustusAdam about this and this seems to be a problem with functions that do not have arguments.

@JustusAdam
Copy link
Member Author

What you are talking about is ohua-dev/alang-clike-parser#7 which is already fixed. I will make a new release for ohuac soon which will include this fix.

What I mean by void functions is something like this

fn foo (a) {
    compute(a);
    flush();
}

Which I would like to desugar to

let foo = \a -> let _ = compute a in let _ = flush () in ()

@sertel
Copy link
Contributor

sertel commented Oct 1, 2018

(I was not sure whether it was already taken care of, so I added it to this issue.)

Sounds good to me.

@sertel
Copy link
Contributor

sertel commented Feb 1, 2019

@JustusAdam is still a valid work item? I know that I fixed this in core at least.

@JustusAdam
Copy link
Member Author

I think so.

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

No branches or pull requests

2 participants