Skip to content

Commit

Permalink
chore: rust toolchain upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ebastien committed Aug 31, 2023
1 parent 7268dc8 commit 1560a0c
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]

resolver = "2"
members = [ "oal-model", "oal-client", "oal-openapi", "oal-syntax", "oal-compiler" ]
14 changes: 7 additions & 7 deletions oal-client/src/lsp/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn go_to_definition(

let Some(folder) = state.folders.iter().find(|f| f.contains(&loc)) else {
// Location not found in any folder.
return Ok(None)
return Ok(None);
};

let tree = folder.module(&loc).unwrap();
Expand Down Expand Up @@ -114,12 +114,12 @@ pub fn references(

let Some(folder) = state.folders.iter().find(|f| f.contains(&loc)) else {
// Location not found in any folder.
return Ok(None)
return Ok(None);
};

let Some(definition) = find_definition(&mut state.workspace, folder, &loc, pos)? else {
// Not a variable or definition.
return Ok(None)
return Ok(None);
};

let refs = find_references(&mut state.workspace, folder, definition)?;
Expand All @@ -136,7 +136,7 @@ pub fn prepare_rename(

let Some(folder) = state.folders.iter().find(|f| f.contains(&loc)) else {
// Location not found in any folder.
return Ok(None)
return Ok(None);
};

let tree = folder.module(&loc).unwrap();
Expand Down Expand Up @@ -169,17 +169,17 @@ pub fn rename(

let Some(folder) = state.folders.iter().find(|f| f.contains(&loc)) else {
// Location not found in any folder.
return Ok(None)
return Ok(None);
};

let Some(definition) = find_definition(&mut state.workspace, folder, &loc, pos)? else {
// Not a variable or definition.
return Ok(None)
return Ok(None);
};

let Definition::External(ref external) = definition else {
// Not an external definition.
return Ok(None)
return Ok(None);
};

let mut changes = HashMap::new();
Expand Down
2 changes: 1 addition & 1 deletion oal-compiler/src/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn deep_extend_mapping(prev: &mut Mapping, other: Mapping) {

/// Extends a sequence by concatenation.
fn deep_extend_sequence(prev: &mut Sequence, other: Sequence) {
prev.extend(other.into_iter());
prev.extend(other);
}

#[test]
Expand Down
19 changes: 12 additions & 7 deletions oal-compiler/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,9 @@ pub fn eval_binding<'a>(
ann: AnnRef,
) -> Result<(Expr<'a>, AnnRef)> {
let ident = binding.ident();
let Some((expr, prev_ann)) = ctx.lookup_binding(&ident)
else { panic!("binding '{}' should exist", ident) };
let Some((expr, prev_ann)) = ctx.lookup_binding(&ident) else {
panic!("binding '{}' should exist", ident)
};
let mut next_ann = prev_ann.as_ref().clone();
next_ann.extend(ann.as_ref().clone());
Ok((expr, AnnRef::new(next_ann)))
Expand Down Expand Up @@ -608,13 +609,15 @@ pub fn eval_literal<'a>(
) -> Result<(Expr<'a>, AnnRef)> {
let expr = match literal.kind() {
syn::LiteralKind::HttpStatus => {
let lex::TokenValue::HttpStatus(status) = literal.value()
else { panic!("expected an HTTP status") };
let lex::TokenValue::HttpStatus(status) = literal.value() else {
panic!("expected an HTTP status")
};
Expr::HttpStatus(*status)
}
syn::LiteralKind::Number => {
let lex::TokenValue::Number(number) = literal.value()
else { panic!("expected a number") };
let lex::TokenValue::Number(number) = literal.value() else {
panic!("expected a number")
};
Expr::Number(*number)
}
syn::LiteralKind::String => {
Expand Down Expand Up @@ -816,6 +819,8 @@ pub fn eval(mods: &ModuleSet) -> Result<Spec> {
let ctx = &mut Context::new(mods);
let ann = AnnRef::default();
let (expr, _) = eval_any(ctx, mods.main().root(), ann)?;
let Expr::Spec(spec) = expr else { panic!("expected a specification") };
let Expr::Spec(spec) = expr else {
panic!("expected a specification")
};
Ok(*spec)
}
84 changes: 63 additions & 21 deletions oal-compiler/src/eval_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ fn eval_composed_annotation() -> anyhow::Result<()> {
assert_eq!(x.ranges.len(), 1);
let c = x.ranges.values().next().unwrap();
let s = c.schema.as_ref().unwrap();
let SchemaExpr::Object(ref o) = s.expr else { panic!("expected an object") };
let SchemaExpr::Object(ref o) = s.expr else {
panic!("expected an object")
};
assert_eq!(o.props.len(), 1);
let p = o.props.first().unwrap();
assert_eq!(p.name, "prop");
Expand All @@ -103,7 +105,9 @@ fn eval_composed_annotation() -> anyhow::Result<()> {
assert_eq!(s.desc.as_ref().unwrap(), "a number");
assert_eq!(s.title.as_ref().unwrap(), "a property type");
assert!(s.required.is_none());
let SchemaExpr::Num(ref n) = s.expr else { panic!("expected a number") };
let SchemaExpr::Num(ref n) = s.expr else {
panic!("expected a number")
};
assert_eq!(n.minimum.unwrap(), 0f64);

Ok(())
Expand Down Expand Up @@ -257,7 +261,9 @@ fn eval_content_schema() -> anyhow::Result<()> {
.as_ref()
.expect("expected transfer on HTTP GET");
let r = x.ranges.values().next().unwrap().schema.as_ref().unwrap();
let SchemaExpr::Object(o) = &r.expr else { panic!("expected an object") };
let SchemaExpr::Object(o) = &r.expr else {
panic!("expected an object")
};
assert_eq!(o.props.len(), 2);
let p = &o.props[0];
assert_eq!(p.name, "a");
Expand All @@ -280,16 +286,22 @@ fn eval_operation_any() -> anyhow::Result<()> {
.as_ref()
.expect("expected transfer on HTTP GET");
let r = x.ranges.values().next().unwrap().schema.as_ref().unwrap();
let SchemaExpr::Op(op) = &r.expr else { panic!("expected an operation") };
let SchemaExpr::Op(op) = &r.expr else {
panic!("expected an operation")
};
assert_eq!(op.op, VariadicOperator::Any);
assert_eq!(op.schemas.len(), 3);

let s = op.schemas.get(0).expect("expected a schema");
let SchemaExpr::Object(o) = &s.expr else { panic!("expected an object") };
let SchemaExpr::Object(o) = &s.expr else {
panic!("expected an object")
};
assert_eq!(o.props.len(), 2);
let p = &o.props[0];
assert_eq!(p.name, "b");
let SchemaExpr::Array(a) = &p.schema.expr else { panic!("expected an array") };
let SchemaExpr::Array(a) = &p.schema.expr else {
panic!("expected an array")
};
assert!(matches!(a.item.expr, SchemaExpr::Bool(_)));
let p = &o.props[1];
assert_eq!(p.name, "c");
Expand All @@ -315,7 +327,9 @@ fn eval_operation_sum() -> anyhow::Result<()> {
.as_ref()
.expect("expected transfer on HTTP GET");
let r = x.ranges.values().next().unwrap().schema.as_ref().unwrap();
let SchemaExpr::Op(op) = &r.expr else { panic!("expected an operation") };
let SchemaExpr::Op(op) = &r.expr else {
panic!("expected an operation")
};
assert_eq!(op.op, VariadicOperator::Sum);
assert_eq!(op.schemas.len(), 2);

Expand All @@ -339,7 +353,9 @@ fn eval_operation_required() -> anyhow::Result<()> {
.as_ref()
.expect("expected transfer on HTTP GET");
let r = x.ranges.values().next().unwrap().schema.as_ref().unwrap();
let SchemaExpr::Object(o) = &r.expr else { panic!("expected an object") };
let SchemaExpr::Object(o) = &r.expr else {
panic!("expected an object")
};
assert_eq!(o.props.len(), 1);
let p = &o.props[0];
assert_eq!(p.name, "a");
Expand All @@ -358,7 +374,9 @@ fn eval_uri() -> anyhow::Result<()> {
let r = s.rels.iter().next().unwrap();

assert!(matches!(r.uri.path[0], UriSegment::Literal(_)));
let UriSegment::Variable(v) = &r.uri.path[1] else { panic!("expected uri variable") };
let UriSegment::Variable(v) = &r.uri.path[1] else {
panic!("expected uri variable")
};
assert!(matches!(v.schema.expr, SchemaExpr::Num(_)));
assert!(matches!(r.uri.path[2], UriSegment::Literal(_)));

Expand Down Expand Up @@ -412,13 +430,17 @@ fn eval_reference() -> anyhow::Result<()> {
.expect("expected transfer on HTTP GET");

let r = x.ranges.values().next().unwrap().schema.as_ref().unwrap();
let SchemaExpr::Ref(i) = &r.expr else { panic!("expected a reference") };
let SchemaExpr::Ref(i) = &r.expr else {
panic!("expected a reference")
};
assert_eq!(*i, "@a");

assert_eq!(s.refs.len(), 1);

let Reference::Schema(r) = s.refs.values().next().unwrap();
let SchemaExpr::Object(o) = &r.expr else { panic!("expected an object") };
let SchemaExpr::Object(o) = &r.expr else {
panic!("expected an object")
};
assert!(o.props.is_empty());

Ok(())
Expand All @@ -440,7 +462,9 @@ fn eval_reference_fallback() -> anyhow::Result<()> {

assert_eq!(s.refs.len(), 1);
let Reference::Schema(r) = s.refs.values().next().unwrap();
let SchemaExpr::Uri(u) = &r.expr else { panic!("expected an URI") };
let SchemaExpr::Uri(u) = &r.expr else {
panic!("expected an URI")
};
assert_eq!(u.path.len(), 1);
assert_eq!(*u.path.first().unwrap(), UriSegment::Literal("".into()));

Expand Down Expand Up @@ -484,13 +508,17 @@ fn eval_application() -> anyhow::Result<()> {
.as_ref()
.expect("expected transfer on HTTP GET");
let r = x.ranges.values().next().unwrap().schema.as_ref().unwrap();
let SchemaExpr::Object(o) = &r.expr else { panic!("expected an object") };
let SchemaExpr::Object(o) = &r.expr else {
panic!("expected an object")
};

assert_eq!(o.props.len(), 2);

let p = &o.props[0];
assert_eq!(p.name, "p");
let SchemaExpr::Op(op) = &p.schema.expr else { panic!("expected an operation") };
let SchemaExpr::Op(op) = &p.schema.expr else {
panic!("expected an operation")
};
assert_eq!(op.op, VariadicOperator::Sum);
assert_eq!(op.schemas.len(), 2);

Expand Down Expand Up @@ -537,7 +565,9 @@ fn eval_subexpr() -> anyhow::Result<()> {
.as_ref()
.expect("expected transfer on HTTP GET");
let r = x.ranges.values().next().unwrap().schema.as_ref().unwrap();
let SchemaExpr::Op(op) = &r.expr else { panic!("expected an operation") };
let SchemaExpr::Op(op) = &r.expr else {
panic!("expected an operation")
};

assert_eq!(op.op, VariadicOperator::Join);
assert_eq!(op.schemas.len(), 2);
Expand Down Expand Up @@ -624,12 +654,18 @@ fn eval_single_recursion() -> anyhow::Result<()> {
.schema
.as_ref()
.unwrap();
let SchemaExpr::Object(obj) = &range.expr else { panic!("range should be an object") };
let SchemaExpr::Object(obj) = &range.expr else {
panic!("range should be an object")
};
let (p1, p2) = (&obj.props[0], &obj.props[1]);
assert_eq!(p1.name, "a");
assert_eq!(p2.name, "b");
let SchemaExpr::Ref(id1) = &p1.schema.expr else { panic!("schema should be a reference") };
let SchemaExpr::Ref(id2) = &p2.schema.expr else { panic!("schema should be a reference") };
let SchemaExpr::Ref(id1) = &p1.schema.expr else {
panic!("schema should be a reference")
};
let SchemaExpr::Ref(id2) = &p2.schema.expr else {
panic!("schema should be a reference")
};
assert!(id1.as_ref().starts_with("hash-"));
assert_eq!(id1, id2);
let recursion = s.refs.get(id1).expect("reference should exist");
Expand Down Expand Up @@ -666,7 +702,9 @@ fn eval_mutual_recursion() -> anyhow::Result<()> {
.as_ref()
.unwrap();

let SchemaExpr::Ref(id_a) = &range.expr else { panic!("range should be a reference") };
let SchemaExpr::Ref(id_a) = &range.expr else {
panic!("range should be a reference")
};
let ref_a = s.refs.get(id_a).expect("reference should exist");
let Reference::Schema(schema) = ref_a;
let SchemaExpr::Object(obj) = &schema.expr else {
Expand All @@ -675,7 +713,9 @@ fn eval_mutual_recursion() -> anyhow::Result<()> {

let prop = &obj.props[0];
assert_eq!(prop.name, "b");
let SchemaExpr::Ref(id_b) = &prop.schema.expr else { panic!("schema should be a reference") };
let SchemaExpr::Ref(id_b) = &prop.schema.expr else {
panic!("schema should be a reference")
};
let ref_b = s.refs.get(id_b).expect("reference should exist");
let Reference::Schema(schema) = ref_b;
let SchemaExpr::Object(obj) = &schema.expr else {
Expand All @@ -684,7 +724,9 @@ fn eval_mutual_recursion() -> anyhow::Result<()> {

let prop = &obj.props[0];
assert_eq!(prop.name, "a");
let SchemaExpr::Ref(id) = &prop.schema.expr else { panic!("schema should be a reference") };
let SchemaExpr::Ref(id) = &prop.schema.expr else {
panic!("schema should be a reference")
};
assert_eq!(id, id_a);

Ok(())
Expand Down
35 changes: 21 additions & 14 deletions oal-compiler/src/inference/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,41 @@ fn infer_tag() -> anyhow::Result<()> {
let prog = Program::cast(mods.main().root()).expect("expected a program");

let decl1 = prog.declarations().nth(0).expect("expected a declaration");
let Tag::Var(t1) = decl1.node().syntax().core_ref().unwrap_tag()
else { panic!("expected a tag variable") };
let Tag::Var(t1) = decl1.node().syntax().core_ref().unwrap_tag() else {
panic!("expected a tag variable")
};

let binding = decl1.bindings().next().expect("expected a binding");
assert_eq!(binding.ident(), "x");
let Tag::Var(t2) = binding.node().syntax().core_ref().unwrap_tag()
else { panic!("expected a tag variable") };
let Tag::Var(t2) = binding.node().syntax().core_ref().unwrap_tag() else {
panic!("expected a tag variable")
};

let term = Terminal::cast(decl1.rhs()).expect("expected a terminal");
let Tag::Var(t3) = term.node().syntax().core_ref().unwrap_tag()
else { panic!("expected a tag variable") };
let Tag::Var(t3) = term.node().syntax().core_ref().unwrap_tag() else {
panic!("expected a tag variable")
};

let variable = Variable::cast(term.inner()).expect("expected a variable");
assert_eq!(variable.ident(), "x");
let Tag::Var(t4) = variable.node().syntax().core_ref().unwrap_tag()
else { panic!("expected a tag variable") };
let Tag::Var(t4) = variable.node().syntax().core_ref().unwrap_tag() else {
panic!("expected a tag variable")
};

let decl2 = prog.declarations().nth(1).expect("expected a declaration");
let Tag::Var(t5) = decl2.node().syntax().core_ref().unwrap_tag()
else { panic!("expected a tag variable") };
let Tag::Var(t5) = decl2.node().syntax().core_ref().unwrap_tag() else {
panic!("expected a tag variable")
};

let app = Application::cast(decl2.rhs()).expect("expected an application");
let Tag::Var(t6) = app.node().syntax().core_ref().unwrap_tag()
else { panic!("expected a tag variable") };
let Tag::Var(t6) = app.node().syntax().core_ref().unwrap_tag() else {
panic!("expected a tag variable")
};

let arg = app.arguments().next().expect("expected an argument");
let Tag::Var(t7) = arg.node().syntax().core_ref().unwrap_tag()
else { panic!("expected a tag variable") };
let Tag::Var(t7) = arg.node().syntax().core_ref().unwrap_tag() else {
panic!("expected a tag variable")
};

assert_eq!(arg.inner().syntax().core_ref().unwrap_tag(), Tag::Primitive);

Expand Down
4 changes: 3 additions & 1 deletion oal-compiler/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ fn declare_import(
) -> Result<()> {
let other = loc.join(import.module())?;
// All modules that are to be imported must be present in the module-set.
let Some(module) = mods.get(&other) else { panic!("unknown module: {other}") };
let Some(module) = mods.get(&other) else {
panic!("unknown module: {other}")
};
let program = Program::cast(module.root()).expect("module root must be a program");
for decl in program.declarations() {
let defn = Definition::External(External::new(decl.node()));
Expand Down
4 changes: 3 additions & 1 deletion oal-compiler/src/resolve_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use oal_syntax::parser::{
fn definition<'a>(mods: &'a ModuleSet, node: NRef<'a>) -> NRef<'a> {
let core = node.syntax().core_ref();
let defn = core.definition().expect("expected a definition");
let Definition::External(ext) = defn else { panic!("expected an external") };
let Definition::External(ext) = defn else {
panic!("expected an external")
};
ext.node(mods)
}

Expand Down
Loading

0 comments on commit 1560a0c

Please sign in to comment.