Implement minimal, internal-only pattern types in the type system by oli-obk · Pull Request #120131 · rust-lang/rust (original) (raw)
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
rebase of #107606
You can create pattern types with std::pat::pattern_type!(ty is pat)
. The feature is incomplete and will panic on you if you use any pattern other than integral range patterns. The only way to create or deconstruct a pattern type is via transmute
.
This PR's implementation differs from the MCP's text. Specifically
This means you could implement different traits for different pattern types with the same base type. Thus, we just forbid implementing any traits for pattern types.
is violated in this PR. The reason is that we do need impls after all in order to make them usable as fields. constants of type std::time::Nanoseconds
struct are used in patterns, so the type must be structural-eq, which it only can be if you derive several traits on it. It doesn't need to be structural-eq recursively, so we can just manually implement the relevant traits on the pattern type and use the pattern type as a private field.
Waiting on:
- move all unrelated commits into their own PRs.
- fix niche computation (see 2db07f9)
- add lots more tests
- T-types MCP Pattern types types-team#126 to finish
- some commit cleanup
- full self-review
- remove 61bd325, it's not necessary anymore I think.
make sure we never accidentally leak pattern types to user code (add stability checks or feature gate checks and appopriate tests)we don't even do this for the new float primitives- get approval that the scope expansion to trait impls is ok
r? @BoxyUwU
mo8it reacted with thumbs up emoji yoshuawuyts, spastorino, Miksel12, jdahlstrom, GrayJack, yerke, and mo8it reacted with hooray emoji slanterns, RossSmyth, clubby789, y21, Nadrieril, tjallingt, juntyr, joboet, Kobzol, glou-nes, and 15 more reacted with heart emoji PatchMixolydic reacted with eyes emoji
rustbot added A-rustdoc-json
Area: Rustdoc JSON backend
Area: The testsuite used to check the correctness of rustc
Status: Awaiting review from the assignee but also interested parties.
Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Relevant to the compiler team, which will review and decide on the PR/issue.
Relevant to the library team, which will review and decide on the PR/issue.
Relevant to the rustdoc team, which will review and decide on the PR/issue.
The Rustc Trait System Refactor Initiative (-Znext-solver)
labels
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors added a commit to rust-lang-ci/rust that referenced this pull request
Don't forget that the lifetime on hir types is 'tcx
This PR just tracks the 'tcx
lifetime to wherever the original objects actually have that lifetime. This code is needed for rust-lang#107606 (now rust-lang#120131) so that ast_ty_to_ty
can invoke lit_to_const
on an argument passed to it. Currently the argument is &hir::Ty<'_>
, but after this PR it is &'tcx hir::Ty<'tcx>
.
bors added a commit to rust-lang-ci/rust that referenced this pull request
Don't forget that the lifetime on hir types is 'tcx
This PR just tracks the 'tcx
lifetime to wherever the original objects actually have that lifetime. This code is needed for rust-lang#107606 (now rust-lang#120131) so that ast_ty_to_ty
can invoke lit_to_const
on an argument passed to it. Currently the argument is &hir::Ty<'_>
, but after this PR it is &'tcx hir::Ty<'tcx>
.
This comment has been minimized.
This comment has been minimized.
flip1995 pushed a commit to flip1995/rust that referenced this pull request
Don't forget that the lifetime on hir types is 'tcx
This PR just tracks the 'tcx
lifetime to wherever the original objects actually have that lifetime. This code is needed for rust-lang#107606 (now rust-lang#120131) so that ast_ty_to_ty
can invoke lit_to_const
on an argument passed to it. Currently the argument is &hir::Ty<'_>
, but after this PR it is &'tcx hir::Ty<'tcx>
.
📌 Commit 18ff131 has been approved by compiler-errors
It is now in the queue for this repository.
bors added S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
A job failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
bors mentioned this pull request
Finished benchmarking commit (537aab7): comparison URL.
Overall result: ❌✅ regressions and improvements - no action needed
@rustbot label: -perf-regression
Instruction count
This is a highly reliable metric that was used to determine the overall result at the top of this comment.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | - | - | 0 |
Regressions ❌ (secondary) | 2.7% | [2.7%, 2.7%] | 1 |
Improvements ✅ (primary) | -0.4% | [-0.4%, -0.4%] | 1 |
Improvements ✅ (secondary) | - | - | 0 |
All ❌✅ (primary) | -0.4% | [-0.4%, -0.4%] | 1 |
Max RSS (memory usage)
Results
This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
mean | range | count | |
---|---|---|---|
Regressions ❌ (primary) | - | - | 0 |
Regressions ❌ (secondary) | 2.1% | [2.1%, 2.1%] | 1 |
Improvements ✅ (primary) | -2.5% | [-2.5%, -2.5%] | 1 |
Improvements ✅ (secondary) | -3.0% | [-4.5%, -1.9%] | 20 |
All ❌✅ (primary) | -2.5% | [-2.5%, -2.5%] | 1 |
Cycles
This benchmark run did not return any relevant results for this metric.
Binary size
This benchmark run did not return any relevant results for this metric.
Bootstrap: 666.152s -> 669.664s (0.53%)
Artifact size: 318.23 MiB -> 318.23 MiB (0.00%)
oli-obk deleted the pattern_types_syntax branch
celinval added a commit to celinval/kani-dev that referenced this pull request
celinval added a commit to model-checking/kani that referenced this pull request
celinval added a commit to celinval/kani-dev that referenced this pull request
flip1995 pushed a commit to flip1995/rust that referenced this pull request
…iler-errors
Implement minimal, internal-only pattern types in the type system
rebase of rust-lang#107606
You can create pattern types with std::pat::pattern_type!(ty is pat)
. The feature is incomplete and will panic on you if you use any pattern other than integral range patterns. The only way to create or deconstruct a pattern type is via transmute
.
This PR's implementation differs from the MCP's text. Specifically
This means you could implement different traits for different pattern types with the same base type. Thus, we just forbid implementing any traits for pattern types.
is violated in this PR. The reason is that we do need impls after all in order to make them usable as fields. constants of type std::time::Nanoseconds
struct are used in patterns, so the type must be structural-eq, which it only can be if you derive several traits on it. It doesn't need to be structural-eq recursively, so we can just manually implement the relevant traits on the pattern type and use the pattern type as a private field.
Waiting on:
- move all unrelated commits into their own PRs.
- fix niche computation (see 2db07f9)
- add lots more tests
- T-types MCP rust-lang/types-team#126 to finish
- some commit cleanup
- full self-review
- remove 61bd325, it's not necessary anymore I think.
-
make sure we never accidentally leak pattern types to user code (add stability checks or feature gate checks and appopriate tests)we don't even do this for the new float primitives - get approval that the scope expansion to trait impls is ok
r? @BoxyUwU
zpzigi754 pushed a commit to zpzigi754/kani that referenced this pull request
Labels
Area: Rustdoc JSON backend
Area: The testsuite used to check the correctness of rustc
`#![feature(pattern_types)]`
This PR was explicitly merged by bors.
Project group: Exploit mitigations
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Relevant to the compiler team, which will review and decide on the PR/issue.
Relevant to the library team, which will review and decide on the PR/issue.
Relevant to the rustdoc team, which will review and decide on the PR/issue.
The Rustc Trait System Refactor Initiative (-Znext-solver)