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

Partial evaluator too eager cont. #91

Open
richardmembarth opened this issue Feb 24, 2018 · 3 comments
Open

Partial evaluator too eager cont. #91

richardmembarth opened this issue Feb 24, 2018 · 3 comments
Assignees

Comments

@richardmembarth
Copy link
Member

The following example should specialize specialize, but it doesn't since PE is too eager.

extern "thorin" {
    fn pe_info[T](&[u8], T) -> (); 
}

enum Num { one, two }
fn num2idx(n: Num) -> i32 { match n { Num::one => 0, _ => 1 } } 

fn @test(n: Num) -> i32 {
    match n { 
        Num::one => {
            let i = num2idx(n);

            fn @(?i) specialize(x: i32) -> i32 {
                pe_info("x", x); 
                if x < 0 { 
                    x   
                } else {
                    specialize(x-1)
                }   
            }   

            pe_info("i", i); 
            specialize(i)
        },  
        _ => 0
    }   
}

extern
fn start() -> i32 {
    test(Num::one) as i32 
}

This produces:

#  impala -log-level info -emit-llvm test.impala 
I:test.impala:22 col 13 - 27: pe_info: i: qs32 0
I:test.impala:14 col 17 - 31: pe_info not constant: x: x_348

While it should yield (removing @(?i) or replacing by @(?x)):

# impala -log-level info -emit-llvm test.impala 
I:test.impala:22 col 13 - 27: pe_info: i: qs32 0
I:test.impala:14 col 17 - 31: pe_info: x: qs32 0
I:test.impala:14 col 17 - 31: pe_info: x: qs32 -1

This seems to be related to #90.

@leissa leissa self-assigned this Feb 26, 2018
@leissa
Copy link
Member

leissa commented Feb 27, 2018

The problem is that the filter (formerly known as pe_policy) is not a real operand of a continuation. It should be, but it isn't. Changing this would introduce many subtle bugs in other passes because currently we assume that op(0) of a continuation is its callee and op(1) to op(1+n-1) is its argument list. We would have to do this:

op(0) -> filter
op(1) -> callee
op(2) to op(2+n-1) -> args

Unless this is a really pressing issue I wouldn't spend time on this because in CoC it is correctly modeled.

@richardmembarth
Copy link
Member Author

Not really urgent. Pops up once in a while for more complex code (which gets then not optimized).
Is there a timeline for CoC integration?

@leissa
Copy link
Member

leissa commented Feb 28, 2018

No yet, but I need more help.

leissa added a commit that referenced this issue Dec 7, 2018
* This addresses issue #91
* Furthermore, all nodes are now consistently hashed into one set
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

2 participants