-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
reimplement ~const Trait
bounds via a fourth kind of generic param
#101900
Conversation
This comment has been minimized.
This comment has been minimized.
9963569
to
815442a
Compare
This comment has been minimized.
This comment has been minimized.
6dc21df
to
c68c262
Compare
Deduplicate two functions that would soon have been three rust-lang#101900 would have added another copy of this for effects
Deduplicate two functions that would soon have been three rust-lang#101900 would have added another copy of this for effects
Deduplicate two functions that would soon have been three rust-lang#101900 would have added another copy of this for effects
3ec01fc
to
2e40ec7
Compare
☔ The latest upstream changes (presumably #102056) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
28262b2
to
74e72c0
Compare
This comment has been minimized.
This comment has been minimized.
04641ab
to
098e59c
Compare
Looks like |
☔ The latest upstream changes (presumably #102461) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
098e59c
to
b98d0d3
Compare
37df7dc
to
8de7869
Compare
@@ -332,6 +359,16 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics { | |||
} | |||
} | |||
|
|||
if has_constness_effect { |
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.
has_host_effect
.
let flags = FlagComputation::for_effect(e); | ||
if flags.intersects(self.needs_canonical_flags) { e.super_fold_with(self) } else { e } |
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.
why is that not simply happening in the _ => {}
branch and we stop explicitly using return
for the other branches.
) -> ty::Effect<'tcx> { | ||
let infcx = self.infcx; | ||
let bound_to = infcx.shallow_resolve(effect_var); | ||
if bound_to != effect_var { |
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.
can you make that an assert instead? shouldn't we shallow resolve in fold_effect
already?
} | ||
GenericArgKind::Effect(result_value) => { | ||
if let ty::EffectValue::Bound(debrujin, b) = result_value.val { | ||
// ...in which case we would set `canonical_vars[0]` to `Some(const X)`. |
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.
Some(const x)
?
@@ -753,6 +755,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { | |||
GenericArgKind::Lifetime(_) => 0, // erased | |||
GenericArgKind::Type(ty) => self.ty_cost(ty), | |||
GenericArgKind::Const(_) => 3, // some non-zero value | |||
GenericArgKind::Effect(_) => 3, // some non-zero value |
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.
would put them together with regions, you cannot explicitly mention effects so they don't have a cost
EffectVariableValue::Unknown { .. } => {} | ||
EffectVariableValue::Known { .. } => continue, | ||
} | ||
let value = self.tcx.mk_effect(ty::EffectValue::Rigid { on: true }, origin.effect_kind); |
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.
not applying vs ty::EffectValue::Rigid { on: true },
. afaict either the function comment or the impl is wrong
b: ty::Effect<'tcx>, | ||
) -> RelateResult<'tcx, ty::Effect<'tcx>> { | ||
match (a.val, b.val) { | ||
// Any effect matches the rigid "on" effect. For example: `T: ~const Trait` (off) implies `T: Trait` (on) |
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.
effects and subtyping seems very sus. What's the default variance for effect parameters?
@@ -185,7 +199,19 @@ impl<'tcx> Elaborator<'tcx> { | |||
// though conceivably we might. | |||
} | |||
ty::PredicateKind::Clause(ty::Clause::Projection(..)) => { | |||
// Nothing to elaborate in a projection predicate. | |||
// `<T as ~const Trait>::TYPE` implies `<T as Trait>::TYPE` |
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.
can you add a comment that this is only correct if the predicate has exactly 1 effect param? If there were multiple params i could imagine us wanting to add all possible combinations of const
+ ~const
.
GenericParamDefKind::Effect { kind } => kind == effect_kind, | ||
_ => false, | ||
}) | ||
.or_else(|| tcx.generics_of(self.parent?).effect_param(effect_kind, tcx)) |
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 am not certain whether we will always only have 1 effect param of the same kind, or I can at least imagine future extensions which will break this code.
Can you add a Debug_assert
to generics_of
whichi check for this?
@@ -338,6 +338,14 @@ impl<'tcx> Instance<'tcx> { | |||
ty::GenericParamDefKind::Const { .. } => { | |||
bug!("Instance::mono: {:?} has const parameters", def_id) | |||
} | |||
ty::GenericParamDefKind::Effect { kind } => { | |||
// FIXME: this is necessary for `panic` and friends in the monomorphization collector. |
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.
// FIXME: this is necessary for `panic` and friends in the monomorphization collector. | |
// FIXME(effects): this is necessary for `panic` and friends in the monomorphization collector. |
// hook in here to catch this case (annoying...), but | ||
// otherwise we do want to remember to visit the rest of the | ||
// effect, as it has types/regions embedded in a lot of other | ||
// places. |
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 understand that comment 🤔
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 think I copy pasted it from constants without looking at the details
@@ -286,27 +286,42 @@ pub fn closure_trait_ref_and_return_type<'tcx>( | |||
tcx: TyCtxt<'tcx>, | |||
fn_trait_def_id: DefId, | |||
self_ty: Ty<'tcx>, | |||
// Make this an array once the effect feature is always active |
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.
// Make this an array once the effect feature is always active | |
// FIXME(effects): Make this an array once the effect feature is always active |
}; | ||
let trait_ref = tcx.mk_trait_ref( | ||
fn_trait_def_id, | ||
// FIXME: have the caller pass the effects here and use them. |
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.
// FIXME: have the caller pass the effects here and use them. | |
// FIXME(effects): have the caller pass the effects here and use them. |
} | ||
|
||
pub fn generator_trait_ref_and_outputs<'tcx>( | ||
tcx: TyCtxt<'tcx>, | ||
fn_trait_def_id: DefId, | ||
self_ty: Ty<'tcx>, | ||
// Make this an array once the effect feature is always active |
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.
// Make this an array once the effect feature is always active | |
// FIXME(effects): Make this an array once the effect feature is always active |
#[inline] | ||
pub const fn extend(&self, next: Self) -> Result<(Self, usize), LayoutError> { | ||
pub fn extend(&self, next: Self) -> Result<(Self, usize), LayoutError> { |
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.
why this change?
@@ -354,7 +354,7 @@ where | |||
type Output = <[T] as Index<I>>::Output; | |||
|
|||
#[inline] | |||
fn index(&self, index: I) -> &Self::Output { | |||
fn index(&self, index: I) -> &<[T] as Index<I>>::Output { |
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.
same here, why these libs changes?
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.
Because Self
didn't work ^^ I'm still figuring out that part
|
||
struct S; | ||
trait T {} | ||
|
||
impl const S {} | ||
//~^ ERROR inherent impls cannot be `const` | ||
//~| ERROR `host` is not constrained |
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.
adding an effect param for inherent impls seems bad ui wise ^^
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.
yea I hate everything about it ^^ I'll remove it and just require everyone to repeat trait bounds on the functions for now
If I am correct this can be switched to waiting on author. Feel free to request a review with @rustbot author |
This PR has become impossible to rebase. I'm starting from scratch on a new branch with a smaller MVP |
Various cleanups This PR pulls changes out of rust-lang/rust#101900 that can land on master immediately r? ``@fee1-dead``
r? @lcnr
tracking issue: #102090