Add derive proc_macro expansion stubs#2076
Merged
Merged
Conversation
Member
Author
|
I'd like some insight on 0e1d6c8 since it modifies the behavior of a widespread component. |
584ceb5 to
fab1dd0
Compare
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>
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>
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
approved these changes
Apr 5, 2023
CohenArthur
left a comment
Member
There was a problem hiding this comment.
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 { ... }
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add proc macros expansion stub functions.
Fixes #1986