Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
aannleax committed Sep 17, 2024
1 parent e02c7e8 commit 9ab76fc
Show file tree
Hide file tree
Showing 60 changed files with 278 additions and 380 deletions.
6 changes: 3 additions & 3 deletions nemo-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn handle_tracing(
fact: fact_string.clone(),
})?;
let mut builder = ValidationErrorBuilder::default();
if fact.validate(&mut builder).is_err() {
if fact.validate(&mut builder).is_none() {
return Err(CliError::TracingInvalidFact {
fact: fact_string.clone(),
});
Expand Down Expand Up @@ -285,7 +285,7 @@ fn run(mut cli: CliApp) -> Result<(), CliError> {
let mut engine: DefaultExecutionEngine = ExecutionEngine::initialize(&program, import_manager)?;

for (predicate, handler) in engine.exports() {
export_manager.validate(&predicate, &handler)?;
export_manager.validate(&predicate, &*handler)?;
}

TimedCode::instance().sub("Reading & Preprocessing").stop();
Expand All @@ -307,7 +307,7 @@ fn run(mut cli: CliApp) -> Result<(), CliError> {
for (predicate, handler) in engine.exports() {
stdout_used |= export_manager.export_table(
&predicate,
&handler,
&*handler,
engine.predicate_rows(&predicate)?,
)?;
}
Expand Down
10 changes: 5 additions & 5 deletions nemo-language-server/src/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Backend {
Parser::initialize(text, text_document.uri.to_string())
.parse()
.map(|prg| (prg, None))
.unwrap_or_else(|(prg, err)| (prg, Some(err)));
.unwrap_or_else(|(prg, err)| (*prg, Some(err)));

// Group errors by position and deduplicate error
let mut errors_by_posision: BTreeMap<CharacterPosition, BTreeSet<String>> = BTreeMap::new();
Expand Down Expand Up @@ -267,7 +267,7 @@ impl LanguageServer for Backend {
)
.parse()
.map(|prg| (prg, None))
.unwrap_or_else(|(prg, err)| (prg, Some(err)));
.unwrap_or_else(|(prg, err)| (*prg, Some(err)));

let node_path = find_in_ast(&program, position);

Expand Down Expand Up @@ -313,7 +313,7 @@ impl LanguageServer for Backend {
Parser::initialize(&text, params.text_document.uri.to_string())
.parse()
.map(|prg| (prg, None))
.unwrap_or_else(|(prg, err)| (prg, Some(err)));
.unwrap_or_else(|(prg, err)| (*prg, Some(err)));

let document_symbols = ast_node_to_document_symbol(&line_index, &program)
.map_err(Into::into)
Expand Down Expand Up @@ -347,7 +347,7 @@ impl LanguageServer for Backend {
)
.parse()
.map(|prg| (prg, None))
.unwrap_or_else(|(prg, err)| (prg, Some(err)));
.unwrap_or_else(|(prg, err)| (*prg, Some(err)));

let node_path = find_in_ast(&program, position);

Expand Down Expand Up @@ -412,7 +412,7 @@ impl LanguageServer for Backend {
Parser::initialize(&text, params.text_document.uri.to_string())
.parse()
.map(|prg| (prg, None))
.unwrap_or_else(|(prg, err)| (prg, Some(err)));
.unwrap_or_else(|(prg, err)| (*prg, Some(err)));

let node_path = find_in_ast(&program, position);

Expand Down
6 changes: 2 additions & 4 deletions nemo-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,7 @@ impl NemoEngine {
fn trace(&mut self, fact_string: String) -> Option<NemoTrace> {
let fact = Fact::parse(&fact_string).ok()?;
let mut builder = ValidationErrorBuilder::default();
if fact.validate(&mut builder).is_err() {
return None;
}
fact.validate(&mut builder)?;

let (trace, handles) = self.engine.trace(self.program.0.clone(), vec![fact]);
let handle = *handles
Expand Down Expand Up @@ -462,7 +460,7 @@ impl NemoEngine {
.0
.export_table(
&tag,
&export_handler,
&*export_handler,
self.engine.predicate_rows(&tag).py_res()?,
)
.py_res()?;
Expand Down
2 changes: 1 addition & 1 deletion nemo-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl NemoEngine {
let export_manager: ExportManager = Default::default();

export_manager
.export_table_with_writer(Box::new(writer), &export_handler, Some(record_iter))
.export_table_with_writer(Box::new(writer), &*export_handler, Some(record_iter))
.map_err(WasmOrInternalNemoError::Nemo)
.map_err(NemoError)
}
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn output_predicates(engine: &Engine) -> Vec<Tag> {
engine
.program()
.exports()
.into_iter()
.iter()
.map(|export| export.predicate())
.cloned()
.collect()
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/chase_model/components/atom/ground_atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl TryFrom<Atom> for GroundAtom {
type Error = GroundAtomConversionError;

fn try_from(value: Atom) -> Result<Self, Self::Error> {
let origin = value.origin().clone();
let origin = *value.origin();
let predicate = value.predicate();
let mut terms = Vec::new();

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/chase_model/components/atom/primitive_atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl TryFrom<Atom> for PrimitiveAtom {
type Error = PrimitiveAtomConversionError;

fn try_from(value: Atom) -> Result<Self, Self::Error> {
let origin = value.origin().clone();
let origin = *value.origin();
let predicate = value.predicate();
let mut terms = Vec::new();

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/chase_model/components/atom/variable_atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl TryFrom<Atom> for VariableAtom {
type Error = VariableAtomConversionError;

fn try_from(value: Atom) -> Result<Self, Self::Error> {
let origin = value.origin().clone();
let origin = *value.origin();
let predicate = value.predicate();
let mut terms = Vec::new();

Expand Down
4 changes: 2 additions & 2 deletions nemo/src/chase_model/components/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ impl ChaseExport {
}

/// Return the handler.
pub(crate) fn handler(&self) -> &Box<dyn ImportExportHandler> {
&self.handler
pub(crate) fn handler(&self) -> Box<dyn ImportExportHandler> {
self.handler.clone()
}

/// Return the arity of this import.
Expand Down
4 changes: 2 additions & 2 deletions nemo/src/chase_model/components/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ impl ChaseImport {
}

/// Return the handler.
pub(crate) fn handler(&self) -> &Box<dyn ImportExportHandler> {
&self.handler
pub(crate) fn handler(&self) -> Box<dyn ImportExportHandler> {
self.handler.clone()
}

/// Return the arity of this import.
Expand Down
14 changes: 7 additions & 7 deletions nemo/src/chase_model/translation/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ impl ProgramChaseTranslation {
&mut self,
result: &mut ChaseRule,
aggregate: &crate::rule_model::components::term::aggregate::Aggregate,
group_by_variables: &Vec<Variable>,
group_by_variables: &[Variable],
) -> ChaseAggregate {
let origin = aggregate.origin().clone();
let origin = *aggregate.origin();
let kind = aggregate.aggregate_kind();
let input_variable = match aggregate.aggregate_term() {
Term::Primitive(Primitive::Variable(variable)) => variable.clone(),
Expand Down Expand Up @@ -71,7 +71,7 @@ impl ProgramChaseTranslation {
input_variable,
output_variable,
distinct_variables,
group_by_variables.clone(),
group_by_variables.to_vec(),
)
}

Expand All @@ -88,10 +88,10 @@ impl ProgramChaseTranslation {
&mut self,
result: &mut ChaseRule,
operation: &crate::rule_model::components::term::operation::Operation,
group_by_variables: &Vec<Variable>,
group_by_variables: &[Variable],
chase_aggregate: &mut Option<ChaseAggregate>,
) -> OperationTerm {
let origin = operation.origin().clone();
let origin = *operation.origin();
let kind = operation.operation_kind();
let mut subterms = Vec::new();

Expand Down Expand Up @@ -130,7 +130,7 @@ impl ProgramChaseTranslation {
&mut self,
result: &mut ChaseRule,
operation: &crate::rule_model::components::term::operation::Operation,
group_by_variables: &Vec<Variable>,
group_by_variables: &[Variable],
output_variable: Variable,
chase_aggregate: &mut Option<ChaseAggregate>,
) -> ChaseOperation {
Expand All @@ -141,6 +141,6 @@ impl ProgramChaseTranslation {
chase_aggregate,
);

ChaseOperation::new(output_variable, operation_term).set_origin(operation.origin().clone())
ChaseOperation::new(output_variable, operation_term).set_origin(*operation.origin())
}
}
11 changes: 3 additions & 8 deletions nemo/src/chase_model/translation/fact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,13 @@ impl ProgramChaseTranslation {
&mut self,
fact: &crate::rule_model::components::fact::Fact,
) -> GroundAtom {
let origin = fact.origin().clone();
let origin = *fact.origin();
let predicate = fact.predicate().clone();
let mut terms = Vec::new();

for term in fact.subterms() {
if let Term::Primitive(primitive) = term {
if let Primitive::Ground(value) = primitive {
terms.push(value.clone());
continue;
} else {
unreachable!("invalid program: fact contains non-ground values")
}
if let Term::Primitive(Primitive::Ground(value)) = term {
terms.push(value.clone());
} else {
unreachable!("invalid program: fact contains non-primitive values")
}
Expand Down
8 changes: 4 additions & 4 deletions nemo/src/chase_model/translation/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl ProgramChaseTranslation {
variable: &Variable,
operation: &crate::rule_model::components::term::operation::Operation,
) -> ChaseFilter {
let origin = operation.origin().clone();
let origin = *operation.origin();
let operation = Self::build_operation_term(operation);

let filter = OperationTerm::Operation(
Expand All @@ -35,7 +35,7 @@ impl ProgramChaseTranslation {
operation,
],
)
.set_origin(origin.clone()),
.set_origin(origin),
);

ChaseFilter::new(filter).set_origin(origin)
Expand All @@ -50,8 +50,8 @@ impl ProgramChaseTranslation {
OperationTerm::Primitive(term.clone()),
],
)
.set_origin(term.origin().clone());
.set_origin(*term.origin());

ChaseFilter::new(OperationTerm::Operation(filter)).set_origin(term.origin().clone())
ChaseFilter::new(OperationTerm::Operation(filter)).set_origin(*term.origin())
}
}
21 changes: 10 additions & 11 deletions nemo/src/chase_model/translation/import_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl ProgramChaseTranslation {
&self,
import: &crate::rule_model::components::import_export::ImportDirective,
) -> ChaseImport {
let origin = import.origin().clone();
let origin = *import.origin();
let predicate = import.predicate().clone();
let attributes = import.attributes();
let file_format = import.file_format();
Expand All @@ -53,7 +53,7 @@ impl ProgramChaseTranslation {
&self,
export: &crate::rule_model::components::import_export::ExportDirective,
) -> ChaseExport {
let origin = export.origin().clone();
let origin = *export.origin();
let predicate = export.predicate().clone();
let attributes = export.attributes();
let file_format = export.file_format();
Expand All @@ -79,13 +79,12 @@ impl ProgramChaseTranslation {
) -> Box<dyn ImportExportHandler> {
let arity = self.predicate_arity.get(&predicate).cloned();

if attributes.get(&ImportExportAttribute::Resource).is_none() {
let default_file_name = format!("{}.{}", predicate, file_format.extension());
attributes.insert(
ImportExportAttribute::Resource,
Term::from(default_file_name),
);
}
attributes
.entry(ImportExportAttribute::Resource)
.or_insert_with(|| {
let default_file_name = format!("{}.{}", predicate, file_format.extension());
Term::from(default_file_name)
});

match file_format {
FileFormat::CSV => {
Expand Down Expand Up @@ -120,7 +119,7 @@ impl ProgramChaseTranslation {
) -> (CompressionFormat, ImportExportResource) {
attributes
.get(&ImportExportAttribute::Resource)
.and_then(|term| ImportExportDirective::string_value(term))
.and_then(ImportExportDirective::string_value)
.map(|resource| CompressionFormat::from_resource(&resource))
.map(|(format, resource)| (format, ImportExportResource::from_string(resource)))
.expect("invalid program: missing resource in import/export")
Expand Down Expand Up @@ -162,7 +161,7 @@ impl ProgramChaseTranslation {
fn read_limit(attributes: &HashMap<ImportExportAttribute, Term>) -> Option<u64> {
attributes
.get(&ImportExportAttribute::Limit)
.and_then(|term| ImportExportDirective::integer_value(term))
.and_then(ImportExportDirective::integer_value)
.map(|limit| u64::try_from(limit).unwrap_or_default())
}

Expand Down
4 changes: 2 additions & 2 deletions nemo/src/chase_model/translation/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl ProgramChaseTranslation {
pub(crate) fn build_operation_term(
operation: &crate::rule_model::components::term::operation::Operation,
) -> OperationTerm {
let origin = operation.origin().clone();
let origin = *operation.origin();
let kind = operation.operation_kind();
let mut subterms = Vec::new();

Expand Down Expand Up @@ -54,7 +54,7 @@ impl ProgramChaseTranslation {
output_variable: &Variable,
operation: &crate::rule_model::components::term::operation::Operation,
) -> ChaseOperation {
let origin = operation.origin().clone();
let origin = *operation.origin();
let operation = Self::build_operation_term(operation);

ChaseOperation::new(output_variable.clone(), operation).set_origin(origin)
Expand Down
29 changes: 14 additions & 15 deletions nemo/src/chase_model/translation/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ impl ProgramChaseTranslation {

for literal in rule.body() {
if let Literal::Operation(operation) = literal {
if let Some((left, term)) = operation.variable_assignment() {
if let Term::Primitive(Primitive::Variable(right)) = term {
// Operation has the form ?left = ?right
if let Some(assigned) = assignment.get(left) {
assignment.insert(right.clone(), assigned.clone());
} else if let Some(assigned) = assignment.get(right) {
assignment.insert(left.clone(), assigned.clone());
} else {
assignment.insert(left.clone(), right.clone());
}
if let Some((left, Term::Primitive(Primitive::Variable(right)))) =
operation.variable_assignment()
{
// Operation has the form ?left = ?right
if let Some(assigned) = assignment.get(left) {
assignment.insert(right.clone(), assigned.clone());
} else if let Some(assigned) = assignment.get(right) {
assignment.insert(left.clone(), assigned.clone());
} else {
assignment.insert(left.clone(), right.clone());
}
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ impl ProgramChaseTranslation {
/// # Panics
/// Panics if atom contains a structured term or an aggregate.
fn build_body_atom(&mut self, atom: &Atom) -> (VariableAtom, Vec<ChaseFilter>) {
let origin = atom.origin().clone();
let origin = *atom.origin();
let predicate = atom.predicate().clone();
let mut variables = Vec::new();

Expand Down Expand Up @@ -234,8 +234,7 @@ impl ProgramChaseTranslation {

if let Literal::Operation(operation) = literal {
let new_operation = Self::build_operation_term(operation);
let new_filter =
ChaseFilter::new(new_operation).set_origin(operation.origin().clone());
let new_filter = ChaseFilter::new(new_operation).set_origin(*operation.origin());

result.add_positive_filter(new_filter);
}
Expand All @@ -244,11 +243,11 @@ impl ProgramChaseTranslation {

/// Translates each head atom into the [PrimitiveAtom],
/// while taking care of operations and aggregates.
fn handle_head(&mut self, result: &mut ChaseRule, head: &Vec<Atom>) {
fn handle_head(&mut self, result: &mut ChaseRule, head: &[Atom]) {
let mut chase_aggregate: Option<ChaseAggregate> = None;

for (head_index, atom) in head.iter().enumerate() {
let origin = atom.origin().clone();
let origin = *atom.origin();
let predicate = atom.predicate().clone();
let mut terms = Vec::new();

Expand Down
Loading

0 comments on commit 9ab76fc

Please sign in to comment.