From 2eaa5a5da9c0f6c9a09bb27f5dcb2d3638d545f4 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Thu, 21 Mar 2024 10:57:25 -0400 Subject: [PATCH] Remove some unused code --- src/code_info/codebase_info/mod.rs | 3 - src/code_info/codebase_info/symbols.rs | 34 +------ src/code_info_builder/classlike_scanner.rs | 92 +++++++++++++++---- src/code_info_builder/functionlike_scanner.rs | 16 +--- src/code_info_builder/lib.rs | 68 +------------- src/file_scanner_analyzer/scanner.rs | 6 +- 6 files changed, 88 insertions(+), 131 deletions(-) diff --git a/src/code_info/codebase_info/mod.rs b/src/code_info/codebase_info/mod.rs index 152809f2..5de9c6f2 100644 --- a/src/code_info/codebase_info/mod.rs +++ b/src/code_info/codebase_info/mod.rs @@ -424,9 +424,6 @@ impl CodebaseInfo { self.classlike_infos.extend(other.classlike_infos); self.functionlike_infos.extend(other.functionlike_infos); self.symbols.all.extend(other.symbols.all); - self.symbols - .classlike_files - .extend(other.symbols.classlike_files); self.type_definitions.extend(other.type_definitions); self.constant_infos.extend(other.constant_infos); self.closures_in_files.extend(other.closures_in_files); diff --git a/src/code_info/codebase_info/symbols.rs b/src/code_info/codebase_info/symbols.rs index c7d112bb..067db7b7 100644 --- a/src/code_info/codebase_info/symbols.rs +++ b/src/code_info/codebase_info/symbols.rs @@ -2,8 +2,6 @@ use hakana_str::StrId; use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; -use crate::code_location::FilePath; - #[derive(Clone, Debug, Serialize, Deserialize)] pub enum SymbolKind { Class, @@ -17,7 +15,6 @@ pub enum SymbolKind { #[derive(Clone, Serialize, Deserialize, Debug)] pub struct Symbols { pub all: FxHashMap, - pub classlike_files: FxHashMap, } impl Default for Symbols { @@ -30,48 +27,27 @@ impl Symbols { pub fn new() -> Symbols { Symbols { all: FxHashMap::default(), - classlike_files: FxHashMap::default(), } } - pub fn add_class_name(&mut self, fq_class_name: &StrId, file_path: Option) { + pub fn add_class_name(&mut self, fq_class_name: &StrId) { self.all.insert(*fq_class_name, SymbolKind::Class); - - if let Some(file_path) = file_path { - self.classlike_files.insert(*fq_class_name, file_path); - } } - pub fn add_enum_class_name(&mut self, fq_class_name: &StrId, file_path: Option) { + pub fn add_enum_class_name(&mut self, fq_class_name: &StrId) { self.all.insert(*fq_class_name, SymbolKind::EnumClass); - - if let Some(file_path) = file_path { - self.classlike_files.insert(*fq_class_name, file_path); - } } - pub fn add_interface_name(&mut self, fq_class_name: &StrId, file_path: Option) { + pub fn add_interface_name(&mut self, fq_class_name: &StrId) { self.all.insert(*fq_class_name, SymbolKind::Interface); - - if let Some(file_path) = file_path { - self.classlike_files.insert(*fq_class_name, file_path); - } } - pub fn add_trait_name(&mut self, fq_class_name: &StrId, file_path: Option) { + pub fn add_trait_name(&mut self, fq_class_name: &StrId) { self.all.insert(*fq_class_name, SymbolKind::Trait); - - if let Some(file_path) = file_path { - self.classlike_files.insert(*fq_class_name, file_path); - } } - pub fn add_enum_name(&mut self, fq_class_name: &StrId, file_path: Option) { + pub fn add_enum_name(&mut self, fq_class_name: &StrId) { self.all.insert(*fq_class_name, SymbolKind::Enum); - - if let Some(file_path) = file_path { - self.classlike_files.insert(*fq_class_name, file_path); - } } pub fn add_typedef_name(&mut self, fq_class_name: StrId) { diff --git a/src/code_info_builder/classlike_scanner.rs b/src/code_info_builder/classlike_scanner.rs index 51e41b85..819329b4 100644 --- a/src/code_info_builder/classlike_scanner.rs +++ b/src/code_info_builder/classlike_scanner.rs @@ -25,7 +25,10 @@ use oxidized::{ ast_defs::{self, ClassishKind}, }; -use crate::{functionlike_scanner::adjust_location_from_comments, simple_type_inferer}; +use crate::{ + functionlike_scanner::{self, adjust_location_from_comments}, + get_function_hashes, simple_type_inferer, +}; use crate::{get_uses_hash, typehint_resolver::get_type_from_hint}; pub(crate) fn scan( @@ -168,9 +171,7 @@ pub(crate) fn scan( storage.is_abstract = matches!(abstraction, ast_defs::Abstraction::Abstract); storage.is_final = classlike_node.final_; - codebase - .symbols - .add_class_name(class_name, Some(file_source.file_path)); + codebase.symbols.add_class_name(class_name); if let Some(parent_class) = classlike_node.extends.first() { if let oxidized::tast::Hint_::Happly(name, params) = &*parent_class.1 { @@ -264,9 +265,7 @@ pub(crate) fn scan( storage.kind = SymbolKind::EnumClass; - codebase - .symbols - .add_enum_class_name(class_name, Some(file_source.file_path)); + codebase.symbols.add_enum_class_name(class_name); if let Some(enum_node) = &classlike_node.enum_ { storage.enum_type = Some( @@ -306,9 +305,7 @@ pub(crate) fn scan( } ClassishKind::Cinterface => { storage.kind = SymbolKind::Interface; - codebase - .symbols - .add_interface_name(class_name, Some(file_source.file_path)); + codebase.symbols.add_interface_name(class_name); handle_reqs( classlike_node, @@ -359,9 +356,7 @@ pub(crate) fn scan( ClassishKind::Ctrait => { storage.kind = SymbolKind::Trait; - codebase - .symbols - .add_trait_name(class_name, Some(file_source.file_path)); + codebase.symbols.add_trait_name(class_name); handle_reqs( classlike_node, @@ -458,9 +453,7 @@ pub(crate) fn scan( }))], ); - codebase - .symbols - .add_enum_name(class_name, Some(file_source.file_path)); + codebase.symbols.add_enum_name(class_name); } } @@ -637,8 +630,75 @@ pub(crate) fn scan( ); } + for m in &classlike_node.methods { + let (method_name, functionlike_storage) = functionlike_scanner::scan_method( + interner, + all_custom_issues, + resolved_names, + m, + *class_name, + &mut storage, + file_source.comments, + &file_source, + user_defined, + ); + + let (signature_hash, body_hash) = get_function_hashes( + &file_source.file_contents, + &functionlike_storage.def_location, + &m.name, + &m.tparams, + &m.params, + &m.ret, + all_uses + .symbol_member_uses + .get(&(*class_name, method_name)) + .unwrap_or(&vec![]), + ); + def_signature_node.children.push(DefSignatureNode { + name: method_name, + start_offset: functionlike_storage.def_location.start_offset, + end_offset: functionlike_storage.def_location.end_offset, + start_line: functionlike_storage.def_location.start_line, + end_line: functionlike_storage.def_location.end_line, + signature_hash, + body_hash: Some(body_hash), + children: vec![], + is_function: true, + is_constant: false, + }); + + if !storage.template_readonly.is_empty() + && matches!(m.visibility, ast_defs::Visibility::Public) + && method_name != StrId::CONSTRUCT + { + for param in &functionlike_storage.params { + if let Some(param_type) = ¶m.signature_type { + let template_types = param_type.get_template_types(); + + for template_type in template_types { + if let TAtomic::TGenericParam { param_name, .. } = template_type { + storage.template_readonly.remove(param_name); + } + } + } + } + } + + storage.methods.push(method_name); + + codebase + .functionlike_infos + .insert((*class_name, method_name), functionlike_storage); + } + + storage.properties.shrink_to_fit(); + storage.methods.shrink_to_fit(); + codebase.classlike_infos.insert(*class_name, storage); + def_signature_node.children.shrink_to_fit(); + ast_nodes.push(def_signature_node); true diff --git a/src/code_info_builder/functionlike_scanner.rs b/src/code_info_builder/functionlike_scanner.rs index da0a3421..9698801e 100644 --- a/src/code_info_builder/functionlike_scanner.rs +++ b/src/code_info_builder/functionlike_scanner.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use super::Context; use crate::simple_type_inferer; use crate::typehint_resolver::get_type_from_hint; use crate::typehint_resolver::get_type_from_optional_hint; @@ -8,7 +7,6 @@ use hakana_reflection_info::attribute_info::AttributeInfo; use hakana_reflection_info::classlike_info::ClassLikeInfo; use hakana_reflection_info::code_location::HPos; use hakana_reflection_info::codebase_info::symbols::SymbolKind; -use hakana_reflection_info::codebase_info::CodebaseInfo; use hakana_reflection_info::functionlike_identifier::FunctionLikeIdentifier; use hakana_reflection_info::functionlike_info::FnEffect; use hakana_reflection_info::functionlike_info::FunctionLikeInfo; @@ -39,26 +37,20 @@ use rustc_hash::FxHashMap; use rustc_hash::FxHashSet; pub(crate) fn scan_method( - codebase: &mut CodebaseInfo, interner: &mut ThreadedInterner, all_custom_issues: &FxHashSet, resolved_names: &FxHashMap, m: &aast::Method_<(), ()>, - c: &mut Context, + classlike_name: StrId, + classlike_storage: &mut ClassLikeInfo, comments: &Vec<(Pos, Comment)>, file_source: &FileSource, user_defined: bool, ) -> (StrId, FunctionLikeInfo) { - let classlike_name = c.classlike_name.unwrap(); let method_name = interner.intern(m.name.1.clone()); let mut type_resolution_context = TypeResolutionContext { - template_type_map: codebase - .classlike_infos - .get(&classlike_name) - .unwrap() - .template_types - .clone(), + template_type_map: classlike_storage.template_types.clone(), template_supers: FxHashMap::default(), }; @@ -94,8 +86,6 @@ pub(crate) fn scan_method( functionlike_info.pure_can_throw = true; } - let classlike_storage = codebase.classlike_infos.get_mut(&classlike_name).unwrap(); - let mut method_info = MethodInfo::new(); method_info.defining_fqcln = Some(classlike_name); diff --git a/src/code_info_builder/lib.rs b/src/code_info_builder/lib.rs index 5085861f..d6daeaa5 100644 --- a/src/code_info_builder/lib.rs +++ b/src/code_info_builder/lib.rs @@ -456,76 +456,10 @@ impl<'ast> Visitor<'ast> for Scanner<'_> { } fn visit_method_(&mut self, c: &mut Context, m: &aast::Method_<(), ()>) -> Result<(), ()> { - let (method_name, functionlike_storage) = functionlike_scanner::scan_method( - self.codebase, - self.interner, - self.all_custom_issues, - self.resolved_names, - m, - c, - self.file_source.comments, - &self.file_source, - self.user_defined, - ); + let method_name = self.interner.intern(m.name.1.clone()); c.member_name = Some(method_name); - if let Some(last_current_node) = self.ast_nodes.last_mut() { - let (signature_hash, body_hash) = get_function_hashes( - &self.file_source.file_contents, - &functionlike_storage.def_location, - &m.name, - &m.tparams, - &m.params, - &m.ret, - self.uses - .symbol_member_uses - .get(&(c.classlike_name.unwrap(), c.member_name.unwrap())) - .unwrap_or(&vec![]), - ); - last_current_node.children.push(DefSignatureNode { - name: method_name, - start_offset: functionlike_storage.def_location.start_offset, - end_offset: functionlike_storage.def_location.end_offset, - start_line: functionlike_storage.def_location.start_line, - end_line: functionlike_storage.def_location.end_line, - signature_hash, - body_hash: Some(body_hash), - children: vec![], - is_function: true, - is_constant: false, - }); - } - - if let Some(classlike_storage) = self - .codebase - .classlike_infos - .get_mut(&c.classlike_name.unwrap()) - { - if !classlike_storage.template_readonly.is_empty() - && matches!(m.visibility, ast_defs::Visibility::Public) - && method_name != StrId::CONSTRUCT - { - for param in &functionlike_storage.params { - if let Some(param_type) = ¶m.signature_type { - let template_types = param_type.get_template_types(); - - for template_type in template_types { - if let TAtomic::TGenericParam { param_name, .. } = template_type { - classlike_storage.template_readonly.remove(param_name); - } - } - } - } - } - - classlike_storage.methods.push(method_name); - - self.codebase - .functionlike_infos - .insert((classlike_storage.name, method_name), functionlike_storage); - } - let result = m.recurse(c, self); c.member_name = None; diff --git a/src/file_scanner_analyzer/scanner.rs b/src/file_scanner_analyzer/scanner.rs index acf0bc53..004f815f 100644 --- a/src/file_scanner_analyzer/scanner.rs +++ b/src/file_scanner_analyzer/scanner.rs @@ -66,9 +66,9 @@ pub fn scan_files( let codebase_path = cache_dir.map(|cache_dir| format!("{}/codebase", cache_dir)); - let symbols_path = cache_dir.map(|cache_dir| format!("{}/symbols", cache_dir)); + let symbols_path = cache_dir.map(|cache_dir| format!("{}/interned_names", cache_dir)); - let aast_names_path = cache_dir.map(|cache_dir| format!("{}/aast_names", cache_dir)); + let aast_names_path = cache_dir.map(|cache_dir| format!("{}/aast_strids", cache_dir)); let mut use_codebase_cache = true; @@ -483,6 +483,7 @@ pub fn scan_files( codebase.type_definitions.shrink_to_fit(); codebase.constant_infos.shrink_to_fit(); codebase.files.shrink_to_fit(); + codebase.symbols.all.shrink_to_fit(); } Ok(ScanFilesResult { @@ -622,7 +623,6 @@ fn invalidate_changed_codebase_elements( .remove(&(ast_node.name, method_name)); } } - codebase.symbols.classlike_files.remove(&ast_node.name); } } None => {