Support for type-checking and lowering method calls. (#3343)

Adds a `BoundMethod` SemIR node to represent an `x.F` bound method, with
a new builtin type `BoundMethodType`. Reorganized conversion of call
expression arguments to also check and convert a `self` parameter in the
implicit parameters list.

In passing, improved diagnostics and error recovery for bad call
expressions. We now build a `call` node with the appropriate type and
value category, but with invalid arguments, if the argument conversion
failed, and diagnose calls to non-callable expressions.

`addr self` methods don't work properly yet; the `addr` is ignored for
now.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard Smith
2023-10-27 20:41:13 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent c3e5721886
commit 57f3c553b8
29 changed files with 493 additions and 165 deletions
+12
View File
@@ -78,6 +78,18 @@ auto FunctionContext::CreateSyntheticBlock() -> llvm::BasicBlock* {
return synthetic_block_;
}
auto FunctionContext::GetLocalOrGlobal(SemIR::NodeId node_id) -> llvm::Value* {
auto target = sem_ir().nodes().Get(node_id);
if (auto function_decl = target.TryAs<SemIR::FunctionDeclaration>()) {
return GetFunction(function_decl->function_id);
}
if (auto class_type = target.TryAs<SemIR::ClassType>()) {
return GetTypeAsValue();
}
// TODO: Handle other kinds of name references to globals.
return GetLocal(node_id);
}
auto FunctionContext::FinishInitialization(SemIR::TypeId type_id,
SemIR::NodeId dest_id,
SemIR::NodeId source_id) -> void {