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 }})

oli-obk

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:

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 rustbot added A-rustdoc-json

Area: Rustdoc JSON backend

A-testsuite

Area: The testsuite used to check the correctness of rustc

S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-bootstrap

Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.

T-rustdoc

Relevant to the rustdoc team, which will review and decide on the PR/issue.

WG-trait-system-refactor

The Rustc Trait System Refactor Initiative (-Znext-solver)

labels

Jan 19, 2024

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 20, 2024

@bors

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

Jan 21, 2024

@bors

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

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors

flip1995 pushed a commit to flip1995/rust that referenced this pull request

Jan 25, 2024

@bors

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>.

@oli-obk

@oli-obk

@bors

📌 Commit 18ff131 has been approved by compiler-errors

It is now in the queue for this repository.

@bors 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

Apr 8, 2024

@rust-log-analyzer

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors

@bors

@bors bors mentioned this pull request

Apr 8, 2024

@rust-timer

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 oli-obk deleted the pattern_types_syntax branch

April 8, 2024 19:49

celinval added a commit to celinval/kani-dev that referenced this pull request

Apr 16, 2024

@celinval

celinval added a commit to model-checking/kani that referenced this pull request

Apr 16, 2024

@celinval

celinval added a commit to celinval/kani-dev that referenced this pull request

Apr 17, 2024

@celinval

flip1995 pushed a commit to flip1995/rust that referenced this pull request

Apr 18, 2024

@bors

…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:

r? @BoxyUwU

zpzigi754 pushed a commit to zpzigi754/kani that referenced this pull request

May 8, 2024

@celinval @zpzigi754

Labels

A-rustdoc-json

Area: Rustdoc JSON backend

A-testsuite

Area: The testsuite used to check the correctness of rustc

F-pattern_types

`#![feature(pattern_types)]`

merged-by-bors

This PR was explicitly merged by bors.

PG-exploit-mitigations

Project group: Exploit mitigations

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-bootstrap

Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.

T-rustdoc

Relevant to the rustdoc team, which will review and decide on the PR/issue.

WG-trait-system-refactor

The Rustc Trait System Refactor Initiative (-Znext-solver)