Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upmacros: stackless expansion #36214
Conversation
rust-highfive
assigned
nrc
Sep 2, 2016
jseyfried
force-pushed the
jseyfried:stackless_expansion
branch
2 times, most recently
from
6497f39
to
d0695b0
Sep 2, 2016
This comment has been minimized.
This comment has been minimized.
|
Hmm, this doesn't seem to be working. I tried it on my most-recursing macro, brainmunch. Having built master and this branch:
This branch is first, then master. I would have expected a more impressive time difference and a smaller memory footprint if the expansion is really stackless. Furthermore, I removed |
This comment has been minimized.
This comment has been minimized.
|
@durka If you don't get a stack overflow with a high recursion limit before this PR, then there's not much to see. |
This comment has been minimized.
This comment has been minimized.
|
@durka This PR doesn't change It would probably be a good idea to raise the default recursion limit or even remove it altogether, but that's for a separate PR. Note that if we remove the recursion limit altogether, I think we should limit the total memory usage or total number of expansions so that if there really is unbounded recursion, the user will still get a nice error message (not a hang or an out of memory error). I'd be happy to help if you want to do this. To test this branch, you can set the recursion limit to something that can't be reached in a reasonable amount of time and space, like This PR doesn't improve performance (I actually measured ~5% regression, but that will be made up by a later PR) nor does it improve memory usage -- after this PR, the heap will have all the information that used to be on the stack and more. |
This comment has been minimized.
This comment has been minimized.
|
Ah I see, I got too excited. |
This comment has been minimized.
This comment has been minimized.
|
Further investigation: I lengthened the test case to stack overflow on master after 1m27s, and it finished compiling on this branch after 5 minutes. Intentionally lowering the recursion limit produces comparable time-to-error for both branches. |
This comment has been minimized.
This comment has been minimized.
|
|
jseyfried
force-pushed the
jseyfried:stackless_expansion
branch
3 times, most recently
from
a9fa986
to
99c896f
Sep 4, 2016
nrc
reviewed
Sep 5, 2016
| syntax_pos::DUMMY_SP => PathBuf::new(), | ||
| _ => PathBuf::from(fld.cx.parse_sess.codemap().span_to_filename(inner)), | ||
| }; | ||
| fld.cx.directory.pop(); |
This comment has been minimized.
This comment has been minimized.
nrc
Sep 5, 2016
Member
This doesn't seem right - in the dummy span case you're popping an empty PathBuf
This comment has been minimized.
This comment has been minimized.
nrc
reviewed
Sep 5, 2016
| if valid_ident { | ||
| fld.cx.mod_push(item.ident); | ||
| let directory = fld.cx.directory.clone(); | ||
| if item.span.contains(inner) { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
jseyfried
added some commits
Aug 31, 2016
This comment has been minimized.
This comment has been minimized.
|
r=me with that boilerplate factored away |
This comment has been minimized.
This comment has been minimized.
|
@bors r=nrc |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Sep 6, 2016
This comment has been minimized.
This comment has been minimized.
|
|
jseyfried
force-pushed the
jseyfried:stackless_expansion
branch
from
3f9b910
to
dc01d96
Sep 6, 2016
This comment has been minimized.
This comment has been minimized.
|
@bors r=nrc |
This comment has been minimized.
This comment has been minimized.
|
|
jseyfried
force-pushed the
jseyfried:stackless_expansion
branch
from
dc01d96
to
323ee43
Sep 6, 2016
jseyfried
added some commits
Sep 2, 2016
jseyfried
force-pushed the
jseyfried:stackless_expansion
branch
from
323ee43
to
9ac91fa
Sep 7, 2016
This comment has been minimized.
This comment has been minimized.
|
@bors r=nrc |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Sep 8, 2016
This comment has been minimized.
This comment has been minimized.
bors
merged commit 9ac91fa
into
rust-lang:master
Sep 8, 2016
bluss
added
the
relnotes
label
Sep 8, 2016
jseyfried
deleted the
jseyfried:stackless_expansion
branch
Sep 8, 2016
This comment has been minimized.
This comment has been minimized.
|
@DanielJCampbell This refactoring might help with expansion visualization / stepwise expansion -- feel free to ping me on IRC if you'd like to discuss. |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I will do that - I have a working solution but it's based on Rust from 6 weeks ago, looks like plenty has changed since then. |
jseyfried commentedSep 2, 2016
•
edited
After this PR, macro expansion cannot overflow the stack unless the expanded crate is too deep to fold.
Everything but the stackless placeholder expansion commit is also groundwork for macro modularization.
cc #35896
r? @nrc or @eddyb