reimplement ~const Trait bounds via a fourth kind of generic param - #101900
reimplement ~const Trait bounds via a fourth kind of generic param#101900oli-obk wants to merge 13 commits into
~const Trait bounds via a fourth kind of generic param#101900Conversation
This comment has been minimized.
This comment has been minimized.
9963569 to
815442a
Compare
This comment has been minimized.
This comment has been minimized.
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
| .unwrap(); | ||
| let substs = if self.tcx.effects() { | ||
| self.tcx | ||
| .mk_substs(instance.substs.iter().chain([self.tcx.effects.always_const.into()])) |
There was a problem hiding this comment.
I explicitly named it this way (it would be host_off fwiw) and I dislike inverses.
| ) | ||
| .into()] | ||
| .into_iter() | ||
| .chain(tcx.host_effect()), |
There was a problem hiding this comment.
| .chain(tcx.host_effect()), | |
| .chain(tcx.default_host_effect()), |
or something like that?
There was a problem hiding this comment.
why are u using mk_trait_ref instead of mk_trait_ref_with_effect here?
There was a problem hiding this comment.
Hmm... I do get the naming confusing between this not returning the effect kind, but a value of the host effect... I'll try out a few namings
There was a problem hiding this comment.
why are u using
mk_trait_refinstead ofmk_trait_ref_with_effecthere?
for diagnostics I opted to just always fall back to host-on. Many times we don't have any context information available anyway
| /// Allows `dyn* Trait` objects. | ||
| (incomplete, dyn_star, "1.65.0", Some(102425), None), | ||
| // Uses generic effect parameters for ~const bounds | ||
| (active, effects, "1.62.0", Some(102090), None), |
There was a problem hiding this comment.
| (active, effects, "1.62.0", Some(102090), None), | |
| (incomplete, effects, "1.62.0", Some(102090), None), |
?
| } | ||
| } | ||
|
|
||
| if has_constness_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.
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.
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)`. |
| 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.
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.
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.
effects and subtyping seems very sus. What's the default variance for effect parameters?
| } | ||
| 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.
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.
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?
| 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.
| // 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.
i don't understand that comment 🤔
There was a problem hiding this comment.
I think I copy pasted it from constants without looking at the details
| 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.
| // 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.
| // FIXME: have the caller pass the effects here and use them. | |
| // FIXME(effects): have the caller pass the effects here and use them. |
| 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.
| // Make this an array once the effect feature is always active | |
| // FIXME(effects): Make this an array once the effect feature is always active |
| #[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")] | ||
| #[inline] | ||
| pub const fn extend(&self, next: Self) -> Result<(Self, usize), LayoutError> { | ||
| pub fn extend(&self, next: Self) -> Result<(Self, usize), LayoutError> { |
|
|
||
| #[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.
same here, why these libs changes?
There was a problem hiding this comment.
Because Self didn't work ^^ I'm still figuring out that part
|
|
||
| impl const S {} | ||
| //~^ ERROR inherent impls cannot be `const` | ||
| //~| ERROR `host` is not constrained |
There was a problem hiding this comment.
adding an effect param for inherent impls seems bad ui wise ^^
There was a problem hiding this comment.
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 |
r? @lcnr
tracking issue: #102090