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 const equality and const wf #340

Closed
1 of 3 tasks
lcnr opened this issue Aug 1, 2020 · 2 comments
Closed
1 of 3 tasks

Implement const equality and const wf #340

lcnr opened this issue Aug 1, 2020 · 2 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@lcnr
Copy link
Contributor

lcnr commented Aug 1, 2020

Proposal

What

The goal is to implement a way to unify different ConstKind::Unevaluated
and to check that all possible instances of const expressions evaluate sucessfully.

The implementation of this PR will not be used with feature(min_const_generics) and does not block its stabilization.

It will however extend the possibilities and expressivity of const generics by a huge amount. For example the following will be possible thanks to these changes:

impl<T, const N: usize> [T; N] {
    fn split_first(self) -> (T, [T; N - 1]) {
        let rest: [T; N - 1] = todo!();
        let fst: T;
        todo!();
        (fst, rest)
    }
}

For more details on the intended design, see https://hackmd.io/OZG_XiLFRs2Xmw5s39jRzA?view.

How

Add a query running after mir_const/mir_validated which tries to build an AbstractConst in case the given DefId is a generic anonymous constant.

AbstractConsts will not support all mir expressions and are for now restricted to basic arithmetic, arbitrary function calls, and generic constants.

This restriction is probably fairly close to simply walking the MIR and erroring when encountering a terminator other than Goto, Return, Call or Assert.

The exact subset which is allowed is not yet fully clear and will be fleshed out while implementing this.

These abstract consts will then be used to check if two ConstKind::Unevaluated unify by walking them while considering their substs.

We implement const wf checks by not trying to satisfy ConstEvaluatable predicates for consts mentioned in the function signature or where clauses, but instead adding them to thecaller_bounds of the given item.

When we now have to satisfy a ConstEvaluatable predicate, we check if the given const can be unified with any of the ConstEvaluatable mentioned in the caller_bounds.

Mentors or Reviewers

@oli-obk, for changes to the type system @varkor, @eddyb or @nikomatsakis

Process

The main points of the Major Change Process is as follows:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

@lcnr lcnr added T-compiler Add this label so rfcbot knows to poll the compiler team major-change A proposal to make a major change to rustc labels Aug 1, 2020
@rustbot
Copy link
Collaborator

rustbot commented Aug 1, 2020

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Aug 1, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Aug 1, 2020

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Aug 1, 2020
@spastorino spastorino added major-change-accepted A major change proposal that was accepted and removed to-announce Announce this issue on triage meeting final-comment-period The FCP has started, most (if not all) team members are in agreement labels Aug 5, 2020
@rustbot rustbot added the to-announce Announce this issue on triage meeting label Aug 12, 2020
@spastorino spastorino removed the to-announce Announce this issue on triage meeting label Aug 12, 2020
tmandry added a commit to tmandry/rust that referenced this issue Sep 10, 2020
add the `const_evaluatable_checked` feature

Implements a rather small subset of rust-lang/compiler-team#340

Unlike the MCP, this does not try to compare different constant, but instead only adds the constants found in where clauses
to the predicates of a function. This PR adds the feature gate `const_evaluatable_checked`, without which nothing should change.

r? @oli-obk @eddyb
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 18, 2020
compare generic constants using `AbstractConst`s

This is a MVP of rust-lang/compiler-team#340. The changes in this PR should only be relevant if `feature(const_evaluatable_checked)` is enabled.

~~currently based on top of rust-lang#76559, so blocked on that.~~

r? `@oli-obk` cc `@varkor` `@eddyb`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

4 participants