Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [Refactor] Defining clippy rules #91

Merged
merged 14 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 8 additions & 6 deletions checker/src/behavior/template_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use source_map::{Span, SpanWithSource};

use crate::{
behavior::objects::ObjectBuilder,
types::{cast_as_string, SynthesisedArgument},
types::{calling::CallingInput, cast_as_string, SynthesisedArgument},
CheckingData, Constant, Environment, Instance, Type, TypeId,
};

Expand Down Expand Up @@ -101,12 +101,14 @@ where
let call_site = position.clone().with_source(environment.get_source());
crate::types::calling::call_type_handle_errors(
tag,
crate::types::calling::CalledWithNew::None,
crate::behavior::functions::ThisValue::UseParent,
None,
arguments,
call_site,
CallingInput {
called_with_new: crate::types::calling::CalledWithNew::None,
this_value: crate::behavior::functions::ThisValue::UseParent,
call_site,
call_site_type_arguments: None,
},
environment,
arguments,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether arguments could be added to the CallingInput? CallingInput already encompasses the sort of hidden arguments that a function call takes, I wonder whether actual values could also be passed here. Or is there a technical reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a reason I didn't add it, it's because fn call in checker/types/callings takes arguments: &[SynthesisedArgument].
So if we want to add arguments in CallingInput, it'll mean that we need another struct with arguments only for this function. Both are fine I think, do you have a preference?

checking_data,
)
.0
Expand Down
12 changes: 7 additions & 5 deletions checker/src/events/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,14 @@ pub(crate) fn apply_event(
CallingTiming::Synchronous => {
let result = crate::types::calling::call_type(
on,
called_with_new,
Default::default(),
None,
crate::types::calling::CallingInput {
called_with_new,
this_value: Default::default(),
call_site_type_arguments: None,
// TODO:
call_site: source_map::SpanWithSource::NULL_SPAN,
},
with,
// TODO
source_map::SpanWithSource::NULL_SPAN,
environment,
target,
types,
Expand Down
5 changes: 4 additions & 1 deletion checker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#![doc = include_str!("../README.md")]
#![deny(clippy::all)]
#![allow(
unreachable_code,
unused_variables,
unused_imports,
unused_mut,
dead_code,
irrefutable_let_patterns,
deprecated
deprecated,
// TODO: Remove when fixed
clippy::result_unit_err
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this one to by pass the Result<_, ()> linting as it needs more than a refactor I think

)]

pub mod behavior;
Expand Down
14 changes: 8 additions & 6 deletions checker/src/synthesis/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
variables::VariableWithValue,
},
synthesis::parser_property_key_to_checker_property_key,
types::properties::PropertyKey,
types::{calling::CallingInput, properties::PropertyKey},
Decidable,
};

Expand Down Expand Up @@ -837,12 +837,14 @@ fn call_function<T: crate::ReadFromFS>(

crate::types::calling::call_type_handle_errors(
function_type_id,
called_with_new,
Default::default(),
generic_type_arguments,
synthesised_arguments,
call_site.clone().with_source(environment.get_source()),
CallingInput {
called_with_new,
this_value: Default::default(),
call_site: call_site.clone().with_source(environment.get_source()),
call_site_type_arguments: generic_type_arguments,
},
environment,
synthesised_arguments,
checking_data,
)
}
Expand Down
13 changes: 8 additions & 5 deletions checker/src/synthesis/extensions/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
diagnostics::{TypeCheckError, TypeStringRepresentation},
synthesis::expressions::synthesise_expression,
types::{
calling::CallingInput,
properties::PropertyKey,
subtyping::{type_is_subtype, BasicEquality, SubTypeResult},
SynthesisedArgument,
Expand Down Expand Up @@ -191,12 +192,14 @@ pub(crate) fn synthesise_jsx_element<T: crate::ReadFromFS>(

call_type_handle_errors(
jsx_function,
crate::types::calling::CalledWithNew::None,
environment.facts.value_of_this,
None,
args,
position.clone(),
CallingInput {
called_with_new: crate::types::calling::CalledWithNew::None,
this_value: environment.facts.value_of_this,
call_site: position.clone(),
call_site_type_arguments: None,
},
environment,
args,
checking_data,
)
.0
Expand Down
99 changes: 49 additions & 50 deletions checker/src/types/calling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,35 @@ use super::{
Constructor, PolyNature, StructureGenerics, TypeStore,
};

pub struct CallingInput {
pub called_with_new: CalledWithNew,
pub this_value: ThisValue,
pub call_site_type_arguments: Option<Vec<(TypeId, SpanWithSource)>>,
pub call_site: SpanWithSource,
}

pub struct CallingInputWithoutThis {
pub called_with_new: CalledWithNew,
pub call_site_type_arguments: Option<Vec<(TypeId, SpanWithSource)>>,
pub call_site: SpanWithSource,
}

pub fn call_type_handle_errors<T: crate::ReadFromFS, M: crate::ASTImplementation>(
ty: TypeId,
// Overwritten by .call, else look at binding
called_with_new: CalledWithNew,
this_value: ThisValue,
call_site_type_arguments: Option<Vec<(TypeId, SpanWithSource)>>,
arguments: Vec<SynthesisedArgument>,
call_site: SpanWithSource,
CallingInput { called_with_new, this_value, call_site_type_arguments, call_site }: CallingInput,
environment: &mut Environment,
arguments: Vec<SynthesisedArgument>,
checking_data: &mut crate::CheckingData<T, M>,
) -> (TypeId, Option<SpecialExpressions>) {
let result = call_type(
ty,
called_with_new,
this_value,
call_site_type_arguments,
CallingInput {
called_with_new,
this_value,
call_site_type_arguments,
call_site: call_site.clone(),
},
arguments,
call_site.clone(),
environment,
&mut CheckThings,
&mut checking_data.types,
Expand Down Expand Up @@ -80,12 +91,8 @@ pub fn call_type_handle_errors<T: crate::ReadFromFS, M: crate::ASTImplementation
/// TODO this and aliases kindof broken
pub(crate) fn call_type<E: CallCheckingBehavior>(
on: TypeId,
called_with_new: CalledWithNew,
// Overwritten by .call, else look at binding
this_value: ThisValue,
call_site_type_arguments: Option<Vec<(TypeId, SpanWithSource)>>,
CallingInput { called_with_new, this_value, call_site_type_arguments, call_site }: CallingInput,
arguments: Vec<SynthesisedArgument>,
call_site: SpanWithSource,
environment: &mut Environment,
behavior: &mut E,
types: &mut TypeStore,
Expand All @@ -105,11 +112,8 @@ pub(crate) fn call_type<E: CallCheckingBehavior>(
if let Some(constraint) = environment.get_poly_base(on, types) {
create_generic_function_call(
constraint,
called_with_new,
this_value,
call_site_type_arguments,
CallingInput { called_with_new, this_value, call_site_type_arguments, call_site },
arguments,
call_site,
on,
environment,
behavior,
Expand All @@ -127,11 +131,9 @@ pub(crate) fn call_type<E: CallCheckingBehavior>(
call_logical(
logical,
types,
called_with_new,
call_site_type_arguments,
CallingInputWithoutThis { called_with_new, call_site_type_arguments, call_site },
structure_generics,
arguments,
&call_site,
environment,
behavior,
)
Expand All @@ -152,24 +154,24 @@ pub(crate) fn call_type<E: CallCheckingBehavior>(
fn call_logical<E: CallCheckingBehavior>(
logical: Logical<(FunctionId, ThisValue)>,
types: &mut TypeStore,
called_with_new: CalledWithNew,
call_site_type_arguments: Option<Vec<(TypeId, source_map::BaseSpan<SourceId>)>>,
CallingInputWithoutThis { called_with_new, call_site_type_arguments, call_site }: CallingInputWithoutThis,
structure_generics: Option<StructureGenericArguments>,
arguments: Vec<SynthesisedArgument>,
call_site: &source_map::BaseSpan<SourceId>,
environment: &mut Environment,
behavior: &mut E,
) -> Result<FunctionCallResult, Vec<FunctionCallingError>> {
match logical {
Logical::Pure((func, this_value)) => {
if let Some(function_type) = types.functions.get(&func) {
function_type.clone().call(
called_with_new,
this_value,
call_site_type_arguments,
CallingInput {
called_with_new,
this_value,
call_site_type_arguments,
call_site,
},
structure_generics,
&arguments,
call_site.clone(),
environment,
behavior,
types,
Expand All @@ -183,11 +185,9 @@ fn call_logical<E: CallCheckingBehavior>(
Logical::Implies { on, antecedent } => call_logical(
*on,
types,
called_with_new,
call_site_type_arguments,
CallingInputWithoutThis { called_with_new, call_site_type_arguments, call_site },
Some(antecedent),
arguments,
call_site,
environment,
behavior,
),
Expand Down Expand Up @@ -232,11 +232,8 @@ fn get_logical_callable_from_type(

fn create_generic_function_call<E: CallCheckingBehavior>(
constraint: TypeId,
called_with_new: CalledWithNew,
this_value: ThisValue,
call_site_type_arguments: Option<Vec<(TypeId, SpanWithSource)>>,
CallingInput { called_with_new, this_value, call_site_type_arguments, call_site }: CallingInput,
arguments: Vec<SynthesisedArgument>,
call_site: SpanWithSource,
on: TypeId,
environment: &mut Environment,
behavior: &mut E,
Expand All @@ -245,12 +242,14 @@ fn create_generic_function_call<E: CallCheckingBehavior>(
// TODO don't like how it is mixed
let result = call_type(
constraint,
called_with_new,
this_value,
call_site_type_arguments,
CallingInput {
called_with_new,
this_value,
call_site_type_arguments,
call_site: call_site.clone(),
},
// TODO clone
arguments.clone(),
call_site.clone(),
environment,
behavior,
types,
Expand All @@ -274,8 +273,7 @@ fn create_generic_function_call<E: CallCheckingBehavior>(
on,
with,
timing: crate::events::CallingTiming::Synchronous,
called_with_new,
// Don't care about output.
called_with_new, // Don't care about output.
reflects_dependency: None,
position: call_site.clone(),
});
Expand Down Expand Up @@ -376,14 +374,13 @@ impl FunctionType {
/// Calls the function
///
/// Returns warnings and errors
// Move references in a wrapping struct can be hard due to lifetimes
#[allow(clippy::too_many_arguments)]
pub(crate) fn call<E: CallCheckingBehavior>(
&self,
called_with_new: CalledWithNew,
mut this_value: ThisValue,
call_site_type_arguments: Option<Vec<(TypeId, SpanWithSource)>>,
CallingInput { called_with_new, mut this_value, call_site_type_arguments, call_site }: CallingInput,
parent_type_arguments: Option<StructureGenericArguments>,
arguments: &[SynthesisedArgument],
call_site: SpanWithSource,
environment: &mut Environment,
behavior: &mut E,
types: &mut crate::TypeStore,
Expand Down Expand Up @@ -470,12 +467,14 @@ impl FunctionType {
// TODO with cloned!!
let result = self
.call(
called_with_new,
this_value,
call_site_type_arguments,
CallingInput {
called_with_new,
this_value,
call_site_type_arguments,
call_site: call_site.clone(),
},
parent_type_arguments,
arguments,
call_site.clone(),
environment,
behavior,
types,
Expand Down
14 changes: 9 additions & 5 deletions checker/src/types/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::{
context::{facts::Publicity, CallCheckingBehavior, Logical, SetPropertyError},
events::Event,
subtyping::{type_is_subtype, SubTypeResult},
types::{printing::print_type, substitute, FunctionType, StructureGenerics},
types::{
calling::CallingInput, printing::print_type, substitute, FunctionType, StructureGenerics,
},
Constant, Environment, TypeId,
};

Expand Down Expand Up @@ -271,13 +273,15 @@ fn get_from_an_object<E: CallCheckingBehavior>(
PropertyValue::Getter(getter) => {
let state = ThisValue::Passed(on);
let call = getter.call(
CalledWithNew::None,
state,
None,
CallingInput {
called_with_new: CalledWithNew::None,
this_value: state,
call_site_type_arguments: None,
call_site: SpanWithSource::NULL_SPAN,
},
// TODO
None,
&[],
SpanWithSource::NULL_SPAN,
environment,
behavior,
types,
Expand Down
1 change: 1 addition & 0 deletions parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![doc = include_str!("../README.md")]
#![deny(clippy::all)]
#![allow(clippy::new_without_default)]

mod block;
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all)]

mod ast_explorer;
mod commands;
mod error_handling;
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(clippy::all)]
use ezno_lib::cli::run_cli;
use std::io;

Expand Down
Loading