mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
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.
This commit is contained in:
@@ -585,7 +585,7 @@ static auto HandleFunctionDefinitionAfterSignature(
|
||||
|
||||
auto HandleFunctionDefinitionSuspend(Context& context,
|
||||
Parse::FunctionDefinitionStartId node_id)
|
||||
-> SuspendedFunction {
|
||||
-> DeferredDefinitionWorklist::SuspendedFunction {
|
||||
// Process the declaration portion of the function.
|
||||
auto [function_id, decl_id] =
|
||||
BuildFunctionDecl(context, node_id, /*is_definition=*/true);
|
||||
@@ -594,9 +594,9 @@ auto HandleFunctionDefinitionSuspend(Context& context,
|
||||
.saved_name_state = context.decl_name_stack().Suspend()};
|
||||
}
|
||||
|
||||
auto HandleFunctionDefinitionResume(Context& context,
|
||||
Parse::FunctionDefinitionStartId node_id,
|
||||
SuspendedFunction&& suspended_fn) -> void {
|
||||
auto HandleFunctionDefinitionResume(
|
||||
Context& context, Parse::FunctionDefinitionStartId node_id,
|
||||
DeferredDefinitionWorklist::SuspendedFunction&& suspended_fn) -> void {
|
||||
context.decl_name_stack().Restore(std::move(suspended_fn.saved_name_state));
|
||||
HandleFunctionDefinitionAfterSignature(
|
||||
context, node_id, suspended_fn.function_id, suspended_fn.decl_id);
|
||||
|
||||
Reference in New Issue
Block a user