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

Implement fallback for effect param #115727

Merged
merged 2 commits into from
Sep 11, 2023

Conversation

fee1-dead
Copy link
Member

@fee1-dead fee1-dead commented Sep 10, 2023

r? @oli-obk or @lcnr

tracking issue for this ongoing work: #110395

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative labels Sep 10, 2023
@rustbot
Copy link
Collaborator

rustbot commented Sep 10, 2023

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@rust-log-analyzer

This comment has been minimized.

@@ -1577,6 +1577,14 @@ pub struct ConstVid<'tcx> {
pub phantom: PhantomData<&'tcx ()>,
}

/// An **effect** **v**ariable **ID**.
Copy link
Member

@compiler-errors compiler-errors Sep 10, 2023

Choose a reason for hiding this comment

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

Why are effects being represented with a separate vid?

There's a weird dichotomy happening here where effects are kinda treated like const and kinda like their own kind, and it's not exactly clear why.

Shouldn't we be able to store whether a const vid comes from an effect parameter in the const vid table so it can participate in fallback later?

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 kinda just followed how int and float type variables also have their own vids. We'd probably want to ensure that we know all variables instantiated for an effect param are actually for an effect param, and having a separate vid helped by catching things like relating a normal const var with an effect var which should never happen.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, maybe that's better. This definitely needs documentation though -- that's a design decision that (afaict? maybe i'm just out of the loop) isn't written anywhere, and it should be probably 😺

Copy link
Member Author

Choose a reason for hiding this comment

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

added a comment

compiler/rustc_infer/src/infer/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/fallback.rs Outdated Show resolved Hide resolved
@@ -443,6 +448,14 @@ impl<'tcx> CanonicalVarValues<'tcx> {
};
ty::Region::new_late_bound(tcx, ty::INNERMOST, br).into()
}
// todo eh?
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover comment

@@ -873,14 +873,14 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
| DefKind::AssocConst
| DefKind::Macro(_)
| DefKind::Field
| DefKind::Impl { .. } => true,
| DefKind::Impl { .. }
| DefKind::ConstParam => true,
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to encode const param attrs in metadata? I'd assume we'd get all the information from ty::Generics if it's from an upstream crate

Comment on lines 1185 to 1186
// todo what about using effect var here
if self.tcx.has_attr(param.def_id, sym::rustc_host) {
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm 🤔 I guess we could add a is_host_effect: bool field to GenericParamDefKind::Const to make this simpler. it's not going to increase the size of GenericParamDefKind, even if we change it to an enum at some point to encode different effect kinds

Comment on lines 548 to 554
fn effect_unification_error<'tcx>(
tcx: TyCtxt<'tcx>,
a_is_expected: bool,
(a, b): (EffectVarValue<'tcx>, EffectVarValue<'tcx>),
) -> TypeError<'tcx> {
TypeError::ConstMismatch(ExpectedFound::new(a_is_expected, a.as_const(tcx), b.as_const(tcx)))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be hit at all at present?

Copy link
Member Author

Choose a reason for hiding this comment

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

The tests pass with changing this to a bug so probably not (but we also don't test effects that much lol) I'll change this to panic and then see if we can get a better diagnostic if we actually hit it.

@rustbot
Copy link
Collaborator

rustbot commented Sep 11, 2023

This PR changes Stable MIR

cc @oli-obk, @celinval, @spastorino

@oli-obk
Copy link
Contributor

oli-obk commented Sep 11, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Sep 11, 2023

📌 Commit 9654d5c has been approved by oli-obk

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 Sep 11, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 11, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#115335 (fix overflow in array length computation)
 - rust-lang#115440 (bootstrap/format: remove unnecessary paths.push)
 - rust-lang#115702 (Update mailmap)
 - rust-lang#115727 (Implement fallback for effect param)
 - rust-lang#115739 (Call `LateLintPass::check_attribute` from `with_lint_attrs`)
 - rust-lang#115743 (Point out if a local trait has no implementations)
 - rust-lang#115744 (Improve diagnostic for generic params from outer items (E0401))
 - rust-lang#115752 (rustdoc: Add missing "Aliased type" title in the sidebar)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e7a347b into rust-lang:master Sep 11, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Sep 11, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 11, 2023
Rollup merge of rust-lang#115727 - fee1-dead-contrib:effect-fallback, r=oli-obk

Implement fallback for effect param

r? `@oli-obk` or `@lcnr`

tracking issue for this ongoing work: rust-lang#110395
@fee1-dead fee1-dead deleted the effect-fallback branch November 24, 2023 14:51
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Nov 24, 2023
…ler-errors

Remove a hack for effects

Fallback was implemented in rust-lang#115727, which addresses the inference errors mentioned in the comments.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 24, 2023
Rollup merge of rust-lang#118246 - fee1-dead-contrib:rm-hack, r=compiler-errors

Remove a hack for effects

Fallback was implemented in rust-lang#115727, which addresses the inference errors mentioned in the comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants