Commit e1cb9ba
committed
Auto merge of rust-lang#40008 - eddyb:lazy-12, r=nikomatsakis
[12/12] On-demand type-checking, const-evaluation, MIR building & const-qualification.
_This is the last of a series ([prev](rust-lang#38813)) of patches designed to rework rustc into an out-of-order on-demand pipeline model for both better feature support (e.g. [MIR-based](https://github.com/solson/miri) early constant evaluation) and incremental execution of compiler passes (e.g. type-checking), with beneficial consequences to IDE support as well.
If any motivation is unclear, please ask for additional PR description clarifications or code comments._
<hr>
As this contains all of the changes that didn't fit neatly into other PRs, I'll be elaborating a bit:
### User-facing changes
* when determining whether an `impl Trait` type implements an auto-trait (e.g. `Send` or `Sync`), the function the `impl Trait` came from has to be inferred and type-checking, disallowing cycles
* this results from not having an obvious place to put the "deferred obligation" in on-demand atm
* while we could model side-effects like that and "post-processing passes" better, it's still more limiting than being able to know the result in the original function (e.g. specialization) *and* there are serious problems around region-checking (if a `Send` impl required `'static`, it wasn't enforced)
* early const-eval requires type-checking and const-qualification to be performed first, which means:
* you get the intended errors before (if any) constant evaluation error that is simply fallout
* associated consts should always work now, and `const fn` type parameters are properly tracked
* don't get too excited, array lengths still can't depend on type parameters
* rust-lang#38864 works as intended now, with `Self` being allowed in `impl` bounds
* rust-lang#32205 is largely improved, with associated types being limited to "exact match" `impl`s (as opposed to traversing the specialization graph to resolve unspecified type parameters to their defaults in another `impl` or in the `trait`) *while* checking for overlaps building the specialization graph for that trait - once all the trait impls' have been checked for coherence (including ahead-of-time/on-demand), it's uniform
* [crater report](https://gist.github.com/eddyb/bbb869072468c7e08d6d808e75938051) looks clean (aside from `clippy` which broke due to `rustc` internal changes)
### Compiler-internal changes
* `ty::Generics`
* no longer contains the actual type parameter defaults, instead they're associated with the type parameter's `DefId`, like associated types in a trait definition
* this allows computing `ty::Generics` as a leaf (reading only its own HIR)
* holds a mapping from `DefIndex` of type parameters to their indices
* `ty::AdtDef`
* only tracks `#[repr(simd)]` in its `ReprOptions` `repr` field
* doesn't contain `enum` discriminant values, but instead each variant either refers to either an explicit value for its discriminant, or the distance from the last explicit discriminant, if any
* the `.discriminants(tcx)` method produces an iterator of `ConstInt` values, looking up explicit discriminants in a separate map, if necessary
* this allows computing `ty::AdtDef` as a leaf (reading only its own HIR)
* Small note: the two above (`Generics`, `AdtDef`), `TraitDef` and `AssociatedItem` should probably end up as part of the HIR, eventually, as they're trivially constructed from it
* `ty::FnSig`
* now also holds ABI and unsafety, alongside argument types, return type and C variadicity
* `&ty::BareFnTy` and `ty::ClosureTy` have been replaced with `PolyFnSig = Binder<FnSig>`
* `BareFnTy` was interned and `ClosureTy` was treated as non-trivial to `Clone` because they had a `PolyFnSig` and so used to contain a `Vec<Ty>` (now `&[Ty]`)
* `ty::maps`
* all the `DepTrackingMap`s have been grouped in a structure available at `tcx.maps`
* when creating the `tcx`, a set of `Providers` (one `fn` pointer per map) is required for the local crate, and one for all other crates (i.e. metadata loading), `librustc_driver` plugging the various crates (e.g. `librustc_metadata`, `librustc_typeck`, `librustc_mir`) into it
* when a map is queried and the value is missing, the appropriate `fn` pointer from the `Providers` of that crate is called with the `TyCtxt` and the key being queried, to produce the value on-demand
* `rustc_const_eval`
* demands both `typeck_tables` and `mir_const_qualif` (in preparation for miri)
* tracks `Substs` in `ConstVal::Function` for `const fn` calls
* returns `TypeckError` if type-checking has failed (or cases that can only be reached if it had)
* this error kind is never reported, resulting in less noisy/redundant diagnostics
* fixes rust-lang#39548 (testcase by @larsluthman, taken from rust-lang#39812, which this supersedes)
* on-demand has so far been hooked up to:
* `rustc_metadata::cstore_impl`: `ty`, `generics`, `predicates`, `super_predicates`, `trait_def`, `adt_def`, `variances`, `associated_item_def_ids`, `associated_item`, `impl_trait_ref`, `custom_coerce_unsized_kind`, `mir`, `mir_const_qualif`, `typeck_tables`, `closure_kind`, `closure_type`
* `rustc_typeck::collect`: `ty`, `generics`, `predicates`, `super_predicates`, `type_param_predicates`, `trait_def`, `adt_def`, `impl_trait_ref`
* `rustc_typeck::coherence`: `coherent_trait`, `coherent_inherent_impls`
* `rustc_typeck::check`: `typeck_tables`, `closure_type`, `closure_kind`
* `rustc_mir::mir_map`: `mir`
* `rustc_mir::transform::qualify_consts`: `mir_const_qualif`File tree
209 files changed
+4934
-5954
lines changed- src
- librustc_borrowck/borrowck
- gather_loans
- mir
- dataflow
- librustc_const_eval
- librustc_const_math
- librustc_driver
- librustc_incremental
- calculate_svh
- persist
- librustc_lint
- librustc_metadata
- librustc_mir
- build
- expr
- matches
- hair/cx
- transform
- librustc_passes
- librustc_privacy
- librustc_resolve
- librustc_save_analysis
- librustc_trans
- debuginfo
- mir
- librustc_typeck
- check
- method
- coherence
- variance
- librustc
- dep_graph
- hir
- map
- infer
- middle
- mir
- session
- traits
- specialize
- ty
- util
- librustdoc
- clean
- libsyntax_ext/deriving/generic
- libsyntax
- parse/lexer
- test
- compile-fail
- impl-trait
- incremental/hashes
- mir-opt
- run-pass
- impl-trait
- ui
- resolve
- span
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
209 files changed
+4934
-5954
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| 113 | + | |
112 | 114 | | |
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
| 119 | + | |
117 | 120 | | |
118 | 121 | | |
119 | 122 | | |
| |||
239 | 242 | | |
240 | 243 | | |
241 | 244 | | |
| 245 | + | |
242 | 246 | | |
243 | 247 | | |
244 | 248 | | |
| |||
258 | 262 | | |
259 | 263 | | |
260 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
261 | 268 | | |
262 | 269 | | |
263 | 270 | | |
264 | 271 | | |
265 | 272 | | |
| 273 | + | |
266 | 274 | | |
267 | 275 | | |
268 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
70 | 76 | | |
71 | 77 | | |
72 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | 393 | | |
432 | 394 | | |
433 | 395 | | |
| |||
627 | 589 | | |
628 | 590 | | |
629 | 591 | | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | 592 | | |
666 | 593 | | |
667 | 594 | | |
| |||
1390 | 1317 | | |
1391 | 1318 | | |
1392 | 1319 | | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
1393 | 1337 | | |
1394 | 1338 | | |
1395 | 1339 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| |||
116 | 119 | | |
117 | 120 | | |
118 | 121 | | |
| 122 | + | |
| 123 | + | |
119 | 124 | | |
120 | 125 | | |
121 | 126 | | |
| |||
201 | 206 | | |
202 | 207 | | |
203 | 208 | | |
| 209 | + | |
| 210 | + | |
204 | 211 | | |
205 | 212 | | |
206 | 213 | | |
| |||
525 | 532 | | |
526 | 533 | | |
527 | 534 | | |
528 | | - | |
| 535 | + | |
529 | 536 | | |
530 | 537 | | |
531 | 538 | | |
| |||
1089 | 1096 | | |
1090 | 1097 | | |
1091 | 1098 | | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
1092 | 1105 | | |
1093 | | - | |
| 1106 | + | |
1094 | 1107 | | |
1095 | 1108 | | |
1096 | 1109 | | |
1097 | 1110 | | |
1098 | 1111 | | |
1099 | 1112 | | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
1100 | 1120 | | |
1101 | 1121 | | |
1102 | 1122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
437 | 437 | | |
438 | 438 | | |
439 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
440 | 484 | | |
441 | 485 | | |
442 | 486 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
413 | 416 | | |
414 | 417 | | |
415 | 418 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
508 | | - | |
| 508 | + | |
509 | 509 | | |
510 | 510 | | |
511 | 511 | | |
| |||
600 | 600 | | |
601 | 601 | | |
602 | 602 | | |
603 | | - | |
| 603 | + | |
604 | 604 | | |
605 | 605 | | |
606 | 606 | | |
| |||
1197 | 1197 | | |
1198 | 1198 | | |
1199 | 1199 | | |
1200 | | - | |
| 1200 | + | |
1201 | 1201 | | |
1202 | 1202 | | |
1203 | | - | |
1204 | | - | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
1205 | 1206 | | |
1206 | 1207 | | |
1207 | | - | |
1208 | | - | |
1209 | | - | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
1210 | 1213 | | |
1211 | 1214 | | |
1212 | 1215 | | |
| |||
1646 | 1649 | | |
1647 | 1650 | | |
1648 | 1651 | | |
1649 | | - | |
1650 | | - | |
1651 | | - | |
1652 | | - | |
1653 | | - | |
| 1652 | + | |
1654 | 1653 | | |
1655 | 1654 | | |
1656 | | - | |
1657 | | - | |
| 1655 | + | |
| 1656 | + | |
1658 | 1657 | | |
1659 | 1658 | | |
1660 | 1659 | | |
1661 | 1660 | | |
1662 | | - | |
| 1661 | + | |
1663 | 1662 | | |
1664 | 1663 | | |
1665 | 1664 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| |||
0 commit comments