From 7d508696496681e61ad2ea4e5fe02e3f7ef13abc Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 19 Mar 2024 14:04:35 -0400 Subject: [PATCH] Simplify storage of parent classes --- src/code_info/classlike_info.rs | 41 +++++++++------------- src/code_info/t_atomic.rs | 2 +- src/code_info_builder/classlike_scanner.rs | 28 +++++++-------- src/ttype/lib.rs | 18 +++++++--- 4 files changed, 45 insertions(+), 44 deletions(-) diff --git a/src/code_info/classlike_info.rs b/src/code_info/classlike_info.rs index 0e3e3785..27daf74e 100644 --- a/src/code_info/classlike_info.rs +++ b/src/code_info/classlike_info.rs @@ -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)] @@ -32,11 +32,6 @@ pub enum ClassConstantType { pub struct ClassLikeInfo { pub constants: IndexMap, - /** - * Aliases to help Hakana understand constant refs - */ - pub aliases: Option, - pub is_populated: bool, pub is_stubbed: bool, @@ -45,29 +40,27 @@ pub struct ClassLikeInfo { pub internal_to: Option, - pub suppressed_issues: Option>, - pub name: StrId, /** * Interfaces this class implements directly */ - pub direct_class_interfaces: FxHashSet, + pub direct_class_interfaces: Vec, /** * Interfaces this class implements explicitly and implicitly */ - pub all_class_interfaces: FxHashSet, + pub all_class_interfaces: Vec, /** * Parent interfaces listed explicitly */ - pub direct_parent_interfaces: FxHashSet, + pub direct_parent_interfaces: Vec, /** * All parent interfaces */ - pub all_parent_interfaces: FxHashSet, + pub all_parent_interfaces: Vec, /** * There can only be one parent class @@ -77,12 +70,12 @@ pub struct ClassLikeInfo { /** * A trait can require extending classes and interfaces */ - pub required_classlikes: FxHashSet, + pub required_classlikes: Vec, /** * Parent classes */ - pub all_parent_classes: FxHashSet, + pub all_parent_classes: Vec, pub def_location: HPos, @@ -178,7 +171,7 @@ pub struct ClassLikeInfo { pub template_type_uses_count: FxHashMap, - pub initialized_properties: FxHashSet, + pub initialized_properties: Vec, pub invalid_dependencies: Vec, @@ -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, @@ -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(), diff --git a/src/code_info/t_atomic.rs b/src/code_info/t_atomic.rs index 6ccd9901..02608cf8 100644 --- a/src/code_info/t_atomic.rs +++ b/src/code_info/t_atomic.rs @@ -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); diff --git a/src/code_info_builder/classlike_scanner.rs b/src/code_info_builder/classlike_scanner.rs index 351edd83..202a7fe7 100644 --- a/src/code_info_builder/classlike_scanner.rs +++ b/src/code_info_builder/classlike_scanner.rs @@ -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, @@ -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 @@ -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, @@ -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, @@ -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, @@ -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; @@ -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!(), }; diff --git a/src/ttype/lib.rs b/src/ttype/lib.rs index 0bbb3afb..ac6f3da7 100644 --- a/src/ttype/lib.rs +++ b/src/ttype/lib.rs @@ -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