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

Extended expand.rs to support alternate expansion behaviours (eg. stepwise expansion) #34811

Merged
merged 1 commit into from
Aug 12, 2016

Conversation

DanielJCampbell
Copy link
Contributor

r? nrc

@nrc
Copy link
Member

nrc commented Jul 14, 2016

r? @nrc

@rust-highfive rust-highfive assigned nrc and unassigned nikomatsakis Jul 14, 2016
@@ -43,6 +44,9 @@ trait MacroGenerable: Sized {
fn fold_with<F: Folder>(self, folder: &mut F) -> Self;
fn visit_with<V: Visitor>(&self, visitor: &mut V);

// Recursively expand this node/list of nodes using the appropriate closure in the Expander.
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain precisely when the closure is called.

@DanielJCampbell
Copy link
Contributor Author

Updated with the suggested changes - definitely looks tidier with the macros gone.

@nrc
Copy link
Member

nrc commented Jul 15, 2016

@bors: r+

@bors
Copy link
Contributor

bors commented Jul 15, 2016

📌 Commit 866da14 has been approved by nrc

@bors
Copy link
Contributor

bors commented Jul 15, 2016

⌛ Testing commit 866da14 with merge 68303be...

@alexcrichton
Copy link
Member

@bors: retry force clean

  • restarted buildbot

@jseyfried
Copy link
Contributor

jseyfried commented Jul 15, 2016

@DanielJCampbell
Could you elaborate on what you mean by "stepwise expansion"? What is the intended use case? In particular, is this intended to support a plugin or is it groundwork for future changes to the compiler?

I ask because I'm not sure how this will interact with macro modularization, which we're planning on prototyping in the next couple of weeks.

@DanielJCampbell
Copy link
Contributor Author

@jseyfried, @nrc
By stepwise I mean if you change the closures to return identity (|_, node| node|) macros only expand one step - you can feed in a crate repeatedly, and with some bookkeeping end up with a series of crates at each successive level of expansion. This is intended to support a plugin I hope to add to save analysis in the next week or two.

@nrc
Copy link
Member

nrc commented Jul 16, 2016

@bors: r-

@nrc
Copy link
Member

nrc commented Jul 16, 2016

@danc: I was discussing with @jseyfried on irc. He suggested a simpler approach would be to add a single_step flag to MacroExpander. You could then check this and if true return after a single step, rather than recursing. Would that work for you?

Separately, there seems to be a limitation with either approach which is that after the first round of expansion, the expander will no longer be able to name macros which are in any module other than the crate root. This is because of the way the expander tracks modularisation of modules. I think we just live with that. It should fix itself once we re-jig macro name resolution. We can talk more on irc on Monday.

@bors
Copy link
Contributor

bors commented Jul 18, 2016

☔ The latest upstream changes (presumably #34860) made this pull request unmergeable. Please resolve the merge conflicts.

@arielb1
Copy link
Contributor

arielb1 commented Jul 24, 2016

@bors r-``

@arielb1
Copy link
Contributor

arielb1 commented Jul 24, 2016

@bors r=nrc

@bors
Copy link
Contributor

bors commented Jul 24, 2016

📌 Commit 866da14 has been approved by nrc

@arielb1
Copy link
Contributor

arielb1 commented Jul 24, 2016

@bors r-

@bors
Copy link
Contributor

bors commented Jul 24, 2016

💥 Test timed out

@alexcrichton
Copy link
Member

Unfortunately this now looks like it has some rebase conflicts, @DanielJCampbell could you rebase so we can re-r+?

krate);
let ret = syntax::ext::expand::expand_crate(&mut ecx,
syntax_exts,
krate);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: these arguments can be on one line.

@DanielJCampbell
Copy link
Contributor Author

Fixed nits

c.module.items = items.into();
for (name, extension) in user_exts {
expander.cx.syntax_env.insert(name, extension);
}
Copy link
Contributor

@jseyfried jseyfried Aug 7, 2016

Choose a reason for hiding this comment

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

One last thing -- user-defined extensions should be inserted before calling expander.load_macros(&items) so that macros imported from extern crates continue to shadow user-defined extensions (#[plugin]s). Otherwise, we might break code for no good reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll also add a comment to that effect, since that seems worth a warning.

@jseyfried
Copy link
Contributor

@DanielJCampbell looks good! Could you squash the two commits?

@nrc r=me unless you have other comments.

@nrc
Copy link
Member

nrc commented Aug 8, 2016

lgtm

@DanielJCampbell
Copy link
Contributor Author

Squashed the commits together.

@jseyfried
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 8, 2016

📌 Commit 2fefe00 has been approved by jseyfried

@bors
Copy link
Contributor

bors commented Aug 8, 2016

⌛ Testing commit 2fefe00 with merge 7637782...

bors added a commit that referenced this pull request Aug 8, 2016
Extended expand.rs to support alternate expansion behaviours (eg. stepwise expansion)

r? nrc
@bors
Copy link
Contributor

bors commented Aug 8, 2016

💔 Test failed - auto-win-msvc-64-opt-rustbuild

@DanielJCampbell
Copy link
Contributor Author

Looks like I missed the tests, I'll fix that up shortly.

Added single_step & keep_macs flags and functionality to expander
@jseyfried
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 12, 2016

📌 Commit 61c7569 has been approved by jseyfried

@bors
Copy link
Contributor

bors commented Aug 12, 2016

⌛ Testing commit 61c7569 with merge 68d9284...

bors added a commit that referenced this pull request Aug 12, 2016
Extended expand.rs to support alternate expansion behaviours (eg. stepwise expansion)

r? nrc
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.

8 participants