Skip to content

Commit

Permalink
Remove some unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 21, 2024
1 parent 3d4a618 commit 2eaa5a5
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 131 deletions.
3 changes: 0 additions & 3 deletions src/code_info/codebase_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 5 additions & 29 deletions src/code_info/codebase_info/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,7 +15,6 @@ pub enum SymbolKind {
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct Symbols {
pub all: FxHashMap<StrId, SymbolKind>,
pub classlike_files: FxHashMap<StrId, FilePath>,
}

impl Default for Symbols {
Expand All @@ -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<FilePath>) {
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<FilePath>) {
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<FilePath>) {
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<FilePath>) {
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<FilePath>) {
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) {
Expand Down
92 changes: 76 additions & 16 deletions src/code_info_builder/classlike_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) = &param.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
Expand Down
16 changes: 3 additions & 13 deletions src/code_info_builder/functionlike_scanner.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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;
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;
Expand Down Expand Up @@ -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<String>,
resolved_names: &FxHashMap<u32, StrId>,
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(),
};

Expand Down Expand Up @@ -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);
Expand Down
68 changes: 1 addition & 67 deletions src/code_info_builder/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) = &param.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;
Expand Down
6 changes: 3 additions & 3 deletions src/file_scanner_analyzer/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -622,7 +623,6 @@ fn invalidate_changed_codebase_elements(
.remove(&(ast_node.name, method_name));
}
}
codebase.symbols.classlike_files.remove(&ast_node.name);
}
}
None => {
Expand Down

0 comments on commit 2eaa5a5

Please sign in to comment.