Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Cranky.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
allow = []

deny = [
"clippy::complexity",
"clippy::expect_used",
"clippy::implicit_clone",
"clippy::manual_string_new",
"clippy::map_unwrap_or",
"clippy::match_same_arms",
"clippy::option_as_ref_deref",
"clippy::option_filter_map",
"clippy::option_map_unit_fn",
"clippy::or_then_unwrap",
"clippy::panic",
"clippy::range_plus_one",
"clippy::redundant_clone",
"clippy::redundant_closure_for_method_calls",
"clippy::semicolon_if_nothing_returned",
"clippy::single_match_else",
"clippy::unnecessary_cast",
"clippy::unnecessary_wraps",
"clippy::unused_self",
"clippy::unwrap_used",
"clippy::useless_asref",
"clippy::useless_conversion",
"clippy::useless_format",
"nonstandard-style",
"rust_2018_idioms",
"rust-2021-compatibility",
"trivial_casts",
"trivial_numeric_casts",
"unsafe_code",
"unused_import_braces",
"unused_lifetimes",
"unused_qualifications",
"warnings",
]

warn = []
16 changes: 5 additions & 11 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@ dependencies = ["install-rustfmt"]
description = "Check format of sources files."

[tasks.lint-rust]
args = [
"clippy",
"--workspace",
"--locked",
"--all-targets",
"--",
"-D",
"clippy::all",
"-D",
"warnings",
]
args = ["cranky"]
command = "cargo"
dependencies = ["install-clippy"]
description = "Check lint of all sources files."
Expand Down Expand Up @@ -513,6 +503,10 @@ install_crate = { rustup_component_name = "llvm-tools-preview" }
[tasks.install-clippy]
install_crate = { rustup_component_name = "clippy" }

[tasks.intall-cranky]
dependencies = ["install-clippy"]
install_crate = { crate_name = "cranky" }

[tasks.install-rustfmt]
install_crate = { rustup_component_name = "rustfmt" }

Expand Down
31 changes: 13 additions & 18 deletions contracts/okp4-cognitarium/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
deps: DepsMut<'_>,
_env: Env,
info: MessageInfo,
msg: InstantiateMsg,
Expand All @@ -31,7 +31,7 @@ pub fn instantiate(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
deps: DepsMut<'_>,
_env: Env,
info: MessageInfo,
msg: ExecuteMsg,
Expand All @@ -52,13 +52,13 @@ pub mod execute {
use std::io::BufReader;

pub fn insert(
deps: DepsMut,
deps: DepsMut<'_>,
info: MessageInfo,
format: DataFormat,
data: Binary,
) -> Result<Response, ContractError> {
if STORE.load(deps.storage)?.owner != info.sender {
Err(ContractError::Unauthorized)?
Err(ContractError::Unauthorized)?;
}

let buf = BufReader::new(data.as_slice());
Expand All @@ -73,7 +73,7 @@ pub mod execute {
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Store => to_binary(&query::store(deps)?),
QueryMsg::Select { query } => to_binary(&query::select(deps, query)?),
Expand All @@ -97,22 +97,22 @@ pub mod query {
use crate::querier::{PlanBuilder, QueryEngine};
use crate::rdf::{self, Atom, TripleWriter};

pub fn store(deps: Deps) -> StdResult<StoreResponse> {
STORE.load(deps.storage).map(|s| s.into())
pub fn store(deps: Deps<'_>) -> StdResult<StoreResponse> {
STORE.load(deps.storage).map(Into::into)
}

pub fn select(deps: Deps, query: SelectQuery) -> StdResult<SelectResponse> {
pub fn select(deps: Deps<'_>, query: SelectQuery) -> StdResult<SelectResponse> {
let store = STORE.load(deps.storage)?;

if query.select.len() > store.limits.max_query_variable_count as usize {
Err(StdError::generic_err(
"Maximum query variable count exceeded",
))?
))?;
}

let count = query.limit.unwrap_or(store.limits.max_query_limit);
if count > store.limits.max_query_limit {
Err(StdError::generic_err("Maximum query limit exceeded"))?
Err(StdError::generic_err("Maximum query limit exceeded"))?;
}

let plan = PlanBuilder::new(deps.storage, &query.prefixes)
Expand All @@ -123,7 +123,7 @@ pub mod query {
}

pub fn describe(
deps: Deps,
deps: Deps<'_>,
query: DescribeQuery,
format: DataFormat,
) -> StdResult<DescribeResponse> {
Expand All @@ -134,7 +134,7 @@ pub mod query {
) -> Result<Value, StdError> {
vars.get(index)
.and_then(|it| bindings.get(it.as_str()))
.map(|it| it.to_owned())
.cloned()
.ok_or_else(|| {
StdError::generic_err(format!(
"Variable index {index} not found (this was unexpected)"
Expand Down Expand Up @@ -192,12 +192,7 @@ pub mod query {
if let VarOrNamedNode::NamedNode(iri) = &query.resource {
vars.insert(0, s.clone());
for b in &mut bindings {
b.insert(
s.clone(),
Value::URI {
value: iri.to_owned(),
},
);
b.insert(s.clone(), Value::URI { value: iri.clone() });
}
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/okp4-cognitarium/src/querier/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'a> QueryEngine<'a> {
})
}

pub fn eval_plan(&'a self, plan: QueryPlan) -> ResolvedVariablesIterator {
pub fn eval_plan(&'a self, plan: QueryPlan) -> ResolvedVariablesIterator<'_> {
return self.eval_node(plan.entrypoint)(ResolvedVariables::with_capacity(
plan.variables.len(),
));
Expand Down
10 changes: 4 additions & 6 deletions contracts/okp4-cognitarium/src/querier/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,14 @@ impl QueryNode {
predicate.lookup_bound_variable(callback);
object.lookup_bound_variable(callback);
}
QueryNode::CartesianProductJoin { left, right } => {
QueryNode::CartesianProductJoin { left, right }
| QueryNode::ForLoopJoin { left, right } => {
left.lookup_bound_variables(callback);
right.lookup_bound_variables(callback);
}
QueryNode::ForLoopJoin { left, right } => {
left.lookup_bound_variables(callback);
right.lookup_bound_variables(callback);
QueryNode::Skip { child, .. } | QueryNode::Limit { child, .. } => {
child.lookup_bound_variables(callback);
}
QueryNode::Skip { child, .. } => child.lookup_bound_variables(callback),
QueryNode::Limit { child, .. } => child.lookup_bound_variables(callback),
}
}
}
Expand Down
44 changes: 28 additions & 16 deletions contracts/okp4-cognitarium/src/querier/plan_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'a> PlanBuilder<'a> {
})
.collect::<StdResult<Vec<QueryNode>>>()?;

self.build_from_bgp(bgp)
Self::build_from_bgp(bgp)
.map(|mut node| {
if let Some(skip) = self.skip {
node = QueryNode::Skip {
Expand All @@ -72,7 +72,7 @@ impl<'a> PlanBuilder<'a> {
})
}

fn build_from_bgp(&self, bgp: Vec<QueryNode>) -> StdResult<QueryNode> {
fn build_from_bgp(bgp: Vec<QueryNode>) -> StdResult<QueryNode> {
bgp.into_iter()
.reduce(|left: QueryNode, right: QueryNode| -> QueryNode {
if left
Expand All @@ -91,8 +91,10 @@ impl<'a> PlanBuilder<'a> {
right: Box::new(right),
}
})
.map(Ok)
.unwrap_or_else(|| Err(StdError::generic_err("Empty basic graph pattern")))
.map_or_else(
|| Err(StdError::generic_err("Empty basic graph pattern")),
Ok,
)
}

fn build_triple_pattern(&mut self, pattern: &TriplePattern) -> StdResult<QueryNode> {
Expand Down Expand Up @@ -156,24 +158,28 @@ impl<'a> PlanBuilder<'a> {
match value {
IRI::Prefixed(prefixed) => prefixed
.rfind(':')
.map(Ok)
.unwrap_or_else(|| {
Err(StdError::generic_err(
"Malformed prefixed IRI: no prefix delimiter found",
))
})
.map_or_else(
|| {
Err(StdError::generic_err(
"Malformed prefixed IRI: no prefix delimiter found",
))
},
Ok,
)
.and_then(|index| {
self.prefixes
.get(&prefixed.as_str()[..index])
.map(|resolved_prefix| {
[resolved_prefix, &prefixed.as_str()[index + 1..]].join("")
})
.map(Ok)
.unwrap_or_else(|| {
Err(StdError::generic_err(
"Malformed prefixed IRI: prefix not found",
))
})
.map_or_else(
|| {
Err(StdError::generic_err(
"Malformed prefixed IRI: prefix not found",
))
},
Ok,
)
}),
IRI::Full(full) => Ok(full),
}
Expand Down Expand Up @@ -307,6 +313,12 @@ mod test {
value: "resource".to_string(),
}),
),
(
IRI::Prefixed("resource".to_string()),
Err(StdError::generic_err(
"Malformed prefixed IRI: no prefix delimiter found",
)),
),
(
IRI::Prefixed("okp5:resource".to_string()),
Err(StdError::generic_err(
Expand Down
6 changes: 3 additions & 3 deletions contracts/okp4-cognitarium/src/querier/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ impl ResolvedVariable {
ResolvedVariable::Predicate(p) => p.clone(),
ResolvedVariable::Object(o) => match o {
Object::Named(node) => node.clone(),
Object::Blank(_) => None?,
Object::Literal(_) => None?,
Object::Blank(_) | Object::Literal(_) => None?,
},
})
}

#[allow(clippy::unnecessary_wraps)]
pub fn as_object(&self) -> Option<Object> {
Some(match self {
ResolvedVariable::Subject(s) => match s {
Expand Down Expand Up @@ -132,7 +132,7 @@ impl ResolvedVariables {
}

pub fn set(&mut self, index: usize, var: ResolvedVariable) {
self.variables[index] = Some(var)
self.variables[index] = Some(var);
}

pub fn get(&self, index: usize) -> &Option<ResolvedVariable> {
Expand Down
15 changes: 5 additions & 10 deletions contracts/okp4-cognitarium/src/rdf/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ pub enum Subject {
impl fmt::Display for Subject {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Subject::NamedNode(s) => write!(f, "{s}"),
Subject::BlankNode(s) => write!(f, "{s}"),
Subject::NamedNode(s) | Subject::BlankNode(s) => write!(f, "{s}"),
}
}
}
Expand All @@ -42,9 +41,7 @@ pub enum Value {
impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Value::NamedNode(s) => write!(f, "{s}"),
Value::BlankNode(s) => write!(f, "{s}"),
Value::LiteralSimple(s) => write!(f, "{s}"),
Value::NamedNode(s) | Value::BlankNode(s) | Value::LiteralSimple(s) => write!(f, "{s}"),
Value::LiteralLang(s, l) => write!(f, "{s}@{l}"),
Value::LiteralDatatype(s, d) => write!(f, "{s}^^{d}"),
}
Expand All @@ -59,7 +56,7 @@ pub struct Atom {
}

impl std::fmt::Display for Atom {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fmt.write_str(&format!(
"<{}> <{}> '{}'",
self.subject, self.property, self.value
Expand All @@ -72,16 +69,14 @@ impl<'a> From<&'a Atom> for Triple<'a> {
fn from(atom: &'a Atom) -> Self {
Triple {
subject: match &atom.subject {
Subject::NamedNode(s) => NamedNode { iri: s.as_str() },
Subject::BlankNode(s) => NamedNode { iri: s.as_str() },
Subject::NamedNode(s) | Subject::BlankNode(s) => NamedNode { iri: s.as_str() },
}
.into(),
predicate: NamedNode {
iri: atom.property.0.as_str(),
},
object: match &atom.value {
Value::NamedNode(s) => NamedNode { iri: s.as_str() }.into(),
Value::BlankNode(s) => NamedNode { iri: s.as_str() }.into(),
Value::NamedNode(s) | Value::BlankNode(s) => NamedNode { iri: s.as_str() }.into(),
Value::LiteralSimple(s) => Literal::Simple { value: s.as_str() }.into(),
Value::LiteralLang(s, l) => Literal::LanguageTaggedString {
value: s.as_str(),
Expand Down
4 changes: 2 additions & 2 deletions contracts/okp4-cognitarium/src/rdf/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ impl<R: BufRead> TripleReader<R> {

pub fn read_all<E, UF>(&mut self, mut use_fn: UF) -> Result<(), E>
where
UF: FnMut(Triple) -> Result<(), E>,
UF: FnMut(Triple<'_>) -> Result<(), E>,
E: From<TurtleError> + From<RdfXmlError>,
{
match &mut self.parser {
TriplesParserKind::NTriples(parser) => parser.parse_all(&mut use_fn),
TriplesParserKind::Turtle(parser) => parser.parse_all(&mut use_fn),
TriplesParserKind::RdfXml(parser) => parser.parse_all(&mut use_fn),
TriplesParserKind::NQuads(parser) => {
parser.parse_all(&mut |quad: Quad| -> Result<(), E> {
parser.parse_all(&mut |quad: Quad<'_>| -> Result<(), E> {
use_fn(Triple {
subject: quad.subject,
predicate: quad.predicate,
Expand Down
2 changes: 1 addition & 1 deletion contracts/okp4-cognitarium/src/rdf/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn explode_iri(iri: &str) -> StdResult<(String, String)> {
}

if let Some(index) = marker_index {
return Ok((iri[..index + 1].to_string(), iri[index + 1..].to_string()));
return Ok((iri[..=index].to_string(), iri[index + 1..].to_string()));
}

Err(StdError::generic_err("Couldn't extract IRI namespace"))
Expand Down
Loading