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

Remove qualify_min_const_fn #76850

Merged
merged 13 commits into from
Sep 23, 2020
Merged

Conversation

ecstatic-morse
Copy link
Contributor

@ecstatic-morse ecstatic-morse commented Sep 17, 2020

Blocked on #76807 (the first six commits).

With this PR, all checks in qualify_min_const_fn are replicated in check_consts, and the former is no longer invoked. My goal was to have as few changes to test output as possible, since making sweeping changes to the code while doing big batches of diagnostics updates turned out to be a headache. To this end, there's a few HACKs in check_consts to achieve parity with qualify_min_const_fn.

The new system that replaces is_min_const_fn is referred to as "const-stability" My end goal for the const-stability rules is this:

  • Const-stability is only applicable to functions defined in staged_api crates.
  • All functions not marked rustc_const_unstable are considered "const-stable".
    • NB. This is currently not implemented. #[unstable] functions are also const-unstable. This causes problems when searching for feature gates.
    • All "const-unstable" functions have an associated feature gate
  • const-stable functions can only call other const-stable functions
    • allow_internal_unstable can be used to circumvent this.
  • All const-stable functions are subject to some additional checks (the ones that were unique to qualify_min_const_fn)

The plan is to remove each HACK individually in subsequent PRs. That way, changes to error message output can be reviewed in isolation.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 17, 2020
@rust-lang rust-lang deleted a comment from rust-highfive Sep 17, 2020
@ecstatic-morse ecstatic-morse force-pushed the const-checking-refactor branch 3 times, most recently from e957778 to de11a42 Compare September 17, 2020 19:45
Comment on lines +271 to +273
if self.const_checking_stopped {
return;
}
Copy link
Contributor Author

@ecstatic-morse ecstatic-morse Sep 17, 2020

Choose a reason for hiding this comment

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

We could get a bit closer to the existing behavior by disabling the "stop after a single error" stuff when #![feature(const_fn)] is enabled. However, this is temporary anyway.

@ecstatic-morse
Copy link
Contributor Author

ecstatic-morse commented Sep 17, 2020

r? @oli-obk

Okay, I think I've done all I can to minimize the diff. After this, qualify_min_const_fn is unused. I can remove it later. There will be quite a few follow-up PRs to this one as I clean up the results of combining the logic from both passes. As always, meant to be reviewed commit-by-commit.

@ecstatic-morse ecstatic-morse marked this pull request as ready for review September 17, 2020 20:44
@jyn514 jyn514 added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 17, 2020
Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

I love it, all the problems now have explicit sites "causing" them (though as you correctly noted, some should just happen in stability checking. I think some of the stability checking here was to prevent any worries about accidental stabilization.

/// Emits an error if `op` is not allowed in the given const context.
pub fn non_const<O: NonConstOp>(ccx: &ConstCx<'_, '_>, op: O, span: Span) {
/// Emits an error and returns `true` if `op` is not allowed in the given const context.
pub fn non_const<O: NonConstOp>(ccx: &ConstCx<'_, '_>, op: O, span: Span) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

a bit too much negation going on for my taste, but inverting that can be delayed to a follow up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's possible that this helper function should folded back into the const-checker, since the return value and (unfortunately) the unstable_in_stable bit are unused in the post-elaboration live drop checker.

@bors

This comment has been minimized.

@ecstatic-morse
Copy link
Contributor Author

Tests are passing, and Oli has approved it, so I'm gonna add it to the queue.

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Sep 22, 2020

📌 Commit 186d148 has been approved by oli-obk

@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 22, 2020
ecstatic-morse added a commit to ecstatic-morse/rust that referenced this pull request Sep 22, 2020
…tor, r=oli-obk

Remove `qualify_min_const_fn`

~~Blocked on rust-lang#76807 (the first six commits).~~

With this PR, all checks in `qualify_min_const_fn` are replicated in `check_consts`, and the former is no longer invoked. My goal was to have as few changes to test output as possible, since making sweeping changes to the code *while* doing big batches of diagnostics updates turned out to be a headache. To this end, there's a few `HACK`s in `check_consts` to achieve parity with `qualify_min_const_fn`.

The new system that replaces `is_min_const_fn` is referred to as "const-stability"  My end goal for the const-stability rules is this:
* Const-stability is only applicable to functions defined in `staged_api` crates.
* All functions not marked `rustc_const_unstable` are considered "const-stable".
    - NB. This is currently not implemented. `#[unstable]` functions are also const-unstable. This causes problems when searching for feature gates.
    - All "const-unstable" functions have an associated feature gate
* const-stable functions can only call other const-stable functions
     - `allow_internal_unstable` can be used to circumvent this.
* All const-stable functions are subject to some additional checks (the ones that were unique to `qualify_min_const_fn`)

The plan is to remove each `HACK` individually in subsequent PRs. That way, changes to error message output can be reviewed in isolation.
@bors
Copy link
Contributor

bors commented Sep 23, 2020

⌛ Testing commit 186d148 with merge f6d5920...

@bors
Copy link
Contributor

bors commented Sep 23, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: oli-obk
Pushing f6d5920 to master...

@RalfJung
Copy link
Member

This is great. :) @ecstatic-morse do you think this would be worth documenting in https://github.com/rust-lang/const-eval/?
I am particularly curious about what these "additional checks" are:

All const-stable functions are subject to some additional checks (the ones that were unique to qualify_min_const_fn)

@ecstatic-morse
Copy link
Contributor Author

I believe it's as simple as "const-stable functions can only call other const-stable functions and cannot depend on any unstable features to pass const-checking". My parenthetical isn't very helpful, since these were only two of the dozen or so checks that were unique to qualify_min_const_fn.

@RalfJung
Copy link
Member

Ah I see.

Also, shouldn't a PR with this title actually delete the qualify_min_const_fn.rs file, or is that still doing something?

@RalfJung
Copy link
Member

Oh, that is still open in #77128. I guess I do not understand what this PR is "removing" then, the description sounds more like it is porting all the min_const_fn checks over to the main checker (but keeps the old checks active).

@ecstatic-morse
Copy link
Contributor Author

ecstatic-morse commented Sep 24, 2020

qualify_min_const_fn.rs is now only used by clippy. I learned about that dependency when I went to remove it as the last commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. 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.

None yet

8 participants