-
-
Notifications
You must be signed in to change notification settings - Fork 17.8k
dont store arbitrary parsed attributes in thir #163009
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,12 +57,14 @@ impl<'tcx> SplattedFunc<'tcx> { | |
| } | ||
| } | ||
|
|
||
| fn parsed_attrs(id: HirId, tcx: TyCtxt<'_>) -> ThinVec<AttributeKind> { | ||
| fn filter_loop_hint_attrs(id: HirId, tcx: TyCtxt<'_>) -> ThinVec<AttributeKind> { | ||
| HasAttrs::get_attrs(id, &tcx) | ||
| .into_iter() | ||
| .filter_map(|attr| match attr { | ||
| rustc_attr_ir::Attribute::Parsed(attrkind) => Some(attrkind.clone()), | ||
| rustc_attr_ir::Attribute::Unparsed(_) => None, | ||
| rustc_attr_ir::Attribute::Parsed(attrkind @ AttributeKind::Unroll(_)) => { | ||
| Some(attrkind.clone()) | ||
| } | ||
| _ => None, | ||
| }) | ||
|
mejrs marked this conversation as resolved.
|
||
| .collect() | ||
| } | ||
|
|
@@ -91,7 +93,7 @@ impl<'tcx> ThirBuildCx<'tcx> { | |
|
|
||
| trace!(?expr.ty); | ||
|
|
||
| let mut attrs = ThinVec::new(); | ||
| let mut loop_hint_attrs = ThinVec::new(); | ||
|
|
||
| if let hir::ExprKind::Loop(_, _, _, span) = hir_expr.kind { | ||
| match span.desugaring_kind() { | ||
|
|
@@ -103,12 +105,12 @@ impl<'tcx> ThirBuildCx<'tcx> { | |
| // ignore async for loops | ||
| if let hir::Node::Expr(expr) = self.tcx.parent_hir_node(expr.hir_id) { | ||
| std::assert_matches!(expr.kind, hir::ExprKind::DropTemps(..)); | ||
| attrs = parsed_attrs(expr.hir_id, self.tcx) | ||
| loop_hint_attrs = filter_loop_hint_attrs(expr.hir_id, self.tcx) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it a problem to store these attributes in the thir, but it is not a problem to store these attributes in the hir?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The solution this PR proposes is fine, but it feels like "this should work" to me
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, I think we just never have them being en/de/coded in queries otherwise?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the hir is also stored in a query, so that's not any different.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah the HIR is never encoded to disk, so this is not a problem in the HIR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For what it's worth, I'm fairly sure THIR is not stored to disk. |
||
| } | ||
| } | ||
| // For loops defined with `loop` and `while`, the expr already has the attrs | ||
| Some(DesugaringKind::WhileLoop) | None => { | ||
| attrs = parsed_attrs(hir_expr.hir_id, self.tcx); | ||
| loop_hint_attrs = filter_loop_hint_attrs(hir_expr.hir_id, self.tcx); | ||
| } | ||
| _ => (), | ||
| } | ||
|
|
@@ -128,8 +130,8 @@ impl<'tcx> ThirBuildCx<'tcx> { | |
| let ty = expr.ty; | ||
| let value = self.thir.exprs.push(expr); | ||
|
|
||
| if !attrs.is_empty() { | ||
| self.thir.attributes.insert(value, attrs); | ||
| if !loop_hint_attrs.is_empty() { | ||
| self.thir.loop_hint_attrs.insert(value, loop_hint_attrs); | ||
| } | ||
|
|
||
| // Finally, wrap this up in the expr's scope. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Calling it
loop_hint_attributeseverywhere is going to be painful when inevitably we add a non-loop-hint attribute in the future.Can we call it
filtered_attributesor sth like that?View changes since the review
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.
It can be renamed again if the meaning changes 🤷
I'm not sure naming it "filtered_attributes" would be clearer, that name doesn't say by what metric it is filtered.