-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[PERF] allow region unification to change region universes #108867
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ pub trait ToType { | |
} | ||
|
||
#[derive(PartialEq, Copy, Clone, Debug)] | ||
pub struct UnifiedRegion<'tcx>(pub Option<ty::Region<'tcx>>); | ||
pub struct UnifiedRegion<'tcx> { | ||
pub universe: ty::UniverseIndex, | ||
pub value: Option<ty::Region<'tcx>>, | ||
} | ||
|
||
#[derive(PartialEq, Copy, Clone, Debug)] | ||
pub struct RegionVidKey<'tcx> { | ||
|
@@ -43,18 +46,8 @@ impl<'tcx> UnifyKey for RegionVidKey<'tcx> { | |
impl<'tcx> UnifyValue for UnifiedRegion<'tcx> { | ||
type Error = NoError; | ||
|
||
fn unify_values(value1: &Self, value2: &Self) -> Result<Self, NoError> { | ||
Ok(match (value1.0, value2.0) { | ||
// Here we can just pick one value, because the full constraints graph | ||
// will be handled later. Ideally, we might want a `MultipleValues` | ||
// variant or something. For now though, this is fine. | ||
(Some(_), Some(_)) => *value1, | ||
|
||
(Some(_), _) => *value1, | ||
(_, Some(_)) => *value2, | ||
|
||
(None, None) => *value1, | ||
}) | ||
fn unify_values(value1: &Self, value2: &Self) -> Result<Self, Self::Error> { | ||
Ok(cmp::min_by_key(*value1, *value2, |val| (val.universe, val.value.is_none()))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can pull down the universe of known regions which seems wrong 🤔 I would expect us to have to eagerly error here if we relate with a known region There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is that unification should always be infallible, the constraint graph will eventually emit a universe error in this case. The only invariant we should maintain in the unification table is that an existential cannot resolve to a region in a higher universe (plus one nice thing to have is to prefer universals over existentials within the same universe, but that's not necessary for soundness). |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: implementation of `Trait` is not general enough | ||
--> $DIR/hrtb-exists-forall-trait-invariant.rs:28:5 | ||
| | ||
LL | foo::<()>(); | ||
| ^^^^^^^^^^^ implementation of `Trait` is not general enough | ||
| | ||
= note: `()` must implement `Trait<for<'b> fn(Cell<&'b u32>)>` | ||
= note: ...but it actually implements `Trait<fn(Cell<&'0 u32>)>`, for some specific lifetime `'0` | ||
|
||
error: aborting due to previous error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to
TypeVariableValue
andConstVariableValue
change this to an enum and only have a universe in theUnknown
case? 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although it seems redundant, but I thought it might be a good idea to store the universe of universals and existentials in the same place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if region unification is infallible i think we even have to keep the universe even if
value
isSome
, don't we? 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
universe
field here is redundant ifvalue
isSome
.