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

Catch misuse of intrinsics #24

Open
PearCoding opened this issue Jul 2, 2024 · 0 comments
Open

Catch misuse of intrinsics #24

PearCoding opened this issue Jul 2, 2024 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@PearCoding
Copy link
Contributor

PearCoding commented Jul 2, 2024

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.

@PearCoding PearCoding added the bug Something isn't working label Jul 2, 2024
@Hugobros3 Hugobros3 added the enhancement New feature or request label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants