Skip to content

Make some traversable types generic over interner #108214

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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3c58c0e
Improve docs of traversable derivation macros
eggyal Feb 26, 2023
1a9c3e5
Generify traversable derivation macros
eggyal Feb 26, 2023
09239c2
Automatically skip traversal of boring fields
eggyal Feb 25, 2023
d2ec961
Use specialisation in ParamEnv traversable impls
eggyal Feb 26, 2023
99e070f
Derive traversable impls for UserTypeProjection
eggyal Feb 25, 2023
408ba98
Derive traversable impls for BindingForm
eggyal Feb 25, 2023
ef97776
Derive traversable impls for Obligation
eggyal Feb 26, 2023
5d4dd4b
Simplify traversable impls for ExternalConstraints
eggyal Feb 25, 2023
b75b00d
Remove superfluous traversable impls
eggyal Feb 25, 2023
8f8a920
Remove superfluous traversable impl for usize
eggyal Feb 25, 2023
4e4b936
Remove superfluous traversable impl for bool
eggyal Feb 25, 2023
e3f58d0
Newtype for FakeRead semi-traversable tuple
eggyal Mar 20, 2023
feaeef5
Newtype for AscribeUserType semi-traversable tuple
eggyal Mar 20, 2023
c79f135
Newtypes not DefId and LocalDefId traversable impl
eggyal Mar 20, 2023
6833eea
Use rustc_type_ir directly in derived traversables
eggyal Feb 25, 2023
8da36bd
Derive traversables over generic interners
eggyal Mar 21, 2023
d1cc6e5
Use Spanned not semi-traversable Span tuples
eggyal Mar 20, 2023
9b8fcc5
Make no-op traversables generic over the interner
eggyal Mar 21, 2023
85f0500
Replace TrivialTypeTraversal macros with derives
eggyal Feb 25, 2023
b0ccdac
Unimpl TypeSuperVisitable for UnevaluatedConst
eggyal Feb 26, 2023
11296fa
Generify traversals of interned types
eggyal Feb 26, 2023
bf618ac
Explain no-op traversable impls
eggyal Mar 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Newtype for AscribeUserType semi-traversable tuple
  • Loading branch information
eggyal committed Mar 21, 2023
commit feaeef5cb902fcf7349fcf83dde5aedee4490311
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);
}
}
StatementKind::AscribeUserType(box (place, projection), variance) => {
StatementKind::AscribeUserType(box AscribeUserType(place, projection), variance) => {
let place_ty = place.ty(body, tcx).ty;
if let Err(terr) = self.relate_type_and_user_type(
place_ty,
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ impl Debug for Statement<'_> {
PlaceMention(ref place) => {
write!(fmt, "PlaceMention({:?})", place)
}
AscribeUserType(box (ref place, ref c_ty), ref variance) => {
AscribeUserType(box self::AscribeUserType(ref place, ref c_ty), ref variance) => {
write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty)
}
Coverage(box self::Coverage { ref kind, code_region: Some(ref rgn) }) => {
Expand Down Expand Up @@ -2693,6 +2693,10 @@ impl<'tcx> UserTypeProjections {
}
}

#[derive(Clone, Debug, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
#[derive(TypeFoldable, TypeVisitable)]
pub struct AscribeUserType<'tcx>(pub Place<'tcx>, pub UserTypeProjection);

/// Encodes the effect of a user-supplied type annotation on the
/// subcomponents of a pattern. The effect is determined by applying the
/// given list of projections to some underlying base type. Often,
Expand All @@ -2709,7 +2713,6 @@ impl<'tcx> UserTypeProjections {
/// `field[0]` (aka `.0`), indicating that the type of `s` is
/// determined by finding the type of the `.0` field from `T`.
#[derive(Clone, Debug, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
#[derive(TypeFoldable, TypeVisitable)]
pub struct UserTypeProjection {
pub base: UserTypeAnnotationIndex,
pub projs: Vec<ProjectionKind>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This is in a dedicated file so that changes to this file can be reviewed more carefully.
//! The intention is that this file only contains datatype declarations, no code.

use super::{BasicBlock, Constant, Field, Local, SwitchTargets, UserTypeProjection};
use super::{AscribeUserType, BasicBlock, Constant, Field, Local, SwitchTargets};

use crate::mir::coverage::{CodeRegion, CoverageKind};
use crate::traits::Reveal;
Expand Down Expand Up @@ -350,7 +350,7 @@ pub enum StatementKind<'tcx> {
/// When executed at runtime this is a nop.
///
/// Disallowed after drop elaboration.
AscribeUserType(Box<(Place<'tcx>, UserTypeProjection)>, ty::Variance),
AscribeUserType(Box<AscribeUserType<'tcx>>, ty::Variance),

/// Marks the start of a "coverage region", injected with '-Cinstrument-coverage'. A
/// `Coverage` statement carries metadata about the coverage region, used to inject a coverage
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ macro_rules! make_mir_visitor {
);
}
StatementKind::AscribeUserType(
box (place, user_ty),
box AscribeUserType(place, user_ty),
variance
) => {
self.visit_ascribe_user_ty(place, $(& $mutability)? *variance, user_ty, location);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/build/expr/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Statement {
source_info,
kind: StatementKind::AscribeUserType(
Box::new((
Box::new(AscribeUserType(
place,
UserTypeProjection { base: annotation_index, projs: vec![] },
)),
Expand All @@ -514,7 +514,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Statement {
source_info,
kind: StatementKind::AscribeUserType(
Box::new((
Box::new(AscribeUserType(
Place::from(temp),
UserTypeProjection { base: annotation_index, projs: vec![] },
)),
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Statement {
source_info: ty_source_info,
kind: StatementKind::AscribeUserType(
Box::new((place, UserTypeProjection { base, projs: Vec::new() })),
Box::new(AscribeUserType(
place,
UserTypeProjection { base, projs: Vec::new() },
)),
// We always use invariant as the variance here. This is because the
// variance field from the ascription refers to the variance to use
// when applying the type to the value being matched, but this
Expand Down Expand Up @@ -2087,7 +2090,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Statement {
source_info,
kind: StatementKind::AscribeUserType(
Box::new((
Box::new(AscribeUserType(
ascription.source,
UserTypeProjection { base, projs: Vec::new() },
)),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/remove_zsts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
}
StatementKind::Deinit(box place)
| StatementKind::SetDiscriminant { box place, variant_index: _ }
| StatementKind::AscribeUserType(box (place, _), _)
| StatementKind::AscribeUserType(box AscribeUserType(place, _), _)
| StatementKind::Retag(_, box place)
| StatementKind::PlaceMention(box place)
| StatementKind::FakeRead(box FakeReadCauseAndPlace(_, place)) => Some(place),
Expand Down