Skip to content

Add derive proc_macro expansion stubs#2076

Merged
CohenArthur merged 7 commits into
Rust-GCC:masterfrom
P-E-P:proc_macro_stub
Apr 5, 2023
Merged

Add derive proc_macro expansion stubs#2076
CohenArthur merged 7 commits into
Rust-GCC:masterfrom
P-E-P:proc_macro_stub

Conversation

@P-E-P

@P-E-P P-E-P commented Mar 30, 2023

Copy link
Copy Markdown
Member

Add proc macros expansion stub functions.

Fixes #1986

@P-E-P

P-E-P commented Mar 30, 2023

Copy link
Copy Markdown
Member Author

I'd like some insight on 0e1d6c8 since it modifies the behavior of a widespread component.

@P-E-P P-E-P force-pushed the proc_macro_stub branch 3 times, most recently from 584ceb5 to fab1dd0 Compare April 3, 2023 09:24
P-E-P added 5 commits April 3, 2023 11:26
Add derive macros expansion stub functions.

gcc/rust/ChangeLog:

	* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Add call
	to derive expander.
	(ExpandVisitor::expand_derive): Expand a single derive.
	(ExpandVisitor::visit_attrs_with_derive): Visit an item with
	derive attributes.
	(ExpandVisitor::is_derive): Identify a derive attribute.
	* expand/rust-expand-visitor.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Add function stubs for inner attribute proc macros expansion.

gcc/rust/ChangeLog:

	* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Add call
	to inner attribute stub.
	(ExpandVisitor::expand_inner_attribute): Expand one single
	attribute.
	(ExpandVisitor::visit_inner_using_attrs): Expand a given item
	using a vector of attributes.
	(ExpandVisitor::visit_inner_attrs): Visit inner attributes of a
	given item.
	* expand/rust-expand-visitor.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
We need to retrieve outer attributes from some Expressions depending on
their context. This means this should be retrieved from their parent
node. But expr did not have a getter for outer attributes since some
expr can't have any outer attribute.

gcc/rust/ChangeLog:

	* ast/rust-ast.h: Add getter to Expr class.
	* ast/rust-expr.h: Add override attribute to existing getters.
	Also implement it for RangeExpr, attempting to retrieve outer
	attributes on those types will crash the compiler.
	* ast/rust-macro.h: Add override attribute to existing getters.
	* ast/rust-path.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Add a stub function and utility functions that should be called on some
nodes to expand attribute procedural macros.

gcc/rust/ChangeLog:

	* expand/rust-expand-visitor.cc (ExpandVisitor::expand_outer_attribute):
	Stub for a single attribute expansion.
	(ExpandVisitor::visit_outer_attrs): Visit the attributes to
	expand on a given item.
	* expand/rust-expand-visitor.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Add call to outer attribute expansion stub on required types.

gcc/rust/ChangeLog:

	* expand/rust-expand-visitor.cc (ExpandVisitor::expand_struct_fields):
	Add call to expand structu fields.
	(ExpandVisitor::expand_function_params): Add call to expand
	function parameters.
	(ExpandVisitor::expand_closure_params): Add call to expand
	closure parameters.
	(ExpandVisitor::visit): Add calls for item outer attribute
	expansions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
@P-E-P P-E-P force-pushed the proc_macro_stub branch from fab1dd0 to 4697b0f Compare April 3, 2023 09:26
@P-E-P P-E-P marked this pull request as ready for review April 3, 2023 09:26
Add a function to identify builtin attributes and skip those on proc
macro expansion phase.

gcc/rust/ChangeLog:

	* expand/rust-expand-visitor.cc (ExpandVisitor::visit_outer_attrs):
	Change condition order.
	(ExpandVisitor::visit_inner_using_attrs): Likewise.
	(ExpandVisitor::visit_attrs_with_derive): Likewise.
	(ExpandVisitor::is_builtin): Add builtin identification
	function.
	* expand/rust-expand-visitor.h: Add function prototype.
	* util/rust-attributes.cc: Add missing rustc_builtin_macro
	attribute.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
@P-E-P P-E-P force-pushed the proc_macro_stub branch from 4697b0f to 665e3e8 Compare April 3, 2023 09:47
Add additional outer attribute expansion on some expressions.

gcc/rust/ChangeLog:

	* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Add call
	to attribute expansion function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

@CohenArthur CohenArthur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good to me :) we talked with @P-E-P offline and this will require some more bits and pieces to do proper context-dependant expansion, so that for example this code

#[derive(Copy)]
struct Foo { value: i32 }

gets expanded to

struct Foo { value: i32 }

impl Copy for Foo {
    fn copy(&self) -> Self { ... }
 }

@CohenArthur CohenArthur added this pull request to the merge queue Apr 5, 2023
Merged via the queue into Rust-GCC:master with commit da41f6d Apr 5, 2023
@P-E-P P-E-P deleted the proc_macro_stub branch November 21, 2023 11:35
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.

Stubs for proc_macro expansion

2 participants