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

Fixed quote_method!() implementation #17409

Closed
wants to merge 1 commit into from

Conversation

farcaller
Copy link
Contributor

Parser.parse_method now has a second argument, I assume ast::Inherited is the correct visibility in this case.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (or someone else) soon.

@@ -465,8 +465,12 @@ pub fn expand_quote_method(cx: &mut ExtCtxt,
tts: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
let e_param_colons = cx.expr_none(sp);
let e_visibility = cx.expr_path(cx.path(syntax::codemap::DUMMY_SP, vec!(
Copy link

Choose a reason for hiding this comment

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

unnecessary syntax::

Copy link
Member

Choose a reason for hiding this comment

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

I think this should actually be sp.

@huonw
Copy link
Member

huonw commented Sep 20, 2014

Thanks!

Could you also add a testcase? E.g. just putting let _j: P<syntax::ast::Method> = quote_method!(cx, fn foo(&self) {}); into src/test/run-pass-fulldeps/quote-tokens.rs should be good.

(Be sure to comment once you update the PR, since GitHub doesn't provide notifications.)

@farcaller
Copy link
Contributor Author

Fixed the sp and added tests.

bors added a commit that referenced this pull request Sep 22, 2014
Parser.parse_method now has a second argument, I assume ast::Inherited is the correct visibility in this case.
@farcaller
Copy link
Contributor Author

Sorry, I'm kind of fixing this without verifying that it actually compiles as I don't have a rustc at hand at the moment to bootstrap the build.

I've fixed the first argument as well (was already_parsed_attrs: Option<Vec<Attribute>>, now attrs: Vec<Attribute>).

@farcaller
Copy link
Contributor Author

Ok, I've verified that it works now. Is it r? or should I squash commits first?

Parser.parse_method now has a second argument, I assume ast::Inherited is the correct visibility in this case.
bors added a commit that referenced this pull request Sep 29, 2014
Parser.parse_method now has a second argument, I assume ast::Inherited is the correct visibility in this case.
@bors bors closed this Sep 29, 2014
lnicola pushed a commit to lnicola/rust that referenced this pull request Jun 23, 2024
…=Veykril

fix: add a breaker to avoid infinite loops from source root cycles

See rust-lang#17409

This patch prevents infinite looping from cycles by giving up if the number of source roots checked for a config value reaches the total number of source roots.

Alternative more precise options include creating a set of all source roots visited and giving up as soon as a cycle is encountered, but I wasn't sure how costly an allocation would be here for performance.

Can confirm that locally this fixes the problem for me.
lnicola pushed a commit to lnicola/rust that referenced this pull request Jun 23, 2024
fix: ensure there are no cycles in the source_root_parent_map

See rust-lang#17409

We can view the connections between roots as a graph. The problem is that this graph may contain cycles, so when adding edges, it is necessary to check whether it will lead to a cycle.

Since we ensure that each node has at most one outgoing edge (because each SourceRoot can have only one parent), we can use a disjoint-set to maintain the connectivity between nodes. If an edge’s two nodes belong to the same set, they are already connected.

Additionally, this PR includes the following three changes:

1. Removed the workaround from rust-lang#17409.
2. Added an optimization: If `map.contains_key(&SourceRootId(*root_id as u32))`, we can skip the current loop iteration since we have already found its parent.
3. Modified the inner loop to iterate in reverse order with `roots[..idx].iter().rev()` at line 319. This ensures that if we are looking for the parent of `a/b/c`, and both `a` and `a/b` meet the criteria, we will choose the longer match (`a/b`).
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.

5 participants