Skip to content
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

Closed
wants to merge 13 commits into from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Sep 16, 2022

r? @lcnr

tracking issue: #102090

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Sep 16, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 16, 2022
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-rustdoc-json Area: Rustdoc JSON backend label Sep 16, 2022
@rust-log-analyzer

This comment has been minimized.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 22, 2022
Deduplicate two functions that would soon have been three

rust-lang#101900 would have added another copy of this for effects
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 22, 2022
Deduplicate two functions that would soon have been three

rust-lang#101900 would have added another copy of this for effects
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 23, 2022
Deduplicate two functions that would soon have been three

rust-lang#101900 would have added another copy of this for effects
@oli-obk oli-obk force-pushed the const_trait_take_two branch 2 times, most recently from 3ec01fc to 2e40ec7 Compare September 23, 2022 10:48
@bors
Copy link
Contributor

bors commented Sep 23, 2022

☔ The latest upstream changes (presumably #102056) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the const_trait_take_two branch 2 times, most recently from 28262b2 to 74e72c0 Compare September 28, 2022 19:07
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the const_trait_take_two branch 2 times, most recently from 04641ab to 098e59c Compare September 29, 2022 09:46
@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 29, 2022

Looks like src/tools/jsondoclint is not covered by ./x.py check

@bors
Copy link
Contributor

bors commented Sep 29, 2022

☔ The latest upstream changes (presumably #102461) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@@ -332,6 +359,16 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
}
}

if has_constness_effect {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has_host_effect.

Comment on lines +564 to +565
let flags = FlagComputation::for_effect(e);
if flags.intersects(self.needs_canonical_flags) { e.super_fold_with(self) } else { e }
Copy link
Contributor

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 {
Copy link
Contributor

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)`.
Copy link
Contributor

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
Copy link
Contributor

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);
Copy link
Contributor

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)
Copy link
Contributor

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`
Copy link
Contributor

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))
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.
Copy link
Contributor

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 🤔

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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> {
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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 ^^

Copy link
Contributor Author

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

@apiraino
Copy link
Contributor

apiraino commented Feb 1, 2023

If I am correct this can be switched to waiting on author. Feel free to request a review with @rustbot ready, thanks!

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 1, 2023
@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 14, 2023

This PR has become impossible to rebase. I'm starting from scratch on a new branch with a smaller MVP

@oli-obk oli-obk closed this Mar 14, 2023
thomcc pushed a commit to tcdi/postgrestd that referenced this pull request May 31, 2023
Various cleanups

This PR pulls changes out of rust-lang/rust#101900 that can land on master immediately

r? ``@fee1-dead``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend A-testsuite Area: The testsuite used to check the correctness of rustc A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants