lambdaclass / concrete

Concrete is a simple programming language specifically crafted for creating highly scalable systems that are reliable, efficient, and easy to maintain.
Apache License 2.0
123 stars 11 forks source link

The compiler doesn't behave the same way when a function does not returns a value #129

Closed kenarab closed 4 months ago

kenarab commented 4 months ago
mod Main {

 fn main() -> i32 {
    //mainOk();
    mainBad();
 }

 fn mainBad() -> i32 {
  let mut value: i32 = 0;
  value = function_wo_return(&value);
  return value;
 }

 /*
 fn mainOk() -> i32 {
  let mut value: i32 = 0;
  return function_wo_return(&value);
 }*/

 fn function_wo_return(value: &i32) {
  value.x = value.x + 1;
 }

}

Running mainOk returns a meaning message (Uncomment mainOk)

[UnexpectedType] Error: expected type i32.
    ╭─[bugWithOpResult.con:14:3]
    │
 12 │  fn mainOk() -> i32 {
    │                 ─┬─  
    │                  ╰─── expected 'i32' due to this type
    │ 
 14 │   return function_wo_return(&value);
    │   ────────────────┬────────────────  
    │                   ╰────────────────── Unexpected type '()', expected 'i32'

Running mainBad panics the compiler. It should return something similiar to mainOk but the output is

Compiling bugWithOpResult (bugWithOpResult.con)
error: 'llvm.load' op result #0 must be LLVM type with size, but got 'none'
thread 'main' panicked at crates/concrete_codegen_mlir/src/context.rs:83:9:
assertion failed: melior_module.as_operation().verify()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
kenarab commented 4 months ago

I tested it and now works ok.