Skip to content

Commit

Permalink
Use more compact storage for impl lookup buckets.
Browse files Browse the repository at this point in the history
If the bucket is of size zero or one, which is expected to be the common
case, then store it directly. For the remaining cases, use a side table
of lookup buckets.
  • Loading branch information
zygoloid committed Sep 27, 2024
1 parent b0df74b commit be3e988
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 88 deletions.
6 changes: 1 addition & 5 deletions toolchain/check/generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,7 @@ auto RequireGenericParams(Context& context, SemIR::InstBlockId block_id)
// constructing a generic based on it. Note this is updating the param
// refs block, not the actual params block, so will not be directly
// reflected in SemIR output.
inst_id = context.AddInstInNoBlock<SemIR::Param>(
context.insts().GetLocId(inst_id),
{.type_id = SemIR::TypeId::Error,
.name_id = SemIR::NameId::Base,
.runtime_index = SemIR::RuntimeParamIndex::Invalid});
inst_id = SemIR::InstId::BuiltinError;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions toolchain/check/handle_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id,
{.self_id = self_type_id, .constraint_id = constraint_type_id}};

// Add the impl declaration.
auto& lookup_bucket = context.impls().GetOrAddLookupBucket(
auto lookup_bucket_ref = context.impls().GetOrAddLookupBucket(
impl_info.self_id, impl_info.constraint_id);
for (auto prev_impl_id : lookup_bucket) {
for (auto prev_impl_id : lookup_bucket_ref) {
if (MergeImplRedecl(context, impl_info, prev_impl_id)) {
impl_decl.impl_id = prev_impl_id;
break;
Expand All @@ -291,7 +291,7 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id,
if (!impl_decl.impl_id.is_valid()) {
impl_info.generic_id = FinishGenericDecl(context, impl_decl_id);
impl_decl.impl_id = context.impls().Add(impl_info);
lookup_bucket.push_back(impl_decl.impl_id);
lookup_bucket_ref.push_back(impl_decl.impl_id);
} else {
FinishGenericRedecl(context, impl_decl_id,
context.impls().Get(impl_decl.impl_id).generic_id);
Expand Down
Loading

0 comments on commit be3e988

Please sign in to comment.