Skip to content

Use IndexVec not FxHashMap for all fields of ScopeTree #4269

@overlookmotel

Description

@overlookmotel

Semantic's ScopeTree consists mostly of IndexVecs, but 2 fields are FxHashMaps.

pub struct ScopeTree {
/// Maps a scope to the parent scope it belongs in
parent_ids: IndexVec<ScopeId, Option<ScopeId>>,
/// Maps a scope to direct children scopes
child_ids: FxHashMap<ScopeId, Vec<ScopeId>>,
// Maps a scope to its node id
node_ids: FxHashMap<ScopeId, AstNodeId>,
flags: IndexVec<ScopeId, ScopeFlags>,
bindings: IndexVec<ScopeId, Bindings>,
unresolved_references: IndexVec<ScopeId, UnresolvedReferences>,
}

I'm not sure why child_ids and node_ids are hash maps, but imagine they could be changed to IndexVecs, which have faster lookup. If for some reason a few scopes don't get records in these fields at present, we could just insert dummies in those cases. Then ScopeId can be used to index them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions