Repository navigation
Avoid impossible type/region/const Bound combinations - #165840
nnethercote wants to merge 1 commit into
Conversation
`TyKind` has this variant:
```
Bound(BoundVarIndexKind, ty::BoundTy<I>),
```
The relevant types within are as follow:
```
enum BoundVarIndexKind {
Bound(DebruijnIndex),
Canonical,
}
struct BoundTy<I: Interner> {
pub var: ty::BoundVar,
pub kind: BoundTyKind<I>,
}
pub enum BoundTyKind<I: Interner> {
Anon,
Param(I::DefId),
}
```
The problem here is that `BoundTyKind` doesn't really apply with
`BoundVarIndexKind::Canonical`, so it's always set to
`BoundTyKind::Anon`, but the types don't enforce this.
It took me a long time to realise this, and got in the way of my
understanding of `Bound` vs. `Canonical`.
This commit changes `TyKind`'s variant to this:
```
Bound(BoundVarIndexKind<ty::BoundTy<I>>),
```
And `BoundVarIndexKind` to this:
```
pub enum BoundVarIndexKind<B> {
Bound(DebruijnIndex, B),
Canonical(BoundVar),
}
```
The `BoundTy` is now inside the `BoundVarIndexKind::Bound`. And
`BoundVarIndexKind::Canonical` only contains a `BoundVar`, which means
it can't have an inappropriate `BoundTyKind`.
There is a similar story for `RegionKind::ReBound` and
`ConstKind::Bound`, and this commit changes them as well.
Note: `BoundConst` debug printing also changed a little; it's now more
like `BoundTy`'s.
|
Some changes occurred in cc @BoxyUwU HIR ty lowering was modified cc @fmease Some changes occurred to the CTFE machinery This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a, @makai410 Some changes occurred in exhaustiveness checking cc @Nadrieril Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri
cc @rust-lang/clippy Some changes occurred in compiler/rustc_sanitizers cc @rcvalle |
|
Shouldn't affect perf, let's check: @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…ns, r=<try> Avoid impossible type/region/const `Bound` combinations
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (bed2628): comparison URL. Overall result: no relevant changes - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)Results (primary 9.1%, secondary -3.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 2.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 484.606s -> 485.041s (0.09%) |
|
Perf is neutral. |
|
Pretty mildly oppose to implementation, although I'm sympathetic to the idea. Today a bound ty can essentially be thought of
the proposed change really obfuscates that mainly because the If we're going to do this, then I would want to just make |
But 3 doesn't really apply in the canonical case, right? That's the whole point of this PR.
I tried something like that originally. It required more mechanical changes, and there's a bigger problem: Another design I played with was introducing a new |
Correct, but it's much more important to treat bound vars as similar regardless if they bound at a given depth or canonical than it is to distinguish between whether a bound var can have different types of debug info.
And this is a clear indication that this type of change is likely not worth it. Though, it may be okay for
I don't really like this option, either.
This isn't true - bound vars have very similar logical meaning whether they are canonical or not. |
| } | ||
| ty::Pat(..) => unreachable!(), | ||
| ty::Bound(_, _) => bug!("bound ty during ctfe"), | ||
| ty::Bound(_) => bug!("bound ty during ctfe"), |
There was a problem hiding this comment.
| ty::Bound(_) => bug!("bound ty during ctfe"), | |
| ty::Bound(..) => bug!("bound ty during ctfe"), |
|
☔ The latest upstream changes (presumably #166152) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
TyKindhas this variant:The relevant types within are as follow:
The problem here is that
BoundTyKinddoesn't really apply withBoundVarIndexKind::Canonical, so it's always set toBoundTyKind::Anon, but the types don't enforce this.It took me a long time to realise this, and got in the way of my understanding of
Boundvs.Canonical.This commit changes
TyKind's variant to this:And
BoundVarIndexKindto this:The
BoundTyis now inside theBoundVarIndexKind::Bound. AndBoundVarIndexKind::Canonicalonly contains aBoundVar, which means it can't have an inappropriateBoundTyKind.There is a similar story for
RegionKind::ReBoundandConstKind::Bound, and this commit changes them as well.Note:
BoundConstdebug printing also changed a little; it's now more likeBoundTy's.r? @jackh726