Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

derive: Add base for builtin derives and #[derive(Clone)] #2216

Merged
merged 2 commits into from Jun 1, 2023

Conversation

CohenArthur
Copy link
Member

This PR adds basic support for builtin derive macros and, more specifically, deriving Clone on some simple structures (tuple structs and empty structs). Keeping it as a draft as it still needs some work. Needs #2214

std::unique_ptr<Expr>
DeriveClone::clone_call (std::unique_ptr<Expr> &&to_clone)
{
// ::core::clone::Clone::clone for the fully qualified path - we don't link
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's $crate::clone::Clone::clone, the pretty printing from rustc prints $crate as the appropriate crate name.

@CohenArthur CohenArthur force-pushed the base-builtin-derive branch 2 times, most recently from 13c1948 to e5079a7 Compare May 25, 2023 12:53
@CohenArthur CohenArthur marked this pull request as ready for review May 25, 2023 12:53
@CohenArthur CohenArthur requested review from matthewjasper, philberty and P-E-P and removed request for matthewjasper May 25, 2023 12:53
{
auto new_item
= derive_item (item, attr, maybe_builtin->second);
// this inserts the derive *before* the item - is it a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rustc inserts the functions after the item

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be an issue, but we'll see in the future if it arises. it's not too hard of a fix either way :)

gcc/rust/util/rust-hir-map.cc Outdated Show resolved Hide resolved
gcc/rust/expand/rust-derive-clone.cc Outdated Show resolved Hide resolved
gcc/rust/ChangeLog:

	* ast/rust-ast-builder.cc: New file.
	* ast/rust-ast-builder.h: New file.
gcc/rust/ChangeLog:

	* Make-lang.in: Add new object files to Makefile.
	* expand/rust-expand-visitor.cc (is_derive): Move function.
	(is_builtin): Likewise.
	(get_traits_to_derive): New function.
	(derive_item): Likewise.
	(ExpandVisitor::visit): Visit item/statements containers.
	(ExpandVisitor::visit_outer_attrs): Take a reference on the attribute
	instead of a copy.
	(ExpandVisitor::is_derive): Deleted function.
	(ExpandVisitor::is_builtin): Likewise.
	* expand/rust-expand-visitor.h (RUST_EXPAND_VISITOR_H): Add missing #ifdef
	guards.
	(is_derive): Declare function.
	(is_builtin): Likewise.
	* expand/rust-macro-builtins.cc (builtin_macro_from_string): Use new
	MacroBuiltin::builtins map.
	(make_macro_path_str): Likewise.
	* expand/rust-macro-builtins.h (enum class): Add builtin derive macros.
	* expand/rust-derive-clone.cc: New file.
	* expand/rust-derive-clone.h: New file.
	* expand/rust-derive.cc: New file.
	* expand/rust-derive.h: New file.
	* util/rust-hir-map.cc (Mappings::insert_macro_def): Fix logic for
	setting builtin macro transcribers.

gcc/testsuite/ChangeLog:

	* rust/compile/macro43.rs: Fix test with new derive macros.
	* rust/compile/derive_macro1.rs: New test.
	* rust/compile/derive_macro3.rs: New test.
	* rust/execute/torture/derive_macro1.rs: New test.
	* rust/execute/torture/derive_macro3.rs: New test.
@CohenArthur CohenArthur added this pull request to the merge queue Jun 1, 2023
Merged via the queue into Rust-GCC:master with commit 1eef155 Jun 1, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants