Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
katat committed Oct 9, 2024
1 parent 0221102 commit 5353d42
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
33 changes: 28 additions & 5 deletions src/negative_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
use crate::{
backends::{r1cs::{R1csBn254Field, R1CS}, Backend}, circuit_writer::{CircuitWriter, VarInfo}, compiler::{get_nast, typecheck_next_file_inner, Sources}, constants::Span, error::{ErrorKind, Result}, imports::FnKind, lexer::Token, mast::Mast, name_resolution::NAST, parser::{types::{FnSig, GenericParameters}, ParserCtx}, type_checker::{FnInfo, FullyQualified, TypeChecker}, var::Var, witness::CompiledCircuit
backends::{
r1cs::{R1csBn254Field, R1CS},
Backend,
},
circuit_writer::{CircuitWriter, VarInfo},
compiler::{get_nast, typecheck_next_file_inner, Sources},
constants::Span,
error::{ErrorKind, Result},
imports::FnKind,
lexer::Token,
mast::Mast,
name_resolution::NAST,
parser::{
types::{FnSig, GenericParameters},
ParserCtx,
},
type_checker::{FnInfo, FullyQualified, TypeChecker},
var::Var,
witness::CompiledCircuit,
};

type R1csBackend = R1CS<R1csBn254Field>;
Expand Down Expand Up @@ -444,7 +462,6 @@ fn test_hint_call_missing_unsafe() {
}
"#;


let res = test_hint_builtin_fn(&qualified, valid_code);
assert!(res.is_ok());

Expand All @@ -457,7 +474,10 @@ fn test_hint_call_missing_unsafe() {
"#;

let res = test_hint_builtin_fn(&qualified, invalid_code);
assert!(matches!(res.unwrap_err().kind, ErrorKind::ExpectedUnsafeAttribute));
assert!(matches!(
res.unwrap_err().kind,
ErrorKind::ExpectedUnsafeAttribute
));
}

#[test]
Expand All @@ -473,5 +493,8 @@ fn test_nonhint_call_with_unsafe() {
"#;

let res = tast_pass(code).0;
assert!(matches!(res.unwrap_err().kind, ErrorKind::UnexpectedUnsafeAttribute));
}
assert!(matches!(
res.unwrap_err().kind,
ErrorKind::UnexpectedUnsafeAttribute
));
}
7 changes: 2 additions & 5 deletions src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,9 @@ impl Expr {
match &mut fn_call.kind {
ExprKind::FnCall { unsafe_attr, .. } => {
*unsafe_attr = true;
},
}
_ => {
return Err(ctx.error(
ErrorKind::InvalidExpression,
fn_call.span,
));
return Err(ctx.error(ErrorKind::InvalidExpression, fn_call.span));
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/parser/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl StructDef {
}

// TODO: why is Default implemented here?
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct CustomType {
pub module: ModulePath, // name resolution
pub name: String,
Expand Down
12 changes: 7 additions & 5 deletions src/parser/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,12 @@ impl FunctionDef {
));
}

let func = Self { sig, body, span, is_hint: false };
let func = Self {
sig,
body,
span,
is_hint: false,
};

Ok(func)
}
Expand All @@ -1175,10 +1180,7 @@ impl FunctionDef {

// make sure that it doesn't shadow a builtin
if BUILTIN_FN_NAMES.contains(&sig.name.value.as_ref()) {
return Err(ctx.error(
ErrorKind::ShadowingBuiltIn(sig.name.value.clone()),
span,
));
return Err(ctx.error(ErrorKind::ShadowingBuiltIn(sig.name.value.clone()), span));
}

// for now the body is empty.
Expand Down
30 changes: 18 additions & 12 deletions src/type_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,12 @@ impl<B: Backend> TypeChecker<B> {
FuncOrMethod::Function(module) => {
FullyQualified::new(module, &function.sig.name.value)
}
FuncOrMethod::Method(_) => unreachable!("methods are not supported")
FuncOrMethod::Method(_) => unreachable!("methods are not supported"),
};

// this will override the builtin function in the global env
let builtin_fn = self.functions
let builtin_fn = self
.functions
.get(&qualified)
.ok_or_else(|| {
Error::new(
Expand All @@ -338,19 +339,24 @@ impl<B: Backend> TypeChecker<B> {
// check it is a builtin function
let fn_handle = match builtin_fn {
FnKind::BuiltIn(_, fn_handle) => fn_handle,
_ => return Err(Error::new(
"type-checker",
ErrorKind::UnexpectedError("expected builtin function"),
function.span,
)),
_ => {
return Err(Error::new(
"type-checker",
ErrorKind::UnexpectedError("expected builtin function"),
function.span,
))
}
};

// override the builtin function as a hint function
self.functions.insert(qualified, FnInfo {
is_hint: true,
kind: FnKind::BuiltIn(function.sig.clone(), fn_handle),
span: function.span,
});
self.functions.insert(
qualified,
FnInfo {
is_hint: true,
kind: FnKind::BuiltIn(function.sig.clone(), fn_handle),
span: function.span,
},
);

continue;
};
Expand Down

0 comments on commit 5353d42

Please sign in to comment.