Fix Clippy

This commit is contained in:
bakaq
2024-09-06 18:54:37 -03:00
parent d32f3ee2f3
commit 16734ec7e4
8 changed files with 37 additions and 39 deletions

View File

@@ -137,7 +137,7 @@ enum InlinedClauseType {
#[allow(dead_code)] #[allow(dead_code)]
#[derive(ToDeriveInput, EnumDiscriminants)] #[derive(ToDeriveInput, EnumDiscriminants)]
#[strum_discriminants(derive(EnumProperty, EnumString))] #[strum_discriminants(derive(EnumProperty, EnumString))]
enum REPLCodePtr { enum ReplCodePtr {
#[strum_discriminants(strum(props(Arity = "4", Name = "$add_discontiguous_predicate")))] #[strum_discriminants(strum(props(Arity = "4", Name = "$add_discontiguous_predicate")))]
AddDiscontiguousPredicate, AddDiscontiguousPredicate,
#[strum_discriminants(strum(props(Arity = "4", Name = "$add_dynamic_predicate")))] #[strum_discriminants(strum(props(Arity = "4", Name = "$add_dynamic_predicate")))]
@@ -534,7 +534,7 @@ enum SystemClauseType {
#[strum_discriminants(strum(props(Arity = "2", Name = "$shell")))] #[strum_discriminants(strum(props(Arity = "2", Name = "$shell")))]
Shell, Shell,
#[strum_discriminants(strum(props(Arity = "1", Name = "$pid")))] #[strum_discriminants(strum(props(Arity = "1", Name = "$pid")))]
PID, Pid,
#[strum_discriminants(strum(props(Arity = "4", Name = "$chars_base64")))] #[strum_discriminants(strum(props(Arity = "4", Name = "$chars_base64")))]
CharsBase64, CharsBase64,
#[strum_discriminants(strum(props(Arity = "1", Name = "$devour_whitespace")))] #[strum_discriminants(strum(props(Arity = "1", Name = "$devour_whitespace")))]
@@ -608,7 +608,7 @@ enum SystemClauseType {
InferenceLimitExceeded, InferenceLimitExceeded,
#[strum_discriminants(strum(props(Arity = "1", Name = "$argv")))] #[strum_discriminants(strum(props(Arity = "1", Name = "$argv")))]
Argv, Argv,
REPL(REPLCodePtr), Repl(ReplCodePtr),
} }
#[allow(dead_code)] #[allow(dead_code)]
@@ -811,7 +811,7 @@ fn derive_input(ty: &Type) -> Option<DeriveInput> {
let system_clause_type: Type = parse_quote! { SystemClauseType }; let system_clause_type: Type = parse_quote! { SystemClauseType };
let compare_term_type: Type = parse_quote! { CompareTerm }; let compare_term_type: Type = parse_quote! { CompareTerm };
let compare_number_type: Type = parse_quote! { CompareNumber }; let compare_number_type: Type = parse_quote! { CompareNumber };
let repl_code_ptr_type: Type = parse_quote! { REPLCodePtr }; let repl_code_ptr_type: Type = parse_quote! { ReplCodePtr };
if ty == &clause_type { if ty == &clause_type {
Some(ClauseType::to_derive_input()) Some(ClauseType::to_derive_input())
@@ -826,7 +826,7 @@ fn derive_input(ty: &Type) -> Option<DeriveInput> {
} else if ty == &compare_term_type { } else if ty == &compare_term_type {
Some(CompareTerm::to_derive_input()) Some(CompareTerm::to_derive_input())
} else if ty == &repl_code_ptr_type { } else if ty == &repl_code_ptr_type {
Some(REPLCodePtr::to_derive_input()) Some(ReplCodePtr::to_derive_input())
} else { } else {
None None
} }
@@ -983,6 +983,7 @@ fn generate_instruction_preface() -> TokenStream {
} }
/// `IndexingInstruction` cf. page 110 of wambook. /// `IndexingInstruction` cf. page 110 of wambook.
#[allow(clippy::enum_variant_names)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum IndexingInstruction { pub enum IndexingInstruction {
// The first index is the optimal argument being indexed. // The first index is the optimal argument being indexed.
@@ -1867,7 +1868,7 @@ fn generate_instruction_preface() -> TokenStream {
&Instruction::CallSetEnv | &Instruction::CallSetEnv |
&Instruction::CallUnsetEnv | &Instruction::CallUnsetEnv |
&Instruction::CallShell | &Instruction::CallShell |
&Instruction::CallPID | &Instruction::CallPid |
&Instruction::CallCharsBase64 | &Instruction::CallCharsBase64 |
&Instruction::CallDevourWhitespace | &Instruction::CallDevourWhitespace |
&Instruction::CallIsSTOEnabled | &Instruction::CallIsSTOEnabled |
@@ -2104,7 +2105,7 @@ fn generate_instruction_preface() -> TokenStream {
&Instruction::ExecuteSetEnv | &Instruction::ExecuteSetEnv |
&Instruction::ExecuteUnsetEnv | &Instruction::ExecuteUnsetEnv |
&Instruction::ExecuteShell | &Instruction::ExecuteShell |
&Instruction::ExecutePID | &Instruction::ExecutePid |
&Instruction::ExecuteCharsBase64 | &Instruction::ExecuteCharsBase64 |
&Instruction::ExecuteDevourWhitespace | &Instruction::ExecuteDevourWhitespace |
&Instruction::ExecuteIsSTOEnabled | &Instruction::ExecuteIsSTOEnabled |
@@ -2357,7 +2358,7 @@ pub fn generate_instructions_rs() -> TokenStream {
let builtin_type_variants = attributeless_enum::<BuiltInClauseType>(); let builtin_type_variants = attributeless_enum::<BuiltInClauseType>();
let inlined_type_variants = attributeless_enum::<InlinedClauseType>(); let inlined_type_variants = attributeless_enum::<InlinedClauseType>();
let system_clause_type_variants = attributeless_enum::<SystemClauseType>(); let system_clause_type_variants = attributeless_enum::<SystemClauseType>();
let repl_code_ptr_variants = attributeless_enum::<REPLCodePtr>(); let repl_code_ptr_variants = attributeless_enum::<ReplCodePtr>();
let compare_number_variants = attributeless_enum::<CompareNumber>(); let compare_number_variants = attributeless_enum::<CompareNumber>();
let compare_term_variants = attributeless_enum::<CompareTerm>(); let compare_term_variants = attributeless_enum::<CompareTerm>();
@@ -2708,14 +2709,14 @@ pub fn generate_instructions_rs() -> TokenStream {
clause_type_from_name_and_arity_arms.push(if !variant_fields.is_empty() { clause_type_from_name_and_arity_arms.push(if !variant_fields.is_empty() {
quote! { quote! {
(atom!(#name), #arity) => ClauseType::System(SystemClauseType::REPL( (atom!(#name), #arity) => ClauseType::System(SystemClauseType::Repl(
REPLCodePtr::#ident(#(#variant_fields),*) ReplCodePtr::#ident(#(#variant_fields),*)
)) ))
} }
} else { } else {
quote! { quote! {
(atom!(#name), #arity) => ClauseType::System(SystemClauseType::REPL( (atom!(#name), #arity) => ClauseType::System(SystemClauseType::Repl(
REPLCodePtr::#ident ReplCodePtr::#ident
)) ))
} }
}); });
@@ -2723,13 +2724,13 @@ pub fn generate_instructions_rs() -> TokenStream {
clause_type_name_arms.push(if !variant_fields.is_empty() { clause_type_name_arms.push(if !variant_fields.is_empty() {
quote! { quote! {
ClauseType::System( ClauseType::System(
SystemClauseType::REPL(REPLCodePtr::#ident(..)) SystemClauseType::Repl(ReplCodePtr::#ident(..))
) => atom!(#name) ) => atom!(#name)
} }
} else { } else {
quote! { quote! {
ClauseType::System( ClauseType::System(
SystemClauseType::REPL(REPLCodePtr::#ident) SystemClauseType::Repl(ReplCodePtr::#ident)
) => atom!(#name) ) => atom!(#name)
} }
}); });
@@ -2743,14 +2744,14 @@ pub fn generate_instructions_rs() -> TokenStream {
clause_type_to_instr_arms.push(if !variant_fields.is_empty() { clause_type_to_instr_arms.push(if !variant_fields.is_empty() {
quote! { quote! {
ClauseType::System(SystemClauseType::REPL( ClauseType::System(SystemClauseType::Repl(
REPLCodePtr::#ident(#(#placeholder_ids),*) ReplCodePtr::#ident(#(#placeholder_ids),*)
)) => Instruction::#instr_ident(#(*#placeholder_ids),*) )) => Instruction::#instr_ident(#(*#placeholder_ids),*)
} }
} else { } else {
quote! { quote! {
ClauseType::System(SystemClauseType::REPL( ClauseType::System(SystemClauseType::Repl(
REPLCodePtr::#ident ReplCodePtr::#ident
)) => Instruction::#instr_ident )) => Instruction::#instr_ident
} }
}); });
@@ -3109,6 +3110,7 @@ pub fn generate_instructions_rs() -> TokenStream {
quote! { quote! {
#preface_tokens #preface_tokens
#[allow(clippy::enum_variant_names)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum CompareTerm { pub enum CompareTerm {
#( #(
@@ -3116,6 +3118,7 @@ pub fn generate_instructions_rs() -> TokenStream {
)* )*
} }
#[allow(clippy::enum_variant_names)]
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub enum CompareNumber { pub enum CompareNumber {
#( #(
@@ -3161,7 +3164,7 @@ pub fn generate_instructions_rs() -> TokenStream {
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum REPLCodePtr { pub enum ReplCodePtr {
#( #(
#repl_code_ptr_variants, #repl_code_ptr_variants,
)* )*
@@ -3228,7 +3231,7 @@ pub fn generate_instructions_rs() -> TokenStream {
} }
} }
pub fn to_default(self) -> Instruction { pub fn into_default(self) -> Instruction {
match self { match self {
#( #(
#to_default_arms, #to_default_arms,
@@ -3237,7 +3240,7 @@ pub fn generate_instructions_rs() -> TokenStream {
} }
} }
pub fn to_execute(self) -> Instruction { pub fn into_execute(self) -> Instruction {
match self { match self {
#( #(
#to_execute_arms, #to_execute_arms,
@@ -3418,8 +3421,8 @@ impl InstructionData {
); );
(name, arity, CountableInference::NotCounted) (name, arity, CountableInference::NotCounted)
} else if id == "REPLCodePtr" { } else if id == "ReplCodePtr" {
let (name, arity) = add_discriminant_data::<REPLCodePtrDiscriminants>( let (name, arity) = add_discriminant_data::<ReplCodePtrDiscriminants>(
&variant, &variant,
prefix, prefix,
&mut self.repl_code_ptr_variants, &mut self.repl_code_ptr_variants,

View File

@@ -156,8 +156,6 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea
let static_strs: &Vec<_> = &visitor.static_strs.into_iter().collect(); let static_strs: &Vec<_> = &visitor.static_strs.into_iter().collect();
quote! { quote! {
use phf;
static STRINGS: [&str; #static_strs_len] = [ static STRINGS: [&str; #static_strs_len] = [
#( #(
#static_strs, #static_strs,

View File

@@ -557,14 +557,14 @@ impl<'b> CodeGenerator<'b> {
match call_policy { match call_policy {
CallPolicy::Default => { CallPolicy::Default => {
if self.marker.in_tail_position { if self.marker.in_tail_position {
code.push_back(call_instr.to_execute().to_default()); code.push_back(call_instr.into_execute().into_default());
} else { } else {
code.push_back(call_instr.to_default()) code.push_back(call_instr.into_default())
} }
} }
CallPolicy::Counted => { CallPolicy::Counted => {
if self.marker.in_tail_position { if self.marker.in_tail_position {
code.push_back(call_instr.to_execute()); code.push_back(call_instr.into_execute());
} else { } else {
code.push_back(call_instr) code.push_back(call_instr)
} }

View File

@@ -1194,11 +1194,8 @@ fn print_overwrite_warning(
key: PredicateKey, key: PredicateKey,
is_dynamic: bool, is_dynamic: bool,
) { ) {
if let CompilationTarget::Module(module_name) = compilation_target { if let CompilationTarget::Module(atom!("builtins") | atom!("loader")) = compilation_target {
match module_name { return;
atom!("builtins") | atom!("loader") => return,
_ => {}
}
} }
match code_ptr.tag() { match code_ptr.tag() {

View File

@@ -4611,11 +4611,11 @@ impl Machine {
self.shell(); self.shell();
step_or_fail!(self, self.machine_st.p = self.machine_st.cp); step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
} }
&Instruction::CallPID => { &Instruction::CallPid => {
self.pid(); self.pid();
step_or_fail!(self, self.machine_st.p += 1); step_or_fail!(self, self.machine_st.p += 1);
} }
&Instruction::ExecutePID => { &Instruction::ExecutePid => {
self.pid(); self.pid();
step_or_fail!(self, self.machine_st.p = self.machine_st.cp); step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
} }

View File

@@ -213,8 +213,7 @@ impl<'a> HeapPStrIter<'a> {
self.brent_st.hare = orig_hare; self.brent_st.hare = orig_hare;
} }
#[allow(clippy::inherent_to_string)] pub fn to_string_mut(&mut self) -> String {
pub fn to_string(&mut self) -> String {
let mut buf = String::with_capacity(32); let mut buf = String::with_capacity(32);
for iteratee in self.by_ref() { for iteratee in self.by_ref() {

View File

@@ -1040,7 +1040,7 @@ impl MachineState {
self.heap.push(value); self.heap.push(value);
let mut iter = HeapPStrIter::new(&self.heap, h); let mut iter = HeapPStrIter::new(&self.heap, h);
let string = iter.to_string(); let string = iter.to_string_mut();
let at_terminator = iter.at_string_terminator(); let at_terminator = iter.at_string_terminator();
self.heap.pop(); self.heap.pop();

View File

@@ -26,6 +26,7 @@ pub type Specifier = u32;
pub const MAX_ARITY: usize = 1023; pub const MAX_ARITY: usize = 1023;
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)] #[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum OpDeclSpec { pub enum OpDeclSpec {
XFX = 0x0001, XFX = 0x0001,
@@ -660,7 +661,7 @@ impl fmt::Display for Literal {
} }
impl Literal { impl Literal {
pub fn to_atom(&self, atom_tbl: &Arc<AtomTable>) -> Option<Atom> { pub fn as_atom(&self, atom_tbl: &Arc<AtomTable>) -> Option<Atom> {
match self { match self {
Literal::Atom(atom) => Some(atom.defrock_brackets(atom_tbl)), Literal::Atom(atom) => Some(atom.defrock_brackets(atom_tbl)),
_ => None, _ => None,