Add well-known identifier caching (#6486)

I'm doing this because I figured it'd be an incremental improvement for
all the operator lookups that we do. Even to the extent that we've
discussed witness caching, I think it'll still apply. It does add one
more step to adding new interfaces (before, you'd just write the string,
now you add it to the def file and reference it).

I'll claim it makes GetClangOperatorKind a lot friendlier to read/edit,
nevermind removing the string comparisons. :)
This commit is contained in:
Jon Ross-Perkins
2025-12-11 21:41:47 +00:00
committed by GitHub
parent a848ae11e4
commit c0b335b87f
19 changed files with 482 additions and 239 deletions
+8 -6
View File
@@ -15,6 +15,7 @@
#include "toolchain/check/action.h"
#include "toolchain/check/context.h"
#include "toolchain/check/control_flow.h"
#include "toolchain/check/core_identifier.h"
#include "toolchain/check/diagnostic_helpers.h"
#include "toolchain/check/eval.h"
#include "toolchain/check/impl_lookup.h"
@@ -1367,7 +1368,8 @@ static auto PerformCopy(Context& context, SemIR::InstId expr_id,
}
auto copy_id = BuildUnaryOperator(
context, SemIR::LocId(expr_id), {"Copy"}, expr_id, [&] {
context, SemIR::LocId(expr_id), {.interface_name = CoreIdentifier::Copy},
expr_id, [&] {
if (!target.diagnose) {
return context.emitter().BuildSuppressed();
}
@@ -1407,14 +1409,14 @@ static auto ConvertValueForCppThunkRef(Context& context, SemIR::InstId expr_id)
// Returns the Core interface name to use for a given kind of conversion.
static auto GetConversionInterfaceName(ConversionTarget::Kind kind)
-> llvm::StringLiteral {
-> CoreIdentifier {
switch (kind) {
case ConversionTarget::ExplicitAs:
return "As";
return CoreIdentifier::As;
case ConversionTarget::ExplicitUnsafeAs:
return "UnsafeAs";
return CoreIdentifier::UnsafeAs;
default:
return "ImplicitAs";
return CoreIdentifier::ImplicitAs;
}
}
@@ -1559,7 +1561,7 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
Operator op = {
.interface_name = GetConversionInterfaceName(target.kind),
.interface_args_ref = interface_args,
.op_name = "Convert",
.op_name = CoreIdentifier::Convert,
};
expr_id = BuildUnaryOperator(context, loc_id, op, expr_id, [&] {
if (!target.diagnose) {