Commit Graph

30888 Commits

Author SHA1 Message Date
Jubilee 9e872b7cd8
Rollup merge of #118933 - nnethercote:cleanup-errors-even-more, r=compiler-errors
Cleanup errors handlers even more

A sequel to #118587.

r? `@compiler-errors`
2023-12-14 16:07:48 -08:00
Jubilee 576a74b8c9
Rollup merge of #118908 - Urgau:check-cfg-target-features, r=TaKO8Ki,GuillaumeGomez,workingjubilee
Add all known `target_feature` configs to check-cfg

This PR adds all the known `target_feature` from ~~`rustc_codegen_ssa`~~ `rustc_target` to the well known list of check-cfg.

It does so by moving the list from `rustc_codegen_ssa` to `rustc_target` ~~`rustc_session` (I not sure about this, but some of the moved function take a `Session`)~~, then using it the `fill_well_known` function.

This already proved to be useful since portable-simd had a bad cfg.

cc `@nnethercote` (since we discussed it in https://github.com/rust-lang/rust/pull/118494)
2023-12-14 16:07:47 -08:00
Nicholas Nethercote 9a78412511 Split `Handler::emit_diagnostic` in two.
Currently, `emit_diagnostic` takes `&mut self`.

This commit changes it so `emit_diagnostic` takes `self` and the new
`emit_diagnostic_without_consuming` function takes `&mut self`.

I find the distinction useful. The former case is much more common, and
avoids a bunch of `mut` and `&mut` occurrences. We can also restrict the
latter with `pub(crate)` which is nice.
2023-12-15 10:13:12 +11:00
Nicholas Nethercote 2c2c7f13a6 Remove `Handler::emit_diag_at_span`.
Compare `Handler::warn` and `Handler::span_warn`. Conceptually they are
almost identical. But their implementations are weirdly different.

`warn`:
- calls `DiagnosticBuilder::<()>::new(self, Warning(None), msg)`, then `emit()`
- which calls `G::diagnostic_builder_emit_producing_guarantee(self)`
- which calls `handler.emit_diagnostic(&mut db.inner.diagnostic)`

`span_warn`:
- calls `self.emit_diag_at_span(Diagnostic::new(Warning(None), msg), span)`
- which calls `self.emit_diagnostic(diag.set_span(sp))`

I.e. they both end up at `emit_diagnostic`, but take very different
routes to get there.

This commit changes `span_*` and similar ones to not use
`emit_diag_at_span`. Instead they just call `struct_span_*` + `emit`.

Some nice side-effects of this:
- `span_fatal` and `span_fatal_with_code` don't need
  `FatalError.raise()`, because `emit` does that.
- `span_err` and `span_err_with_code` doesn't need `unwrap`.
- `struct_span_note`'s `span` arg type is changed from `Span` to
  `impl Into<MultiSpan>` like all the other functions.
2023-12-15 09:48:00 +11:00
Nicholas Nethercote b0d5b442e9 Avoid `DiagnosticBuilder::<T>::new` calls.
The `Handler` functions that directly emit diagnostics can be more
easily implemented using `struct_foo(msg).emit()`. This mirrors
`Handler::emit_err` which just does `create_err(err).emit()`.

`Handler::bug` is not converted because of weirdness involving
conflation bugs and fatal errors with `EmissionGuarantee`. I'll fix that
later.
2023-12-15 09:42:14 +11:00
Nicholas Nethercote 19d28a4f28 Change `msg: impl Into<String>` for bug diagnostics.
To `msg: impl Into<DiagnosticMessage>`, like all the other diagnostics.
For consistency.
2023-12-15 09:42:14 +11:00
bors de686cbc65 Auto merge of #118949 - matthiaskrgr:rollup-rdzlb9h, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #118910 ([rustdoc] Use Map instead of Object for source files and search index)
 - #118914 (Unconditionally register alias-relate in projection goal)
 - #118935 (interpret: extend comment on the inhabitedness check in downcast)
 - #118945 (rustc_codegen_ssa: Remove trailing spaces in Display impl for CguReuse)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-14 21:20:48 +00:00
Matthias Krüger 4d016c781a
Rollup merge of #118945 - Enselic:remove-trailing, r=compiler-errors
rustc_codegen_ssa: Remove trailing spaces in Display impl for CguReuse

Otherwise errors will look like this:

    error: CGU-reuse for `cgu_invalidated_via_import-bar` is `PreLto ` but should be `PostLto `

### Background

I noticed that error messages looked wonky while investigating if
529047cfc3/compiler/rustc_codegen_ssa/src/assert_module_sources.rs (L281-L287)
should not be wrapped by `sess.emit_err(...)`. Right now it looks like the error is accidentally ignored. It looks like 706452eba7 might have accidentally started ignoring it (by removing the `diag.span_err()` call). I am still investigating, but regardless of the outcome we should fix the trailing whitespace.
2023-12-14 20:33:11 +01:00
Matthias Krüger 49a2fc22e9
Rollup merge of #118935 - RalfJung:interpret-downcast, r=saethlin
interpret: extend comment on the inhabitedness check in downcast

Cc https://github.com/rust-lang/rust/issues/115145
r? ``@saethlin``
2023-12-14 20:33:11 +01:00
bors 740cea81d6 Auto merge of #118375 - ouz-a:add_emit_stable_mir_tests, r=celinval
Add -Zunpretty=stable-mir output test

As strongly suggested here https://github.com/rust-lang/rust/pull/118364#issuecomment-1827974148 this adds output test for `-Zunpretty=stable-mir`, added test shows almost all the functionality of the current printer.

r? `@compiler-errors`
2023-12-14 19:17:52 +00:00
Michael Goulet 929d632b54 Unconditionally register alias-relate in projection goal 2023-12-14 18:41:23 +00:00
Martin Nordholts 2ddd8b4f19 rustc_codegen_ssa: Remove trailing spaces in Display impl for CguReuse
Otherwise errors will look like this:

    error: CGU-reuse for `cgu_invalidated_via_import-bar` is `PreLto ` but should be `PostLto `
2023-12-14 16:49:18 +01:00
ouz-a 82ee18c4ea add stable_mir output test 2023-12-14 18:10:38 +03:00
lcnr fa03289ddf review 2023-12-14 15:22:37 +01:00
lcnr 0947070871 consistently use "next solver" instead of "new solver" 2023-12-14 15:22:37 +01:00
lcnr 11d16c4082 update use of feature flags 2023-12-14 15:22:37 +01:00
lcnr 5d97ada1ec rename `-Ztrait-solver` to `-Znext-solver` 2023-12-14 15:22:37 +01:00
Urgau c355040a5c Don't forget pure rustc target features in check-cfg 2023-12-14 14:50:32 +01:00
Urgau acac133997 Use all the known features in check-cfg 2023-12-14 14:49:42 +01:00
Urgau 428395e064 Move rustc_codegen_ssa target features to rustc_target 2023-12-14 14:40:55 +01:00
bors 1aa6aefdc9 Auto merge of #118566 - klensy:cstr-new, r=WaffleLapkin
use c literals in compiler and library

Relands refreshed https://github.com/rust-lang/rust/pull/111647
2023-12-14 11:14:03 +00:00
bors 9d49eb76c4 Auto merge of #118417 - anforowicz:default-hidden-visibility, r=TaKO8Ki
Add unstable `-Zdefault-hidden-visibility` cmdline flag for `rustc`.

The new flag has been described in the Major Change Proposal at
https://github.com/rust-lang/compiler-team/issues/656
2023-12-14 09:16:15 +00:00
Ralf Jung 5d87d8307f interpret: extend comment on the inhabitedness check in downcast 2023-12-14 09:50:47 +01:00
bors 1a8afa0e74 Auto merge of #118538 - RalfJung:size-of-val-comments, r=WaffleLapkin
fix dynamic size/align computation logic for packed types with dyn trait tail

This logic was never updated to support `packed(N)` where `N > 1`, and it turns out to be wrong for that case.

Fixes https://github.com/rust-lang/rust/issues/80925

`@bjorn3` I have not looked at cranelift; I assume it basically copied the size-of-val logic and hence could use much the same patch.
2023-12-14 07:19:07 +00:00
Nicholas Nethercote e3b7ecc1ef Remove one use of `span_bug_no_panic`.
It's unclear why this is used here. All entries in the third column of
`UNICODE_ARRAY` are covered by `ASCII_ARRAY`, so if the lookup fails
it's a genuine compiler bug. It was added way back in #29837, for no
clear reason.

This commit changes it to `span_bug`, which is more typical.
2023-12-14 15:53:55 +11:00
Nicholas Nethercote 7bdb227567 Avoid `struct_diagnostic` where possible.
It's necessary for `derive(Diagnostic)`, but is best avoided elsewhere
because there are clearer alternatives.

This required adding `Handler::struct_almost_fatal`.
2023-12-14 15:53:55 +11:00
Nicholas Nethercote dc05a30996 Inline and remove `HandlerInner::emit_diag_at_span`.
It has a single call site.
2023-12-14 15:53:55 +11:00
Nicholas Nethercote 43a0f55506 Remove unused `Handler::treat_err_as_bug`. 2023-12-14 15:53:55 +11:00
bors d23e1a6894 Auto merge of #117749 - aliemjay:perf-canon-cache, r=lcnr
cache param env canonicalization

Canonicalize ParamEnv only once and store it. Then whenever we try to canonicalize `ParamEnvAnd<'tcx, T>` we only have to canonicalize `T` and then merge the results.

Prelimiary results show ~3-4% savings in diesel and serde benchmarks.

Best to review commits individually. Some commits have a short description.

Initial implementation had a soundness bug (https://github.com/rust-lang/rust/pull/117749#issuecomment-1840453387) due to cache invalidation:
- When canonicalizing `Ty<'?0>` we first try to resolve region variables in the current InferCtxt which may have a constraint `?0 == 'static`. This means that we register `Ty<'?0> => Canonical<Ty<'static>>` in the cache, which is obviously incorrect in another inference context.
- This is fixed by not doing region resolution when canonicalizing the query *input* (vs. response), which is the only place where ParamEnv is used, and then in a later commit we *statically* guard against any form of inference variable resolution of the cached canonical ParamEnv's.

r? `@ghost`
2023-12-14 04:04:10 +00:00
Ali MJ Al-Nasrawy e452c94912 remove canonicalize_query_preserving_universes
unused!
2023-12-14 03:03:03 +00:00
Ali MJ Al-Nasrawy 3b55869615 make infcx optional in canonicalizer
This doesn't change behavior.
It should prevent unintentional resolution of inference variables
during canonicalization, which previously caused a soundness bug.
See PR description for more.
2023-12-14 03:03:03 +00:00
bors e6d1b0ec98 Auto merge of #118491 - cuviper:aarch64-stack-probes, r=wesleywiser
Enable stack probes on aarch64 for LLVM 18

I tested this on `aarch64-unknown-linux-gnu` with LLVM main (~18).

cc #77071, to be closed once we upgrade our LLVM submodule.
2023-12-14 02:01:13 +00:00
Esteban Küber 9d846fcc11 Tweak `short_ty_string` to reduce number of files
When shortening types and writing them to disk, make `short_ty_string`
capable of reusing the same file, instead of writing a file per
shortened type.
2023-12-13 23:07:10 +00:00
Lukasz Anforowicz 981c4e3ce6 Add unstable `-Zdefault-hidden-visibility` cmdline flag for `rustc`.
The new flag has been described in the Major Change Proposal at
https://github.com/rust-lang/compiler-team/issues/656
2023-12-13 21:14:23 +00:00
bors a90372c6e8 Auto merge of #118213 - Urgau:check-cfg-diagnostics-rustc-cargo, r=petrochenkov
Add more suggestions to unexpected cfg names and values

This pull request adds more suggestion to unexpected cfg names and values diagnostics:
 - it first adds a links to the [rustc unstable book](https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html) or the [Cargo reference](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg), depending if rustc is invoked by Cargo
 - it secondly adds a suggestion on how to expect the cfg name or value:
    *excluding well known names and values*
    - for Cargo: it suggest using a feature or `cargo:rust-check-cfg` in build script
    - for rustc: it suggest using `--check-cfg` (with the correct invocation)

Those diagnostics improvements are directed towards enabling users to fix the issue if the previous suggestions weren't good enough.

r? `@petrochenkov`
2023-12-13 19:45:57 +00:00
Ralf Jung 7e4c4271f4 fix computing the dynamic alignment of packed structs with dyn trait tails 2023-12-13 20:21:57 +01:00
Matthias Krüger 1dd36119d0
Rollup merge of #118871 - tmiasko:coroutine-maybe-uninit-fields, r=compiler-errors
Coroutine variant fields can be uninitialized

Wrap coroutine variant fields in MaybeUninit to indicate that they might be uninitialized. Otherwise an uninhabited field will make the entire variant uninhabited and introduce undefined behaviour.

The analogous issue in the prefix of coroutine layout was addressed by 6fae7f8071.
2023-12-13 18:03:33 +01:00
Matthias Krüger dbc6ec6636
Rollup merge of #118759 - compiler-errors:bare-unit-structs, r=petrochenkov
Support bare unit structs in destructuring assignments

We should be allowed to use destructuring assignments on *bare* unit structs, not just unit structs that are located within other pattern constructors.

Fixes #118753

r? petrochenkov since you reviewed #95380, reassign if you're busy or don't want to review this.
2023-12-13 18:03:33 +01:00
Urgau 5345a166fe Add more suggestion to unexpected cfg names and values 2023-12-13 17:48:04 +01:00
Ali MJ Al-Nasrawy fafe66d438 don't resolve regions in query input
fixes a soundness regression described in the PR description.
2023-12-13 14:57:52 +00:00
Ali MJ Al-Nasrawy a1459c3fca fix small perf regressions 2023-12-13 14:57:52 +00:00
Ali MJ Al-Nasrawy 85338197d4 don't store OriginalQueryValues::universe_map
ParamEnv is canonicalized in *queries input* rather than query response.
In such case we don't "preserve universes" of canonical variable.
This means that `universe_map` always has the default value, which is
wasteful to store in the cache.
2023-12-13 14:57:52 +00:00
Ali MJ Al-Nasrawy f38d1e971d global param_env canonicalization cache 2023-12-13 14:57:52 +00:00
bors c3def263a4 Auto merge of #118870 - Enselic:rustc_passes-query-stability, r=compiler-errors
rustc_passes: Enforce `rustc::potential_query_instability` lint

Stop allowing `rustc::potential_query_instability` in all of `rustc_passes` and instead allow it on a case-by-case basis if it is safe. In this case, all instances of the lint are safe to allow.

Part of https://github.com/rust-lang/rust/issues/84447 which is E-help-wanted.
2023-12-13 12:47:43 +00:00
bors 56d25ba5ea Auto merge of #118500 - ZetaNumbers:tcx_hir_refactor, r=petrochenkov
Move some methods from `tcx.hir()` to `tcx`

https://github.com/rust-lang/rust/pull/118256#issuecomment-1826442834

Renamed:
- find -> opt_hir_node
- get -> hir_node
- find_by_def_id -> opt_hir_node_by_def_id
- get_by_def_id -> hir_node_by_def_id
2023-12-13 10:31:56 +00:00
bors 2fdd9eda0c Auto merge of #118534 - RalfJung:extern-type-size-of-val, r=WaffleLapkin
codegen: panic when trying to compute size/align of extern type

The alignment is also computed when accessing a field of extern type at non-zero offset, so we also panic in that case.

Previously `size_of_val` worked because the code path there assumed that "thin pointer" means "sized". But that's not true any more with extern types. The returned size and align are just blatantly wrong, so it seems better to panic than returning wrong results. We use a non-unwinding panic since code probably does not expect size_of_val to panic.
2023-12-13 08:33:05 +00:00
bors f651b436ce Auto merge of #117050 - c410-f3r:here-we-go-again, r=petrochenkov
[`RFC 3086`] Attempt to try to resolve blocking concerns

Implements what is described at https://github.com/rust-lang/rust/issues/83527#issuecomment-1744822345 to hopefully make some progress.

It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities.

`@rustbot` labels +I-compiler-nominated
2023-12-13 06:37:08 +00:00
Jubilee f9078a40ee
Rollup merge of #118891 - compiler-errors:async-gen-blocks, r=eholk
Actually parse async gen blocks correctly

1. I got the control flow in `parse_expr_bottom` messed up, and obviously forgot a test for `async gen`, so we weren't actually ever parsing it correctly.
2. I forgot to gate the span for `async gen {}`, so even if we did parse it, we wouldn't have correctly denied it in `cfg(FALSE)`.

r? eholk
2023-12-12 18:48:55 -08:00
Jubilee 4583a0134f
Rollup merge of #118889 - matthiaskrgr:compl_2023_2, r=WaffleLapkin
more clippy::complexity fixes

      redundant_guards
      redundant_slicing
      filter_next
      needless_borrowed_reference
      useless_format
2023-12-12 18:48:54 -08:00
Jubilee df0686b629
Rollup merge of #118887 - smoelius:patch-1, r=Nilstrieb
Typo
2023-12-12 18:48:54 -08:00