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

Found a case where compiler should throw an Error but panics #134

Open
kenarab opened this issue May 10, 2024 · 4 comments
Open

Found a case where compiler should throw an Error but panics #134

kenarab opened this issue May 10, 2024 · 4 comments

Comments

@kenarab
Copy link
Collaborator

kenarab commented May 10, 2024

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
────╯
@kenarab
Copy link
Collaborator Author

kenarab commented May 10, 2024

This requirement was a consequence of PR #124

@edg-l
Copy link
Member

edg-l commented May 10, 2024

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

@kenarab
Copy link
Collaborator Author

kenarab commented May 10, 2024

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.

@kenarab kenarab changed the title Need mutable parameters for building a test case for borrowing a Lineartype Found a case where compiler should throw an Error but panics May 11, 2024
@kenarab
Copy link
Collaborator Author

kenarab commented May 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants