Skip to content

Upgrade to Syn 2 #1271

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Upgrade to Syn 2 #1271

wants to merge 6 commits into from

Conversation

bungcip
Copy link
Contributor

@bungcip bungcip commented Jul 10, 2025

upgrade to syn 2 for crate c2rust-transpile, c2rust-ast-builder, c2rust-bitfields-derive, and c2rust-ast-printer. c2rust-macros excluded because it only used by c2rust-refactor

syn introduces many breaking changes which can be viewed in https://github.com/dtolnay/syn/releases/tag/2.0.0

Copy link
Contributor

@kkysen kkysen left a comment

Choose a reason for hiding this comment

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

cc @ahomescu since he's working on resurrecting c2rust-refactor. Generally, I think upgrading syn to 2 is good. @fw-immunant do you have any concerns?

@fw-immunant fw-immunant self-requested a review July 10, 2025 20:33
@fw-immunant
Copy link
Contributor

This is a pretty wide-reaching change that might have impacts all over; I want to give it a close review when I get a chance.

Copy link
Contributor

@fw-immunant fw-immunant left a comment

Choose a reason for hiding this comment

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

Mostly looks great! But there are a number of places where control flow has changed around the distinction between Stmt::Semi and Stmt::Expr, and I'd like those to be careful to match the existing behavior, or justify why they should change.

else_branch: Some((token, else_)),
..
}),
_semi,
Copy link
Contributor

Choose a reason for hiding this comment

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

None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

solved in 9cf4b36

Copy link
Contributor

Choose a reason for hiding this comment

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

This occurrence still needs fixing.

Comment on lines +187 to +194
impl SetSpan for Block {
fn set_span(&mut self, s: Span) {
if self.stmts.is_empty() == false {
self.stmts[0].set_span(s);
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there still a way to set the span for the brace token so that we handle empty blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

self.brace_token.span is DelimSpan, and DelimSpan::new() is pub(crate) so this is the closest functionality to set span. IMHO, if we want to revive comment functionality, i think the best way is to contribute changes in prettyplease & syn to add comment in AST node. The current way to store comment id is already abusing poor span 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, our current span-mangling is really hacky. I'm not sure adding comments to AST nodes in syn would be acceptable upstream nor whether it would be sufficient for perfect comment preservation. That said, it would be good to have a comment here to explain the omission. I can add one in a follow-up; don't consider this a blocker.

@bungcip
Copy link
Contributor Author

bungcip commented Jul 18, 2025

hi @ fw-immunant, thanks for the review. will check it tomorow

Copy link
Contributor

@fw-immunant fw-immunant left a comment

Choose a reason for hiding this comment

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

One last missed case of Expr/Semi fixup. Otherwise looks good.

else_branch: Some((token, else_)),
..
}),
_semi,
Copy link
Contributor

Choose a reason for hiding this comment

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

This occurrence still needs fixing.

Comment on lines +187 to +194
impl SetSpan for Block {
fn set_span(&mut self, s: Span) {
if self.stmts.is_empty() == false {
self.stmts[0].set_span(s);
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, our current span-mangling is really hacky. I'm not sure adding comments to AST nodes in syn would be acceptable upstream nor whether it would be sufficient for perfect comment preservation. That said, it would be good to have a comment here to explain the omission. I can add one in a follow-up; don't consider this a blocker.

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.

3 participants