lambdaclass/concrete

Found a case where compiler should throw an Error but panics

Opened this issue · 4 comments

mod LinearExampleStub {

	struct Linear {
	    x: i32,
	    y: i32,
	}
	
	fn main() -> i32 {
		let mut xy: Linear = 
                    Linear {
                        x: 0,
                        y: 1,
                    };
		// linear value is written/consumed
		consume_x(&xy);
		return xy.x;
	}
	
	fn consume_x(value: & mut Linear) {
		value.x = value.x + 1;
	}
	
}
$cargo r build linearExample02.con --ir
   Compiling linearExample02 (linearExample02.con)
thread 'main' panicked at crates/concrete_ir/src/lib.rs:475:38:
not yet implemented
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Lines 474-475 of lib.rs

            TyKind::Param { .. } => todo!(),
            TyKind::Struct { .. } => todo!(),

Changing parameter as non mutable yields an expected error conducting to make the parameter mutable. So this new feature (checking mutable types) should implement mutable parameters for being able to cover borrow checking part of LinearityCheck

mod LinearExampleStub {

	struct Linear {
	    x: i32,
	    y: i32,
	}
	
	fn main() -> i32 {
		let mut xy: Linear = 
                    Linear {
                        x: 0,
                        y: 1,
                    };
		// linear value is written/consumed
		consume_x(&xy);
		return xy.x;
	}
	
	fn consume_x(value: & Linear) {
		value.x = value.x + 1;
	}
	
}
$cargo r build linearExample02.con --ir
   Compiling linearExample02 (linearExample02.con)
[NotMutable] Error: 
    ╭─[linearExample02.con:22:3]
    │
 21 │     fn consume_x(value: & Linear) {
    │                  ──┬──  
    │                    ╰──── variable declared here
 22 │        value.x = value.x + 1;
    │        ──────────┬──────────  
    │                  ╰──────────── can't mutate this variable because it's not mutable
────╯

This requirement was a consequence of PR #124

Can you try with &mut on the function call and definition?

You are correct, it runs when rewriting to

consume_x(&mut xy);

The first example panics the compiler, it is better if it gives a compilation error than panic.

Changed issue title. Will convert the panic case into a testcase