Commit Graph

182 Commits

Author SHA1 Message Date
Guillaume Gomez
3da96aed94
Rollup merge of #118680 - djkoloski:shell_argfiles, r=compiler-errors
Add support for shell argfiles

Closes https://github.com/rust-lang/compiler-team/issues/684
2024-01-09 17:52:21 +01:00
Guillaume Gomez
d3574beb5d
Rollup merge of #119527 - klensy:ordering, r=compiler-errors
don't reexport atomic::ordering via rustc_data_structures, use std import

This looks simpler.
2024-01-09 13:23:17 +01:00
David Koloski
684aa2c9d1 Add support for shell argfiles 2024-01-08 15:25:55 -05:00
Nicholas Nethercote
b1b9278851 Make DiagnosticBuilder::emit consuming.
This works for most of its call sites. This is nice, because `emit` very
much makes sense as a consuming operation -- indeed,
`DiagnosticBuilderState` exists to ensure no diagnostic is emitted
twice, but it uses runtime checks.

For the small number of call sites where a consuming emit doesn't work,
the commit adds `DiagnosticBuilder::emit_without_consuming`. (This will
be removed in subsequent commits.)

Likewise, `emit_unless` becomes consuming. And `delay_as_bug` becomes
consuming, while `delay_as_bug_without_consuming` is added (which will
also be removed in subsequent commits.)

All this requires significant changes to `DiagnosticBuilder`'s chaining
methods. Currently `DiagnosticBuilder` method chaining uses a
non-consuming `&mut self -> &mut Self` style, which allows chaining to
be used when the chain ends in `emit()`, like so:
```
    struct_err(msg).span(span).emit();
```
But it doesn't work when producing a `DiagnosticBuilder` value,
requiring this:
```
    let mut err = self.struct_err(msg);
    err.span(span);
    err
```
This style of chaining won't work with consuming `emit` though. For
that, we need to use to a `self -> Self` style. That also would allow
`DiagnosticBuilder` production to be chained, e.g.:
```
    self.struct_err(msg).span(span)
```
However, removing the `&mut self -> &mut Self` style would require that
individual modifications of a `DiagnosticBuilder` go from this:
```
    err.span(span);
```
to this:
```
    err = err.span(span);
```
There are *many* such places. I have a high tolerance for tedious
refactorings, but even I gave up after a long time trying to convert
them all.

Instead, this commit has it both ways: the existing `&mut self -> Self`
chaining methods are kept, and new `self -> Self` chaining methods are
added, all of which have a `_mv` suffix (short for "move"). Changes to
the existing `forward!` macro lets this happen with very little
additional boilerplate code. I chose to add the suffix to the new
chaining methods rather than the existing ones, because the number of
changes required is much smaller that way.

This doubled chainging is a bit clumsy, but I think it is worthwhile
because it allows a *lot* of good things to subsequently happen. In this
commit, there are many `mut` qualifiers removed in places where
diagnostics are emitted without being modified. In subsequent commits:
- chaining can be used more, making the code more concise;
- more use of chaining also permits the removal of redundant diagnostic
  APIs like `struct_err_with_code`, which can be replaced easily with
  `struct_err` + `code_mv`;
- `emit_without_diagnostic` can be removed, which simplifies a lot of
  machinery, removing the need for `DiagnosticBuilderState`.
2024-01-08 15:24:49 +11:00
klensy
56173611d6 don't reexport atomic::ordering via rustc_data_structures, use std import 2024-01-06 15:01:10 +03:00
Michael Goulet
da700b39df
Rollup merge of #119601 - nnethercote:Emitter-cleanups, r=oli-obk
`Emitter` cleanups

Some improvements I found while looking at this code.

r? `@oli-obk`
2024-01-05 10:57:24 -05:00
Nicholas Nethercote
cb9abcae79 Rename EmitterWriter as HumanEmitter.
For consistency with other `Emitter` impls, such as `JsonEmitter`,
`SilentEmitter`, `SharedEmitter`, etc.
2024-01-05 10:02:40 +11:00
DaniPopes
7e3f5f858d
Use Result::flatten in catch_with_exit_code 2023-12-28 21:22:34 +01:00
bors
2fe50cd72c Auto merge of #119129 - jyn514:verbose, r=compiler-errors,estebank
rework `-Zverbose`

implements the changes described in https://github.com/rust-lang/compiler-team/issues/706

the first commit is only a name change from `-Zverbose` to `-Zverbose-internals` and does not change behavior. the second commit changes diagnostics.

possible follow up work:
- `ty::pretty` could print more info with `--verbose` than it does currently. `-Z verbose-internals` shows too much info in a way that's not helpful to users. michael had ideas about this i didn't fully understand: https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/uplift.20some.20-Zverbose.20calls.20and.20rename.20to.E2.80.A6.20compiler-team.23706/near/408984200
- `--verbose` should imply `-Z write-long-types-to-disk=no`. the code in `ty_string_with_limit` should take `--verbose` into account (apparently this affects `Ty::sort_string`, i'm not familiar with this code). writing a file to disk should suggest passing `--verbose`.

r? `@compiler-errors` cc `@estebank`
2023-12-26 12:27:29 +00:00
Nicholas Nethercote
8a9db25459 Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
Nicholas Nethercote
99472c7049 Remove Session methods that duplicate DiagCtxt methods.
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
2023-12-24 08:05:28 +11:00
Nicholas Nethercote
3a1b8e643a Rename EarlyDiagCtxt methods to match DiagCtxt.
- `early_error_no_abort` -> `early_err`
- `early_error` -> `early_fatal`
- `early_struct_error` -> `early_struct_fatal`
2023-12-23 13:23:28 +11:00
jyn
b5d8361909 rename to verbose-internals 2023-12-19 13:35:37 -05:00
Nicholas Nethercote
f6aa418c9f Rename many DiagCtxt and EarlyDiagCtxt locals. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
d58e372853 Rename many EarlyDiagCtxt arguments. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
cce1701c4c Rename EarlyErrorHandler as EarlyDiagCtxt. 2023-12-18 16:06:21 +11:00
Nicholas Nethercote
cde19c016e Rename Handler as DiagCtxt. 2023-12-18 16:06:19 +11:00
Matthias Krüger
d707461a1a clippy::complexity fixes
filter_map_identity
 needless_bool
 search_is_some
 unit_arg
 map_identity
 needless_question_mark
 derivable_impls
2023-12-12 19:28:13 +01:00
Nadrieril
281002d42c Extract exhaustiveness into its own crate 2023-12-11 11:20:55 +01:00
Martin Nordholts
0e3e16cb5e rustc_driver_impl: Address all rustc::potential_query_instability lints
Instead of allowing `rustc::potential_query_instability` on the whole
crate we go over each lint and allow it individually if it is safe to
do. Turns out there were no instances of this lint in this crate.
2023-12-05 06:19:14 +01:00
bors
1d726a2be0 Auto merge of #118472 - nnethercote:rustc_session, r=bjorn3
`rustc_session` cleanups

r? `@bjorn3`
2023-12-01 00:08:04 +00:00
Nicholas Nethercote
99ac405b96 Move MetadataLoader{,Dyn} to rustc_metadata.
They're not used in `rustc_session`, and `rustc_metadata` is a more
obvious location.

`MetadataLoader` was originally put into `rustc_session` in #41565 to
avoid a dependency on LLVM, but things have changed a lot since then and
that's no longer relevant, e.g. `rustc_codegen_llvm` depends on
`rustc_metadata`.
2023-11-30 17:05:54 +11:00
bjorn3
d7e9a30941 Turn write_dep_info into a regular function
It has side-effects and as such can't be cached.
2023-11-26 18:02:47 +00:00
bjorn3
365a580bc4 Mostly revert "Accept crate name instead of attributes in build_output_filenames" 2023-11-26 18:02:47 +00:00
bjorn3
4acaa0284e Feed the output filenames into the TyCtxt
Since the introduction of the crate attribute pre-expansion pass we
don't need access to the TyCtxt to compute it.
2023-11-26 18:02:47 +00:00
bjorn3
98a6eaa7f8 Serialize OutputFilenames into rmeta file
This ensures that linking will use the correct crate name even when
`#![crate_name = "..."]` is used to specify the crate name.
2023-11-26 18:02:42 +00:00
bjorn3
eacbe65dfe Accept crate name instead of attributes in build_output_filenames 2023-11-26 17:43:49 +00:00
Nicholas Nethercote
af3fbb3607 Remove unnecessary dependencies. 2023-11-26 08:38:42 +11:00
Nicholas Nethercote
57cd5e6551 Use rustc_fluent_macro::fluent_messages! directly.
Currently we always do this:
```
use rustc_fluent_macro::fluent_messages;
...
fluent_messages! { "./example.ftl" }
```
But there is no need, we can just do this everywhere:
```
rustc_fluent_macro::fluent_messages! { "./example.ftl" }
```
which is shorter.
2023-11-26 08:38:40 +11:00
Nicholas Nethercote
a733082be9 Avoid need for {D,Subd}iagnosticMessage imports.
The `fluent_messages!` macro produces uses of
`crate::{D,Subd}iagnosticMessage`, which means that every crate using
the macro must have this import:
```
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
```

This commit changes the macro to instead use
`rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the
imports.
2023-11-26 08:38:00 +11:00
Nicholas Nethercote
df9f83987a Remove rustc_error_messages/messages.ftl.
It's empty, and it doesn't even make sense, because
`rustc_error_messages` is a lower-level crate than `rustc_errors`.
2023-11-26 08:37:27 +11:00
Nicholas Nethercote
971010ea5a Merge Queries::{ongoing_codegen,linker}.
There is no real need for them to be separate.
2023-11-22 13:22:49 +11:00
Nicholas Nethercote
3a4798c92d Make Compiler::{sess,codegen_backend} public.
And remove the relevant getters on `Compiler` and `Queries`.
2023-11-22 13:22:41 +11:00
Nicholas Nethercote
09c807ed82 Add two useful comments. 2023-11-22 13:20:56 +11:00
bors
28345f06d7 Auto merge of #118002 - nnethercote:unify-input-no-input, r=bjorn3
Unify "input" and "no input" paths in `run_compiler`

A follow-up to #117649.

r? `@bjorn3`
2023-11-18 16:43:47 +00:00
Matthias Krüger
6227455345
Rollup merge of #117745 - ouz-a:emit_smir, r=celinval
Emit smir

This adds ability to `-Zunpretty=smir` and get smir output of a Rust file, this is obliviously pretty basic compared to `mir` output but I think we could iteratively improve it, and even at this state this is useful for us.

r? ``@celinval``
2023-11-17 23:04:23 +01:00
Nicholas Nethercote
472f7c97a6 Simplify run_compiler control flow.
I find `Compilation::and_then` hard to read. This commit removes it,
simplifying the control flow in `run_compiler`, and reducing the number
of lines of code.

In particular, `list_metadata` and `process_try_link` (renamed `rlink`)
are now only called if the relevant condition is true, rather than that
condition being checked within the function.
2023-11-18 07:43:51 +11:00
Nicholas Nethercote
5659cc57e9 Factor out two print_crate_info calls. 2023-11-18 07:40:37 +11:00
Nicholas Nethercote
446c8e06d9 Move describe_lints calls.
Currently we have an inconsistency between the "input" and "no input"
cases:
- no input: `rustc --print=sysroot -Whelp` prints the lint help.
- input:    `rustc --print=sysroot -Whelp a.rs` prints the sysroot.

It makes sense to print the lint help in both cases, because that's what
happens with `--help`/`-Zhelp`/`-Chelp`.

In fact, the `describe_lints` in the "input" case happens amazingly
late, after *parsing*. This is because, with plugins, lints used to be
registered much later, when the global context was created. But #117649
moved lint registration much earlier, during session construction.

So this commit moves the `describe_lints` call to a single spot for both
for both the "input" and "no input" cases, as early as possible. This is
still not as early as `--help`/`-Zhelp`/`-Chelp`, because `-Whelp` must
wait until the session is constructed.
2023-11-18 07:39:15 +11:00
Nicholas Nethercote
8aee35e2ed Merge interface::run_compiler calls.
`rustc_driver_impl::run_compiler` currently has two
`interface::run_compiler` calls: one for the "no input" case, and one
for the normal case.

This commit merges the former into the latter, which makes the control
flow easier to read and avoids some duplication.

It also makes it clearer that the "no input" case will describe lints
before printing crate info, while the normal case does it in the reverse
order. Possibly a bug?
2023-11-18 07:38:05 +11:00
Nicholas Nethercote
706eb1604b Rename early_error_handler as default_handler.
Yes, its type is `EarlyErrorHandler`, but there is another value of that
type later on in the function called `handler` that is initialized with
`sopts.error_format`. So `default_handler` is a better name because it
clarifies that it is initialized with `ErrorOutputType::default()`.
2023-11-18 07:17:35 +11:00
Oğuz Ağcayazı
3883645a9b change smir to StableMir 2023-11-17 13:28:07 +03:00
Oğuz Ağcayazı
ebd9c145f6 better formatting for statements 2023-11-17 13:28:07 +03:00
Oğuz Ağcayazı
ae179a04b6 emit basic smir 2023-11-17 13:28:07 +03:00
Nicholas Nethercote
aed8e1f3b6 Move CodegenBackend out of Linker.
It can easily be passed in. And that removes the single clone of
`Compiler::codegen_backend`, which means it no longer needs to be `Lrc`.
2023-11-17 17:30:36 +11:00
Nicholas Nethercote
de91b6d249 Move Session out of Linker.
It can easily be passed in. And that removes the single clone of
`Compiler::session`, which means it no longer needs to be `Lrc`.
2023-11-17 17:14:17 +11:00
Nicholas Nethercote
a3b4961d5f Move lint_store from GlobalCtxt to Session.
This was made possible by the removal of plugin support, which
simplified lint store creation.

This simplifies the places in rustc and rustdoc that call
`describe_lints`, which are early on. The lint store is now built before
those places, so they don't have to create their own lint store for
temporary use, they can just use the main one.
2023-11-17 10:39:18 +11:00
Mark Rousskov
db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
bors
ee85f7fc48 Auto merge of #117814 - RalfJung:rustc-logger-without-set-var, r=TaKO8Ki
rustc_log: provide a way to init logging based on the values, not names, of the env vars

Miri wants to affect how rustc does logging. So far this required setting environment variables before calling `rustc_driver::init_rustc_env_logger`. However, `set_var` is a function one should really [avoid calling](https://github.com/rust-lang/rust/issues/90308), so this adds the necessary APIs to rustc such that Miri can just pass it the *values* of all the log-relevant environment variables, rather than having to change the global environment.
2023-11-15 08:03:07 +00:00
Nicholas Nethercote
aefbb616af Remove -Zperf-stats.
The included measurements have varied over the years. At one point there
were quite a few more, but #49558 deleted a lot that were no longer
used. Today there's just four, and it's a motley collection that doesn't
seem particularly valuable.

I think it has been well and truly subsumed by self-profiling, which
collects way more data.
2023-11-13 09:45:20 +11:00