generic_const_exprs: use thir for abstract consts instead of mir#88709
generic_const_exprs: use thir for abstract consts instead of mir#88709bors merged 18 commits intorust-lang:masterfrom
Conversation
f0064e4 to
578387d
Compare
lcnr
left a comment
There was a problem hiding this comment.
💖 💖 💖
a bunch of small nits which might even be slightly too pedantic.
The error messages for overly complex constants are a bit worse now, but improving them can be done in followup PRs.
There was a problem hiding this comment.
ExprKind::Cast also contains a Ty and afaict you don't look at thir::Pat at all 🤔
maybe it makes sense to add a fn visit_ty to the Visitor trait and only manually implement visit_ty and visit_const here.
There was a problem hiding this comment.
ExprKind::Cast just contains an ExprId the type of the cast is from expr.ty so that's correct.
There was a problem hiding this comment.
I did forget about thir::Pat i think I thought it was unnecessary as i dont think you can currently use a pattern in a generic constant but that doesn't matter for checking this
There was a problem hiding this comment.
I'm not sure that visiting patterns is actually important, I cant think of anything in patterns that could be generic that wouldnt be handled by either visit_const from when a pattern is a constant or visit_expr for what's being matched on/let = on
There was a problem hiding this comment.
woups, meant ExprKind::Call 😅
I personally don't think thir::Pat is too important either, or well, only for is_polymorphic (which we should be able to remove from mir::Body now). But the current impls seems fragile if we ever add a Ty to some other ExprKind or something, so i would like a safer approach here
There was a problem hiding this comment.
oh right, I assumed that the ty in ExprKind::Call was the same as the type of the fun expr which is why I didnt visit that
edit: looking at code it does infact seem so, it's fine to ignore the ty in ExprKind::Call when checking if the thir is polymorphic as we'll visit that ty when we visit the fun expr
There was a problem hiding this comment.
I changed how we check if thir is polymorphic to explicitly match on ExprKind and PatKind some of the arms are doing definitely_has_param_types_or_consts but im not really sure it actually makes any difference to be doing so
edit: yeah as far as I can tell these match arms arent doing anything so I've removed them which leaves us with two match statements that exhaustively match on ExprKind and PatKind without actually doing anything which seems incredibly silly but does solve the problem of "what happens if someone adds a Ty field to an ExprKind variant"
think it might just be smarter to add tests that we give an "unsupported operation in generic constant" error for each of these variants
There was a problem hiding this comment.
two match statements that exhaustively match on ExprKind and PatKind without actually doing anything which seems incredibly silly
🤔 that doesn't make me too happy. not sure how easy and useful it is to add tests for this, but I think that having an exhaustive match here is more annoying than helpful '^^
imo its fine to just remove the match, we have enough time on nightly to see whether this is a problem
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d08155a to
afa9b39
Compare
|
☔ The latest upstream changes (presumably #80522) made this pull request unmergeable. Please resolve the merge conflicts. |
afa9b39 to
25c5033
Compare
There was a problem hiding this comment.
| fn foo<const N: Foo>(a: Evaluatable<{ N + N }>) { | |
| bar::<{ std::ops::Add::add(N, N) }>(); | |
| } | |
| fn bar<const N: Foo>() {} | |
| fn foo<const N: Foo>(a: Evaluatable<{ N + N }>) { | |
| bar::<{ std::ops::Add::add(N, N) }>(); | |
| } | |
| fn bar<const N: Foo>() {} | |
| fn baz<const N: usize>(a: [u8; N + N]) { | |
| biz::<{ std::ops::Add::add(N, N) }>(); | |
| } | |
| fn biz<const N: usize>() {} |
interested in seeing this tested for builtin types
There was a problem hiding this comment.
hmm yeah Add::add(N, N) doesnt unify with N + N for builtin types
There was a problem hiding this comment.
I think we could totally support this by just making Node::BinOp(..) for operator functions but probably ought to do that in a separate PR rather than alongside this mir -> thir refactor (or alternatively get rid of Node::BinOp and just lower to Node::Function(..) but either way there is probably solutions)
|
some more nits and the match in |
25c5033 to
ee48c18
Compare
ee48c18 to
8295e4a
Compare
|
@rust-lang/project-const-generics we're now using thir instead of mir for the unification of generic constants @bors r+ |
|
📌 Commit 8295e4a has been approved by |
|
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
generic_const_exprs: use thir for abstract consts instead of mir not sure if this is handling some of the weirder `thir::ExprKind` correctly in `recurse_build` (it probably isnt) r? `@lcnr`
generic_const_exprs: use thir for abstract consts instead of mir not sure if this is handling some of the weirder `thir::ExprKind` correctly in `recurse_build` (it probably isnt) r? ``@lcnr``
generic_const_exprs: use thir for abstract consts instead of mir Changes `AbstractConst` building to use `thir` instead of `mir` so that there's less chance of consts unifying when they shouldn't because lowering to mir dropped information (see `abstract-consts-as-cast-5.rs` test) r? `@lcnr`
…arth Rollup of 7 pull requests Successful merges: - rust-lang#88336 ( Detect stricter constraints on gats where clauses in impls vs trait) - rust-lang#88677 (rustc: Remove local variable IDs from `Export`s) - rust-lang#88699 (Remove extra unshallow from cherry-pick checker) - rust-lang#88709 (generic_const_exprs: use thir for abstract consts instead of mir) - rust-lang#88711 (Rework DepthFirstSearch API) - rust-lang#88810 (rustdoc: Cleanup `clean` part 1) - rust-lang#88813 (explicitly link to external `ena` docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
|
The rollup caused an instruction count increase on perf, do you think that's due to this PR? |
|
Im not sure how this would cause a perf regression given all the changed code is gated behind |
Changes
AbstractConstbuilding to usethirinstead ofmirso that there's less chance of consts unifying when they shouldn't because lowering to mir dropped information (seeabstract-consts-as-cast-5.rstest)r? @lcnr