Skip to content

Commit 0cafb8f

Browse files
authored
Store the CppOverloadSetId on CalleeFunction. (#6067)
1 parent ccca7f3 commit 0cafb8f

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

toolchain/check/call.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id,
299299
if (callee_function.is_error) {
300300
return SemIR::ErrorInst::InstId;
301301
}
302-
if (callee_function.is_cpp_overload_set) {
303-
auto resolved_fn_id =
304-
PerformCppOverloadResolution(context, loc_id, callee_id, arg_ids);
302+
if (callee_function.cpp_overload_set_id.has_value()) {
303+
auto resolved_fn_id = PerformCppOverloadResolution(
304+
context, loc_id, callee_function.cpp_overload_set_id, arg_ids);
305305
if (!resolved_fn_id) {
306306
return SemIR::ErrorInst::InstId;
307307
}
@@ -310,7 +310,7 @@ auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id,
310310
if (callee_function.is_error) {
311311
return SemIR::ErrorInst::InstId;
312312
}
313-
CARBON_CHECK(!callee_function.is_cpp_overload_set);
313+
CARBON_CHECK(!callee_function.cpp_overload_set_id.has_value());
314314
}
315315
if (callee_function.function_id.has_value()) {
316316
return PerformCallToFunction(context, loc_id, callee_id, callee_function,

toolchain/check/cpp_overload_resolution.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Carbon::Check {
1313

1414
auto PerformCppOverloadResolution(Context& context, SemIR::LocId loc_id,
15-
SemIR::InstId callee_id,
15+
SemIR::CppOverloadSetId overload_set_id,
1616
llvm::ArrayRef<SemIR::InstId> arg_ids)
1717
-> std::optional<SemIR::InstId> {
1818
Diagnostics::AnnotationScope annotate_diagnostics(
@@ -41,17 +41,8 @@ auto PerformCppOverloadResolution(Context& context, SemIR::LocId loc_id,
4141
clang::ExprValueKind::VK_LValue));
4242
}
4343

44-
auto overload_set_type =
45-
context.types()
46-
.GetAsInst(context.insts().Get(callee_id).type_id())
47-
.TryAs<SemIR::CppOverloadSetType>();
48-
// TODO: CHECK-fail or store CppOverloadSetId in the CalleeFunction and pass
49-
// it in here.
50-
if (!overload_set_type) {
51-
return std::nullopt;
52-
}
5344
const SemIR::CppOverloadSet& overload_set =
54-
context.cpp_overload_sets().Get(overload_set_type->overload_set_id);
45+
context.cpp_overload_sets().Get(overload_set_id);
5546

5647
// Add candidate functions from the name lookup.
5748
clang::OverloadCandidateSet candidate_set(

toolchain/check/cpp_overload_resolution.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define CARBON_TOOLCHAIN_CHECK_CPP_OVERLOAD_RESOLUTION_H_
77

88
#include "toolchain/check/context.h"
9+
#include "toolchain/sem_ir/ids.h"
910

1011
namespace Carbon::Check {
1112

@@ -23,7 +24,7 @@ namespace Carbon::Check {
2324
// consistency and supporting migrations so that the migrated callers from C++
2425
// remain valid.
2526
auto PerformCppOverloadResolution(Context& context, SemIR::LocId loc_id,
26-
SemIR::InstId callee_id,
27+
SemIR::CppOverloadSetId overload_set_id,
2728
llvm::ArrayRef<SemIR::InstId> arg_ids)
2829
-> std::optional<SemIR::InstId>;
2930

toolchain/sem_ir/function.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ namespace Carbon::SemIR {
1616
auto GetCalleeFunction(const File& sem_ir, InstId callee_id,
1717
SpecificId specific_id) -> CalleeFunction {
1818
CalleeFunction result = {.function_id = FunctionId::None,
19+
.cpp_overload_set_id = CppOverloadSetId::None,
1920
.enclosing_specific_id = SpecificId::None,
2021
.resolved_specific_id = SpecificId::None,
2122
.self_type_id = InstId::None,
2223
.self_id = InstId::None,
23-
.is_error = false,
24-
.is_cpp_overload_set = false};
24+
.is_error = false};
2525
if (auto bound_method = sem_ir.insts().TryGetAs<BoundMethod>(callee_id)) {
2626
result.self_id = bound_method->object_id;
2727
callee_id = bound_method->function_decl_id;
@@ -48,9 +48,8 @@ auto GetCalleeFunction(const File& sem_ir, InstId callee_id,
4848
auto fn_type_inst =
4949
sem_ir.types().GetAsInst(sem_ir.insts().Get(val_id).type_id());
5050

51-
if (fn_type_inst.TryAs<CppOverloadSetType>()) {
52-
// TODO: Consider evaluating this at runtime instead of having a field.
53-
result.is_cpp_overload_set = true;
51+
if (auto cpp_overload_set_type = fn_type_inst.TryAs<CppOverloadSetType>()) {
52+
result.cpp_overload_set_id = cpp_overload_set_type->overload_set_id;
5453
return result;
5554
}
5655

toolchain/sem_ir/function.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ class File;
188188
struct CalleeFunction : public Printable<CalleeFunction> {
189189
// The function. `None` if not a function.
190190
FunctionId function_id;
191+
// The overload set, if this is a C++ overload set rather than a function.
192+
CppOverloadSetId cpp_overload_set_id;
191193
// The specific that contains the function.
192194
SpecificId enclosing_specific_id;
193195
// The specific for the callee itself, in a resolved call.
@@ -199,13 +201,15 @@ struct CalleeFunction : public Printable<CalleeFunction> {
199201
InstId self_id;
200202
// True if an error instruction was found.
201203
bool is_error;
202-
// True if the function is a C++ overload set.
203-
// TODO: Store the CppOverloadSetId instead of a bool.
204-
bool is_cpp_overload_set;
205204

206205
auto Print(llvm::raw_ostream& out) const -> void {
207-
out << "{function_id: " << function_id
208-
<< ", enclosing_specific_id: " << enclosing_specific_id
206+
out << "{";
207+
if (cpp_overload_set_id.has_value()) {
208+
out << "cpp_overload_set_id: " << cpp_overload_set_id;
209+
} else {
210+
out << "function_id: " << function_id;
211+
}
212+
out << ", enclosing_specific_id: " << enclosing_specific_id
209213
<< ", resolved_specific_id: " << resolved_specific_id
210214
<< ", self_type_id: " << self_type_id << ", self_id: " << self_id
211215
<< ", is_error: " << is_error << "}";

0 commit comments

Comments
 (0)