Repository navigation
Raw handle macros for field projection experiments - #164627
dingxiangfei2009 wants to merge 2 commits into
Conversation
4cdb718 to
d5bad9f
Compare
This comment has been minimized.
This comment has been minimized.
d5bad9f to
a0c239f
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
a0c239f to
33785a7
Compare
|
@rustbot ready |
|
Some changes occurred in compiler/rustc_attr_ir cc @jdonszelmann, @JonathanBrouwer
cc @rust-lang/clippy HIR ty lowering was modified cc @fmease
cc @rust-lang/rustfmt The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
|
hey @oli-obk it would be great if we could get this merged before the cutoff for 1.102. we have some further additions that we'll want to make, but those can be done in separate PRs. I'd also really like to get to a more incremental dev cycle here. one note on this PR, Ding and I were in a meeting just now and we noticed that we don't yet have a |
33785a7 to
7815525
Compare
This comment has been minimized.
This comment has been minimized.
bd6ca0b to
aeca9e4
Compare
Co-authored-by: Xiangfei Ding <dingxiangfei2009protonmail.ch> Signed-off-by: Rasmus Piorr <piorr@google.com> Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
aeca9e4 to
fddb240
Compare
|
☔ The latest upstream changes (presumably #165760) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
| let place_with_id = self.cat_res(opr.hir_id, opr.span, root_ty, res)?; | ||
| // NOTE(dingxiangfei2009,shaddydc): Technically we should capture the root | ||
| // local **via LocalHandle**, but upvar does not understand this yet. | ||
| // We shall come back and add a new upvar capture just for this. |
There was a problem hiding this comment.
what is the effect of the current capture system? overcapturing? document the current behaviour and what changing it would mean
| } | ||
| } | ||
|
|
||
| fn lower_raw_handle_step( |
There was a problem hiding this comment.
move these functions and everything else field projection related into a seprate module
| pub macro raw_handle($place:expr) { | ||
| k#raw_handle($place) | ||
| } |
There was a problem hiding this comment.
btw, why does this go through the custom syntax scheme instead of just having a builtin macro expand directly to the right ast without having the parser handle it?
There was a problem hiding this comment.
As per MCP 580 | Add builtin# for compiler-intrinsic syntax, built-in macros should not expand to syntactic constructs that cannot be otherwise named in the surface language since it would blur the line between macros and "language extensions" as the MCP calls it.
So for example a built-in macro like line is fine because it it expands to a string literal which can be named in the surface language.
Expanding to internal syntax isn't necessarily done to write less code in the compiler, it's mainly just a matter of principle.
| OffsetOf(&'hir Ty<'hir>, &'hir [Ident]), | ||
|
|
||
| /// Raw place handle (`raw_handle!`) | ||
| RawHandle(&'hir FieldProject<'hir>), |
There was a problem hiding this comment.
do you need this as a hir::Node anywhere? It's always part of an expression, so it could just not have its own HirId and just live in the ExprKind
| self.pclose(); | ||
| } | ||
| ast::ExprKind::RawHandle(expr) => { | ||
| self.word("k#raw_handle"); |
There was a problem hiding this comment.
may be better to print as the macro, and probably should add a rustfmt test now, too, otherwise you may get funny things like rustfmt changing your raw_handle!(...) call into k#raw_handle(...)
| fn visit_expr(&mut self, ex: &'v Expr<'v>) -> Self::Result { | ||
| walk_expr(self, ex) | ||
| } | ||
| fn visit_field_project(&mut self, fp: &'v FieldProject<'v>) -> Self::Result { |
There was a problem hiding this comment.
do you need this for anything? Could only add it once needed
| #[derive(Debug, Clone, Copy, StableHash)] | ||
| pub struct FieldProject<'hir> { | ||
| #[stable_hash(ignore)] | ||
| pub hir_id: HirId, |
There was a problem hiding this comment.
Don't really need this id afaict, the surrounding expression always already has an id. Or is this its own node because you wanna store sth per nested FieldProject?
I wonder if we should just have prefix: &[FieldProjectKind] and path: QPath fields instead of having a nested enum structure that always terminates with Path.
|
Reminder, once the PR becomes ready for a review, use |
🐉 Highly experimental field projection primitive
raw_handle!r? @oli-obk
cc @ShaddyDC
cc @ojeda
cc @BennoLossin
We would like to submit this patch to start the experiment with the
LocalHandleandPlaceHandle. We intend to continue polishing it in a patch series following this initial patch.We know that the following items are not working.