Skip to content

Catch misuse of intrinsics #24

@PearCoding

Description

@PearCoding

Some builtin intrinsics (e.g., sin) are generic and artic allows to pass any type to them. This however crashes down the pipeline in thorin, which is not able to handle arbitrary types for that specific intrinsics.
The following is a simple example of such misuse which might occur very easily due to regression/refactoring:

struct ABC {
    a: f32,
    b: f32,
    c: f32
}

// Same as in intrinsics_math.impala in AnyDSL runtime
#[import(cc = "builtin")] fn sin[T](T) -> T;

// Some imaginary functions to prevent optimization
#[import(cc = "C", name = "foo_f32")] fn foo_f32(_: f32) -> ();
#[import(cc = "C", name = "foo_abc")] fn foo_abc(_: ABC) -> ();

#[export] fn main() -> () {
    // The following works
    let v = 42:f32;
    foo_f32(sin(v)); 

    // This does not work and has to be caught somehow, as artic thinks it is valid
    let abc = ABC { a=4, b=2, c=0 };
    foo_abc(sin(abc)); 
}

Catching and printing (always!) an error would be a good initial way to approach this. Currently, artic crashes and thorin prints an error when checks are enabled (which is off by default).

A better way is to prevent such misuse by utilizing implicits.

thorin: AnyDSL/thorin@cf797d7
artic: 2263837

PS: This has no high-priority, but is an issue by design due to bad error management and must be handled in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions