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

Support const args in type dependent paths (Take 2) #74113

Merged
merged 25 commits into from
Jul 15, 2020

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Jul 6, 2020

once more, except it is sound this time 🥰 previously #71154


#![feature(const_generics)]

struct A;
impl A {
    fn foo<const N: usize>(&self) -> usize { N }
}
struct B;
impl B {
    fn foo<const N: usize>(&self) -> usize { 42 }
}

fn main() {
    let a = A;
    a.foo::<7>();
}

When calling type_of for generic const arguments, we now use the TypeckTables of the surrounding body to get the expected type.

This alone causes cycle errors though, as we now have typeck_tables_of(main) -> ... ->
type_of(main_ANON0 := 7) -> typeck_tables_of(main) ⚡ (see #68400 (comment))

To prevent this we must not call type_of(const_arg) during typeck_tables_of. This is achieved by
calling type_of(param_def_id) instead.

We have to somehow remember the DefId of the param through all of typeck, which is done using the
struct ty::WithOptConstParam<DefId>, which replaces DefId where needed and contains an Option<DefId> to
be able to store the const parameter in case it exists.

Queries which are currently cached on disk are split into two variants: query_name(cached) and query_name_(of|for)_const_arg(not cached), with query_name_of_const_arg taking a pair (did, param_did): (LocalDefId, DefId).

For some queries a method query_name_of_opt_const_arg is added to TyCtxt which takes a ty::WithOptConstParam and either calls query_name or query_name_of_const_arg depending on the value of const_param_did.

r? @eddyb @varkor

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 6, 2020
@lcnr lcnr marked this pull request as draft July 6, 2020 22:08
@lcnr lcnr changed the title Support const args in type dependent paths Support const args in type dependent paths (Take 2) Jul 6, 2020
@lcnr lcnr force-pushed the type-dependent-consts-2 branch from 0c5695a to 1e02449 Compare July 6, 2020 22:35
@lcnr

This comment has been minimized.

@rust-timer

This comment has been minimized.

@bors

This comment has been minimized.

@lcnr lcnr marked this pull request as ready for review July 6, 2020 22:44
@bors

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Queued e4220b3fb9c17c338cf69c14e8f91a7803b0d0b5 with parent 0c03aee, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (e4220b3fb9c17c338cf69c14e8f91a7803b0d0b5): comparison url.

@lcnr lcnr force-pushed the type-dependent-consts-2 branch from 6fa206c to 26ad65e Compare July 7, 2020 08:51
@lcnr
Copy link
Contributor Author

lcnr commented Jul 7, 2020

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Jul 7, 2020

⌛ Trying commit 26ad65e7ac660a24f37813cb754fcaa1db0d9940 with merge b68a4014ccd7f0a6a24bd4662f34b565ca658c28...

@lcnr lcnr added the F-const_generics `#![feature(const_generics)]` label Jul 7, 2020
@lcnr
Copy link
Contributor Author

lcnr commented Jul 7, 2020

@rust-timer build b68a4014ccd7f0a6a24bd4662f34b565ca658c28

@rust-timer
Copy link
Collaborator

Queued b68a4014ccd7f0a6a24bd4662f34b565ca658c28 with parent 70f9d23, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (b68a4014ccd7f0a6a24bd4662f34b565ca658c28): comparison url.

@lcnr
Copy link
Contributor Author

lcnr commented Jul 7, 2020

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Jul 7, 2020

⌛ Trying commit 26f789f87b073a641d599e24c47d69d22b27c5a0 with merge 38457fb462ba475360cbcca5d21700c4e9b76596...

@bors
Copy link
Contributor

bors commented Jul 8, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 38457fb462ba475360cbcca5d21700c4e9b76596 (38457fb462ba475360cbcca5d21700c4e9b76596)

Manishearth added a commit to Manishearth/rust that referenced this pull request Jul 20, 2020
…=eddyb

test caching opt_const_param_of on disc

Followup to rust-lang#74113, implements parts of rust-lang#74360

Tried caching `opt_const_param_of` on disk and adding an early exit if `tcx.dep_kind(def_id) != DefKind::AnonConst`.

Ended up causing a perf regression instead, so we just remove the FIXME and a short note to `opt_const_param_of`.

r? @eddyb
@nnethercote
Copy link
Contributor

This was a small perf loss, as expected.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 22, 2020
remove some const arg in ty dep path boilerplate

followup to rust-lang#74113, together with rust-lang#74376, this closes rust-lang#74360.

r? @eddyb
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 1, 2020
add `slice::array_chunks` to std

Now that rust-lang#74113 has landed, these methods are suddenly usable. A rebirth of rust-lang#72334

Tests are directly copied from `chunks_exact` and some additional tests for type inference.

r? @withoutboats as you are both part of t-libs and working on const generics. closes rust-lang#60735
Xanewok added a commit to Xanewok/rust-semverver that referenced this pull request Nov 18, 2020
Xanewok added a commit to Xanewok/rust-semverver that referenced this pull request Nov 18, 2020
Xanewok added a commit to Xanewok/rust-semverver that referenced this pull request Nov 18, 2020
Xanewok added a commit to Xanewok/rust-semverver that referenced this pull request Nov 19, 2020
Xanewok added a commit to Xanewok/rust-semverver that referenced this pull request Nov 19, 2020
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-const_generics `#![feature(const_generics)]` 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants