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

Replace C NULL for iter stop with StopIteration #2054

Merged
merged 7 commits into from
Jan 8, 2025

Conversation

plajjan
Copy link
Contributor

@plajjan plajjan commented Jan 2, 2025

No description provided.

@plajjan
Copy link
Contributor Author

plajjan commented Jan 2, 2025

@nordlander I added a new test case which demonstrates some failure in the compiler to mark variables volatile. The new test case is in test/core_lang_auto/exceptions_volatile.act

First we can look at the working case, although note the two lines I commented out:

def fun2():
    a = "FOOBAR2" # easy to find in C source
    my_list = [1]
    complete = True
    #if 1 == 1:
    #    complete = False
    for r in my_list:
        complete = False
    return complete
kll@Kristians-MacBook-Air core_lang_auto % actonc --cgen exceptions_volatile.act | grep -A20 FOOBA
    B_str a = to$str("FOOBAR2");
    B_list my_list = B_mk_list(1, to$int(1));
    volatile B_bool complete = B_True;
    B_Iterator N_1iter = ((B_Iterator (*) (B_Iterable, B_list))W_27->$class->__iter__)(W_27, my_list);
    if ($PUSH()) {
        while ((B_True)->val) {
            B_int N_2val = ((B_int (*) (B_Iterator))N_1iter->$class->__next__)(N_1iter);
            B_int r = N_2val;
            complete = B_False;
        }
        $DROP();
    }
    else {
        B_BaseException N_3x = $POP();
        if ($ISINSTANCE0(N_3x, B_StopIteration)) {
        }
        else {
            $RAISE(N_3x);
        }
    }
    return complete;

most importantly we see volatile B_bool complete = B_True;. Now uncomment the lines, so we have:

def fun2():
    a = "FOOBAR2" # easy to find in C source
    my_list = [1]
    complete = True
    if 1 == 1:
        complete = False
    for r in my_list:
        complete = False
    return complete

and notice how volatile disappears. That doesn't look right...

kll@Kristians-MacBook-Air core_lang_auto % actonc --cgen exceptions_volatile.act | grep -A20 FOOBA
    B_str a = to$str("FOOBAR2");
    B_list my_list = B_mk_list(1, to$int(1));
    B_bool complete = B_True;
    if (ORD_B_int__eq__(to$int(1), to$int(1))) {
        complete = B_False;
    }
    B_Iterator N_1iter = ((B_Iterator (*) (B_Iterable, B_list))W_37->$class->__iter__)(W_37, my_list);
    if ($PUSH()) {
        while ((B_True)->val) {
            B_int N_2val = ((B_int (*) (B_Iterator))N_1iter->$class->__next__)(N_1iter);
            B_int r = N_2val;

@plajjan plajjan force-pushed the iterator_exceptions3 branch from a8aa3bc to 78edddf Compare January 2, 2025 23:01
@nordlander
Copy link
Contributor

I've spotted the error. It's in Björn's recent additions to CodeGen, duplicating an error I also made in my recent mod to CPS (but was lucky enough to find and iron out!). Essentially, its root is the dubious nature of our utility function bound, which cannot tell a binding occurrence from a reassignment. There are alternatives in the compiler, but the honest truth is that the overloading of bound on Statements is a mess. :-(

I'll commit a fix to CodeGen tomorrow. But ideally we should also straighten up all code that deals with scopes in the compiler, for the benefit of our future selves! :-/

@plajjan
Copy link
Contributor Author

plajjan commented Jan 4, 2025

@nordlander the telemetrify test is failing. Compilation and the (very small) test suite passes but then the final somewhat larger test of loading in a schema from a replay file fails:

/__w/acton/acton/telemetrify/telemetrify-core/out/bin/telemetrify.test maapi-schema
Current time: 2025-01-03T16:06:37.627548212Z
Starting up...
�S���MAAPI connected!!!! 
*d�l�m�adminh�a�aaa�d�systemajMAAPI user session started!!!! 
�������MAAPI loaded schema!!!! 
<$Actor -160 telemetrifyQ_nsoapiQ_schemaQ_SharedSchema at 0x7fef659a0f50>
MAAPI end user session failed: ValueError: Invalid `EObject` tag: 46
make: *** [Makefile:15: test] Error 1

I can only presume that control flow is messed up somehow. This is normally a very stable & deterministic test - I . Nonetheless, I have just cleared all CI caches and started a rerun just on the off chance there was an intermittent failure here.

@plajjan
Copy link
Contributor Author

plajjan commented Jan 4, 2025

Same failure after clean rebuild... @nordlander

sydow and others added 7 commits January 8, 2025 09:41
Instead of returning a C NULL when we want to stop iteration, we now
raise the StopIteration exception. This is a prerequisite for doing
unboxed values since we need the NULL value for unboxed values.

Longer term, we might go back to using NULL but packed in a tuple, like
a tagged union basically, which is likely faster than raising an
exception (that uses longjmp) but that requires some other support.
@nordlander nordlander force-pushed the iterator_exceptions3 branch from dd42d54 to a6e67c1 Compare January 8, 2025 08:41
@nordlander nordlander merged commit 0331f53 into main Jan 8, 2025
24 of 25 checks passed
@nordlander nordlander deleted the iterator_exceptions3 branch January 8, 2025 09:47
@plajjan
Copy link
Contributor Author

plajjan commented Jan 8, 2025

🎆

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

Successfully merging this pull request may close these issues.

3 participants