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

Compilation aborts when the member function of a mutable struct is called inside a higher-order function #75

Open
jonas-schmitt opened this issue Nov 28, 2017 · 0 comments

Comments

@jonas-schmitt
Copy link

jonas-schmitt commented Nov 28, 2017

For the following code the compilation aborts without error message:

type real = f64;
type size_t = u64;

struct vector{
    n: size_t,
    buf: fn()->Buffer,
    set: fn(size_t, real) -> (),
    get: fn(size_t) -> real
}

fn get_vector(n: size_t)->vector{
    let tmp : Buffer = alloc_cpu(n as i32 * sizeof[real]());
    vector{
        n: n,
        buf: ||{tmp},
        set: |i,v|{bitcast[&mut[real]](tmp.data)(i) = v},
        get: |i| {bitcast[&[real]](tmp.data)(i)}
    }
}

fn loop(lower: size_t, upper: size_t, body: fn(size_t) -> ()) -> () {
    if lower < upper {
        body(lower);
        loop(lower+(1 as size_t), upper, body, return)
    }
}

fn main ()->(){
    let mut v = get_vector(10 as size_t);
    for i in loop (1 as size_t, 10 as size_t ) {
        v.set(i, 42.0);
    }
}

The problem only occurs if the variable "v" is declared mutable.
Impala flags: -emit-llvm -O3 -log-level error
impala commit 16c3ff7
thorin commit 72e23ec

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

1 participant