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

Compiler segfaults for recursive functions #76

Open
muellan opened this issue Dec 7, 2017 · 2 comments
Open

Compiler segfaults for recursive functions #76

muellan opened this issue Dec 7, 2017 · 2 comments
Assignees

Comments

@muellan
Copy link

muellan commented Dec 7, 2017

The Impala compiler segfaults on the following minmal example:

struct node {
    value : value_t,
    left  : &node,
    right : &node
}

fn post_order_visit(n: &node, visit: fn(value_t) -> ()) -> () {
    if(n.left != 0 as &node)  { post_order_visit(n.left, visit);  }
    if(n.right != 0 as &node) { post_order_visit(n.right, visit); }
    visit(n.value);
}

extern
fn tree_sum(levels: int) -> value_t {
    let tree = ~node{value: 0 as value_t, left: 0 as &node, right: 0 as &node }; 
    let mut sum = 0 as value_t;
    post_order_visit(tree, |x| { sum += x; } );
    sum
}

This one will also fail:

struct node {
    value : value_t,
    left  : &node,
    right : &node
}

fn make_tree(gen: fn() -> value_t, levels: int) -> &node {
    if(levels < 1) { return (0 as &node) }
    ~node { value: gen(),
            left:  make_tree(gen, levels-1), 
            right: make_tree(gen, levels-1)
    }
}

extern
fn tree_sum(levels: int) -> value_t {    
    let tree = make_tree(||{0 as value_t}, levels);
   0 as value_t;
}

Note that removing the recursive calls will fix it.

@leissa leissa self-assigned this Dec 7, 2017
@leissa
Copy link
Member

leissa commented Dec 7, 2017

This is a known problem. Please be patient with this one. Maybe, I'll have a look at this issue over the holidays.

@Hugobros3
Copy link
Contributor

I tested these two examples with the latest version and they compile fine.

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