Reverse nesting of BoundMethod and SpecificFunction. (#5079)

During SemIR, when identifying a specific in a specific context, we'd
have to either look through a specific or through a bound method.
Canonicalize which one to look through first, by having the BoundMethod
created around a SpecificFunction instead.
This changes a lot of check tests.

TODO: As the SemIr does not currently allow removal (access to insts()
is intentionally const), the bound instruction created prior to finding
the specific is not removed from the instructions.
Options: (1) leave as is, (2) add a way to remove the previous bound,
(3) rethink how/when the BoundMethod inst is created.
This commit is contained in:
Alina Sbirlea
2025-03-08 01:34:06 +00:00
committed by GitHub
parent 820ace95e8
commit 7fd54eded0
165 changed files with 2795 additions and 1958 deletions
+5 -5
View File
@@ -18,6 +18,11 @@ auto GetCalleeFunction(const File& sem_ir, InstId callee_id,
.self_type_id = InstId::None,
.self_id = InstId::None,
.is_error = false};
if (auto bound_method = sem_ir.insts().TryGetAs<BoundMethod>(callee_id)) {
result.self_id = bound_method->object_id;
callee_id = bound_method->function_decl_id;
}
if (specific_id.has_value()) {
callee_id = sem_ir.constant_values().GetInstIdIfValid(
GetConstantValueInSpecific(sem_ir, specific_id, callee_id));
@@ -31,11 +36,6 @@ auto GetCalleeFunction(const File& sem_ir, InstId callee_id,
callee_id = specific_function->callee_id;
}
if (auto bound_method = sem_ir.insts().TryGetAs<BoundMethod>(callee_id)) {
result.self_id = bound_method->object_id;
callee_id = bound_method->function_decl_id;
}
// Identify the function we're calling by its type.
auto val_id = sem_ir.constant_values().GetConstantInstId(callee_id);
if (!val_id.has_value()) {