Conversation
2f8538e to
367c4d8
Compare
9884df3 to
00e7abe
Compare
| info.arguments.insert(parameter.clone(), expr_id); | ||
| } else { | ||
| // This expression is the result of a macro expansion. | ||
| info.expr_id = expr_id; |
There was a problem hiding this comment.
Could this already be a different value that's not u64::MAX or expr_id? We could check.
There was a problem hiding this comment.
expr_id = CExprId(new_id) so is it guaranteed to always be unique? In that case we don't need to check.
There was a problem hiding this comment.
The only way it could be not unique is if the macro invocation key is reused for multiple invocations. I've added an assert for that now.
| .into_iter() | ||
| .map(|key| { | ||
| let info = macro_infos | ||
| .remove(&key) |
There was a problem hiding this comment.
Can't a key be needed multiple times here?
There was a problem hiding this comment.
A key refers to a single macro invocation, and each invocation should end up in macro_invocations exactly once.
| .map(|key| { | ||
| let info = macro_infos | ||
| .remove(&key) | ||
| .expect("No macro_infos entry for key {key}"); |
There was a problem hiding this comment.
expect takes a fixed string not a format, so {key} here is printed as is.
| .try_fold::<Option<(WithStmts<Box<Expr>>, CTypeId)>, _, _>(None, |canonical, &id| { | ||
| self.can_convert_const_macro_expansion(id)?; | ||
| .try_fold::<Option<(WithStmts<Box<Expr>>, CTypeId)>, _, _>(None, |canonical, info| { | ||
| let &MacroInvocationInfo { expr_id, .. } = info.as_ref(); |
There was a problem hiding this comment.
let expr_id = info.expr_id; would be simpler (and you wouldn't need the new import).
There was a problem hiding this comment.
I expect to add more fields here in a future PR.
| @@ -1047,13 +1068,38 @@ impl ConversionContext { | |||
| }; | |||
|
|
|||
| if expected_ty & EXPR != 0 { | |||
There was a problem hiding this comment.
What about the callers of expr_possibly_as_stmt? I.e. expressions used as statements?
There was a problem hiding this comment.
Those get wrapped in a CStmtKind::Expr, in which the statement part and the expression part are handled separately.
58d0ef4 to
2a6372a
Compare
2a6372a to
759cf38
Compare
Following up from #1792, this adds the necessary infrastructure to the AST to handle functional macro arguments. The
MacroInvocationInfo::argumentsvalue is currently unused.