Provide the callee expression to the Call node. (#3291)

Track the callee expression in full, instead of only tracking the
callee's FunctionId. This results in the `name_reference` denoting the
function actually being used.

Lowering now propagates a `llvm::Function*` as the value associated with
expressions of type `<function>`.

We were not creating `NameReference` node for names produced by member
access into a namespace, such as the second name in
`Namespace.Function`, which caused lowering of calls to such names to
fail. This is now fixed, but the resulting `NameReference` node only
refers to the name and the lookup result, not to the `Namespace.`
qualifier. We'll need to decide how to fit a third operand into that
node (perhaps we can stop storing the `name_id`, since it can be derived
from the lookup result) but for now the qualifier is not tracked.
This commit is contained in:
Richard Smith
2023-10-13 22:06:23 +00:00
committed by GitHub
parent c61b6a0e1d
commit 1ae5fe0cd5
43 changed files with 110 additions and 101 deletions
+7 -7
View File
@@ -14,16 +14,16 @@ auto HandleCallExpression(Context& context, Parse::Node parse_node) -> bool {
context.ParamOrArgEndNoPop(Parse::NodeKind::CallExpressionStart);
// TODO: Convert to call expression.
auto [call_expr_parse_node, name_id] =
auto [call_expr_parse_node, callee_id] =
context.node_stack()
.PopWithParseNode<Parse::NodeKind::CallExpressionStart>();
auto name_node =
context.semantics_ir().GetNode(context.FollowNameReferences(name_id));
auto function_name = name_node.TryAs<SemIR::FunctionDeclaration>();
auto callee_node =
context.semantics_ir().GetNode(context.FollowNameReferences(callee_id));
auto function_name = callee_node.TryAs<SemIR::FunctionDeclaration>();
if (!function_name) {
// TODO: Work on error.
context.TODO(parse_node, "Not a callable name");
context.node_stack().Push(parse_node, name_id);
context.node_stack().Push(parse_node, callee_id);
context.ParamOrArgPop();
return true;
}
@@ -50,14 +50,14 @@ auto HandleCallExpression(Context& context, Parse::Node parse_node) -> bool {
// Convert the arguments to match the parameters.
auto refs_id = context.ParamOrArgPop();
if (!ConvertCallArgs(context, call_expr_parse_node, refs_id,
name_node.parse_node(), callable.param_refs_id,
callee_node.parse_node(), callable.param_refs_id,
callable.return_slot_id.is_valid())) {
context.node_stack().Push(parse_node, SemIR::NodeId::BuiltinError);
return true;
}
auto call_node_id = context.AddNode(
SemIR::Call(call_expr_parse_node, type_id, refs_id, function_id));
SemIR::Call(call_expr_parse_node, type_id, callee_id, refs_id));
context.node_stack().Push(parse_node, call_node_id);
return true;