Files
carbon-lang/toolchain/check/function.h
T
Jon Ross-PerkinsandChandler Carruth b49e89e97e Add a no-op builtin function which shouldn't generate code. (#5306)
This is part of a broader plan to have noop destructor functions for
trivial destruction.

Note this emits a SemIR call (`%no_op: init %empty_tuple.type = call
%NoOp.ref() [concrete = constants.%empty_tuple]`), but not LLVM IR. My
thought was this was probably okay, since even though it'll be a little
spammy with destructor calls, the flipside is there'll probably already
be a fair amount for the name reference, and this at least shows when
the call is injected (and discarded).

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2025-04-15 00:33:39 +00:00

64 lines
2.8 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_FUNCTION_H_
#define CARBON_TOOLCHAIN_CHECK_FUNCTION_H_
#include "toolchain/check/context.h"
#include "toolchain/check/decl_name_stack.h"
#include "toolchain/check/subst.h"
#include "toolchain/sem_ir/function.h"
#include "toolchain/sem_ir/ids.h"
namespace Carbon::Check {
// State saved for a function definition that has been suspended after
// processing its declaration and before processing its body. This is used for
// inline method handling.
struct SuspendedFunction {
// The function that was declared.
SemIR::FunctionId function_id;
// The instruction ID of the FunctionDecl instruction.
SemIR::InstId decl_id;
// The declaration name information of the function. This includes the scope
// information, such as parameter names.
DeclNameStack::SuspendedName saved_name_state;
};
// Checks that `new_function` has the same parameter types and return type as
// `prev_function`, or if `prev_function_id` is specified, a specific version of
// `prev_function`. Prints a suitable diagnostic and returns false if not.
//
// `check_syntax` is false if the redeclaration can be called via a thunk with
// implicit conversions from the original declaration.
// `check_self` is false if the self declaration does not have to match (for
// instance in impls of virtual functions).
auto CheckFunctionTypeMatches(Context& context,
const SemIR::Function& new_function,
const SemIR::Function& prev_function,
SemIR::SpecificId prev_specific_id,
bool check_syntax, bool check_self) -> bool;
inline auto CheckFunctionTypeMatches(Context& context,
const SemIR::Function& new_function,
const SemIR::Function& prev_function)
-> bool {
return CheckFunctionTypeMatches(context, new_function, prev_function,
SemIR::SpecificId::None,
/*check_syntax=*/true, /*check_self=*/true);
}
// Checks that the return type of the specified function is complete, issuing an
// error if not. This computes the return slot usage for the function if
// necessary, and returns information about how the function returns its return
// value.
auto CheckFunctionReturnType(Context& context, SemIR::LocId loc_id,
const SemIR::Function& function,
SemIR::SpecificId specific_id)
-> SemIR::ReturnTypeInfo;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_FUNCTION_H_