rust/compiler
Dylan DPC 4b0014e3bb
Rollup merge of #85633 - lqd:stackless_span_stacks, r=oli-obk
Post-monomorphization errors traces MVP

This PR works towards better diagnostics for the errors encountered in #85155 and similar.

We can encounter post-monomorphization errors (PMEs) when collecting mono items. The current diagnostics are confusing for these cases when they happen in a dependency (but are acceptable when they happen in the local crate).

These kinds of errors will be more likely now that `stdarch` uses const generics for its intrinsics' immediate arguments, and validates these const arguments with a mechanism that triggers such PMEs.

(Not to mention that the errors happen during codegen, so only when building code that actually uses these code paths. Check builds don't trigger them, neither does unused code)

So in this PR, we detect these kinds of errors during the mono item graph walk: if any error happens while collecting a node or its neighbors, we print a diagnostic about the current collection step, so that the user has at least some context of which erroneous code and dependency triggered the error.

The diagnostics for issue #85155 now have this note showing the source of the erroneous const argument:
```
note: the above error was encountered while instantiating `fn std::arch::x86_64::_mm_blend_ps::<51_i32>`
  --> issue-85155.rs:11:24
   |
11 |         let _blended = _mm_blend_ps(a, b, 0x33);
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error
```

Note that #85155 is a reduced version of a case happening in the wild, to indirect users of the `rustfft` crate, as seen in https://github.com/ejmahler/RustFFT/issues/74. The crate had a few of these out-of-range immediates. Here's how the diagnostics in this PR would have looked on one of its examples before it was fixed:

<details>

```
error[E0080]: evaluation of constant value failed
 --> ./stdarch/crates/core_arch/src/macros.rs:8:9
  |
8 |         assert!(IMM >= MIN && IMM <= MAX, "IMM value not in expected range");
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'IMM value not in expected range', ./stdarch/crates/core_arch/src/macros.rs:8:9
  |
  = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)

note: the above error was encountered while instantiating `fn _mm_blend_ps::<51_i32>`
    --> /tmp/RustFFT/src/avx/avx_vector.rs:1314:23
     |
1314 |         let blended = _mm_blend_ps(rows[0], rows[2], 0x33);
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

note: the above error was encountered while instantiating `fn _mm_permute_pd::<5_i32>`
    --> /tmp/RustFFT/src/avx/avx_vector.rs:1859:9
     |
1859 |         _mm_permute_pd(self, 0x05)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^

note: the above error was encountered while instantiating `fn _mm_permute_pd::<15_i32>`
    --> /tmp/RustFFT/src/avx/avx_vector.rs:1863:32
     |
1863 |         (_mm_movedup_pd(self), _mm_permute_pd(self, 0x0F))
     |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
error: could not compile `rustfft`

To learn more, run the command again with --verbose.
```

</details>

I've developed and discussed this with them, so maybe r? `@oli-obk` -- but feel free to redirect to someone else of course.

(I'm not sure we can say that this PR definitely closes issue 85155, as it's still unclear exactly which diagnostics and information would be interesting to report in such cases -- and we've discussed printing backtraces before. I have prototypes of some complete and therefore noisy backtraces I showed Oli, but we decided to not include them in this PR for now)
2021-05-26 13:32:08 +02:00
..
rustc
rustc_apfloat remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_arena
rustc_ast remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_ast_lowering remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_ast_passes
rustc_ast_pretty remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_attr remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_builtin_macros remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_codegen_cranelift (try to) fix cranelift 2021-05-23 12:44:05 +02:00
rustc_codegen_llvm remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_codegen_ssa remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_data_structures
rustc_driver
rustc_error_codes
rustc_errors
rustc_expand remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_feature remove native_link_modifiers from the list of incomplete features. 2021-05-24 00:36:55 +08:00
rustc_fs_util
rustc_graphviz
rustc_hir remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_hir_pretty remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_incremental
rustc_index
rustc_infer remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_interface Make thir_check_unsafety itself responsible for checking gate 2021-05-24 15:09:33 +02:00
rustc_lexer
rustc_lint remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_lint_defs
rustc_llvm Auto merge of #85416 - durin42:llvm-catchup-may-2021, r=nagisa 2021-05-21 11:21:06 +00:00
rustc_macros
rustc_metadata remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_middle Rollup merge of #85633 - lqd:stackless_span_stacks, r=oli-obk 2021-05-26 13:32:08 +02:00
rustc_mir Rollup merge of #85633 - lqd:stackless_span_stacks, r=oli-obk 2021-05-26 13:32:08 +02:00
rustc_mir_build Fix unused_unsafe in THIR unsafeck 2021-05-25 20:11:29 +02:00
rustc_parse remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_parse_format remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_passes remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_plugin_impl
rustc_privacy remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_query_impl
rustc_query_system
rustc_resolve Rollup merge of #85478 - FabianWolff:issue-85348, r=petrochenkov 2021-05-26 13:32:05 +02:00
rustc_save_analysis remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_serialize
rustc_session Rollup merge of #85361 - bjorn3:rustdoc_target_json_path_canonicalize, r=jyn514 2021-05-25 13:05:09 +02:00
rustc_span Rollup merge of #85439 - mgacek8:add_diagnostic_item_to_CStr_type, r=davidtwco 2021-05-20 00:19:07 +02:00
rustc_symbol_mangling remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_target Remove linker_is_gnu: true cases as that is now the default. 2021-05-20 23:36:04 -07:00
rustc_trait_selection Auto merge of #85481 - lcnr:const-equate, r=matthewjasper 2021-05-25 13:53:48 +00:00
rustc_traits
rustc_ty_utils
rustc_type_ir
rustc_typeck remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00