Skip to content

Don't normalize in AstConv#101947

Merged
bors merged 9 commits intorust-lang:masterfrom
aliemjay:astconv-normalize
Jan 9, 2023
Merged

Don't normalize in AstConv#101947
bors merged 9 commits intorust-lang:masterfrom
aliemjay:astconv-normalize

Conversation

@aliemjay
Copy link
Contributor

@aliemjay aliemjay commented Sep 17, 2022

See individual commits.

Fixes #101350
Fixes #54940

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 17, 2022
@rust-highfive
Copy link
Contributor

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 17, 2022
@aliemjay aliemjay force-pushed the astconv-normalize branch 2 times, most recently from c874486 to c3bf78b Compare October 26, 2022 14:19
@rust-log-analyzer

This comment has been minimized.

@the8472
Copy link
Member

the8472 commented Oct 27, 2022

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 27, 2022
@bors
Copy link
Collaborator

bors commented Oct 27, 2022

⌛ Trying commit 82fa1136489005893be02555b865ca6a90d923f3 with merge 1ab52f9b015fe3b11f0862dd6cbf44c426995a28...

@bors
Copy link
Collaborator

bors commented Oct 27, 2022

☀️ Try build successful - checks-actions
Build commit: 1ab52f9b015fe3b11f0862dd6cbf44c426995a28 (1ab52f9b015fe3b11f0862dd6cbf44c426995a28)

@rust-timer
Copy link
Collaborator

Queued 1ab52f9b015fe3b11f0862dd6cbf44c426995a28 with parent 44fcfb0, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1ab52f9b015fe3b11f0862dd6cbf44c426995a28): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 27, 2022
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Oct 31, 2022
@aliemjay aliemjay changed the title [WIP] don't normalize in AstConv Don't normalize in AstConv Oct 31, 2022
@aliemjay aliemjay marked this pull request as ready for review October 31, 2022 14:29
@aliemjay
Copy link
Contributor Author

r? @lcnr

@rustbot rustbot assigned lcnr and unassigned jackh726 Oct 31, 2022
@bors
Copy link
Collaborator

bors commented Nov 6, 2022

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

Copy link
Contributor

Choose a reason for hiding this comment

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

recording types with escaping bound vars is pretty cursed anyways 🤔 ideally we just don't™. Do you know where that currently happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This happens in nested hir::Ty's, e.g. &'a str in let _: for<'a> fn(&'a str). But I don't think they're relevant to typeck since the outer type has no escaping bound vars. One place where it actually matters is in closures - underscore lifetimes are always late-bound regions (e.g. |_: &'_ str| {}) but we currently handle this in closure.rs by normalizing the complete signature rather than each input type separately.

Copy link
Contributor

Choose a reason for hiding this comment

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

this means that self_ctor_substs are already normalized, but are used as substs_raw further down. I would expect this to be a bug (where we again ignore region obligations from user written types)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SelfCtor type is already checked by item wfcheck, so I don't think we will miss region obligations when normalizing.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, we can't rely on probe_adt here because we also need the substs 🤔 i guess that's fine then.

While I am not sure whether we could land this, can you add something like the following here?

FIXME: Try to change this to use the unnormalized type here and check the resulting breakage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was indeed problematic. I have fixed it in e05158d.

Copy link
Contributor

Choose a reason for hiding this comment

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

no, we shouldn't imo

imo we should have never relied on normalization during ast lowering. We won't be able to remove the existing normalization due to backwards compatibility. I think we should just live with the existing inconsistency, potentially even linting when normalization is required to remove it 2030 or whatever

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 tend to agree. The fact that path resolution depends on normalization may be an unintended behavior.

Copy link
Contributor

@lcnr lcnr Nov 21, 2022

Choose a reason for hiding this comment

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

cc @rust-lang/types I generally don't think we should normalize during astconv to resolve stuff like Self::A if Self is a projection. Examples include

trait Identity {
    type Id;
}
impl<T> Identity for T {
    type Id = T;
}

enum Foo {
    A,
    B,
}

trait Trait {
    fn return_a() -> Self;
}

impl Trait for <Foo as Identity>::Id {
    fn return_a() -> Self {
        Self::A
    }
}

fn main() {
    let x = <<Foo as Identity>::Id>::A;
}

We do have to keep supporting this for backwards compatibility however.

I therefore think that we should 1) remove the FIXME here and add a comment for "we cannot normalize inside of a binder" 2) rename this method to probe_adt_normalize_for_backcompat to prevent us from at least adding further uses of that method.

edit: we do normalize for resolve_fully_qualified_call as well it's not as simple as only warning on this method 🤔 idk

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This looks like T-lang issue. Can we open a new issue and nominate it for t-lang?

Anyway I toned down the FIXME comment and opened a new ticket for it #104767. See also #103640.

@lcnr
Copy link
Contributor

lcnr commented Nov 7, 2022

Thanks ❤️

As this is a breaking change, going to run crater and then go through a t-types FCP. r=me on the impl after some nits

@bors try

@bors
Copy link
Collaborator

bors commented Nov 7, 2022

⌛ Trying commit a1a29a30952de6b1aed11075b0979825595c5275 with merge c4ca63acfd7111dc43e5bc36534474f323ca449a...

@bors
Copy link
Collaborator

bors commented Nov 7, 2022

☀️ Try build successful - checks-actions
Build commit: c4ca63acfd7111dc43e5bc36534474f323ca449a (c4ca63acfd7111dc43e5bc36534474f323ca449a)

Projection types in user annotations may contain inference variables.
This makes the normalization depend on the unification with the actual
type and thus requires a separate TypeOp to track the obligations.
Otherwise simply calling `TypeChecker::normalize` would ICE with
"unexpected ambiguity"
Delay until user annotations are registered.
See the added test.
@lcnr
Copy link
Contributor

lcnr commented Jan 9, 2023

@bors r+ rollup=never

@bors
Copy link
Collaborator

bors commented Jan 9, 2023

📌 Commit bf228ac has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 9, 2023
@bors
Copy link
Collaborator

bors commented Jan 9, 2023

⌛ Testing commit bf228ac with merge af58fc8...

@bors
Copy link
Collaborator

bors commented Jan 9, 2023

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing af58fc8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 9, 2023
@bors bors merged commit af58fc8 into rust-lang:master Jan 9, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 9, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (af58fc8): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.1% [0.1%, 0.1%] 1
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 3
Improvements ✅
(primary)
-1.0% [-1.0%, -1.0%] 1
Improvements ✅
(secondary)
-0.8% [-0.9%, -0.8%] 7
All ❌✅ (primary) -0.5% [-1.0%, 0.1%] 2

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.1% [-1.1%, -1.1%] 1

@rustbot rustbot added the perf-regression Performance regression. label Jan 9, 2023
@aliemjay aliemjay deleted the astconv-normalize branch January 10, 2023 01:01
@Mark-Simulacrum
Copy link
Member

Mixed results, but overall small in magnitude and relatively scattered. Marking as triaged -- I don't think we need to dig in further. This change fixes a couple bugs, so it's worthwhile to accept small regressions like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-borrow-checker Area: The borrow checker disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ignored regions constraints when normalizing user-provided types user type annotations are captured post normalization