Files
carbon-lang/toolchain/check/handle.h
T
Richard Smith 2472f44e44 Track pending thunks on the deferred definition worklist. (#5609)
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.
2025-06-10 22:09:31 +00:00

37 lines
1.5 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_HANDLE_H_
#define CARBON_TOOLCHAIN_CHECK_HANDLE_H_
#include "toolchain/check/context.h"
#include "toolchain/check/deferred_definition_worklist.h"
#include "toolchain/check/function.h"
#include "toolchain/parse/node_ids.h"
namespace Carbon::Check {
// Parse node handlers. Returns false for unrecoverable errors.
#define CARBON_PARSE_NODE_KIND(Name) \
auto HandleParseNode(Context& context, Parse::Name##Id node_id) -> bool;
#include "toolchain/parse/node_kind.def"
// Handle suspending the definition of a function. This is used for inline
// methods, which are processed out of the normal lexical order. This plus
// HandleFunctionDefinitionResume carry out the same actions as
// HandleFunctionDefinitionStart, except that the various context stacks are
// cleared out in between.
auto HandleFunctionDefinitionSuspend(Context& context,
Parse::FunctionDefinitionStartId node_id)
-> DeferredDefinitionWorklist::SuspendedFunction;
// Handle resuming the definition of a function, after a previous suspension.
auto HandleFunctionDefinitionResume(
Context& context, Parse::FunctionDefinitionStartId node_id,
DeferredDefinitionWorklist::SuspendedFunction&& suspended_fn) -> void;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_HANDLE_H_