Skip to content

Commit 66a28e9

Browse files
committed
facetaccesstype-roundtrip
1 parent 412d911 commit 66a28e9

File tree

2 files changed

+401
-63
lines changed

2 files changed

+401
-63
lines changed

toolchain/check/convert.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,11 +1211,26 @@ static auto PerformBuiltinConversion(
12111211

12121212
if (auto facet_access_type_inst =
12131213
sem_ir.insts().TryGetAs<SemIR::FacetAccessType>(const_value_id)) {
1214-
// Conversion from a `FacetAccessType` to a `FacetValue` of the target
1215-
// `FacetType` if the instruction in the `FacetAccessType` is of a
1216-
// `FacetType` that satisfies the requirements of the target `FacetType`.
1217-
// If the `FacetType` exactly matches the target `FacetType` then we can
1218-
// shortcut and use that value, and avoid impl lookup.
1214+
// Lossless round trips through a FacetAccessType when converting back to
1215+
// the type of its original facet value.
1216+
//
1217+
// Given a symbolic facet value X, if a FacetAccessType(X) is converted to
1218+
// the type of X, we make the past introduction of the FacetAccessType
1219+
// preserve the original facet value by converting back into that original
1220+
// facet value. This is only needed when the (facet type) types match
1221+
// exactly, which allows the result to have equality with the original
1222+
// facet value.
1223+
//
1224+
// ```
1225+
// fn F(A:! Interface, B:! A) {
1226+
// // typeof(B) is a FacetAccessType(A). We want the following to be
1227+
// // true:
1228+
// (typeof(B) as typeof(A)) == A;
1229+
// }
1230+
// ```
1231+
//
1232+
// See also test:
1233+
// facet_access_type_converts_back_to_original_facet_value.carbon
12191234
auto facet_value_inst_id = facet_access_type_inst->facet_value_inst_id;
12201235
if (sem_ir.insts().Get(facet_value_inst_id).type_id() == target.type_id) {
12211236
return facet_value_inst_id;

0 commit comments

Comments
 (0)