From 5223a09cdefea1543798dd5fc15be2bbd77a4352 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Thu, 21 Mar 2024 11:10:49 -0400 Subject: [PATCH] Use simpler storage --- .../call/function_call_return_type_fetcher.rs | 5 ---- src/code_info/functionlike_info.rs | 14 ----------- src/code_info/type_resolution.rs | 5 ++-- src/code_info_builder/classlike_scanner.rs | 24 +++++++++---------- src/code_info_builder/functionlike_scanner.rs | 6 ++--- src/code_info_builder/lib.rs | 6 ++--- src/code_info_builder/typehint_resolver.rs | 6 ++++- 7 files changed, 25 insertions(+), 41 deletions(-) diff --git a/src/analyzer/expr/call/function_call_return_type_fetcher.rs b/src/analyzer/expr/call/function_call_return_type_fetcher.rs index 0c2ad4f3..dc9d79c7 100644 --- a/src/analyzer/expr/call/function_call_return_type_fetcher.rs +++ b/src/analyzer/expr/call/function_call_return_type_fetcher.rs @@ -747,11 +747,6 @@ fn add_dataflow( None }, ); - - if !functionlike_storage.return_source_params.is_empty() { - // todo dispatch AddRemoveTaintEvent - // and also handle simple preg_replace calls - } } else { function_call_node = DataFlowNode::get_for_method_return( functionlike_id.to_string(statements_analyzer.get_interner()), diff --git a/src/code_info/functionlike_info.rs b/src/code_info/functionlike_info.rs index 37fcb331..ae7b0566 100644 --- a/src/code_info/functionlike_info.rs +++ b/src/code_info/functionlike_info.rs @@ -1,11 +1,9 @@ use std::sync::Arc; use hakana_str::StrId; -use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; use crate::{ - assertion::Assertion, attribute_info::AttributeInfo, code_location::HPos, function_context::FunctionLikeIdentifier, @@ -87,12 +85,6 @@ pub struct FunctionLikeInfo { */ pub template_types: Vec<(StrId, Vec<(GenericParent, Arc)>)>, - pub assertions: Option>, - - pub if_true_assertions: Option>, - - pub if_false_assertions: Option>, - pub has_visitor_issues: bool, pub has_yield: bool, @@ -130,8 +122,6 @@ pub struct FunctionLikeInfo { pub removed_taints: Vec, - pub return_source_params: FxHashMap, - pub attributes: Vec, pub method_info: Option>, @@ -176,9 +166,6 @@ impl FunctionLikeInfo { suppressed_issues: None, deprecated: false, template_types: vec![], - assertions: None, - if_true_assertions: None, - if_false_assertions: None, has_visitor_issues: false, has_yield: false, mutation_free: false, @@ -187,7 +174,6 @@ impl FunctionLikeInfo { taint_source_types: vec![], added_taints: vec![], removed_taints: vec![], - return_source_params: FxHashMap::default(), attributes: Vec::new(), method_info: None, is_async: false, diff --git a/src/code_info/type_resolution.rs b/src/code_info/type_resolution.rs index 0496cf67..1a27f069 100644 --- a/src/code_info/type_resolution.rs +++ b/src/code_info/type_resolution.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use hakana_str::StrId; -use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; @@ -10,7 +9,7 @@ use crate::{t_union::TUnion, GenericParent}; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TypeResolutionContext { pub template_type_map: Vec<(StrId, Vec<(GenericParent, Arc)>)>, - pub template_supers: FxHashMap, + pub template_supers: Vec<(StrId, TUnion)>, } impl Default for TypeResolutionContext { @@ -23,7 +22,7 @@ impl TypeResolutionContext { pub fn new() -> Self { Self { template_type_map: vec![], - template_supers: FxHashMap::default(), + template_supers: vec![], } } } diff --git a/src/code_info_builder/classlike_scanner.rs b/src/code_info_builder/classlike_scanner.rs index 819329b4..f1b3577e 100644 --- a/src/code_info_builder/classlike_scanner.rs +++ b/src/code_info_builder/classlike_scanner.rs @@ -86,7 +86,7 @@ pub(crate) fn scan( if !classlike_node.tparams.is_empty() { let mut type_context = TypeResolutionContext { template_type_map: vec![], - template_supers: FxHashMap::default(), + template_supers: vec![], }; for type_param_node in classlike_node.tparams.iter() { @@ -197,7 +197,7 @@ pub(crate) fn scan( Some(class_name), &TypeResolutionContext { template_type_map: storage.template_types.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, resolved_names, file_source.file_path, @@ -244,7 +244,7 @@ pub(crate) fn scan( Some(class_name), &TypeResolutionContext { template_type_map: storage.template_types.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, resolved_names, file_source.file_path, @@ -339,7 +339,7 @@ pub(crate) fn scan( Some(class_name), &TypeResolutionContext { template_type_map: storage.template_types.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, resolved_names, file_source.file_path, @@ -391,7 +391,7 @@ pub(crate) fn scan( Some(class_name), &TypeResolutionContext { template_type_map: storage.template_types.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, resolved_names, file_source.file_path, @@ -511,7 +511,7 @@ pub(crate) fn scan( None, &TypeResolutionContext { template_type_map: storage.template_types.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, resolved_names, file_source.file_path, @@ -740,7 +740,7 @@ fn handle_reqs( Some(class_name), &TypeResolutionContext { template_type_map: storage.template_types.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, resolved_names, file_source.file_path, @@ -772,7 +772,7 @@ fn visit_xhp_attribute( None, &TypeResolutionContext { template_type_map: vec![], - template_supers: FxHashMap::default(), + template_supers: vec![], }, resolved_names, file_source.file_path, @@ -885,7 +885,7 @@ fn visit_class_const_declaration( Some(&classlike_storage.name), &TypeResolutionContext { template_type_map: classlike_storage.template_types.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, resolved_names, file_source.file_path, @@ -955,7 +955,7 @@ fn visit_class_typeconst_declaration( Some(&classlike_storage.name), &TypeResolutionContext { template_type_map: classlike_storage.template_types.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, resolved_names, file_source.file_path, @@ -973,7 +973,7 @@ fn visit_class_typeconst_declaration( Some(&classlike_storage.name), &TypeResolutionContext { template_type_map: classlike_storage.template_types.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, resolved_names, file_source.file_path, @@ -1031,7 +1031,7 @@ fn visit_property_declaration( Some(&classlike_storage.name), &TypeResolutionContext { template_type_map: classlike_storage.template_types.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, resolved_names, file_source.file_path, diff --git a/src/code_info_builder/functionlike_scanner.rs b/src/code_info_builder/functionlike_scanner.rs index 9698801e..15762a26 100644 --- a/src/code_info_builder/functionlike_scanner.rs +++ b/src/code_info_builder/functionlike_scanner.rs @@ -51,7 +51,7 @@ pub(crate) fn scan_method( let mut type_resolution_context = TypeResolutionContext { template_type_map: classlike_storage.template_types.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }; let mut functionlike_info = get_functionlike( @@ -172,7 +172,7 @@ pub(crate) fn get_functionlike( let mut functionlike_info = FunctionLikeInfo::new(definition_location, meta_start); - let mut template_supers = FxHashMap::default(); + let mut template_supers = vec![]; if !tparams.is_empty() { for type_param_node in tparams.iter() { @@ -233,7 +233,7 @@ pub(crate) fn get_functionlike( extra_types: None, }); - template_supers.insert(*param_name, super_type); + template_supers.push((*param_name, super_type)); } } diff --git a/src/code_info_builder/lib.rs b/src/code_info_builder/lib.rs index d6daeaa5..a7b8586f 100644 --- a/src/code_info_builder/lib.rs +++ b/src/code_info_builder/lib.rs @@ -330,7 +330,7 @@ impl<'ast> Visitor<'ast> for Scanner<'_> { None, &TypeResolutionContext { template_type_map: template_type_map.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, self.resolved_names, self.file_source.file_path, @@ -344,7 +344,7 @@ impl<'ast> Visitor<'ast> for Scanner<'_> { None, &TypeResolutionContext { template_type_map: template_type_map.clone(), - template_supers: FxHashMap::default(), + template_supers: vec![], }, self.resolved_names, self.file_source.file_path, @@ -611,7 +611,7 @@ impl<'a> Scanner<'a> { let mut type_resolution_context = TypeResolutionContext { template_type_map, - template_supers: FxHashMap::default(), + template_supers: vec![], }; let mut functionlike_storage = functionlike_scanner::get_functionlike( diff --git a/src/code_info_builder/typehint_resolver.rs b/src/code_info_builder/typehint_resolver.rs index 389d8d26..29e7957c 100644 --- a/src/code_info_builder/typehint_resolver.rs +++ b/src/code_info_builder/typehint_resolver.rs @@ -497,7 +497,11 @@ pub fn get_type_from_hint( let applied_type = &id.1; if let Some(resolved_name) = resolved_names.get(&(id.0.start_offset() as u32)) { - if let Some(type_name) = type_context.template_supers.get(resolved_name) { + if let Some((_, type_name)) = type_context + .template_supers + .iter() + .find(|(id, _)| id == resolved_name) + { return Some(type_name.clone()); } }