Defer building thunks until the end of the enclosing definition. (#5403)

Instead of building the definition of a thunk immediately when we
generate the thunk declaration, wait until we reach the `}` of the
outermost class, interface, etc. -- at the same time when we would parse
the definition of the thunk if it were defined inline.

This fixes issues where we fail to define the thunk because it requires
an enclosing class to be complete, or its definition depends on
something declared later in the enclosing class.

Make the representation of a suspended function scope, and its
constituent suspended components, be move-only, and switch to passing it
around by rvalue reference instead of by value because it's expensive
both to move and especially to copy.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard Smith
2025-05-07 22:20:39 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 6f32a003d2
commit e060342411
21 changed files with 629 additions and 259 deletions
+1 -1
View File
@@ -108,7 +108,7 @@ auto DeclNameStack::Suspend() -> SuspendedName {
return result;
}
auto DeclNameStack::Restore(SuspendedName sus) -> void {
auto DeclNameStack::Restore(SuspendedName&& sus) -> void {
// The parent state must be the same when a name is restored.
CARBON_CHECK(context_->scope_stack().PeekIndex() ==
sus.name_context.initial_scope_index,