Skip to content

Commit

Permalink
Merge branch 'main' into array_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l authored May 10, 2024
2 parents 859afb7 + 56a8221 commit ea228dc
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 46 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,25 @@ jobs:
run: sudo apt-get install libc-dev build-essential
- name: test
run: make test

test-macos:
name: test (macOS)
runs-on: macos-14
env:
CARGO_TERM_COLOR: always
LIBRARY_PATH: /opt/homebrew/lib
MLIR_SYS_180_PREFIX: /opt/homebrew/opt/llvm@18
LLVM_SYS_180_PREFIX: /opt/homebrew/opt/llvm@18
TABLEGEN_180_PREFIX: /opt/homebrew/opt/llvm@18
RUST_LOG: debug
steps:
- uses: actions/checkout@v4
- name: Rustup toolchain install
uses: dtolnay/[email protected]
- uses: homebrew/actions/setup-homebrew@master
- name: install llvm
run: brew install llvm@18
- name: Run tests
run: make test
coverage:
name: coverage
runs-on: ubuntu-latest
Expand Down
90 changes: 78 additions & 12 deletions crates/concrete_check/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn lowering_error_to_report(
program_id,
} => {
let offset = span.from;
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
Report::build(ReportKind::Error, path.clone(), offset)
.with_code("ModuleNotFound")
.with_label(
Expand All @@ -33,7 +33,7 @@ pub fn lowering_error_to_report(
function,
program_id,
} => {
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
Report::build(ReportKind::Error, path.clone(), span.from)
.with_code("FunctionNotFound")
.with_label(
Expand All @@ -48,7 +48,7 @@ pub fn lowering_error_to_report(
name,
program_id,
} => {
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
Report::build(ReportKind::Error, path.clone(), span.from)
.with_code("StructFieldNotFound")
.with_label(
Expand All @@ -64,7 +64,7 @@ pub fn lowering_error_to_report(
symbol,
program_id,
} => {
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
let offset = symbol.span.from;
Report::build(ReportKind::Error, path.clone(), offset)
.with_code("ImportNotFound")
Expand All @@ -90,7 +90,7 @@ pub fn lowering_error_to_report(
type_span,
program_id,
} => {
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
let mut labels = vec![Label::new((path.clone(), span.into()))
.with_message(format!(
"Can't mutate {name:?} because it's behind a immutable borrow"
Expand All @@ -115,7 +115,7 @@ pub fn lowering_error_to_report(
name,
program_id,
} => {
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
Report::build(ReportKind::Error, path.clone(), span.from)
.with_code("UnrecognizedType")
.with_label(
Expand All @@ -131,7 +131,7 @@ pub fn lowering_error_to_report(
id,
program_id,
} => {
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
Report::build(ReportKind::Error, path.clone(), span.from)
.with_code("E_ID")
.with_label(
Expand All @@ -147,7 +147,7 @@ pub fn lowering_error_to_report(
message,
program_id,
} => {
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
Report::build(ReportKind::Error, path.clone(), span.from)
.with_code("NotYetImplemented")
.with_label(
Expand All @@ -163,7 +163,7 @@ pub fn lowering_error_to_report(
expected,
program_id,
} => {
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
let mut labels = vec![Label::new((path.clone(), span.into()))
.with_message(format!(
"Unexpected type '{}', expected '{}'",
Expand All @@ -190,7 +190,7 @@ pub fn lowering_error_to_report(
name,
program_id,
} => {
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
Report::build(ReportKind::Error, path.clone(), span.from)
.with_code("UseOfUndeclaredVariable")
.with_label(
Expand All @@ -205,7 +205,7 @@ pub fn lowering_error_to_report(
name,
program_id,
} => {
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
Report::build(ReportKind::Error, path.clone(), span.from)
.with_code("ExternFnWithBody")
.with_label(
Expand All @@ -216,11 +216,77 @@ pub fn lowering_error_to_report(
.finish()
}
LoweringError::InternalError(msg, program_id) => {
let path = file_paths[program_id].to_str().unwrap().to_string();
let path = file_paths[program_id].display().to_string();
Report::build(ReportKind::Error, path.clone(), 0)
.with_code("InternalError")
.with_message(msg)
.finish()
}
LoweringError::CallParamCountMismatch {
span,
found,
needs,
program_id,
} => {
let path = file_paths[program_id].display().to_string();
Report::build(ReportKind::Error, path.clone(), span.from)
.with_code("CallParamCountMismatch")
.with_label(
Label::new((path, span.into()))
.with_message(format!(
"function call parameter count mismatch: found {}, needs {}.",
found, needs
))
.with_color(colors.next()),
)
.finish()
}

LoweringError::NotMutable {
span,
declare_span,
program_id,
} => {
let path = file_paths[program_id].display().to_string();
let mut report = Report::build(ReportKind::Error, path.clone(), span.from)
.with_code("NotMutable")
.with_label(
Label::new((path.clone(), span.into()))
.with_message("can't mutate this variable because it's not mutable")
.with_color(colors.next()),
);

if let Some(declare_span) = declare_span {
report = report.with_label(
Label::new((path, declare_span.into()))
.with_message("variable declared here")
.with_color(colors.next()),
);
}
report.finish()
}
LoweringError::CantTakeMutableBorrow {
span,
declare_span,
program_id,
} => {
let path = file_paths[program_id].display().to_string();
let mut report = Report::build(ReportKind::Error, path.clone(), span.from)
.with_code("CantTakeMutableBorrow")
.with_label(
Label::new((path.clone(), span.into()))
.with_message("can't take a mutate borrow to this variable because it's not declared mutable")
.with_color(colors.next()),
);

if let Some(declare_span) = declare_span {
report = report.with_label(
Label::new((path, declare_span.into()))
.with_message("variable declared here")
.with_color(colors.next()),
);
}
report.finish()
}
}
}
88 changes: 83 additions & 5 deletions crates/concrete_driver/tests/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ fn import_not_found() {

#[test]
fn invalid_borrow_mut() {
let (source, name) = (include_str!("invalid_programs/refmut.con"), "refmut");
let (source, name) = (
include_str!("invalid_programs/invalid_borrow_mut.con"),
"invalid_borrow_mut",
);
let error = check_invalid_program(source, name);

assert!(
matches!(
&error,
LoweringError::BorrowNotMutable { name, .. } if name == "a"
),
matches!(&error, LoweringError::NotMutable { .. }),
"{:#?}",
error
);
Expand Down Expand Up @@ -102,3 +102,81 @@ fn undeclared_var() {
error
);
}

#[test]
fn call_param_count_mismatch() {
let (source, name) = (
include_str!("invalid_programs/call_param_count_mismatch.con"),
"call_param_count_mismatch",
);
let error = check_invalid_program(source, name);

assert!(
matches!(
&error,
LoweringError::CallParamCountMismatch { found, needs, .. } if *found == 2 && *needs == 1
),
"{:#?}",
error
);
}

#[test]
fn call_param_type_mismatch() {
let (source, name) = (
include_str!("invalid_programs/call_param_type_mismatch.con"),
"call_param_type_mismatch",
);
let error = check_invalid_program(source, name);

assert!(
matches!(&error, LoweringError::UnexpectedType { .. }),
"{:#?}",
error
);
}

#[test]
fn invalid_assign() {
let (source, name) = (
include_str!("invalid_programs/invalid_assign.con"),
"invalid_assign",
);
let error = check_invalid_program(source, name);

assert!(
matches!(&error, LoweringError::UnexpectedType { .. }),
"{:#?}",
error
);
}

#[test]
fn immutable_mutation() {
let (source, name) = (
include_str!("invalid_programs/immutable_mutation.con"),
"immutable_mutation",
);
let error = check_invalid_program(source, name);

assert!(
matches!(&error, LoweringError::NotMutable { .. }),
"{:#?}",
error
);
}

#[test]
fn mutable_nonmut_borrow() {
let (source, name) = (
include_str!("invalid_programs/mutable_nonmut_borrow.con"),
"mutable_nonmut_borrow",
);
let error = check_invalid_program(source, name);

assert!(
matches!(&error, LoweringError::CantTakeMutableBorrow { .. }),
"{:#?}",
error
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mod Test {
fn main() -> i32 {
return hello(1, 2);
}

fn hello(a: i32) -> i32 {
return a * 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mod Test {
fn main() -> i32 {
let x: u32 = 1;
return hello(x);
}

fn hello(a: i32) -> i32 {
return a * 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod Simple {
fn main() -> i32 {
let x: i32 = 2;
x = 4;
return x;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod Simple {
fn main() -> i32 {
let mut x: i32 = 2;
let y: i64 = 4;
x = y;
return x;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod Simple {

fn main() -> i32 {
let x: i32 = 1;
let mut x: i32 = 1;
hello(&x);
return x;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod Simple {
fn main() -> i32 {
let x: i32 = 2;
let y: &mut i32 = &mut x;
*y = 4;
return *y;
}
}
Loading

0 comments on commit ea228dc

Please sign in to comment.