Files
Nathaniel Shead 400e3b66b7 c++: modules and coroutines
While working on another issue I found that currently modules do not
work with coroutines at all.  This patch fixes a number of issues in
both the coroutines logic and modules logic to ensure that they play
well together.  To summarize:

- The coroutine proxy objects did not have a DECL_CONTEXT set (required
  for modules to merge declarations).

- The coroutine transformation functions are always non-inline, even
  for an inline ramp function, which means that modules need an override
  to ensure the definitions are available where needed.

- Coroutine transformation functions were not marked DECL_COROUTINE_P,
  despite accessors implying that they were.

- In an importing TU we had lost the connection between the ramp
  functions and the transform functions, as they were kept in a pair
  of global maps.

- Modules streaming couldn't discriminate between the actor or destroy
  functions when merging.

- Modules streaming wasn't setting the cfun->coroutine_component flag,
  needed to activate the middle-end coroutine lowering pass.

This patch also separates the coroutine_info_table initialization from
the ensure_coro_initialized function.  If the first time we see a
coroutine is from a module import, we need to register the
transformation functions now but calling ensure_coro_initialized would
lookup e.g. std::coroutine_traits, which may only be visible from this
module that we're currently reading, causing a recursive load.
Separating the concerns allows this to work correctly.

gcc/cp/ChangeLog:

	* coroutines.cc (create_coroutine_info_table): New function.
	(get_or_insert_coroutine_info): Mark static.
	(ensure_coro_initialized): Likewise; use
	create_coroutine_info_table.
	(coro_promise_type_found_p): Set DECL_CONTEXT for proxies.
	(coro_set_ramp_function): New function.
	(coro_set_transform_functions): New function.
	(coro_build_actor_or_destroy_function): Use
	coro_set_ramp_function, mark as DECL_COROUTINE_P.
	* cp-tree.h (coro_set_transform_functions): Declare.
	(coro_set_ramp_function): Declare.
	* module.cc (struct merge_key): New field coro_disc.
	(dumper::impl::nested_name): Distinguish coroutine transform
	functions.
	(get_coroutine_discriminator): New function.
	(trees_out::key_mergeable): Stream coroutine discriminator.
	(check_mergeable_decl): Adjust comment, check for matching
	coroutine discriminator.
	(trees_in::key_mergeable): Read coroutine discriminator.
	(has_definition): Override for coroutine transform functions.
	(trees_out::write_function_def): Stream linked ramp, actor, and
	destroy functions for coroutines.
	(trees_in::read_function_def): Read them.
	(module_state::read_cluster): Set cfun->coroutine_component.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/coro-1_a.C: New test.
	* g++.dg/modules/coro-1_b.C: New test.

Reviewed-by: Iain Sandoe <iain@sandoe.co.uk>
Reviewed-by: Jason Merrill <jason@redhat.com>
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2026-01-14 08:52:14 +11:00
..
2025-09-04 17:42:47 +10:00
2025-09-04 17:42:47 +10:00
2025-09-04 17:42:47 +10:00
2025-09-04 17:42:47 +10:00
2025-09-04 17:42:47 +10:00
2025-09-04 17:42:47 +10:00
2025-09-04 17:42:47 +10:00
2025-09-04 17:42:47 +10:00
2025-09-04 17:42:47 +10:00
2025-09-04 17:42:47 +10:00
2025-11-03 21:32:26 +03:00
2025-11-03 21:32:26 +03:00
2026-01-14 08:52:14 +11:00
2026-01-14 08:52:14 +11:00
2026-01-02 09:56:11 +01:00
2025-11-15 11:41:56 +05:30
2025-11-15 11:41:56 +05:30