Compare ImplWitnessAccess into Self as canonical constants (#5883)

This makes all `.Self` references in a facet type canonically the same
(which will remain true iff they refer to the same `Self` type in the
future), removing the need to do more complex comparisons between them
using the EntityName, interface, and index. This allows the comparison
of types containing `.Self` references to be done correctly regardless
of where the `.Self` appears, as such type expressions will all be
canonically equal if they otherwise equal now, regardless of whether
they are written in the context where `.Self` could have seen different
`Self` facet types.

In order to retain access to constraints on a base `.Self` facet type,
in the case of applying `where` to an existing facet type, we:
- Give the base facet type as a `RequirementBaseFacetType` constraint so
that eval of `WhereExpr` can find and copy all the constraints off of
it.
- Introduce eager/early rewrite constraint resolution, which allows a
constraint to eagerly resolve access to earlier rewrite constraints
(`where .A = () and .B = .A` is eagerly transformed into `where .A = ()
and .B = ()`) before the full constraint resolution step. This allows
use of rewrite constraints in larger type expressions, such as `where .A
= () and .B = C(.A)` and `C` will know that the argument is `()`.
This commit is contained in:
Dana Jansens
2025-08-08 18:36:39 +00:00
committed by GitHub
parent edcc24ecf7
commit 3d77c4441b
39 changed files with 558 additions and 207 deletions
+7
View File
@@ -7,6 +7,7 @@
#include "toolchain/check/eval.h"
#include "toolchain/check/facet_type.h"
#include "toolchain/check/type_completion.h"
#include "toolchain/sem_ir/facet_type_info.h"
namespace Carbon::Check {
@@ -157,6 +158,12 @@ auto GetInterfaceType(Context& context, SemIR::InterfaceId interface_id,
FacetTypeFromInterface(context, interface_id, specific_id).facet_type_id);
}
auto GetFacetType(Context& context, const SemIR::FacetTypeInfo& info)
-> SemIR::TypeId {
return GetTypeImpl<SemIR::FacetType>(context,
context.facet_types().Add(info));
}
auto GetPointerType(Context& context, SemIR::TypeInstId pointee_type_id)
-> SemIR::TypeId {
return GetTypeImpl<SemIR::PointerType>(context, pointee_type_id);