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

Tweak ItemDecorator API #12234

Merged
merged 1 commit into from
Feb 14, 2014
Merged

Conversation

sfackler
Copy link
Member

The old method of building up a list of items and threading it through
all of the decorators was unwieldy and not really scalable as
non-deriving ItemDecorators become possible. The API is now that the
decorator gets an immutable reference to the item it's attached to, and
a callback that it can pass new items to. If we want to add syntax
extensions that can modify the item they're attached to, we can add that
later, but I think it'll have to be separate from ItemDecorator to avoid
strange ordering issues.

@huonw

@@ -233,12 +233,13 @@ pub fn expand_mod_items(module_: &ast::Mod, fld: &mut MacroExpander) -> ast::Mod
span: None
}
});
let r = dec_fn(fld.cx, attr.span, attr.node.value, items);
items.push_all(dec_fn(fld.cx, attr.span, attr.node.value, *item));
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this would be noticeably more efficient as

dec_fn(fld.cx, attr.span, attr.node.value, *item, |new| items.push(new))

after modifying ItemDecorator to take a pusher: |@Item| as the last argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure. I think that this PR keeps roughly the same allocation patterns as before.

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't mean we have to repeat them :)

@sfackler
Copy link
Member Author

@huonw updated

@huonw
Copy link
Member

huonw commented Feb 14, 2014

r=me if you update the commit message & pr description to match the fact it's passing in a callback, not returning the vector.

The old method of building up a list of items and threading it through
all of the decorators was unwieldy and not really scalable as
non-deriving ItemDecorators become possible. The API is now that the
decorator gets an immutable reference to the item it's attached to, and
a callback that it can pass new items to. If we want to add syntax
extensions that can modify the item they're attached to, we can add that
later, but I think it'll have to be separate from ItemDecorator to avoid
strange ordering issues.
bors added a commit that referenced this pull request Feb 14, 2014
The old method of building up a list of items and threading it through
all of the decorators was unwieldy and not really scalable as
non-deriving ItemDecorators become possible. The API is now that the
decorator gets an immutable reference to the item it's attached to, and
a callback that it can pass new items to. If we want to add syntax
extensions that can modify the item they're attached to, we can add that
later, but I think it'll have to be separate from ItemDecorator to avoid
strange ordering issues.

@huonw
@bors bors closed this Feb 14, 2014
@bors bors merged commit 3c02749 into rust-lang:master Feb 14, 2014
@sfackler sfackler deleted the restructure-item-decorator branch May 15, 2014 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants