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

Begin to abstract rustc_type_ir for rust-analyzer #116828

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Oct 17, 2023

This adds the "nightly" feature which is used by the compiler, and falls back to more simple implementations when that is not active.

r? @lcnr or @jackh726

@compiler-errors compiler-errors marked this pull request as ready for review October 17, 2023 00:41
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 17, 2023
@compiler-errors
Copy link
Member Author

@bors try @rust-timer queue

the debug formatting changed to use the non-convenience functions -- shouldn't affect perf but weirder things have happened

@rust-timer

This comment has been minimized.

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

bors commented Oct 17, 2023

⌛ Trying commit 6f43680 with merge 26d6e91...

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 17, 2023
…e_ir, r=<try>

Begin to abstract `rustc_type_ir` for rust-analyzer

Not totally happy with this yet, but if the new trait solver is ever to be used by external users, we need to make rustc-type-ir build without internal deps. This adds the "nightly" feature which is used by the compiler, and falls back to more simple implementations when that is not active.

r? `@lcnr` or `@jackh726` -- happy to block this pr on a discussion about design and long-term direction for rustc-type-ir tho
@bors
Copy link
Contributor

bors commented Oct 17, 2023

☀️ Try build successful - checks-actions
Build commit: 26d6e91 (26d6e91c6bb9c044b86d4d74f56fc8029a907b85)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (26d6e91): 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-perf -perf-regression

Instruction count

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

Max RSS (memory usage)

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)
2.0% [2.0%, 2.0%] 1
Improvements ✅
(primary)
-1.4% [-1.4%, -1.4%] 1
Improvements ✅
(secondary)
-1.3% [-1.3%, -1.3%] 1
All ❌✅ (primary) -1.4% [-1.4%, -1.4%] 1

Cycles

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

Binary size

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

Bootstrap: 627.292s -> 625.722s (-0.25%)
Artifact size: 305.57 MiB -> 305.62 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 17, 2023
@jackh726
Copy link
Member

Let's schedule some time to discuss this? I think some of these are okay to do short-term, but I'd like to have some idea of what we want long-term.

type Never = !;

#[cfg(not(feature = "nightly"))]
type Never = std::convert::Infallible;
Copy link
Member

Choose a reason for hiding this comment

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

Half serious: you could just use <fn() -> !>::Output

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems to have problems with type inference later on in the crate:'

error[E0284]: type annotations needed
   --> compiler/rustc_type_ir/src/fold.rs:223:18
    |
223 |     type Error = Never;
    |                  ^^^^^ cannot infer type
    |
    = note: cannot satisfy `<F as FallibleTypeFolder<I>>::Error == _`

Copy link
Member

Choose a reason for hiding this comment

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

Huh 🤔

Copy link
Member

Choose a reason for hiding this comment

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

So the MRE is this: (play).

FallibleTypeFolder<Error = Never> from TypeFolder super-traits gets checked against type Error = Never in the blanket impl of FallibleTypeFolder for F: TypeFolder.

First of all, are cycles like this even allowed? I.e. can you satisfy a super-trait bound by a blanket impl that asks for the same trait? I would think that this causes a cycle...

Second of all, can't we just remove the super trait? It seems like all the things that can be proven with the supertrait bound can be proven via the blanket impl (that might be wrong, not sure).

Lastly, why the compiler can't evaluate this projection here? It seems to be fine in other places, and I don't see what can't it infer...

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 see why it should cause a cycle... impls (blanket or otherwise) can be provided even where supertraits are not satisfied.

We can't "just" remove the supertrait because the default implementations of the subtrait's provided methods ultimately call into the supertrait — and I don't think the existence of the blanket impl is provable there, within the trait definition.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, so the error arises whenever the associated type doesn't match the supertrait constraint: (play).

Not sure why the compiler is unable to prove that the Never types are equal, though...

compiler/rustc_type_ir/src/fold.rs Outdated Show resolved Hide resolved
compiler/rustc_type_ir/src/index.rs Outdated Show resolved Hide resolved
@rustbot
Copy link
Collaborator

rustbot commented Oct 18, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@compiler-errors
Copy link
Member Author

Ending up pulling out the newtype macro and applying the changes from #116830, so I'm slightly happier with the changes now.

@rust-log-analyzer

This comment has been minimized.

@eggyal
Copy link
Contributor

eggyal commented Oct 20, 2023

I'm interested in understanding the long-term direction here too: could you direct me towards any discussion you end up having over this @compiler-errors and @jackh726 ? Thanks!

@compiler-errors
Copy link
Member Author

@eggyal: Yeah I haven't had too many conversations about this, but I'll make sure to open a topic on the t-types zulip stream if I do.

@bors
Copy link
Contributor

bors commented Oct 20, 2023

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

@bors
Copy link
Contributor

bors commented Oct 24, 2023

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

@compiler-errors
Copy link
Member Author

Would appreciate a review on this, since it's very bitrotty :'(

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

One question - but r=me once you resolve that.

#[debug_format = "DebruijnIndex({})"]
#[gate_rustc_only]
Copy link
Member

Choose a reason for hiding this comment

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

Wait, am I confused, or does this mean that DebruijnIndex (and UniverseIndex) below are nightly (rustc) only?

Copy link
Member

Choose a reason for hiding this comment

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

If so, why? If there is no reason, this shouldn't be gated.

If not, ignore me :)

Copy link
Member Author

@compiler-errors compiler-errors Nov 19, 2023

Choose a reason for hiding this comment

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

No, sorry for the confusion. The attribute just means "emit all the nightly stuff (e.g. Step and Encodable/Decodable) with a cfg(feature = "nightly") so it can be compiled on stable too". Maybe it should be renamed, but can be later.

@compiler-errors
Copy link
Member Author

@bors r=jackh726

@bors
Copy link
Contributor

bors commented Nov 19, 2023

📌 Commit 4506681 has been approved by jackh726

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 Nov 19, 2023
@bors
Copy link
Contributor

bors commented Nov 19, 2023

⌛ Testing commit 4506681 with merge 4f3da90...

@bors
Copy link
Contributor

bors commented Nov 20, 2023

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing 4f3da90 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 20, 2023
@bors bors merged commit 4f3da90 into rust-lang:master Nov 20, 2023
12 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 20, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4f3da90): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

Max RSS (memory usage)

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)
3.6% [3.6%, 3.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

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)
- - 0
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 676.7s -> 678.667s (0.29%)
Artifact size: 313.73 MiB -> 313.77 MiB (0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants