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

Move abstract const to middle #99000

Merged
merged 2 commits into from
Jul 14, 2022

Conversation

JulianKnodt
Copy link
Contributor

@JulianKnodt JulianKnodt commented Jul 7, 2022

Moves AbstractConst (and all associated methods) to rustc middle for use in rustc_infer.
This allows for const resolution in infer to use abstract consts to walk consts and check if
they are resolvable.

This attempts to resolve the issue where Foo<{ concrete const }, generic T> is incorrectly marked as conflicting, and is independent from the other issue where nested abstract consts must be resolved.

r? @lcnr

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 7, 2022
@rustbot
Copy link
Collaborator

rustbot commented Jul 7, 2022

Some changes occurred in const_evaluatable.rs

cc @lcnr

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 7, 2022
@JulianKnodt JulianKnodt force-pushed the allow_resolve_no_substs branch 4 times, most recently from 88d4c71 to b189045 Compare July 7, 2022 06:13
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

please move some more stuff, then r=me

compiler/rustc_infer/src/infer/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/thir/abstract_const.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/thir/abstract_const.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@JulianKnodt JulianKnodt force-pushed the allow_resolve_no_substs branch 3 times, most recently from a2847a2 to 916a91d Compare July 8, 2022 07:33
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jul 8, 2022

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

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jul 9, 2022

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

@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 11, 2022

doesnt seem like this PR has any changes to rustc_infer to solve the bug this PR is talking about.

compiler/rustc_ty_utils/src/consts.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/abstract_const.rs Outdated Show resolved Hide resolved
Comment on lines 117 to 137
#[instrument(skip(tcx), level = "debug")]
pub fn try_unify_abstract_consts<'tcx>(
tcx: TyCtxt<'tcx>,
(a, b): (ty::Unevaluated<'tcx, ()>, ty::Unevaluated<'tcx, ()>),
param_env: ty::ParamEnv<'tcx>,
) -> bool {
(|| {
if let Some(a) = AbstractConst::new(tcx, a)? {
if let Some(b) = AbstractConst::new(tcx, b)? {
let const_unify_ctxt = ConstUnifyCtxt { tcx, param_env };
return Ok(const_unify_ctxt.try_unify(a, b));
}
}

Ok(false)
})()
.unwrap_or_else(|_: ErrorGuaranteed| true)
// FIXME(generic_const_exprs): We should instead have this
// method return the resulting `ty::Const` and return `ConstKind::Error`
// on `ErrorGuaranteed`.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

it feels weird to have this be a query which is provided in rustc_trait_selectioneven though it's fully defined in rustc_middle.

I guess we actually want to keep try_unify_abstract_const and the ConstUnifyCtxt in rustc_trait_selection for now?

Copy link
Member

Choose a reason for hiding this comment

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

i feel like this should be in rustc_trait_selection still since it seems reasonable for try_unify to want to be able to unify inference vars eventaully- although "eventually" we probably want to remove try_unify_abstract_consts so I dont know how important this is

Copy link
Contributor

Choose a reason for hiding this comment

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

still relevant

@JulianKnodt
Copy link
Contributor Author

@BoxyUwU oops I initially made this PR to fix the bug, but turns out I would have to move this to rustc_middle::ty, and doing both seemed to mix two different concerns

@rust-log-analyzer

This comment has been minimized.

@JulianKnodt JulianKnodt force-pushed the allow_resolve_no_substs branch 2 times, most recently from f9d9386 to de618fb Compare July 13, 2022 04:32
@JulianKnodt
Copy link
Contributor Author

JulianKnodt commented Jul 13, 2022

It seems that it works just by attempting the identity substs without actually walking the abstract const,
so I removed the HasTyError variant from FailureKind (although it might make sense to have it in there otherwise).

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

there's still a final nit, and then r=me ❤️ thanks a lot

Comment on lines 117 to 137
#[instrument(skip(tcx), level = "debug")]
pub fn try_unify_abstract_consts<'tcx>(
tcx: TyCtxt<'tcx>,
(a, b): (ty::Unevaluated<'tcx, ()>, ty::Unevaluated<'tcx, ()>),
param_env: ty::ParamEnv<'tcx>,
) -> bool {
(|| {
if let Some(a) = AbstractConst::new(tcx, a)? {
if let Some(b) = AbstractConst::new(tcx, b)? {
let const_unify_ctxt = ConstUnifyCtxt { tcx, param_env };
return Ok(const_unify_ctxt.try_unify(a, b));
}
}

Ok(false)
})()
.unwrap_or_else(|_: ErrorGuaranteed| true)
// FIXME(generic_const_exprs): We should instead have this
// method return the resulting `ty::Const` and return `ConstKind::Error`
// on `ErrorGuaranteed`.
}
Copy link
Contributor

Choose a reason for hiding this comment

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

still relevant

@lcnr
Copy link
Contributor

lcnr commented Jul 14, 2022

@bors delegate+

@bors
Copy link
Contributor

bors commented Jul 14, 2022

✌️ @JulianKnodt can now approve this pull request

@lcnr
Copy link
Contributor

lcnr commented Jul 14, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jul 14, 2022

📌 Commit 20fb8ab 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 Jul 14, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 14, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#98072 (Add provider API to error trait)
 - rust-lang#98580 (Emit warning when named arguments are used positionally in format)
 - rust-lang#99000 (Move abstract const to middle)
 - rust-lang#99192 (Fix spans for asm diagnostics)
 - rust-lang#99222 (Better error message for generic_const_exprs inference failure)
 - rust-lang#99236 (solaris: unbreak build on native platform)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ecae3d7 into rust-lang:master Jul 14, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jul 14, 2022
@JulianKnodt JulianKnodt deleted the allow_resolve_no_substs branch July 14, 2022 20:17
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants