mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Facet types support rewrite (where .A =...) constraints (#4613)
* Rewrite constraints are stored in a facet type, substituted, imported, and formatted. * We now distinguish `.Self` from other symbolic bindings in two ways: * `.Self` itself now has an invalid compile time binding index (since it doesn't bind to any of the generic parameters). As a result, we no longer need to create a generic region in `handle_where.cpp`. * There is a new phase tracking values that are only symbolic because they transitively depend on `.Self`. This allows us to give the result of a `where` expression template phase as long as it doesn't use any symbolic constants other than `.Self` or other designators. * `AddConstant` has been removed from `check/context` since it was only used from `eval`. This meant less plumbing of the phase change. * Evaluation of `BindSymbolicName` now also performs substitution into its type. * Include a bit more information in some diagnostics. * `StringifyTypeExpr` outputs rewrites, which required adding support for associated entities as well. * Associated entities now have an entity name set when importing. * Adds tests for some interesting cases with rewrites and uses of `.Self` mixed with other symbolic constants. Still to do: * There is no validation that any particular type satisfies rewrite constraints. * Access to members of a facet type do not see the rewritten values. * Impls don't recognize whether associated constants have rewrites setting their values. * No support for resolving facet types. --------- Co-authored-by: Josh L <josh11b@users.noreply.github.com> Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Josh L
Richard Smith
parent
dc5edb88fb
commit
33110d096c
@@ -115,7 +115,8 @@ auto Context::FinishInst(SemIR::InstId inst_id, SemIR::Inst inst) -> void {
|
||||
|
||||
// If the instruction has a symbolic constant type, track that we need to
|
||||
// substitute into it.
|
||||
if (types().GetConstantId(inst.type_id()).is_symbolic()) {
|
||||
if (constant_values().DependsOnGenericParameter(
|
||||
types().GetConstantId(inst.type_id()))) {
|
||||
dep_kind |= GenericRegionStack::DependencyKind::SymbolicType;
|
||||
}
|
||||
|
||||
@@ -128,7 +129,7 @@ auto Context::FinishInst(SemIR::InstId inst_id, SemIR::Inst inst) -> void {
|
||||
|
||||
// If the constant value is symbolic, track that we need to substitute into
|
||||
// it.
|
||||
if (const_id.is_symbolic()) {
|
||||
if (constant_values().DependsOnGenericParameter(const_id)) {
|
||||
dep_kind |= GenericRegionStack::DependencyKind::SymbolicConstant;
|
||||
}
|
||||
}
|
||||
@@ -1281,7 +1282,7 @@ auto Context::TryToDefineType(SemIR::TypeId type_id,
|
||||
ResolveSpecificDefinition(*this, interface.specific_id);
|
||||
}
|
||||
}
|
||||
// TODO: Process other requirements.
|
||||
// TODO: Finish facet type resolution.
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1304,9 +1305,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 = 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}},
|
||||
.other_requirements = false});
|
||||
return {.type_id = SemIR::TypeId::TypeType, .facet_type_id = facet_type_id};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user