mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:10:12 +01:00
Instead of using somewhat different approaches for defining in-line methods at the end of the enclosing scope and defining thunks at the end of the enclosing scope, we now use the same worklist for both. This fixes a bug where we would crash when defining thunks if there happens to be nothing else on the deferred definition worklist, leading to our leaving the enclosing impl scope before we try to define the pending thunk. That would only happen if the impl contains no in-line member function bodies, so only if the impl has only a forward declaration or a builtin declaration for every method. The latter case happens (a lot) if we start using thunks in the prelude impls. One complicating factor here is that this means the deferred definition worklist moves from the layer containing `check/handle*` and `check/check_unit.cpp` into the layer containing `check/context.cpp`. Allowing that required moving a couple of other things that it depends on -- notably `SuspendedFunction` and `HandleSuspendedFunction` -- around.
74 lines
3.4 KiB
C++
74 lines
3.4 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 {
|
|
|
|
// Returns the ID of the self parameter pattern, or None.
|
|
// TODO: Do this during initial traversal of implicit params.
|
|
auto FindSelfPattern(Context& context,
|
|
SemIR::InstBlockId implicit_param_patterns_id)
|
|
-> SemIR::InstId;
|
|
|
|
// Checks that `new_function` has the same 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. Never checks for a
|
|
// syntactic match.
|
|
auto CheckFunctionReturnTypeMatches(Context& context,
|
|
const SemIR::Function& new_function,
|
|
const SemIR::Function& prev_function,
|
|
SemIR::SpecificId prev_specific_id,
|
|
bool diagnose = true) -> bool;
|
|
|
|
// 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 diagnose = true) -> 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;
|
|
|
|
// Checks that a function declaration's signature is suitable to support a
|
|
// function definition. This requires the parameter types to be complete and the
|
|
// return type to be concrete.
|
|
auto CheckFunctionDefinitionSignature(Context& context,
|
|
SemIR::FunctionId function_id) -> void;
|
|
|
|
} // namespace Carbon::Check
|
|
|
|
#endif // CARBON_TOOLCHAIN_CHECK_FUNCTION_H_
|