-
Notifications
You must be signed in to change notification settings - Fork 268
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
base: master
Are you sure you want to change the base?
Upgrade to Syn 2 #1271
Conversation
There was a problem hiding this 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?
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. |
There was a problem hiding this 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solved in 9cf4b36
There was a problem hiding this comment.
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.
impl SetSpan for Block { | ||
fn set_span(&mut self, s: Span) { | ||
if self.stmts.is_empty() == false { | ||
self.stmts[0].set_span(s); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
😅
There was a problem hiding this comment.
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.
hi @ fw-immunant, thanks for the review. will check it tomorow |
…Literal in IntLit
…match the existing behavior
There was a problem hiding this 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, |
There was a problem hiding this comment.
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.
impl SetSpan for Block { | ||
fn set_span(&mut self, s: Span) { | ||
if self.stmts.is_empty() == false { | ||
self.stmts[0].set_span(s); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.
upgrade to syn 2 for crate
c2rust-transpile
,c2rust-ast-builder
,c2rust-bitfields-derive
, andc2rust-ast-printer
.c2rust-macros
excluded because it only used byc2rust-refactor
syn introduces many breaking changes which can be viewed in https://github.com/dtolnay/syn/releases/tag/2.0.0