diff --git a/common/set.h b/common/set.h index f0b7b4976612..7d1c3d8b42eb 100644 --- a/common/set.h +++ b/common/set.h @@ -131,7 +131,7 @@ class SetView : RawHashtable::ViewImpl { // A pointer or reference to this type is the preferred way to pass a mutable // handle to a `Set` type across API boundaries as it avoids encoding specific // SSO sizing information while providing a near-complete mutable API. -template +template class SetBase : protected RawHashtable::BaseImpl { protected: diff --git a/toolchain/check/class.cpp b/toolchain/check/class.cpp index 1c74cb2cab03..3c1df1a6c161 100644 --- a/toolchain/check/class.cpp +++ b/toolchain/check/class.cpp @@ -222,7 +222,7 @@ static auto BuildVtable(Context& context, Parse::ClassDefinitionId node_id, }; llvm::SmallVector vtable; - Set implemented_impls; + Set implemented_impls; bool carbon_native_vtable = true; // Add vtable entries from the base class, updating them to point to a derived diff --git a/toolchain/check/convert.cpp b/toolchain/check/convert.cpp index 171a4fb49f7d..e2535eb23a70 100644 --- a/toolchain/check/convert.cpp +++ b/toolchain/check/convert.cpp @@ -649,15 +649,15 @@ static auto ConvertStructToStructOrClass( value_id = MaterializeIfInitializer(context, value_id); } - Set dest_field_names; - for (auto field : dest_elem_fields) { - dest_field_names.Insert(field.name_id); - } - // Prepare to look up fields in the source by index. Also check for // source fields that don't match any field in the destination. Map src_field_indexes; if (src_type.fields_id != dest_type.fields_id) { + Set dest_field_names; + for (auto field : dest_elem_fields) { + dest_field_names.Insert(field.name_id); + } + for (auto [i, field] : llvm::enumerate(src_elem_fields)) { if (!dest_field_names.Lookup(field.name_id)) { if (target.diagnose) { diff --git a/toolchain/check/facet_type.cpp b/toolchain/check/facet_type.cpp index 39f590299a10..2e14d63ddc5a 100644 --- a/toolchain/check/facet_type.cpp +++ b/toolchain/check/facet_type.cpp @@ -550,7 +550,7 @@ auto FindWhere(Context& context, SemIR::ConstantId const_id) -> bool { private: bool* found_; - Set searched_; + Set searched_; }; if (!const_id.is_constant()) { diff --git a/toolchain/check/scope_stack.h b/toolchain/check/scope_stack.h index 07c12991ee25..ac4585bb71d2 100644 --- a/toolchain/check/scope_stack.h +++ b/toolchain/check/scope_stack.h @@ -359,7 +359,7 @@ class ScopeStack { // Names which are registered with lexical_lookup_, and will need to be // unregistered when the scope ends. - Set names = {}; + Set names = {}; }; // A scope in which `return` can be used. diff --git a/toolchain/lower/BUILD b/toolchain/lower/BUILD index e4537d4763c4..e119cbb03b54 100644 --- a/toolchain/lower/BUILD +++ b/toolchain/lower/BUILD @@ -69,6 +69,7 @@ cc_library( "//common:map", "//common:pretty_stack_trace_function", "//common:raw_string_ostream", + "//common:set", "//common:vlog", "//toolchain/base:fixed_size_value_store", "//toolchain/base:kind_switch", diff --git a/toolchain/lower/specific_coalescer.cpp b/toolchain/lower/specific_coalescer.cpp index 553a86313595..40582bc232a4 100644 --- a/toolchain/lower/specific_coalescer.cpp +++ b/toolchain/lower/specific_coalescer.cpp @@ -59,7 +59,7 @@ auto SpecificCoalescer::CoalesceEquivalentSpecifics( continue; } - Set> + Set, 16> visited_equivalent_specifics; InsertPair(specifics[i], specifics[j], visited_equivalent_specifics); // Function type information matches; check usages inside the function @@ -205,7 +205,7 @@ auto SpecificCoalescer::AreFunctionTypesEquivalent( auto SpecificCoalescer::AreFunctionBodiesEquivalent( SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2, - Set>& + SetBase>& visited_equivalent_specifics) -> bool { llvm::SmallVector> worklist; worklist.push_back({specific_id1, specific_id2}); @@ -251,7 +251,7 @@ auto SpecificCoalescer::AreFunctionBodiesEquivalent( auto SpecificCoalescer::InsertPair( SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2, - Set>& set_of_pairs) + SetBase>& set_of_pairs) -> bool { if (specific_id1.index > specific_id2.index) { std::swap(specific_id1.index, specific_id2.index); @@ -263,7 +263,7 @@ auto SpecificCoalescer::InsertPair( auto SpecificCoalescer::ContainsPair( SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2, - const Set>& set_of_pairs) + SetView> set_of_pairs) -> bool { if (specific_id1.index > specific_id2.index) { std::swap(specific_id1.index, specific_id2.index); diff --git a/toolchain/lower/specific_coalescer.h b/toolchain/lower/specific_coalescer.h index 7f627b43b04a..c8a716b0a73b 100644 --- a/toolchain/lower/specific_coalescer.h +++ b/toolchain/lower/specific_coalescer.h @@ -5,6 +5,7 @@ #ifndef CARBON_TOOLCHAIN_LOWER_SPECIFIC_COALESCER_H_ #define CARBON_TOOLCHAIN_LOWER_SPECIFIC_COALESCER_H_ +#include "common/set.h" #include "llvm/Support/BLAKE3.h" #include "toolchain/lower/context.h" #include "toolchain/sem_ir/ids.h" @@ -87,7 +88,7 @@ class SpecificCoalescer { // found, if the two specifics given as arguments are found to be equivalent. auto AreFunctionBodiesEquivalent( SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2, - Set>& + SetBase>& visited_equivalent_specifics) -> bool; // Given an equivalent pair of specifics, updates the canonical specific to @@ -118,13 +119,13 @@ class SpecificCoalescer { // checks entry already existed if it cannot be inserted. auto InsertPair( SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2, - Set>& set_of_pairs) + SetBase>& set_of_pairs) -> bool; // Checks if a pair is contained into a set of pairs, in canonical form. auto ContainsPair( SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2, - const Set>& set_of_pairs) + SetView> set_of_pairs) -> bool; // The optional vlog stream. @@ -154,7 +155,7 @@ class SpecificCoalescer { // Non-equivalent specifics found. // TODO: Revisit this due to its quadratic space growth. - Set> + Set, 16> non_equivalent_specifics_; };