mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Make FacetAccessType evaluate to SymbolicBindingType for type-of a BindSymbolicName (#6115)
The SymbolicBindingType refers to the type value that will be substituted in for the BindSymbolicName, but holds onto the EntityNameId from the BindSymbolicName instead of (or in addition to, for now) the instruction. The EntityNameId will be used to look in the ScopeStack to find the witnesses either from the BindSymbolicName instruction, or other instructions that specify `impls` constraints against the EntityName. This will allow us to have the `T` in `I(T)` resolve to a `.Self` reference in the type so that we get type equality with the binding's type: `T:! I(.Self)`.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "toolchain/sem_ir/copy_on_write_block.h"
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
#include "toolchain/sem_ir/inst.h"
|
||||
#include "toolchain/sem_ir/typed_insts.h"
|
||||
|
||||
namespace Carbon::Check {
|
||||
|
||||
@@ -423,6 +424,27 @@ class SubstConstantCallbacks final : public SubstInstCallbacks {
|
||||
return SubstResult::FullySubstituted;
|
||||
}
|
||||
|
||||
// A symbolic binding `as type` contains the EntityNameId of that symbolic
|
||||
// binding. If it matches a substitution, then we want to point the
|
||||
// EntityNameId to the substitution facet value.
|
||||
if (auto bind =
|
||||
context().insts().TryGetAs<SemIR::SymbolicBindingType>(inst_id)) {
|
||||
auto& entity_name = context().entity_names().Get(bind->entity_name_id);
|
||||
|
||||
for (auto [bind_index, replacement_id] : substitutions_) {
|
||||
if (entity_name.bind_index() == bind_index) {
|
||||
auto replacement_inst_id =
|
||||
context().constant_values().GetInstId(replacement_id);
|
||||
inst_id = RebuildNewInst<SemIR::FacetAccessType>(
|
||||
loc_id_, {
|
||||
.type_id = SemIR::TypeType::TypeId,
|
||||
.facet_value_inst_id = replacement_inst_id,
|
||||
});
|
||||
return SubstResult::FullySubstituted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto entity_name_id = SemIR::EntityNameId::None;
|
||||
if (auto bind =
|
||||
context().insts().TryGetAs<SemIR::BindSymbolicName>(inst_id)) {
|
||||
@@ -435,12 +457,13 @@ class SubstConstantCallbacks final : public SubstInstCallbacks {
|
||||
return SubstResult::SubstOperands;
|
||||
}
|
||||
|
||||
auto& entity_name = context().entity_names().Get(entity_name_id);
|
||||
|
||||
// This is a symbolic binding. Check if we're substituting it.
|
||||
// TODO: Consider building a hash map for substitutions. We might have a
|
||||
// lot of them.
|
||||
for (auto [bind_index, replacement_id] : substitutions_) {
|
||||
if (context().entity_names().Get(entity_name_id).bind_index() ==
|
||||
bind_index) {
|
||||
if (entity_name.bind_index() == bind_index) {
|
||||
// This is the binding we're replacing. Perform substitution.
|
||||
inst_id = context().constant_values().GetInstId(replacement_id);
|
||||
return SubstResult::FullySubstituted;
|
||||
|
||||
Reference in New Issue
Block a user