Skip to content

Commit

Permalink
Use build.rs in place of macro for string interning
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 10, 2024
1 parent a43e7e8 commit 8d9f5f1
Show file tree
Hide file tree
Showing 113 changed files with 559 additions and 400 deletions.
1 change: 1 addition & 0 deletions src/aast_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ naming_special_names_rust = { path = "../../third-party/hhvm/hphp/hack/src/namin
aast_parser = { path = "../../third-party/hhvm/hphp/hack/src/parser/cargo/aast_parser" }
ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" }
hakana-reflection-info = { path = "../code_info" }
hakana-str = { path = "../str" }
serde = { version = "1.0", features = ["derive"] }
bincode = "1.3.3"
xxhash-rust = { version = "0.8.3", features = ["xxh3", "xxh32"] }
Expand Down
2 changes: 1 addition & 1 deletion src/aast_utils/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use aast_parser::rust_aast_parser_types::Env as AastParserEnv;

use hakana_reflection_info::code_location::{FilePath, HPos};
use hakana_reflection_info::{str::StrId, str::ThreadedInterner};
use hakana_str::{StrId, ThreadedInterner};
use name_context::NameContext;
use naming_visitor::Scanner;
use oxidized::ast_defs::Pos;
Expand Down
2 changes: 1 addition & 1 deletion src/aast_utils/name_context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hakana_reflection_info::str::{StrId, ThreadedInterner};
use hakana_str::{StrId, ThreadedInterner};
use rustc_hash::FxHashMap;

use oxidized::aast::NsKind;
Expand Down
2 changes: 1 addition & 1 deletion src/aast_utils/naming_visitor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hakana_reflection_info::str::{StrId, ThreadedInterner};
use hakana_str::{StrId, ThreadedInterner};

use oxidized::{
aast,
Expand Down
1 change: 1 addition & 0 deletions src/algebra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ indexmap = "1.8.0"
itertools = "0.10.1"
xxhash-rust = { version = "0.8.3", features = ["xxh3", "xxh32"] }
hakana-reflection-info = { path = "../code_info" }
hakana-str = { path = "../str" }
hakana-type = { path = "../ttype" }
rustc-hash = "1.1.0"

Expand Down
2 changes: 1 addition & 1 deletion src/algebra/clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::hash::{Hash, Hasher};
use std::num::Wrapping;

use hakana_reflection_info::assertion::Assertion;
use hakana_reflection_info::str::Interner;
use hakana_str::Interner;
use indexmap::IndexMap;

#[derive(Clone, Debug, Eq)]
Expand Down
1 change: 1 addition & 0 deletions src/analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ hakana-type = { path = "../ttype" }
hakana-algebra = { path = "../algebra" }
hakana-logger = { path = "../logger" }
hakana-reflection-info = { path = "../code_info" }
hakana-str = { path = "../str" }
hakana-reflector = { path = "../code_info_builder" }
parser_core_types = { path = "../../third-party/hhvm/hphp/hack/src/parser/cargo/core_types" }
oxidized = { path = "../../third-party/hhvm/hphp/hack/src/oxidized" }
Expand Down
5 changes: 2 additions & 3 deletions src/analyzer/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use hakana_reflection_info::{
data_flow::{graph::GraphKind, tainted_node::TaintedNode},
issue::{Issue, IssueKind},
taint::{SinkType, SourceType},
str::Interner,
};
use hakana_str::Interner;
use rustc_hash::{FxHashMap, FxHashSet};

use crate::custom_hook::CustomHook;
Expand Down Expand Up @@ -115,8 +115,7 @@ impl Config {
.collect();

if let Some(v) = json_config.ignore_issue_files.get("*") {
self.ignore_all_issues_in_files =
v.iter().map(|v| format!("{}/{}", cwd, v)).collect();
self.ignore_all_issues_in_files = v.iter().map(|v| format!("{}/{}", cwd, v)).collect();
}

self.allowed_issues = if json_config.allowed_issues.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/custom_hook.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hakana_reflection_info::analysis_result::AnalysisResult;
use hakana_reflection_info::function_context::FunctionLikeIdentifier;
use hakana_reflection_info::str::Interner;
use hakana_str::Interner;
use hakana_reflection_info::{
codebase_info::CodebaseInfo, functionlike_info::FunctionLikeInfo, t_union::TUnion,
};
Expand Down
4 changes: 2 additions & 2 deletions src/analyzer/dataflow/program_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use hakana_logger::Logger;
use hakana_logger::Verbosity;
use hakana_reflection_info::code_location::FilePath;
use hakana_reflection_info::data_flow::node::DataFlowNodeKind;
use hakana_reflection_info::str::Interner;
use hakana_reflection_info::str::StrId;
use hakana_str::Interner;
use hakana_str::StrId;
use rustc_hash::FxHashMap;
use rustc_hash::FxHashSet;
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/expr/assertion_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{formula_generator::AssertionContext, function_analysis_data::Functio
use hakana_reflection_info::code_location::HPos;
use hakana_reflection_info::function_context::FunctionLikeIdentifier;
use hakana_reflection_info::issue::{Issue, IssueKind};
use hakana_reflection_info::str::StrId;
use hakana_str::StrId;
use hakana_reflection_info::symbol_references::ReferenceSource;
use hakana_reflection_info::t_atomic::DictKey;
use hakana_reflection_info::{
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/expr/assignment/array_assignment_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use hakana_reflection_info::{
node::{DataFlowNode, DataFlowNodeKind},
path::{ArrayDataKind, PathKind},
},
str::StrId,
t_atomic::{DictKey, TAtomic},
t_union::TUnion,
};
use hakana_str::StrId;
use hakana_type::{
combine_union_types, get_arrayish_params, get_arraykey, get_int, get_mixed_any, get_nothing,
template::TemplateBound, type_combiner, wrap_atomic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use hakana_reflection_info::{
codebase_info::CodebaseInfo,
data_flow::{graph::GraphKind, node::DataFlowNode, path::PathKind},
issue::{Issue, IssueKind},
str::StrId,
t_atomic::TAtomic,
t_union::TUnion,
EFFECT_WRITE_PROPS,
};
use hakana_str::StrId;
use hakana_type::{
add_optional_union_type, get_mixed_any,
type_comparator::{type_comparison_result::TypeComparisonResult, union_type_comparator},
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/expr/binop/assignment_analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hakana_reflection_info::data_flow::graph::WholeProgramKind;
use hakana_reflection_info::data_flow::node::DataFlowNodeKind;
use hakana_reflection_info::str::StrId;
use hakana_str::StrId;
use hakana_reflection_info::EFFECT_WRITE_LOCAL;
use indexmap::IndexMap;
use rustc_hash::FxHashSet;
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/expr/call/argument_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use hakana_reflection_info::issue::{Issue, IssueKind};
use hakana_reflection_info::t_atomic::TAtomic;
use hakana_reflection_info::t_union::TUnion;
use hakana_reflection_info::taint::{string_to_sink_types, SinkType};
use hakana_reflection_info::str::Interner;
use hakana_str::Interner;
use hakana_type::type_comparator::type_comparison_result::TypeComparisonResult;
use hakana_type::type_comparator::union_type_comparator;
use hakana_type::{add_union_type, get_arraykey, get_int, get_mixed, get_mixed_any, get_nothing};
Expand Down
3 changes: 2 additions & 1 deletion src/analyzer/expr/call/arguments_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::collections::BTreeMap;
use std::sync::Arc;

use hakana_reflection_info::assertion::Assertion;
use hakana_reflection_info::{str::Interner, str::StrId, EFFECT_WRITE_LOCAL};
use hakana_reflection_info::EFFECT_WRITE_LOCAL;

use hakana_reflection_info::data_flow::node::DataFlowNode;
use hakana_reflection_info::taint::SinkType;
use hakana_str::{Interner, StrId};
use rustc_hash::{FxHashMap, FxHashSet};

use crate::expr::binop::assignment_analyzer;
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/expr/call/atomic_method_call_analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use hakana_str::StrId;
use rustc_hash::FxHashSet;

use hakana_reflection_info::{
issue::{Issue, IssueKind},
str::StrId,
t_atomic::TAtomic,
t_union::TUnion,
};
Expand Down
3 changes: 2 additions & 1 deletion src/analyzer/expr/call/atomic_static_call_analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use hakana_reflection_info::{
issue::{Issue, IssueKind},
t_atomic::TAtomic,
str::StrId, EFFECT_IMPURE,
EFFECT_IMPURE,
};
use hakana_str::StrId;
use oxidized::{
aast,
ast_defs::{self, Pos},
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/expr/call/class_template_param_collector.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::sync::Arc;

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

use hakana_reflection_info::{
classlike_info::ClassLikeInfo, codebase_info::CodebaseInfo, t_atomic::TAtomic, t_union::TUnion,
str::StrId,
};
use hakana_type::{add_optional_union_type, get_mixed_any, wrap_atomic};
use indexmap::IndexMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use hakana_reflection_info::{
t_atomic::{DictKey, TAtomic},
t_union::TUnion,
};
use hakana_reflection_info::{str::StrId, EFFECT_WRITE_LOCAL, EFFECT_WRITE_PROPS};
use hakana_reflection_info::{EFFECT_WRITE_LOCAL, EFFECT_WRITE_PROPS};
use hakana_str::StrId;
use hakana_type::get_null;
use hakana_type::template::standin_type_replacer;
use hakana_type::{
Expand Down
17 changes: 9 additions & 8 deletions src/analyzer/expr/call/function_call_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use hakana_reflection_info::analysis_result::Replacement;
use hakana_reflection_info::codebase_info::CodebaseInfo;
use hakana_reflection_info::t_atomic::DictKey;
use hakana_reflection_info::t_union::TUnion;
use hakana_reflection_info::{str::StrId, EFFECT_WRITE_LOCAL, EFFECT_WRITE_PROPS};
use hakana_reflection_info::{EFFECT_WRITE_LOCAL, EFFECT_WRITE_PROPS};
use hakana_str::StrId;
use hakana_type::type_comparator::union_type_comparator;
use hakana_type::{get_arrayish_params, get_void};
use rustc_hash::{FxHashMap, FxHashSet};
Expand Down Expand Up @@ -221,10 +222,10 @@ pub(crate) fn analyze(
process_invariant(first_arg, context, statements_analyzer, analysis_data);
}
}
StrId::C_CONTAINS
| StrId::C_CONTAINS_KEY
| StrId::DICT_CONTAINS
| StrId::DICT_CONTAINS_KEY => {
StrId::LIB_C_CONTAINS
| StrId::LIB_C_CONTAINS_KEY
| StrId::LIB_DICT_CONTAINS
| StrId::LIB_DICT_CONTAINS_KEY => {
let expr_var_id = expression_identifier::get_var_id(
&expr.2[0].1,
context.function_context.calling_class.as_ref(),
Expand All @@ -235,7 +236,7 @@ pub(crate) fn analyze(
)),
);

if name == StrId::C_CONTAINS || name == StrId::DICT_CONTAINS {
if name == StrId::LIB_C_CONTAINS || name == StrId::LIB_DICT_CONTAINS {
let container_type = analysis_data.get_expr_type(expr.2[0].1.pos()).cloned();
let second_arg_type = analysis_data.get_expr_type(expr.2[1].1.pos()).cloned();
check_array_key_or_value_type(
Expand Down Expand Up @@ -333,7 +334,7 @@ pub(crate) fn analyze(
}
}
}
StrId::STR_STARTS_WITH => {
StrId::LIB_STR_STARTS_WITH => {
if expr.2.len() == 2 {
if let GraphKind::WholeProgram(_) = &analysis_data.data_flow_graph.kind {
let expr_var_id = expression_identifier::get_var_id(
Expand Down Expand Up @@ -375,7 +376,7 @@ pub(crate) fn analyze(
}
}
}
StrId::REGEX_MATCHES => {
StrId::LIB_REGEX_MATCHES => {
if expr.2.len() == 2 {
if let GraphKind::WholeProgram(_) = &analysis_data.data_flow_graph.kind {
let expr_var_id = expression_identifier::get_var_id(
Expand Down
16 changes: 8 additions & 8 deletions src/analyzer/expr/call/function_call_return_type_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use hakana_reflection_info::functionlike_info::FunctionLikeInfo;
use hakana_reflection_info::t_atomic::{DictKey, TAtomic};
use hakana_reflection_info::t_union::TUnion;
use hakana_reflection_info::taint::SinkType;
use hakana_reflection_info::{str::Interner, str::StrId};
use hakana_str::{Interner, StrId};
use hakana_type::type_comparator::type_comparison_result::TypeComparisonResult;
use hakana_type::type_comparator::union_type_comparator;
use hakana_type::type_expander::TypeExpansionOptions;
Expand Down Expand Up @@ -337,7 +337,7 @@ fn handle_special_functions(
known_count: None,
non_empty: true,
})),
&StrId::STR_REPLACE_LEGACY => {
&StrId::STR_REPLACE => {
// returns string if the second arg is a string
if let Some((_, arg_expr)) = args.get(1) {
if let Some(expr_type) = analysis_data.get_expr_type(arg_expr.pos()) {
Expand Down Expand Up @@ -403,7 +403,7 @@ fn handle_special_functions(
None
}
}
&StrId::STR_JOIN => {
&StrId::LIB_STR_JOIN => {
if let (Some((_, first_arg_expr)), Some((_, second_arg_expr))) =
(args.first(), args.get(1))
{
Expand Down Expand Up @@ -434,7 +434,7 @@ fn handle_special_functions(
None
}
}
&StrId::STR_FORMAT => {
&StrId::LIB_STR_FORMAT => {
if let Some(first_arg) = args.first() {
if let aast::Expr_::String(simple_string) = &first_arg.1 .2 {
let mut escaped = false;
Expand Down Expand Up @@ -506,7 +506,7 @@ fn handle_special_functions(

None
}
&StrId::STR_TRIM | &StrId::STR_STRIP_SUFFIX | &StrId::STR_SLICE | &StrId::STR_REPLACE => {
&StrId::LIB_STR_TRIM | &StrId::LIB_STR_STRIP_SUFFIX | &StrId::LIB_STR_SLICE | &StrId::LIB_STR_REPLACE => {
let mut all_literals = true;
for (_, arg_expr) in args {
if let Some(arg_expr_type) = analysis_data.get_expr_type(arg_expr.pos()) {
Expand All @@ -526,7 +526,7 @@ fn handle_special_functions(
TAtomic::TString
}))
}
&StrId::STR_SPLIT => {
&StrId::LIB_STR_SPLIT => {
let mut all_literals = true;
for (_, arg_expr) in args {
if let Some(arg_expr_type) = analysis_data.get_expr_type(arg_expr.pos()) {
Expand Down Expand Up @@ -566,7 +566,7 @@ fn handle_special_functions(
None
}
}
&StrId::IDX => {
&StrId::IDX_FN => {
if args.len() >= 2 {
let dict_type = analysis_data.get_rc_expr_type(args[0].1.pos()).cloned();
let dim_type = analysis_data.get_rc_expr_type(args[1].1.pos()).cloned();
Expand Down Expand Up @@ -687,7 +687,7 @@ fn get_type_structure_type(
{
if let Some(type_constant_info) = classlike_info.type_constants.get(&const_name) {
return Some(wrap_atomic(TAtomic::TTypeAlias {
name: StrId::TYPE_STRUCTURE_OBJ,
name: StrId::TYPE_STRUCTURE,
type_params: Some(vec![match type_constant_info {
ClassConstantType::Concrete(actual_type) => actual_type.clone(),
ClassConstantType::Abstract(Some(as_type)) => as_type.clone(),
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/expr/call/method_call_info.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hakana_reflection_info::classlike_info::ClassLikeInfo;
use hakana_reflection_info::method_identifier::MethodIdentifier;
use hakana_reflection_info::str::StrId;
use hakana_str::StrId;

pub(crate) struct MethodCallInfo<'a> {
pub self_fq_classlike_name: StrId,
Expand Down
8 changes: 4 additions & 4 deletions src/analyzer/expr/call/method_call_return_type_fetcher.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use std::rc::Rc;

use hakana_reflection_info::functionlike_identifier::FunctionLikeIdentifier;
use hakana_reflection_info::str::StrId;
use hakana_str::{Interner, StrId};
use oxidized::{aast, ast_defs};
use rustc_hash::{FxHashMap, FxHashSet};

use hakana_reflection_info::classlike_info::ClassLikeInfo;
use hakana_reflection_info::data_flow::graph::GraphKind;
use hakana_reflection_info::data_flow::node::{DataFlowNode, DataFlowNodeKind};
use hakana_reflection_info::data_flow::path::PathKind;
use hakana_reflection_info::method_identifier::MethodIdentifier;
use hakana_reflection_info::t_atomic::TAtomic;
use hakana_reflection_info::t_union::TUnion;
use hakana_reflection_info::{classlike_info::ClassLikeInfo, str::Interner};
use hakana_type::{
get_mixed_any, get_nothing, get_string, template,
type_expander::{self, TypeExpansionOptions},
Expand Down Expand Up @@ -157,7 +157,7 @@ pub(crate) fn fetch(

fn get_special_method_return(method_id: &MethodIdentifier, interner: &Interner) -> Option<TUnion> {
match method_id.0 {
StrId::DATETIME | StrId::DATETIME_IMMUTABLE => {
StrId::DATE_TIME | StrId::DATE_TIME_IMMUTABLE => {
if interner.lookup(&method_id.1) == "createFromFormat" {
let mut false_or_datetime = TUnion::new(vec![
TAtomic::TNamedObject {
Expand All @@ -173,7 +173,7 @@ fn get_special_method_return(method_id: &MethodIdentifier, interner: &Interner)
return Some(false_or_datetime);
}
}
StrId::DOM_DOCUMENT => {
StrId::DOMDOCUMENT => {
if interner.lookup(&method_id.1) == "createElement" {
let mut false_or_domelement = TUnion::new(vec![
TAtomic::TNamedObject {
Expand Down
3 changes: 2 additions & 1 deletion src/analyzer/expr/call/new_analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::sync::Arc;

use hakana_reflection_info::classlike_info::Variance;
use hakana_reflection_info::{str::StrId, EFFECT_WRITE_GLOBALS};
use hakana_reflection_info::EFFECT_WRITE_GLOBALS;

use hakana_reflection_info::data_flow::node::DataFlowNode;
use hakana_reflection_info::functionlike_info::FunctionLikeInfo;
use hakana_str::StrId;
use hakana_type::template::standin_type_replacer::get_most_specific_type_from_bounds;
use rustc_hash::{FxHashMap, FxHashSet};

Expand Down
3 changes: 2 additions & 1 deletion src/analyzer/expr/call_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::sync::Arc;

use hakana_reflection_info::code_location::HPos;
use hakana_reflection_info::issue::{Issue, IssueKind};
use hakana_reflection_info::{str::StrId, EFFECT_IMPURE, EFFECT_WRITE_PROPS};
use hakana_reflection_info::{EFFECT_IMPURE, EFFECT_WRITE_PROPS};
use hakana_str::StrId;
use hakana_type::template::standin_type_replacer::get_relevant_bounds;
use hakana_type::type_comparator::type_comparison_result::TypeComparisonResult;
use hakana_type::type_comparator::union_type_comparator;
Expand Down
Loading

0 comments on commit 8d9f5f1

Please sign in to comment.