Skip to content

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

Merged
bors merged 25 commits into
rust-lang:masterfrom
lcnr:type-dependent-consts-2
Jul 15, 2020
Merged

Support const args in type dependent paths (Take 2)#74113
bors merged 25 commits into
rust-lang:masterfrom
lcnr:type-dependent-consts-2

Conversation

@lcnr

@lcnrlcnr commented Jul 6, 2020

Copy link
Copy Markdown
Contributor

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


#![feature(const_generics)]structA;implA{fnfoo<constN:usize>(&self) -> usize{N}}structB;implB{fnfoo<constN:usize>(&self) -> usize{42}}fnmain(){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-highfiverust-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
Comment threadsrc/test/ui/const-generics/type-dependent/issue-61936.rs Outdated
@lcnrlcnr changed the title Support const args in type dependent pathsSupport const args in type dependent paths (Take 2)Jul 6, 2020
@lcnr
lcnrforce-pushed the type-dependent-consts-2 branch from 0c5695a to 1e02449CompareJuly 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
Copy Markdown
Collaborator

Queued e4220b3fb9c17c338cf69c14e8f91a7803b0d0b5 with parent 0c03aee, future comparison URL.

Comment threadsrc/test/ui/const-generics/type-dependent/issue-61936.rs Outdated
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking try commit (e4220b3fb9c17c338cf69c14e8f91a7803b0d0b5): comparison url.

@lcnr
lcnrforce-pushed the type-dependent-consts-2 branch from 6fa206c to 26ad65eCompareJuly 7, 2020 08:51
@lcnr

lcnr commented Jul 7, 2020

Copy link
Copy Markdown
ContributorAuthor

@bors try @rust-timer queue

@rust-timer

Copy link
Copy Markdown
Collaborator

Awaiting bors try build completion

@bors

bors commented Jul 7, 2020

Copy link
Copy Markdown
Collaborator

⌛ Trying commit 26ad65e7ac660a24f37813cb754fcaa1db0d9940 with merge b68a4014ccd7f0a6a24bd4662f34b565ca658c28...

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

lcnr commented Jul 7, 2020

Copy link
Copy Markdown
ContributorAuthor

@rust-timer build b68a4014ccd7f0a6a24bd4662f34b565ca658c28

@rust-timer

Copy link
Copy Markdown
Collaborator

Queued b68a4014ccd7f0a6a24bd4662f34b565ca658c28 with parent 70f9d23, future comparison URL.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking try commit (b68a4014ccd7f0a6a24bd4662f34b565ca658c28): comparison url.

@lcnr

lcnr commented Jul 7, 2020

Copy link
Copy Markdown
ContributorAuthor

@bors try @rust-timer queue

@rust-timer

Copy link
Copy Markdown
Collaborator

Awaiting bors try build completion

@bors

bors commented Jul 7, 2020

Copy link
Copy Markdown
Collaborator

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

@bors

bors commented Jul 8, 2020

Copy link
Copy Markdown
Collaborator

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

@lcnrlcnr mentioned this pull request Jul 15, 2020
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
Copy Markdown
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 closesrust-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. closesrust-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
@cuvipercuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-const_generics`#![feature(const_generics)]`merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: 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

@lcnr@rust-timer@bors@eddyb@nnethercote@cynecx@leonardo-m@cuviper@rust-highfive