Skip to content

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

@jonas-schmitt

Description

@jonas-schmitt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions