Skip to content

Commit

Permalink
Use simpler storage
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 21, 2024
1 parent 2eaa5a5 commit 5223a09
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 41 deletions.
5 changes: 0 additions & 5 deletions src/analyzer/expr/call/function_call_return_type_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
14 changes: 0 additions & 14 deletions src/code_info/functionlike_info.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -87,12 +85,6 @@ pub struct FunctionLikeInfo {
*/
pub template_types: Vec<(StrId, Vec<(GenericParent, Arc<TUnion>)>)>,

pub assertions: Option<FxHashMap<usize, Assertion>>,

pub if_true_assertions: Option<FxHashMap<usize, Assertion>>,

pub if_false_assertions: Option<FxHashMap<usize, Assertion>>,

pub has_visitor_issues: bool,

pub has_yield: bool,
Expand Down Expand Up @@ -130,8 +122,6 @@ pub struct FunctionLikeInfo {

pub removed_taints: Vec<SinkType>,

pub return_source_params: FxHashMap<u32, StrId>,

pub attributes: Vec<AttributeInfo>,

pub method_info: Option<Box<MethodInfo>>,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions src/code_info/type_resolution.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use hakana_str::StrId;
use rustc_hash::FxHashMap;

use serde::{Deserialize, Serialize};

Expand All @@ -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<TUnion>)>)>,
pub template_supers: FxHashMap<StrId, TUnion>,
pub template_supers: Vec<(StrId, TUnion)>,
}

impl Default for TypeResolutionContext {
Expand All @@ -23,7 +22,7 @@ impl TypeResolutionContext {
pub fn new() -> Self {
Self {
template_type_map: vec![],
template_supers: FxHashMap::default(),
template_supers: vec![],
}
}
}
24 changes: 12 additions & 12 deletions src/code_info_builder/classlike_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/code_info_builder/functionlike_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/code_info_builder/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion src/code_info_builder/typehint_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down

0 comments on commit 5223a09

Please sign in to comment.