From 0085e0effc1d7787018ea98bde788e535e222ad2 Mon Sep 17 00:00:00 2001 From: danakj Date: Thu, 4 Dec 2025 11:04:32 -0500 Subject: [PATCH] comment --- toolchain/sem_ir/facet_type_info.cpp | 4 ++++ toolchain/sem_ir/facet_type_info.h | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/toolchain/sem_ir/facet_type_info.cpp b/toolchain/sem_ir/facet_type_info.cpp index fe216e8bd692c..485684b05b1f2 100644 --- a/toolchain/sem_ir/facet_type_info.cpp +++ b/toolchain/sem_ir/facet_type_info.cpp @@ -267,6 +267,10 @@ auto AddCanonicalWitnessesBlock(File& sem_ir, CARBON_FATAL("Unhandled inst: {0}", inst); } } + // This matches the sort order of IdentifiedFacetType::required_interfaces, + // which is the order of the witnesses returned from impl lookup, and is + // canonical order in which the witnesses must appear for a given facet type + // so that ImplWitnessAccess can find the appropriate witness. llvm::sort(sortable, [](auto& lhs, auto& rhs) { return ImplsLess(lhs.first, rhs.first); }); diff --git a/toolchain/sem_ir/facet_type_info.h b/toolchain/sem_ir/facet_type_info.h index 3833a16973e69..e1ff319e88eea 100644 --- a/toolchain/sem_ir/facet_type_info.h +++ b/toolchain/sem_ir/facet_type_info.h @@ -213,9 +213,11 @@ inline auto CarbonHashValue(const FacetTypeInfo& value, uint64_t seed) return static_cast(hasher); } -// Given an array of witnesses, sorts them to match the FacetTypeInfo ordering -// and returns the resulting block ID. This assumes witnesses have already been -// deduplicated, because it's mainly for imports. +// Given an array of witnesses, sorts them to match the ordering of the specific +// interfaces in the IdentifiedFacetType that produced the witness set, which is +// the canonical witness order, and returns the resulting block ID. This assumes +// witnesses have already been deduplicated, and do not contain errors, because +// it's mainly for imports. auto AddCanonicalWitnessesBlock(File& sem_ir, llvm::SmallVector& witnesses) -> InstBlockId;