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

Structurally normalize weak and inherent in new solver #114594

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> {
// we have some type like `&<Ty as Trait>::Assoc`, since users of
// autoderef expect this type to have been structurally normalized.
if self.infcx.next_trait_solver()
&& let ty::Alias(ty::Projection, _) = ty.kind()
&& let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _) = ty.kind()
{
let (normalized_ty, obligations) = self.structurally_normalize(ty)?;
self.state.obligations.extend(obligations);
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
cause: Option<ObligationCause<'tcx>>,
) -> RelateResult<'tcx, Ty<'tcx>> {
let source = self.try_structurally_resolve_type(expr.span, expr_ty);
let target = self.try_structurally_resolve_type(
Copy link
Member Author

Choose a reason for hiding this comment

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

I take it back -- @lqd: this line may have changed the order we process obligations, re: perf #114604.

I'd be surprised if this had a meaningful effect on perf, tho.

Copy link
Member

Choose a reason for hiding this comment

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

I’ll check if cachegrind has anything interesting to say

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm also just getting rid of this one line and running perf in #114648.

Copy link
Member Author

Choose a reason for hiding this comment

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

If this is the culprit, I guess I may be able to work around it.

Copy link
Member

Choose a reason for hiding this comment

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

Processing obligations seems to be the main source of change, but hopefully we'll learn more in the new PR if it's not some kind of noise.

260,711,737  ???:<rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>

cause.as_ref().map_or(expr.span, |cause| cause.span),
target,
);
debug!("coercion::try({:?}: {:?} -> {:?})", expr, source, target);

let cause =
Expand Down Expand Up @@ -1097,8 +1101,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
where
E: AsCoercionSite,
{
let prev_ty = self.resolve_vars_with_obligations(prev_ty);
let new_ty = self.resolve_vars_with_obligations(new_ty);
let prev_ty = self.try_structurally_resolve_type(cause.span, prev_ty);
let new_ty = self.try_structurally_resolve_type(new.span, new_ty);
debug!(
"coercion::try_find_coercion_lub({:?}, {:?}, exprs={:?} exprs)",
prev_ty,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.resolve_vars_with_obligations(ty);

if self.next_trait_solver()
&& let ty::Alias(ty::Projection, _) = ty.kind()
&& let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _) = ty.kind()
{
match self
.at(&self.misc(sp), self.param_env)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ impl<'tcx> StructurallyNormalizeExt<'tcx> for At<'_, 'tcx> {
assert!(!ty.is_ty_var(), "should have resolved vars before calling");

if self.infcx.next_trait_solver() {
while let ty::Alias(ty::Projection, projection_ty) = *ty.kind() {
while let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, projection_ty) =
*ty.kind()
{
let new_infer_ty = self.infcx.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::NormalizeProjectionType,
span: self.cause.span,
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/for/issue-20605.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ error: the type `&mut <dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIte
LL | for item in *things { *item = 0 }
| ^^^^^^^

error[E0614]: type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced
--> $DIR/issue-20605.rs:5:27
|
LL | for item in *things { *item = 0 }
| ^^^^^

error[E0277]: the size for values of type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be known at compilation time
--> $DIR/issue-20605.rs:5:9
|
Expand All @@ -66,6 +60,12 @@ LL | for item in *things { *item = 0 }
note: required by a bound in `None`
--> $SRC_DIR/core/src/option.rs:LL:COL

error[E0614]: type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced
--> $DIR/issue-20605.rs:5:27
|
LL | for item in *things { *item = 0 }
| ^^^^^

error: aborting due to 9 previous errors

Some errors have detailed explanations: E0277, E0614.
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/lazy-type-alias/coerce-behind-lazy.current.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/coerce-behind-lazy.rs:5:12
|
LL | #![feature(lazy_type_alias)]
| ^^^^^^^^^^^^^^^
|
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted

11 changes: 11 additions & 0 deletions tests/ui/lazy-type-alias/coerce-behind-lazy.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/coerce-behind-lazy.rs:5:12
|
LL | #![feature(lazy_type_alias)]
| ^^^^^^^^^^^^^^^
|
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted

16 changes: 16 additions & 0 deletions tests/ui/lazy-type-alias/coerce-behind-lazy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// check-pass
// revisions: current next
//[next] compile-flags: -Ztrait-solver=next

#![feature(lazy_type_alias)]
//~^ WARN the feature `lazy_type_alias` is incomplete

use std::any::Any;

type Coerce = Box<dyn Any>;

fn test() -> Coerce {
Box::new(1)
}

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/traits/new-solver/lazy-nested-obligations-2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// compile-flags: -Ztrait-solver=next
// known-bug: #95863
// check-pass

pub trait With {
type F;
Expand Down
39 changes: 0 additions & 39 deletions tests/ui/traits/new-solver/lazy-nested-obligations-2.stderr

This file was deleted.

4 changes: 2 additions & 2 deletions tests/ui/traits/new-solver/more-object-bound.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `dyn Trait<A = A, B = B>: Trait` is not satisfied
--> $DIR/more-object-bound.rs:12:17
--> $DIR/more-object-bound.rs:12:5
|
LL | foo::<A, B, dyn Trait<A = A, B = B>>(x)
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `dyn Trait<A = A, B = B>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `dyn Trait<A = A, B = B>`
|
note: required by a bound in `foo`
--> $DIR/more-object-bound.rs:18:8
Expand Down
Loading