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

Unnecessary ctrl operator with no arguments #32

Closed
Feliix42 opened this issue Feb 15, 2019 · 4 comments
Closed

Unnecessary ctrl operator with no arguments #32

Feliix42 opened this issue Feb 15, 2019 · 4 comments
Assignees

Comments

@Feliix42
Copy link
Member

Feliix42 commented Feb 15, 2019

The current version of ohua-core (cab3ff9) and I think the current version from master as well produce an unnecessary ctrl operator for this simple smap algorithm:

ns some_ns;

use sf smap::smap_fns::{gen_input, printout, splice};

fn main() -> Vec<String> {
    let input = gen_input();
    for i in input {
        let s = splice(i);
        printout(s);
        s
    }
}

This leads to the problem that incorrect code is being generated for the ctrl operator, as there is nothing to context. The current workaround is that the backend contains an optimization pass that identifies these ctrl operators and removes them, leaving behind a DeadEndArc that just discards all inputs. But as @sertel pointed out it would be wiser to do this in an earlier step in core.

alang-resolved|dflang-initial|dflang-core

@Feliix42 Feliix42 changed the title Incorrectly generated ctrl operator Unnecessary ctrl operator with no arguments Feb 15, 2019
Feliix42 added a commit to ohua-dev/ohua-rust-runtime that referenced this issue Feb 15, 2019
@sertel
Copy link
Contributor

sertel commented Feb 15, 2019

The problem is that we always create a ctrl assuming that we always need to context a variable or independent function. This is only true for conditionals because these do not have an input, i.e., the branches themselves are independent functions. This is not true for smap and recur.

The right thing to do is to alter the transformations for both of these constructs in such a way that they do not produce a ctrl when there is nothing to be contexted. This is trivial but has a little twist: smapFun and recur always have an output arc for the ctrl. If we do not create a ctrl then the versions of smapFun and recur must also change, i.e., to versions without this ctrl. This would require to implement them twice at the backend and would probably lead to code duplication.

That's why we might want to consider leaving the concept of DeadEndArcs in and only make sure that we do not create the ctrl.

Comments, opinions?

@Feliix42
Copy link
Member Author

I agree with your view that the ctrl operator in question should not be created but the concept of DeadEndArcs should be retained. This allows for a rather smooth fix that avoids unnecessary duplicate code and is probably the easiest to implement.

@JustusAdam
Copy link
Member

I think I fixed it and I'll close the issue. Should more problems arise feel free to reopen

@Feliix42 Feliix42 reopened this Feb 21, 2019
JustusAdam added a commit that referenced this issue Feb 21, 2019
Now recognizes function references
@JustusAdam
Copy link
Member

I'm pretty sure the problems with unused ctrl args are done.

However a related issue has arisen, which I am now tracking with #33

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

No branches or pull requests

3 participants