Skip to content

Commit

Permalink
Allow codegen to target classes, cutting down on time
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 18, 2024
1 parent 5b02134 commit a105652
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/analyzer/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod json_config;
pub struct Config {
pub migration_symbols: FxHashMap<String, String>,
pub in_migration: bool,
pub in_codegen: bool,
pub find_unused_expressions: bool,
pub find_unused_definitions: bool,
pub allowed_issues: Option<FxHashSet<IssueKind>>,
Expand Down Expand Up @@ -80,6 +81,7 @@ impl Config {
all_custom_issues,
ast_diff: false,
in_migration: false,
in_codegen: false,
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/analyzer/custom_hook.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use hakana_reflection_info::analysis_result::AnalysisResult;
use hakana_reflection_info::function_context::FunctionLikeIdentifier;
use hakana_str::Interner;
use hakana_reflection_info::{
codebase_info::CodebaseInfo, functionlike_info::FunctionLikeInfo, t_union::TUnion,
};
use hakana_str::{Interner, StrId};
use oxidized::{
aast,
ast_defs::{self, Pos},
};
use rustc_hash::FxHashMap;

use crate::{
config, function_analysis_data::FunctionAnalysisData, scope_context::ScopeContext,
Expand Down Expand Up @@ -137,6 +138,17 @@ pub trait InternalHook {
) -> Vec<String> {
vec![]
}

#[allow(unused_variables)]
fn can_codegen_def(
&self,
interner: &Interner,
codebase: &CodebaseInfo,
resolved_names: &FxHashMap<u32, StrId>,
def: &aast::Def<(), ()>,
) -> bool {
return false;
}
}

pub trait CustomHook: InternalHook + Send + Sync + core::fmt::Debug {}
13 changes: 13 additions & 0 deletions src/analyzer/def_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ pub(crate) fn analyze(
analysis_data: &mut FunctionAnalysisData,
analysis_result: &mut AnalysisResult,
) -> Result<(), InternalError> {
if statements_analyzer.get_config().in_codegen {
if !statements_analyzer.get_config().hooks.iter().any(|hook| {
hook.can_codegen_def(
statements_analyzer.get_interner(),
statements_analyzer.get_codebase(),
statements_analyzer.get_file_analyzer().resolved_names,
def,
)
}) {
return Ok(());
}
}

match def {
aast::Def::Fun(_) => {
let file_analyzer = scope_analyzer.get_file_analyzer();
Expand Down
1 change: 1 addition & 0 deletions src/cli/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ fn do_codegen(

let mut config = config::Config::new(root_dir.to_string(), all_custom_issues);
config.hooks = analysis_hooks;
config.in_codegen = true;

if let Some(codegen_name) = codegen_name {
codegen_hooks.retain(|hook| {
Expand Down

0 comments on commit a105652

Please sign in to comment.