Commit graph

30915 commits

Author SHA1 Message Date
Michael Goulet 1cc0d7d56c Annotate some more bugs 2023-12-15 14:45:06 +00:00
Michael Goulet 70b9dad3dc Annotate some bugs 2023-12-15 14:45:06 +00:00
bors d253bf61ad Auto merge of #118970 - aliemjay:rollup-or33al2, r=aliemjay
Rollup of 2 pull requests

Successful merges:

 - #118927 (Erase late bound regions from `Instance::fn_sig()` and add a few more details to StableMIR APIs)
 - #118964 (Opportunistically resolve region var in canonicalizer (instead of resolving root var))

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-15 08:51:00 +00:00
Ali MJ Al-Nasrawy 9a07292ce6
Rollup merge of #118964 - compiler-errors:resolve, r=aliemjay
Opportunistically resolve region var in canonicalizer (instead of resolving root var)

See comment in `compiler/rustc_type_ir/src/infcx.rs`.

The **root** infer region for a given region vid may not actually be nameable from the universe of the original vid. That means that the assertion in the canonicalizer was too strict, since the `EagerResolver` that we use before canonicalizing is doing only as much resolving as it can.

This replaces `resolve_lt_var` and `probe_lt_var` in the `rustc_type_ir` API with `opportunistic_resolve_lt_var`, which acts as you expect it should. I left a FIXME that complains about the inconsistency.

This test is really gnarly, but I have no idea how to minimize it, since it seems to kind of just be coincidental that it triggered this issue. I hope the underlying root cause is easy enough to understand, though.

r? `@lcnr` or `@aliemjay`

Fixes #118950
2023-12-15 10:58:23 +03:00
Ali MJ Al-Nasrawy 578758ae04
Rollup merge of #118927 - celinval:smir-missing-info, r=compiler-errors
Erase late bound regions from `Instance::fn_sig()` and add a few more details to StableMIR APIs

The Instance `fn_sig()` still included a late bound regions which needed a new compiler function in order to be erased. I've also bundled the following small fixes in this PR, let me know if you want me to isolate any of them.

  - Add missing `CoroutineKind::AsyncGen`.
  - Add optional spread argument to function body which is needed to properly analyze compiler shims.
  - Add a utility method to iterate over all locals together with their declaration.
  - Add a method to get the description of `AssertMessage`*.

* For the last one, we could consider eventually calling the internal `AssertKind::description()` to avoid code duplication. However, we still don't have ways to convert `AssertMessage`, `Operand`, `Place` and others, in order to use that. The other downside of using the internal method is that it will panic for some of the variants.

r ? `@ouz-a`
2023-12-15 10:58:23 +03:00
bors cca2bda07e Auto merge of #118966 - matthiaskrgr:rollup-sdvjwy6, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #116888 (Add discussion that concurrent access to the environment is unsafe)
 - #118888 (Uplift `TypeAndMut` and `ClosureKind` to `rustc_type_ir`)
 - #118929 (coverage: Tidy up early parts of the instrumentor pass)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-15 06:52:44 +00:00
Celina G. Val 600438679d Revert signature change for AssertMessage description 2023-12-14 22:04:14 -08:00
Matthias Krüger 6659b5ec9f
Rollup merge of #118929 - Zalathar:look-hir, r=cjgillot
coverage: Tidy up early parts of the instrumentor pass

This is extracted from #118237, which needed to be manually rebased anyway.

Unlike that PR, this one only affects the coverage instrumentor, and doesn't attempt to move any code into the MIR builder. That can be left to a future version of #118305, which can still benefit from these improvements.

So this is now mostly a refactoring of some internal parts of the instrumentor.
2023-12-15 06:50:18 +01:00
Matthias Krüger d5af762fe5
Rollup merge of #118888 - compiler-errors:uplift-more-things, r=jackh726
Uplift `TypeAndMut` and `ClosureKind` to `rustc_type_ir`

Uplifts `TypeAndMut` and `ClosureKind`

I know I said I was just going to get rid of `TypeAndMut` (https://github.com/rust-lang/types-team/issues/124) but I think this is much simpler, lol

r? `@jackh726` or `@lcnr`
2023-12-15 06:50:18 +01:00
Michael Goulet 146e345d8b Opportunistically resolve region var in canonicalizer 2023-12-15 05:02:37 +00:00
bors 1559dd2dbf Auto merge of #118770 - saethlin:fix-inline-never-uses, r=nnethercote
Fix cases where std accidentally relied on inline(never)

This PR increases the power of `-Zcross-crate-inline-threshold=always` so that it applies through `#[inline(never)]`. Note that though this is called "cross-crate-inlining" in this case especially it is _just_ lazy per-CGU codegen. The MIR inliner and LLVM still respect the attribute as much as they ever have.

Trying to bootstrap with the new `-Zcross-crate-inline-threshold=always` change revealed two bugs:

We have special intrinsics `assert_inhabited`, `assert_zero_valid`, and `assert_mem_uniniitalized_valid` which codegen backends will lower to nothing or a call to `panic_nounwind`.  Since we may not have any call to `panic_nounwind` in MIR but emit one anyway, we need to specially tell `MirUsedCollector` about this situation.

`#[lang = "start"]` is special-cased already so that `MirUsedCollector` will collect it, but then when we make it cross-crate-inlinable it is only assigned to a CGU based on whether `MirUsedCollector` saw a call to it, which of course we didn't.

---

I started looking into this because https://github.com/rust-lang/rust/pull/118683 revealed a case where we were accidentally relying on a function being `#[inline(never)]`, and cranking up cross-crate-inlinability seems like a way to find other situations like that.

r? `@nnethercote` because I don't like what I'm doing to the CGU partitioning code here but I can't come up with something much better
2023-12-15 04:54:14 +00:00
Celina G. Val c0f1207a12 Address PR comments
- Remove `fn_sig()` from Instance.
- Change return value of `AssertMessage::description` to `Cow<>`.
- Add assert to instance `ty()`.
- Generalize uint / int type creation.
2023-12-14 17:56:33 -08:00
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
Zalathar 684b9ea408 coverage: Check that the function signature span precedes the body
This will normally be true, but in cases where it's not true we're better off
not making any assumptions about the signature.
2023-12-15 10:59:32 +11:00
Zalathar 3b610c764d coverage: Compare span source files without involving Lrc<SourceFile>
If we want to know whether two byte positions are in the same file, we don't
need to clone and compare `Lrc<SourceFile>`; we can just get their indices and
compare those instead.
2023-12-15 10:59:32 +11:00
Zalathar 7de2156bfd coverage: Inline and simplify fn_sig_and_body 2023-12-15 10:59:32 +11:00
Zalathar e2f449bcc9 coverage: Use LocalDefId in extract_hir_info 2023-12-15 10:59:32 +11:00
Zalathar b9955fb340 coverage: Extract helper for getting HIR info for coverage 2023-12-15 10:59:32 +11:00
Zalathar bf424c28d2 coverage: Don't bother storing the source file in Instrumentor
We can just as easily look it up again from the source map and body span when
needed.
2023-12-15 10:59:32 +11:00
Zalathar 3d5d5b7ef8 coverage: Extract is_eligible_for_coverage 2023-12-15 10:59:32 +11:00
Zalathar 315c0cf358 coverage: Simplify parts of InstrumentCoverage::run_pass
Changes in this patch:
  - Extract local variable `def_id`
  - Check `is_fn_like` without retrieving HIR
  - Inline some locals that are used once and aren't needed for clarity
2023-12-15 10:59:32 +11:00
Zalathar 87cffb2377 coverage: Assert that the instrumentor never sees promoted MIR 2023-12-15 10:59:32 +11: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 742f193ef8 Move special methods from ClosureKind back into rustc 2023-12-14 19:10:03 +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
Ben Kimock e559172249 Fix cases where std accidentally relied on inline(never) 2023-12-14 08:30:36 -05: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