Skip to content

view-types: store view types in the AST#156016

Open
scrabsha wants to merge 2 commits intorust-lang:mainfrom
scrabsha:view-types/in-ast
Open

view-types: store view types in the AST#156016
scrabsha wants to merge 2 commits intorust-lang:mainfrom
scrabsha:view-types/in-ast

Conversation

@scrabsha
Copy link
Copy Markdown
Contributor

@scrabsha scrabsha commented Apr 30, 2026

View all comments

Tracking issue: #155938.

Instead of discarding view types, we store them in the AST now!

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 30, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@scrabsha scrabsha force-pushed the view-types/in-ast branch from 52c4eee to 2bafb0c Compare May 1, 2026 13:55
@rust-log-analyzer

This comment has been minimized.

@scrabsha scrabsha force-pushed the view-types/in-ast branch from 2bafb0c to 7f6749b Compare May 1, 2026 15:17
@rustbot rustbot added T-clippy Relevant to the Clippy team. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels May 1, 2026
@scrabsha scrabsha force-pushed the view-types/in-ast branch from 7f6749b to 77bdbc2 Compare May 1, 2026 15:21
@rust-log-analyzer

This comment has been minimized.

@scrabsha scrabsha force-pushed the view-types/in-ast branch 4 times, most recently from d9ef8d8 to ec789ac Compare May 3, 2026 09:31
Comment thread compiler/rustc_ast/src/ast.rs Outdated
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 3, 2026
rust-bors Bot pushed a commit that referenced this pull request May 3, 2026
view-types: store borrows of view types in the AST
Comment thread compiler/rustc_parse/src/parser/ty.rs Outdated
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 3, 2026

☀️ Try build successful (CI)
Build commit: 9d3dea7 (9d3dea74651f758e35177070e510be8f3639a7fd, parent: 6769f690f947f12e36db6b6503bab265b7b2cced)

@rust-timer

This comment has been minimized.

@scrabsha scrabsha mentioned this pull request May 3, 2026
8 tasks
@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9d3dea7): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-1.4%, -0.3%] 6
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.1%] 2
All ❌✅ (primary) -0.7% [-1.4%, -0.3%] 6

Max RSS (memory usage)

Results (primary 0.1%, secondary -2.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.9% [1.9%, 1.9%] 1
Regressions ❌
(secondary)
1.2% [1.2%, 1.2%] 1
Improvements ✅
(primary)
-0.8% [-0.8%, -0.7%] 2
Improvements ✅
(secondary)
-4.4% [-7.3%, -1.5%] 2
All ❌✅ (primary) 0.1% [-0.8%, 1.9%] 3

Cycles

Results (secondary 3.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
5.0% [0.5%, 9.9%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.3% [-1.3%, -1.3%] 1
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 503.61s -> 496.571s (-1.40%)
Artifact size: 394.46 MiB -> 394.47 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 3, 2026
@rust-bors

This comment has been minimized.

@scrabsha scrabsha force-pushed the view-types/in-ast branch from ec789ac to 93208f2 Compare May 3, 2026 16:11
@scrabsha
Copy link
Copy Markdown
Contributor Author

scrabsha commented May 3, 2026

^

r? nikomatsakis

@scrabsha scrabsha marked this pull request as ready for review May 3, 2026 16:12
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 3, 2026

The Rustfmt subtree was changed

cc @rust-lang/rustfmt

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

Changes to the size of AST and/or HIR nodes.

cc @nnethercote

The Clippy subtree was changed

cc @rust-lang/clippy

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 3, 2026
Comment thread compiler/rustc_ast/src/ast.rs Outdated
Comment thread compiler/rustc_ast/src/ast.rs Outdated
@scrabsha scrabsha force-pushed the view-types/in-ast branch 2 times, most recently from 661a680 to 6035af1 Compare May 4, 2026 17:52
Comment thread compiler/rustc_ast/src/ast.rs Outdated
Ptr(MutTy),
/// A reference (`&'a T` or `&'a mut T`).
Ref(#[visitable(extra = LifetimeCtxt::Ref)] Option<Lifetime>, MutTy),
Ref(#[visitable(extra = LifetimeCtxt::Ref)] Option<Lifetime>, MutTy, ViewKind),
Copy link
Copy Markdown
Contributor

@nikomatsakis nikomatsakis May 7, 2026

Choose a reason for hiding this comment

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

This is not the right model. The view is not attached to the reference but rather to the path type. You can have a view type without any reference at all (e.g., Foo.{F1, F2}).

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hi! Unless you have an objection, i would like to go with the following:

  • Have a TyKind::View(Box<Ty>, ThinVec<Ident>) variant (instead of the change you highlight)
  • Parse any $ty.{ $( $ident ),* }
  • Check later in the compilation that $ty is a kind of type we expect

Unless I have missed something, this is functionally identical to what you suggest, but leaves more room for nice error messages to be added.

I just pushed a commit that does what I just described, let me know what you think :)

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 7, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 7, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@scrabsha scrabsha force-pushed the view-types/in-ast branch from 6035af1 to 9bdbdb2 Compare May 7, 2026 19:53
Comment thread compiler/rustc_ast/src/ast.rs Outdated
Comment thread compiler/rustc_ast/src/ast.rs Outdated
Comment thread compiler/rustc_ast_pretty/src/pprust/state.rs
Comment thread compiler/rustc_ast_pretty/src/pprust/state.rs Outdated
Comment thread src/tools/clippy/clippy_lints/src/redundant_static_lifetimes.rs Outdated
Comment thread src/tools/clippy/clippy_utils/src/check_proc_macro.rs Outdated
Comment thread src/tools/rustfmt/src/types.rs
Comment thread compiler/rustc_ast/src/ast.rs Outdated
@scrabsha scrabsha force-pushed the view-types/in-ast branch from 9bdbdb2 to 7b29ee5 Compare May 8, 2026 18:08
@scrabsha scrabsha changed the title view-types: store borrows of view types in the AST view-types: store view types in the AST May 8, 2026
@scrabsha scrabsha force-pushed the view-types/in-ast branch 2 times, most recently from 56b58a1 to b103cec Compare May 8, 2026 18:40
@rust-log-analyzer

This comment has been minimized.

@scrabsha scrabsha force-pushed the view-types/in-ast branch from b103cec to f0d6895 Compare May 8, 2026 18:54
@scrabsha
Copy link
Copy Markdown
Contributor Author

scrabsha commented May 9, 2026

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants