Skip to content

Commit

Permalink
Add facet_types() accessor to Check::Context (carbon-language#4518)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh L <josh11b@users.noreply.github.com>
  • Loading branch information
josh11b and josh11b authored Nov 13, 2024
1 parent e0e3055 commit 39ed62d
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 23 deletions.
10 changes: 4 additions & 6 deletions toolchain/check/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,7 @@ auto Context::TryToDefineType(SemIR::TypeId type_id,
}

if (auto facet_type = types().TryGetAs<SemIR::FacetType>(type_id)) {
const auto& facet_type_info =
sem_ir().facet_types().Get(facet_type->facet_type_id);
const auto& facet_type_info = facet_types().Get(facet_type->facet_type_id);
for (auto interface : facet_type_info.impls_constraints) {
auto interface_id = interface.interface_id;
if (!interfaces().Get(interface_id).is_defined()) {
Expand Down Expand Up @@ -1224,10 +1223,9 @@ auto Context::GetTypeIdForTypeConstant(SemIR::ConstantId constant_id)
auto Context::FacetTypeFromInterface(SemIR::InterfaceId interface_id,
SemIR::SpecificId specific_id)
-> SemIR::FacetType {
SemIR::FacetTypeId facet_type_id =
sem_ir().facet_types().Add(SemIR::FacetTypeInfo{
.impls_constraints = {{interface_id, specific_id}},
.requirement_block_id = SemIR::InstBlockId::Invalid});
SemIR::FacetTypeId facet_type_id = facet_types().Add(SemIR::FacetTypeInfo{
.impls_constraints = {{interface_id, specific_id}},
.requirement_block_id = SemIR::InstBlockId::Invalid});
return {.type_id = SemIR::TypeId::TypeType, .facet_type_id = facet_type_id};
}

Expand Down
3 changes: 3 additions & 0 deletions toolchain/check/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ class Context {
auto interfaces() -> ValueStore<SemIR::InterfaceId>& {
return sem_ir().interfaces();
}
auto facet_types() -> CanonicalValueStore<SemIR::FacetTypeId>& {
return sem_ir().facet_types();
}
auto impls() -> SemIR::ImplStore& { return sem_ir().impls(); }
auto generics() -> SemIR::GenericStore& { return sem_ir().generics(); }
auto specifics() -> SemIR::SpecificStore& { return sem_ir().specifics(); }
Expand Down
5 changes: 2 additions & 3 deletions toolchain/check/deduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ class DeductionWorklist {
auto AddAll(SemIR::FacetTypeId params, SemIR::FacetTypeId args,
bool needs_substitution) -> void {
const auto& param_impls =
context_.sem_ir().facet_types().Get(params).impls_constraints;
const auto& arg_impls =
context_.sem_ir().facet_types().Get(args).impls_constraints;
context_.facet_types().Get(params).impls_constraints;
const auto& arg_impls = context_.facet_types().Get(args).impls_constraints;
if (param_impls.size() != arg_impls.size()) {
// TODO: Decide whether to error on this or just treat the parameter list
// as non-deduced. For now we treat it as non-deduced.
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ static auto MakeConstantForCall(EvalContext& eval_context, SemIRLoc loc,
static auto MakeFacetTypeResult(Context& context,
const SemIR::FacetTypeInfo& info, Phase phase)
-> SemIR::ConstantId {
SemIR::FacetTypeId facet_type_id = context.sem_ir().facet_types().Add(info);
SemIR::FacetTypeId facet_type_id = context.facet_types().Add(info);
return MakeConstantResult(context,
SemIR::FacetType{.type_id = SemIR::TypeId::TypeType,
.facet_type_id = facet_type_id},
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/handle_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static auto ExtendImpl(Context& context, Parse::NodeId extend_node,
return;
}
const SemIR::FacetTypeInfo& info =
context.sem_ir().facet_types().Get(facet_type->facet_type_id);
context.facet_types().Get(facet_type->facet_type_id);
for (auto interface_type : info.impls_constraints) {
auto& interface = context.interfaces().Get(interface_type.interface_id);
if (!interface.is_defined()) {
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/handle_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static auto GetIndexWithArgs(Context& context, Parse::NodeId node_id,
continue;
}
const auto& facet_type_info =
context.sem_ir().facet_types().Get(facet_type->facet_type_id);
context.facet_types().Get(facet_type->facet_type_id);
auto interface_type = facet_type_info.TryAsSingleInterface();
if (!interface_type) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ auto BuildImplWitness(Context& context, SemIR::ImplId impl_id)
return SemIR::InstId::BuiltinError;
}
const SemIR::FacetTypeInfo& facet_type_info =
context.sem_ir().facet_types().Get(facet_type->facet_type_id);
context.facet_types().Get(facet_type->facet_type_id);

auto interface = facet_type_info.TryAsSingleInterface();
if (!interface) {
Expand Down
2 changes: 1 addition & 1 deletion toolchain/check/impl_lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static auto FindAssociatedImportIRs(Context& context,
}
case SemIR::IdKind::For<SemIR::FacetTypeId>: {
const auto& facet_type_info =
context.sem_ir().facet_types().Get(SemIR::FacetTypeId(arg));
context.facet_types().Get(SemIR::FacetTypeId(arg));
for (const auto& impl : facet_type_info.impls_constraints) {
add_entity(context.interfaces().Get(impl.interface_id));
}
Expand Down
8 changes: 4 additions & 4 deletions toolchain/check/import_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ class ImportRefResolver {
}
case CARBON_KIND(SemIR::FacetType inst): {
const SemIR::FacetTypeInfo& facet_type_info =
context_.sem_ir().facet_types().Get(inst.facet_type_id);
context_.facet_types().Get(inst.facet_type_id);
// This is specifically the facet type produced by an interface
// declaration, and so should consist of a single interface.
// TODO: Will also have to handle named constraints here, once those are
Expand Down Expand Up @@ -2015,7 +2015,7 @@ class ImportRefResolver {
context_.constant_values().GetInstId(interface_const_id));
if (auto facet_type = interface_const_inst.TryAs<SemIR::FacetType>()) {
const SemIR::FacetTypeInfo& facet_type_info =
context_.sem_ir().facet_types().Get(facet_type->facet_type_id);
context_.facet_types().Get(facet_type->facet_type_id);
auto interface_type = facet_type_info.TryAsSingleInterface();
CARBON_CHECK(interface_type);
interface_id = interface_type->interface_id;
Expand Down Expand Up @@ -2095,7 +2095,7 @@ class ImportRefResolver {
context_.constant_values().GetInstId(interface_const_id));
if (auto facet_type = interface_const_inst.TryAs<SemIR::FacetType>()) {
const SemIR::FacetTypeInfo& new_facet_type_info =
context_.sem_ir().facet_types().Get(facet_type->facet_type_id);
context_.facet_types().Get(facet_type->facet_type_id);
impls_constraints.append(new_facet_type_info.impls_constraints);
} else {
auto generic_interface_type =
Expand All @@ -2109,7 +2109,7 @@ class ImportRefResolver {
}
// TODO: Also process the other requirements.
SemIR::FacetTypeId facet_type_id =
context_.sem_ir().facet_types().Add(SemIR::FacetTypeInfo{
context_.facet_types().Add(SemIR::FacetTypeInfo{
.impls_constraints = impls_constraints,
.requirement_block_id = SemIR::InstBlockId::Invalid});
return ResolveAs<SemIR::FacetType>(
Expand Down
4 changes: 2 additions & 2 deletions toolchain/check/member_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static auto GetAsLookupScope(Context& context, SemIR::LocId loc_id,
loc_id, QualifiedExprInUndefinedInterfaceScope, base_id);
});
const auto& facet_type_info =
context.sem_ir().facet_types().Get(base_as_facet_type->facet_type_id);
context.facet_types().Get(base_as_facet_type->facet_type_id);
auto base_as_interface = facet_type_info.TryAsSingleInterface();
if (base_as_interface) {
auto& interface_info =
Expand Down Expand Up @@ -184,7 +184,7 @@ static auto PerformImplLookup(
auto facet_type =
context.types().GetAs<SemIR::FacetType>(assoc_type.interface_type_id);
const auto& facet_type_info =
context.sem_ir().facet_types().Get(facet_type.facet_type_id);
context.facet_types().Get(facet_type.facet_type_id);
auto interface_type = facet_type_info.TryAsSingleInterface();
if (!interface_type) {
context.TODO(loc_id,
Expand Down
6 changes: 3 additions & 3 deletions toolchain/check/subst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static auto PushOperand(Context& context, Worklist& worklist,
break;
case SemIR::IdKind::For<SemIR::FacetTypeId>: {
const auto& facet_type_info =
context.sem_ir().facet_types().Get(SemIR::FacetTypeId(arg));
context.facet_types().Get(SemIR::FacetTypeId(arg));
for (auto interface : facet_type_info.impls_constraints) {
PushOperand(context, worklist, SemIR::IdKind::For<SemIR::SpecificId>,
interface.specific_id.index);
Expand Down Expand Up @@ -188,7 +188,7 @@ static auto PopOperand(Context& context, Worklist& worklist, SemIR::IdKind kind,
}
case SemIR::IdKind::For<SemIR::FacetTypeId>: {
const auto& old_facet_type_info =
context.sem_ir().facet_types().Get(SemIR::FacetTypeId(arg));
context.facet_types().Get(SemIR::FacetTypeId(arg));
SemIR::FacetTypeInfo new_facet_type_info = old_facet_type_info;
// Since these were added to a stack, we get them back in reverse order.
for (auto i : llvm::reverse(
Expand All @@ -199,7 +199,7 @@ static auto PopOperand(Context& context, Worklist& worklist, SemIR::IdKind kind,
new_facet_type_info.impls_constraints[i].specific_id =
SemIR::SpecificId(specific_id);
}
return context.sem_ir().facet_types().Add(new_facet_type_info).index;
return context.facet_types().Add(new_facet_type_info).index;
}
default:
return arg;
Expand Down

0 comments on commit 39ed62d

Please sign in to comment.