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

Dead code and node reuse in generated code when using async #7568

Open
arnetheduck opened this issue Apr 11, 2018 · 3 comments
Open

Dead code and node reuse in generated code when using async #7568

arnetheduck opened this issue Apr 11, 2018 · 3 comments
Labels
Async Everything related to Nim's async Code Generation

Comments

@arnetheduck
Copy link
Contributor

compiling https://github.com/nim-lang/Nim/blob/master/tests/async/tasync_traceback.nim, the async code gets transformed into a state machine - in this state machine, there are two issues with the generated tree:

  1. there's an extra call to complete_rqmfICbsG8zaMmva4T4xIg after the last goto BeforeRet_ that will never be hit

  2. the snippet (*(*colonenvP_).colonup_).retFuture1 is generated by a single node instance appearing twice in the tree - at this point the tree is no longer a tree (the node has two parents, so it's more of a graph), and the node ID can suddenly be found in two branches of the tree - this makes it difficult to use for things that depend on it being unique, such as dead code elimination or lazy code generation (unlike the C gen, nlvm uses it this)!

{   result = (tyObject_FutureBasecolonObjectType__cnXnCCtV9cjKaEq9alHheOFg*)0;
    colonenvP_ = (tyObject_Env_libslashpureslashasyncmacrodotnim__fhbkBamT1XdhWaGDl4D4JA*) ClE_0;
    switch ((*colonenvP_).colonstate_) {
    case -1: goto BeforeRet_;
    case 0: goto STATE0;
    case 1: goto STATE1;
    }
    STATE0: ;
    (*colonenvP_).future3 = b_POGshUH6CHI2ak8lki3jtg_2();
    (*colonenvP_).colonstate_ = ((NI) 1);
    result = &(*colonenvP_).future3->Sup;
    goto BeforeRet_;
    STATE1: ;
    T1_ = (NI)0;
    T1_ = read_4NOxxpXfTo1DJap5zqepHw((*colonenvP_).future3);
    complete_rqmfICbsG8zaMmva4T4xIg((*(*colonenvP_).colonup_).retFuture1, T1_);
    (*colonenvP_).colonstate_ = ((NI) -1);
    result = NIM_NIL;
    goto BeforeRet_;
    complete_rqmfICbsG8zaMmva4T4xIg((*(*colonenvP_).colonup_).retFuture1, (*colonenvP_).result1);
    (*colonenvP_).colonstate_ = ((NI) -1);
    }BeforeRet_: ;
    return result;
}

using Nim 673f5f3

@andreaferretti andreaferretti added Code Generation Async Everything related to Nim's async labels Apr 11, 2018
@Araq
Copy link
Member

Araq commented Jul 1, 2018

Is this still an issue with the newer async transformation?

@dom96
Copy link
Contributor

dom96 commented Jul 3, 2018

Surely you mean newer closure iterator transformation.

@Araq
Copy link
Member

Araq commented Jul 3, 2018

Well yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Async Everything related to Nim's async Code Generation
Projects
None yet
Development

No branches or pull requests

4 participants