Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Rock unrolls an n-tuple to n function calls when autoreturning a function #499

Closed
shamanas opened this Issue · 5 comments

2 participants

@shamanas
Collaborator

For example:

f: func -> (Int, Int, Int) { (1, 2, 3) }
g: func -> (Int, Int, Int) { f() }

Gives the following C code:

void test__g(lang_Numbers__Int* __tupleArg4, lang_Numbers__Int* __tupleArg5, lang_Numbers__Int* __tupleArg6) {
    lang_Numbers__Int __genCall118;
    lang_Numbers__Int __returnVal119 = (test__f(&(__genCall118), NULL, NULL), __genCall118);
    if (__tupleArg4) {
        (*__tupleArg4) = __returnVal119;
    }
    lang_Numbers__Int __returnVal120 = (test__f(&(__genCall118), NULL, NULL), __genCall118);
    if (__tupleArg5) {
        (*__tupleArg5) = __returnVal120;
    }
    lang_Numbers__Int __returnVal121 = (test__f(&(__genCall118), NULL, NULL), __genCall118);
    if (__tupleArg6) {
        (*__tupleArg6) = __returnVal121;
    }
    return;
}

Of course, in this case there is no reason for concern, however if f had side-effects, shit would go wild.
Here is a workaround until this is fixed:

f: func -> (Int, Int, Int) { (1, 2, 3) }
g: func -> (Int, Int, Int) {
    (a,b,c) := f()
    (a,b,c)
}
@shamanas shamanas was assigned
@shamanas
Collaborator

Here is a sample with problematic behavior:

f: func -> (Int, Int, Int) {
    x := static 0
    x += 1

    (x, x, x)
}

g: func -> (Int, Int, Int) {
    f()
}

(a, b, c) := g()
"(%d, %d, %d)" printfln(a, b, c)

It should print "(1, 1, 1)" but it prints "(1, 2, 3)"

@shamanas
Collaborator

This is surprisingly difficult to fix >_>

@nddrylliog
Collaborator
@nddrylliog
Collaborator

@shamanas wasn't that hard ;) There were a few silly things FunctionCall was doing though...

@nddrylliog
Collaborator

Closed by bd688d2

@nddrylliog nddrylliog closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.