Files
fdb188ccfd Implement unused pattern bindings, continued (#6518)
Implementation of unused pattern bindings #2022, continued.

Whereas previous PR #6460 took care of parsing, and PR #6479 prepared
the stage by using _ in some test cases, this PR has the the actual
implementation, using a simple dataflow analysis.

---------

Co-authored-by: Burak Emir <bqe@google.com>
Co-authored-by: jonmeow <jperkins@google.com>
2026-02-19 23:33:36 +00:00

42 lines
1.7 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_CHECK_RETURN_H_
#define CARBON_TOOLCHAIN_CHECK_RETURN_H_
#include "toolchain/check/context.h"
#include "toolchain/parse/node_ids.h"
namespace Carbon::Check {
// Gets the function that a `return` statement in the current context would
// return from.
auto GetCurrentFunctionForReturn(Context& context) -> SemIR::Function&;
// Gets the return parameter corresponding to `function`'s `returned var`.
// Returns None if the `returned var` doesn't correspond to a return parameter
// (e.g. because it doesn't have an in-place init representation).
auto GetReturnedVarParam(Context& context, const SemIR::Function& function)
-> SemIR::InstId;
// Checks a `returned var` binding and registers it as the current `returned
// var` in this scope.
auto RegisterReturnedVar(Context& context, Parse::NodeId returned_node,
Parse::NodeId type_node, SemIR::TypeId type_id,
SemIR::InstId bind_id, SemIR::NameId name_id) -> void;
// Checks and builds SemIR for a `return;` statement.
auto BuildReturnWithNoExpr(Context& context, SemIR::LocId loc_id) -> void;
// Checks and builds SemIR for a `return <expression>;` statement.
auto BuildReturnWithExpr(Context& context, SemIR::LocId loc_id,
SemIR::InstId expr_id) -> void;
// Checks and builds SemIR for a `return var;` statement.
auto BuildReturnVar(Context& context, Parse::ReturnStatementId node_id) -> void;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_RETURN_H_