Skip to content

Commit

Permalink
Simplify storage of parent classes
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 19, 2024
1 parent 35ba326 commit 7d50869
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 44 deletions.
41 changes: 16 additions & 25 deletions src/code_info/classlike_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use indexmap::IndexMap;
use serde::{Deserialize, Serialize};

use crate::{
aliases::Aliases, attribute_info::AttributeInfo, class_constant_info::ConstantInfo,
enum_case_info::EnumCaseInfo, property_info::PropertyInfo,
attribute_info::AttributeInfo, class_constant_info::ConstantInfo, enum_case_info::EnumCaseInfo,
property_info::PropertyInfo,
};

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand All @@ -32,11 +32,6 @@ pub enum ClassConstantType {
pub struct ClassLikeInfo {
pub constants: IndexMap<StrId, ConstantInfo>,

/**
* Aliases to help Hakana understand constant refs
*/
pub aliases: Option<Aliases>,

pub is_populated: bool,

pub is_stubbed: bool,
Expand All @@ -45,29 +40,27 @@ pub struct ClassLikeInfo {

pub internal_to: Option<String>,

pub suppressed_issues: Option<FxHashMap<u32, String>>,

pub name: StrId,

/**
* Interfaces this class implements directly
*/
pub direct_class_interfaces: FxHashSet<StrId>,
pub direct_class_interfaces: Vec<StrId>,

/**
* Interfaces this class implements explicitly and implicitly
*/
pub all_class_interfaces: FxHashSet<StrId>,
pub all_class_interfaces: Vec<StrId>,

/**
* Parent interfaces listed explicitly
*/
pub direct_parent_interfaces: FxHashSet<StrId>,
pub direct_parent_interfaces: Vec<StrId>,

/**
* All parent interfaces
*/
pub all_parent_interfaces: FxHashSet<StrId>,
pub all_parent_interfaces: Vec<StrId>,

/**
* There can only be one parent class
Expand All @@ -77,12 +70,12 @@ pub struct ClassLikeInfo {
/**
* A trait can require extending classes and interfaces
*/
pub required_classlikes: FxHashSet<StrId>,
pub required_classlikes: Vec<StrId>,

/**
* Parent classes
*/
pub all_parent_classes: FxHashSet<StrId>,
pub all_parent_classes: Vec<StrId>,

pub def_location: HPos,

Expand Down Expand Up @@ -178,7 +171,7 @@ pub struct ClassLikeInfo {

pub template_type_uses_count: FxHashMap<String, u32>,

pub initialized_properties: FxHashSet<StrId>,
pub initialized_properties: Vec<StrId>,

pub invalid_dependencies: Vec<StrId>,

Expand Down Expand Up @@ -236,26 +229,25 @@ impl ClassLikeInfo {
preserve_constructor_signature: false,
enforce_template_inheritance: false,

direct_class_interfaces: FxHashSet::default(),
aliases: None,
all_parent_classes: FxHashSet::default(),
direct_class_interfaces: vec![],
all_parent_classes: vec![],
appearing_method_ids: FxHashMap::default(),
attributes: Vec::new(),
all_class_interfaces: FxHashSet::default(),
all_parent_interfaces: FxHashSet::default(),
all_class_interfaces: vec![],
all_parent_interfaces: vec![],
declaring_method_ids: FxHashMap::default(),
appearing_property_ids: FxHashMap::default(),
declaring_property_ids: FxHashMap::default(),
direct_parent_class: None,
direct_parent_interfaces: FxHashSet::default(),
required_classlikes: FxHashSet::default(),
direct_parent_interfaces: vec![],
required_classlikes: vec![],
inheritable_method_ids: FxHashMap::default(),
enum_cases: None,
enum_type: None,
enum_constraint: None,
hash: None,
inheritable_property_ids: FxHashMap::default(),
initialized_properties: FxHashSet::default(),
initialized_properties: vec![],
internal_to: None,
invalid_dependencies: Vec::new(),
def_location,
Expand All @@ -265,7 +257,6 @@ impl ClassLikeInfo {
overridden_property_ids: FxHashMap::default(),
potential_declaring_method_ids: FxHashMap::default(),
properties: FxHashMap::default(),
suppressed_issues: None,
generic_variance: FxHashMap::default(),
template_extended_count: 0,
template_extended_params: FxHashMap::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/code_info/t_atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ impl TAtomic {
ref mut as_type, ..
} = type_part
{
as_type.clone_from(extends_as_type);
as_type.clone_from(&extends_as_type);
}
new_intersection_types.push(type_part);

Expand Down
28 changes: 14 additions & 14 deletions src/code_info_builder/classlike_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub(crate) fn scan(
}

storage.direct_parent_class = Some(parent_name);
storage.all_parent_classes.insert(parent_name);
storage.all_parent_classes.push(parent_name);

storage.template_extended_offsets.insert(
parent_name,
Expand Down Expand Up @@ -217,8 +217,8 @@ pub(crate) fn scan(
signature_end = params.last().unwrap().0.end_offset() as u32;
}

storage.direct_class_interfaces.insert(interface_name);
storage.all_class_interfaces.insert(interface_name);
storage.direct_class_interfaces.push(interface_name);
storage.all_class_interfaces.push(interface_name);

if class_name == &StrId::SIMPLE_XML_ELEMENT
&& interface_name == StrId::TRAVERSABLE
Expand Down Expand Up @@ -280,7 +280,7 @@ pub(crate) fn scan(
}

storage.direct_parent_class = Some(StrId::BUILTIN_ENUM_CLASS);
storage.all_parent_classes.insert(StrId::BUILTIN_ENUM_CLASS);
storage.all_parent_classes.push(StrId::BUILTIN_ENUM_CLASS);

storage.template_extended_offsets.insert(
StrId::BUILTIN_ENUM_CLASS,
Expand Down Expand Up @@ -324,8 +324,8 @@ pub(crate) fn scan(
signature_end = params.last().unwrap().0.end_offset() as u32;
}

storage.direct_parent_interfaces.insert(parent_name);
storage.all_parent_interfaces.insert(parent_name);
storage.direct_parent_interfaces.push(parent_name);
storage.all_parent_interfaces.push(parent_name);

storage.template_extended_offsets.insert(
parent_name,
Expand Down Expand Up @@ -378,8 +378,8 @@ pub(crate) fn scan(
signature_end = params.last().unwrap().0.end_offset() as u32;
}

storage.direct_class_interfaces.insert(interface_name);
storage.all_class_interfaces.insert(interface_name);
storage.direct_class_interfaces.push(interface_name);
storage.all_class_interfaces.push(interface_name);

storage.template_extended_offsets.insert(
interface_name,
Expand Down Expand Up @@ -410,7 +410,7 @@ pub(crate) fn scan(
storage.kind = SymbolKind::Enum;

storage.direct_parent_class = Some(StrId::BUILTIN_ENUM);
storage.all_parent_classes.insert(StrId::BUILTIN_ENUM);
storage.all_parent_classes.push(StrId::BUILTIN_ENUM);

if let Some(enum_node) = &classlike_node.enum_ {
signature_end = enum_node.base.0.end_offset() as u32;
Expand Down Expand Up @@ -654,13 +654,13 @@ fn handle_reqs(
match &req.1 {
aast::RequireKind::RequireExtends => {
storage.direct_parent_class = Some(require_name);
storage.all_parent_classes.insert(require_name);
storage.required_classlikes.insert(require_name);
storage.all_parent_classes.push(require_name);
storage.required_classlikes.push(require_name);
}
aast::RequireKind::RequireImplements => {
storage.direct_class_interfaces.insert(require_name);
storage.all_class_interfaces.insert(require_name);
storage.required_classlikes.insert(require_name);
storage.direct_class_interfaces.push(require_name);
storage.all_class_interfaces.push(require_name);
storage.required_classlikes.push(require_name);
}
aast::RequireKind::RequireClass => todo!(),
};
Expand Down
18 changes: 14 additions & 4 deletions src/ttype/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,20 @@ pub fn combine_union_types(
combined_type.ignore_falsable_issues = true;
}

if !type_1.parent_nodes.is_empty() || !type_2.parent_nodes.is_empty() {
let mut parent_nodes = type_1.parent_nodes.clone();
parent_nodes.extend(type_2.parent_nodes.clone());
combined_type.parent_nodes = parent_nodes;
let type_1_parent_nodes_empty = type_1.parent_nodes.is_empty();
let type_2_parent_nodes_empty = type_2.parent_nodes.is_empty();

if !type_1_parent_nodes_empty || !type_2_parent_nodes_empty {
if type_1_parent_nodes_empty {
combined_type.parent_nodes.clone_from(&type_2.parent_nodes);
} else if type_2_parent_nodes_empty {
combined_type.parent_nodes.clone_from(&type_1.parent_nodes);
} else {
combined_type.parent_nodes.clone_from(&type_1.parent_nodes);
combined_type
.parent_nodes
.extend(type_2.parent_nodes.clone());
}
}

combined_type
Expand Down

0 comments on commit 7d50869

Please sign in to comment.