@@ -1211,11 +1211,26 @@ static auto PerformBuiltinConversion(
1211
1211
1212
1212
if (auto facet_access_type_inst =
1213
1213
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
1219
1234
auto facet_value_inst_id = facet_access_type_inst->facet_value_inst_id ;
1220
1235
if (sem_ir.insts ().Get (facet_value_inst_id).type_id () == target.type_id ) {
1221
1236
return facet_value_inst_id;
0 commit comments