Commit Graph

310 Commits

Author SHA1 Message Date
bjorn3
fdff4d7682 Move metadata header and version checks together
This will make it easier to report rustc versions for older metadata
formats.
2024-03-08 14:49:28 +00:00
Matthias Krüger
a8e3543b19
Rollup merge of #121194 - beetrees:rustc-raw-args, r=petrochenkov
Refactor pre-getopts command line argument handling

Rebased version of #111658. I've also fixed the Windows CI failure (although I don't have access to Windows to test it myself).
2024-03-08 13:22:25 +01:00
Guillaume Gomez
4de78d2a8d
Rollup merge of #121089 - oli-obk:create_def_feed, r=petrochenkov
Remove `feed_local_def_id`

best reviewed commit by commit

Basically I returned `TyCtxtFeed` from `create_def` and then preserved that in the local caches

based on https://github.com/rust-lang/rust/pull/121084

r? ````@petrochenkov````
2024-03-07 18:32:47 +01:00
beetrees
fb87e606cc
Refactor argument UTF-8 checking into rustc_driver::args::raw_args() 2024-03-07 00:20:01 +00:00
beetrees
63091b105d
Make arg_expand_all not short-circuit on first error 2024-03-07 00:19:55 +00:00
Matthias Krüger
efe9deace8
Rollup merge of #121382 - nnethercote:rework-untranslatable_diagnostic-lint, r=davidtwco
Rework `untranslatable_diagnostic` lint

Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This PR changes it to check calls to any function with an `impl Into<{D,Subd}iagnosticMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. It also lets us add `#[rustc_lint_diagnostics]` to a number of functions that don't have an `impl Into<{D,Subd}iagnosticMessage>`, such as `Diag::span`.

r? ``@davidtwco``
2024-03-06 22:02:46 +01:00
Nicholas Nethercote
b7d58eef4b Rewrite the untranslatable_diagnostic lint.
Currently it only checks calls to functions marked with
`#[rustc_lint_diagnostics]`. This commit changes it to check calls to
any function with an `impl Into<{D,Subd}iagMessage>` parameter. This
greatly improves its coverage and doesn't rely on people remembering to
add `#[rustc_lint_diagnostics]`.

The commit also adds `#[allow(rustc::untranslatable_diagnostic)`]
attributes to places that need it that are caught by the improved lint.
These places that might be easy to convert to translatable diagnostics.

Finally, it also:
- Expands and corrects some comments.
- Does some minor formatting improvements.
- Adds missing `DecorateLint` cases to
  `tests/ui-fulldeps/internal-lints/diagnostics.rs`.
2024-03-06 14:19:01 +11:00
Matthias Krüger
1b30268e5b
Rollup merge of #121658 - jieyouxu:ice-outdated-nightly, r=oli-obk
Hint user to update nightly on ICEs produced from outdated nightly

This is a conservative best-effort approach to detect a potentially outdated nightly; it will fallback to the regular ICE-reporting if any of the following cases are true:
- Channel is not nightly
- Version information is not available
- Version date is not parseable as a YYYY-MM-DD or is missing
- System time is at least 36 hours ahead of the user's nightly release datetime.
- Any internal features are used.

Note that I'm not sure how to make a test for this: I tested this manually by `CFG_VER_DATE="2020-02-02" ./x build library --stage 1`, and also changing the channel detection in `rustc_driver_impl` from `Some("nightly")` to `Some("nightly" | "dev")`, and then running `rustc +stage1 test.rs -Ztreat-err-as-bug=1` with a non-existent `test.rs`.

<img width="1145" alt="Screenshot 2024-02-27 at 01 12 28" src="https://github.com/rust-lang/rust/assets/39484203/eff6af2e-4b19-4a70-af57-cd739ecf0e84">

Closes #118832.
2024-03-05 19:53:20 +01:00
Oli Scherer
ef00fae46d Avoid using feed_unit_query from within queries 2024-03-05 10:02:39 +00:00
Nicholas Nethercote
80d2bdb619 Rename all ParseSess variables/fields/lifetimes as psess.
Existing names for values of this type are `sess`, `parse_sess`,
`parse_session`, and `ps`. `sess` is particularly annoying because
that's also used for `Session` values, which are often co-located, and
it can be difficult to know which type a value named `sess` refers to.
(That annoyance is the main motivation for this change.) `psess` is nice
and short, which is good for a name used this much.

The commit also renames some `parse_sess_created` values as
`psess_created`.
2024-03-05 08:11:45 +11:00
Nicholas Nethercote
067d7c3d00 Inline and remove HumanEmitter::stderr.
Because `HumanEmitter::new` is enough, in conjunction with the (renamed)
`stderr_destination` function.
2024-02-29 17:50:23 +11:00
Nicholas Nethercote
880c1c585f Rename DiagCtxt::with_emitter as DiagCtxt::new.
Because it's now the only constructor.
2024-02-29 16:30:12 +11:00
许杰友 Jieyou Xu (Joe)
9c963fc5bc
Adjust wording 2024-02-27 12:53:41 +00:00
许杰友 Jieyou Xu (Joe)
a0ca9b1633
Don't suggest update nightly if using internal features 2024-02-27 12:40:02 +00:00
许杰友 Jieyou Xu (Joe)
a5245ef284
Hint user to update nightly on ICEs produced from outdated nightly 2024-02-27 01:13:14 +00:00
Nicholas Nethercote
f16c226af3 Inline and remove abort_on_err.
It's clumsy and doesn't improve readability.
2024-02-22 08:03:47 +11:00
Nicholas Nethercote
c2512a130f Inline and remove Session::compile_status.
Because it's now simple enough that it doesn't provide much benefit.
2024-02-22 08:03:47 +11:00
Nicholas Nethercote
9919c3dab3 Remove EarlyDiagCtxt::abort_if_errors.
Its one use isn't necessary, because it's not possible for errors to
have been emitted at that point.
2024-02-22 08:03:47 +11:00
klensy
35fe26757a windows bump to 0.52 2024-02-18 16:02:16 +03:00
Maybe Waffle
5441523f07 Refactor out a repeating pattern with get_or_default_sysroot 2024-02-15 00:09:40 +00:00
Maybe Waffle
a03d19ef63 Allow targets to override default codegen backend 2024-02-14 23:43:00 +00:00
Matthias Krüger
46a0448405
Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco
Invert diagnostic lints.

That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has been converted to use translated diagnostics.

This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.

r? ````@davidtwco````
2024-02-09 14:41:50 +01:00
Nicholas Nethercote
e55df623ea Remove an unchecked_claim_error_was_emitted call.
When `catch_fatal_errors` catches a `FatalErrorMarker`, it returns an
`ErrorGuaranteed` that is conjured out of thin air with
`unchecked_claim_error_was_emitted`. But that `ErrorGuaranteed` is never
used.

This commit changes it to instead conjure a `FatalError` out of thin
air. (A non-deprecated action!) This makes more sense because
`FatalError` and `FatalErrorMarker` are a natural pairing -- a
`FatalErrorMarker` is created by calling `FatalError::raise`, so this is
effectively getting back the original `FatalError`.

This requires a tiny change in `catch_with_exit_code`. The old result of
the `catch_fatal_errors` call there was
`Result<Result<(), ErrorGuaranteed>, ErrorGuaranteed>` which could be
`flatten`ed into `Result<(), ErrorGuaranteed>`. The new result of the
`catch_fatal_errors` calls is
`Result<Result<(), ErrorGuaranteed>, FatalError>`, which can't be
`flatten`ed but is still easily matched for the success case.
2024-02-07 18:57:38 +11:00
Nicholas Nethercote
0ac1195ee0 Invert diagnostic lints.
That is, change `diagnostic_outside_of_impl` and
`untranslatable_diagnostic` from `allow` to `deny`, because more than
half of the compiler has be converted to use translated diagnostics.

This commit removes more `deny` attributes than it adds `allow`
attributes, which proves that this change is warranted.
2024-02-06 13:12:33 +11:00
Nicholas Nethercote
5d9dfbd08f Stop using String for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!

This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.

With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123)  // macro call

struct_span_code_err!(dcx, span, E0123, "msg");  // bare ident arg to macro call

\#[diag(name, code = "E0123")]  // string
struct Diag;
```

With the new code, they all use the `E0123` constant.
```
E0123  // constant

struct_span_code_err!(dcx, span, E0123, "msg");  // constant

\#[diag(name, code = E0123)]  // constant
struct Diag;
```

The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
  used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
  moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
  code constants and the `DIAGNOSTIC_TABLES`. This is in its new
  `codes.rs` file.
2024-01-29 07:41:41 +11:00
clubby789
fd29f74ff8 Remove unused features 2024-01-25 14:01:33 +00:00
Nicholas Nethercote
32de78cade Replace TrimmedDefPaths with a bool.
It's a tri-state enum but the `Always` variant is never used, so a bool
is simpler.
2024-01-15 09:16:14 +11:00
Nicholas Nethercote
3c4f1d85af Rename {create,emit}_warning as {create,emit}_warn.
For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`,
all of which use an abbreviated form.
2024-01-10 07:33:06 +11:00
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
Ralf Jung
581a317bbb rustc_log: provide a way to init logging based on the values, not names, of the env vars 2023-11-11 15:24:33 +01:00
bjorn3
ba82056a14 Use the actual computed crate name for -Zprint-vtable-sizes 2023-11-05 16:29:15 +00:00
bjorn3
1a1b10fa63 Don't steal the parse query when using --pretty
This is the only place aside from the global_ctxt query where it is
stolen.
2023-11-05 16:29:15 +00:00
Nicholas Nethercote
5c462a32bd Remove support for compiler plugins.
They've been deprecated for four years.

This commit includes the following changes.
- It eliminates the `rustc_plugin_impl` crate.
- It changes the language used for lints in
  `compiler/rustc_driver_impl/src/lib.rs` and
  `compiler/rustc_lint/src/context.rs`. External lints are now called
  "loaded" lints, rather than "plugins" to avoid confusion with the old
  plugins. This only has a tiny effect on the output of `-W help`.
- E0457 and E0498 are no longer used.
- E0463 is narrowed, now only relating to unfound crates, not plugins.
- The `plugin` feature was moved from "active" to "removed".
- It removes the entire plugins chapter from the unstable book.
- It removes quite a few tests, mostly all of those in
  `tests/ui-fulldeps/plugin/`.

Closes #29597.
2023-11-04 08:50:46 +11:00
Nicholas Nethercote
f405ce86c2 Minimize pub usage in source_map.rs.
Most notably, this commit changes the `pub use crate::*;` in that file
to `use crate::*;`. This requires a lot of `use` items in other crates
to be adjusted, because everything defined within `rustc_span::*` was
also available via `rustc_span::source_map::*`, which is bizarre.

The commit also removes `SourceMap::span_to_relative_line_string`, which
is unused.
2023-11-02 19:35:00 +11:00
Guillaume Gomez
d96bdbe218
Rollup merge of #117376 - nnethercote:rustc_interface-more, r=oli-obk
More `rustc_interface` cleanups

In particular, following up #117268 with more improvement to `--cfg`/`--check-cfg` handling.

r? ``@oli-obk``
2023-10-30 17:33:18 +01:00
Nicholas Nethercote
678e01a3fc Delay parsing of --cfg and --check-cfg options.
By storing the unparsed values in `Config` and then parsing them within
`run_compiler`, the parsing functions can use the main symbol interner,
and not create their own short-lived interners.

This change also eliminates the need for one `EarlyErrorHandler` in
rustdoc, because parsing errors can be reported by another, slightly
later `EarlyErrorHandler`.
2023-10-30 13:46:53 +11:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
Jubilee
48a3865218
Rollup merge of #117268 - nnethercote:rustc_interface, r=oli-obk
`rustc_interface` cleanups

Particularly in and around `--cfg` and `--check-cfg` handling.

r? `@oli-obk`
2023-10-28 01:07:38 -07:00
Nicholas Nethercote
5e54997157 Clean up config mess.
`parse_cfgspecs` and `parse_check_cfg` run very early, before the main
interner is running. They each use a short-lived interner and convert
all interned symbols to strings in their output data structures. Once
the main interner starts up, these data structures get converted into
new data structures that are identical except with the strings converted
to symbols.

All is not obvious from the current code, which is a mess, particularly
with inconsistent naming that obscures the parallel string/symbol data
structures. This commit clean things up a lot.

- The existing `CheckCfg` type is generic, allowing both
  `CheckCfg<String>` and `CheckCfg<Symbol>` forms. This is really
  useful, but it defaults to `String`. The commit removes the default so
  we have to use `CheckCfg<String>` and `CheckCfg<Symbol>` explicitly,
  which makes things clearer.

- Introduces `Cfg`, which is generic over `String` and `Symbol`, similar
  to `CheckCfg`.

- Renames some things.
  - `parse_cfgspecs` -> `parse_cfg`
  - `CfgSpecs` -> `Cfg<String>`, plus it's used in more places, rather
    than the underlying `FxHashSet` type.
  - `CrateConfig` -> `Cfg<Symbol>`.
  - `CrateCheckConfig` -> `CheckCfg<Symbol>`

- Adds some comments explaining the string-to-symbol conversions.

- `to_crate_check_config`, which converts `CheckCfg<String>` to
  `CheckCfg<Symbol>`, is inlined and removed and combined with the
  overly-general `CheckCfg::map_data` to produce
  `CheckCfg::<String>::intern`.

- `build_configuration` now does the `Cfg<String>`-to-`Cfg<Symbol>`
  conversion, so callers don't need to, which removes the need for
  `to_crate_config`.

The diff for two of the fields in `Config` is a good example of the
improved clarity:
```
-    pub crate_cfg: FxHashSet<(String, Option<String>)>,
-    pub crate_check_cfg: CheckCfg,
+    pub crate_cfg: Cfg<String>,
+    pub crate_check_cfg: CheckCfg<String>,
```
Compare that with the diff for the corresponding fields in `ParseSess`,
and the relationship to `Config` is much clearer than before:
```
-    pub config: CrateConfig,
-    pub check_config: CrateCheckConfig,
+    pub config: Cfg<Symbol>,
+    pub check_config: CheckCfg<Symbol>,
```
2023-10-28 09:03:51 +11:00
Matthias Krüger
df8852a934
Rollup merge of #116834 - nnethercote:rustc_symbol_mangling, r=davidtwco
Remove `rustc_symbol_mangling/messages.ftl`.

It contains a single message that (a) doesn't contain any natural language, and (b) is only used in tests.

r? `@davidtwco`
2023-10-27 19:46:06 +02:00
bors
6d674af861 Auto merge of #116818 - Nilstrieb:stop-submitting-bug-reports, r=wesleywiser
Stop telling people to submit bugs for internal feature ICEs

This keeps track of usage of internal features, and changes the message to instead tell them that using internal features is not supported.

I thought about several ways to do this but now used the explicit threading of an `Arc<AtomicBool>` through `Session`. This is not exactly incremental-safe, but this is fine, as this is set during macro expansion, which is pre-incremental, and also only affects the output of ICEs, at which point incremental correctness doesn't matter much anyways.

See [MCP 620.](https://github.com/rust-lang/compiler-team/issues/596)

![image](https://github.com/rust-lang/rust/assets/48135649/be661f05-b78a-40a9-b01d-81ad2dbdb690)
2023-10-26 02:08:07 +00:00
Nilstrieb
9d42b1e268 Stop telling people to submit bugs for internal feature ICEs
This keeps track of usage of internal features, and changes the message
to instead tell them that using internal features is not supported.

See MCP 620.
2023-10-25 23:23:04 +02:00
bors
6d7160ce97 Auto merge of #116814 - estebank:windows-ice-path, r=petrochenkov
Use `YYYY-MM-DDTHH_MM_SS` as datetime format for ICE dump files

Windows paths do not support `:`, so use a datetime format in ICE dump paths that Windows will accept.

CC #116809, fix #115180.
2023-10-18 07:45:56 +00:00
Esteban Küber
e1aa5adc78 Use YYYY-MM-DDTHH_MM_SS as datetime format for ICE dump files
Windows paths do not support `:`, so use a datetime format in ICE dump
paths that Windows will accept.

Fix #116809, fix #115180.
2023-10-17 17:31:47 +00:00
Matthias Krüger
6e6cd68cd0
Rollup merge of #116827 - nnethercote:pub-handle_options, r=compiler-errors
Make `handle_options` public again.

r? ``@compiler-errors``
2023-10-17 19:07:24 +02:00
Nicholas Nethercote
f4a9d29c50 Remove rustc_symbol_mangling/messages.ftl.
It contains a single message that (a) doesn't contain any natural
language, and (b) is only used in tests.
2023-10-17 16:15:36 +11:00
bors
c07693c160 Auto merge of #116477 - nnethercote:tidy-alpha-deps, r=wesleywiser
Use tidy to enforce alphabetical dependency ordering

I get annoyed when dependencies in `Cargo.toml` files are not in alphabetical order. The [style guide](https://github.com/rust-lang/rust/blob/master/src/doc/style-guide/src/cargo.md) agrees with me.

There are ongoing efforts to provide linting/formatting of `Cargo.toml` files, e.g. https://github.com/rust-lang/rustfmt/pull/5240, https://crates.io/crates/cargo-toml-lint, and https://github.com/TimonPost/cargo-toml-format. But it's far from clear what's the right approach.

So this PR does something very simple: it uses the order checking already present in tidy. This allows incremental application of ordering, starting right now, and avoiding the need for any kind of all-at-once conversion.

If we do end up using some more comprehensive `Cargo.toml` linting/formatting solution in the future, the `tidy-alphabetical` lines will be easy to remove.

r? `@wesleywiser`
2023-10-17 02:48:03 +00:00
Nicholas Nethercote
b0e1a52e37 Make handle_options public again. 2023-10-17 13:25:58 +11:00
bors
4af886f8ab Auto merge of #116731 - Alexendoo:hash-untracked-state, r=oli-obk
Add `Config::hash_untracked_state` callback

For context, I'm looking to use [late module passes](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LintStore.html#structfield.late_module_passes) in Clippy which unlike regular late passes run incrementally per module

However we have a config file which can change between runs, we need changes to that to invalidate the `lint_mod` query. This PR adds a side channel for us to hash some extra state into `Options` in order to do that

This does not make any changes to Clippy, I plan to do that in a PR to the Clippy repo along with some other required changes

An alternative implementation would be to add a new query to track this state and override the `lint_mod` query in Clippy to first call that

cc `@rust-lang/clippy`
2023-10-16 16:33:42 +00:00
Alex Macleod
59f6f044f5 Add Config::hash_untracked_state callback 2023-10-14 15:54:26 +00:00
Michael Goulet
b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Nicholas Nethercote
2b4c33817a Remove unneeded pubs. 2023-10-13 06:35:19 +11:00
Nicholas Nethercote
2e2924f263 Split and rename the annotation structs.
`NoAnn` and `IdentifiedAnnotation` impl both `pprust_ast::PpAnn` and
`pprust_hir::PpAnn`, which is a bit confusing, because the optional
`tcx` is only needed for the HIR cases. (Currently the `tcx` is
unnecessarily provided in the `expanded` AST cases.)

This commit splits each one into `Ast` and `Hir` versions, which makes
things clear about where the `tcx` is needed. The commit also renames
all the traits so they consistently end with `Ann`.
2023-10-13 06:35:19 +11:00
Nicholas Nethercote
b65227a9ee Make needs_analysis true for PpHirMode::Typed.
This avoids the need for a bespoke `tcx.analysis()` call.
2023-10-13 06:35:19 +11:00
Nicholas Nethercote
ba58e3213d Rename some 'hir lifetimes as 'tcx.
Because they all end up within a `TyCtxt`.
2023-10-13 06:35:19 +11:00
Nicholas Nethercote
060851b764 Remove pretty-printing traits.
`call_with_pp_support_ast` and `call_with_pp_support_hir` how each have
a single call site. This commit inlines and removes them, which also
removes the need for all the supporting traits: `Sess`,
`AstPrinterSupport`, and `HirPrinterSupport`. The `sess` member is also
removed from several structs.
2023-10-13 06:35:17 +11:00
Nicholas Nethercote
7d145a0fde Merge print_* functions.
The handling of the `PpMode` variants is currently spread across three
functions: `print_after_parsing`, `print_after_hir_lowering`, and
`print_with_analysis`. Each one handles some of the variants. This split
is primarily because `print_after_parsing` has slightly different
arguments to the other two.

This commit changes the structure. It merges the three functions into a
single `print` function, and encapsulates the different arguments in a
new enum `PrintExtra`.

Benefits:
- The code is a little shorter.
- All the `PpMode` variants are handled in a single `match`, with no
  need for `unreachable!` arms.
- It enables the trait removal in the subsequent commit by reducing
  the number of `call_with_pp_support_ast` call sites from two to one.
2023-10-13 06:34:55 +11:00
Nicholas Nethercote
e3d8bbbfe2 Simplify support traits.
First, both `AstPrinterSupport` and `HirPrinterSupport` have a `sess`
method. This commit introduces a `Sess` trait and makes the support
traits be subtraits of `Sess`, to avoid some duplication.

Second, both support traits have a `pp_ann` method that isn't needed if
we enable `trait_upcasting`. This commit removes those methods.

(Both of these traits will be removed in a subsequent commit, as will
the `trait_upcasting` use.)
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
d5e7c5f3cc Remove unused PrinterSupport::hir_map method. 2023-10-13 06:20:11 +11:00
Nicholas Nethercote
1467ba06b6 Remove PpAstTreeMode.
It's simpler to distinguish the two AST modes directly in `PpMode`.
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
87090a97e3 Remove an outdated comment.
`phase_3_run_analysis_passes` no longer exists, and AFAICT this code has
been refactored so much since this comment was written that it no longer
has any useful meaning.
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
c5cfcdc4ac Remove unnecessary call to call_with_pp_support_hir.
The callback is trivial and no pp support is actually needed. This makes
the `HirTree` case more like the `AstTree` case above.
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
ef8701a4a0 Rename some things.
- Rename `pprust` as `pprust_ast`, to align with `pprust_hir`.
- Rename `PrinterSupport` as `AstPrinterSupport`, to align with
  `HirPrinterSupport`.
2023-10-13 06:20:11 +11:00
Michael Howell
c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
Tamir Duberstein
a081007265
rustc_driver: avoid fallible conversions
Use `std::path::PathBuf` rather than `String`; use `std::env::var_os`
rather than `std::env::var`. These changes avoid a number of error paths
which can arise in the presence of non-UTF-8 paths.
2023-10-06 08:54:14 -04:00
Tamir Duberstein
7654d4b398
compiler: always use var_os("RUST_BACKTRACE")
There are 3 instances of var(...) and 3 instances of var_os(...); the
latter avoids an appearance of unhandled error, so use it everywhere.
2023-10-06 08:53:23 -04:00
Nicholas Nethercote
10ab51d69d Sort rustc_driver_impl dependencies.
As per
https://github.com/rust-lang/rust/blob/master/src/doc/style-guide/src/cargo.md,
which says:

> Sort key names alphabetically within each section, with the exception
> of the [package] section.

And use tidy to enforce it.
2023-10-06 17:53:01 +11:00
bors
42f5828b01 Auto merge of #115627 - compiler-errors:icedump-no-std, r=m-ou-se
Don't modify libstd to dump rustc ICEs

Do a much simpler thing and just dump a `std::backtrace::Backtrace` to file.

r? `@estebank` `@oli-obk`

Fixes #115610
2023-09-19 16:56:25 +00:00
bors
7e0261e7ea Auto merge of #115735 - bjorn3:better_list_crate_metadata, r=wesleywiser
Extend rustc -Zls

This makes it show a lot more things and thus a lot more useful.
2023-09-13 10:23:57 +00:00
bjorn3
ff00763dd1 Show lib features in -Zls and allow configuring which things are shown 2023-09-10 13:24:20 +00:00
bjorn3
2eca717a24 Remove EarlyErrorHandler argument from after_analysis callback
It is only used by miri which can create a new one using the Session.
2023-09-10 09:44:03 +00:00
bjorn3
0ed291453d Rename after_parsing callback to after_crate_root_parsing
To avoid confusion if it is called after all parsing is done or not.
2023-09-10 09:31:10 +00:00
Florian Schmiderer
4cdc633301 Add missing Debuginfo to PDB debug file on windows.
Set Arg0 and CommandLineArgs in MCTargetoptions so LLVM outputs correct CL and CMD in LF_DEBUGINFO instead of empty/invalid values.
2023-09-08 00:28:40 +02:00
Michael Goulet
b59480784d Make ICE backtrace actually match the panic handler 2023-09-07 05:33:36 +00:00
Michael Goulet
8ad2379407 Don't modify libstd to dump rustc ICEs 2023-09-07 04:16:06 +00:00
Matthias Krüger
dafea5f919
Rollup merge of #113565 - workingjubilee:better-signal-handler-message, r=pnkfelix
Make SIGSEGV handler emit nicer backtraces

This annotates the code heavily with comments to explain what is going on, for the benefit of other compiler contributors. The backtrace also emits appropriate comments to clarify, to a programmer who may not know why a bunch of file paths and hexadecimal blather was just dumped into stderr, what is going on. Finally, it detects cycles and uses their regularity to avoid repeating a bunch of text. The previous backtraces we were emitting was extremely unfriendly, potentially confusing, and often alarming, and this makes things almost "nice".

We can't necessarily make them much nicer than this, because a signal handler must use "signal-safe" functions. This precludes conveniences like dynamic allocations. Fortunately, Rust's stdlib has allocation-free formatting, but it may hinder integrating this error with our localization middleware, as I wasn't able to clearly ascertain, at a glance, whether there was a zero-alloc path through it.

r? `@Nilstrieb`
2023-08-30 07:18:10 +02:00
bors
84a9f4c6e6 Auto merge of #114114 - keith:ks/always-add-lc_build_version-for-metadata-object-files, r=wesleywiser
Always add LC_BUILD_VERSION for metadata object files

As of Xcode 15 Apple's linker has become a bit more strict about the warnings it produces. One of those new warnings requires all valid Mach-O object files in an archive to have a LC_BUILD_VERSION load command:

```
ld: warning: no platform load command found in 'ARCHIVE[arm64][2106](lib.rmeta)', assuming: iOS-simulator
```

This was already being done for Mac Catalyst so this change expands this logic to include it for all Apple platforms. I filed this behavior change as FB12546320 and was told it was the new intentional behavior.
2023-08-29 21:17:13 +00:00
Martin Nordholts
9f1de6171c Move extra_compiler_flags() to rustc_session
To make it available to other parts of the compiler.
2023-08-24 06:31:11 +02:00
Keith Smiley
d37fdc95d4
Always add LC_BUILD_VERSION for metadata object files
As of Xcode 15 Apple's linker has become a bit more strict about the
warnings it produces. One of those new warnings requires all valid
Mach-O object files in an archive to have a LC_BUILD_VERSION load
command:

```
ld: warning: no platform load command found in 'ARCHIVE[arm64][2106](lib.rmeta)', assuming: iOS-simulator
```

This was already being done for Mac Catalyst so this change expands this
logic to include it for all Apple platforms. I filed this behavior
change as FB12546320 and was told it was the new intentional behavior.
2023-08-21 13:31:57 -07:00
Vadim Petrochenkov
0b89aac08d rustc: Move crate_types from Session to GlobalCtxt
Removes a piece of mutable state.
Follow up to #114578.
2023-08-09 14:17:54 +08:00
Vadim Petrochenkov
b6ac576487 rustc_interface: Dismantle register_plugins query 2023-08-07 19:33:23 +08:00
bors
8236f63aba Auto merge of #114476 - Urgau:missing-dep-file-112898, r=oli-obk
Fix missing dependency file with `-Zunpretty`

This PR force the `output_filenames` to be run ~~in every early exits like~~ when using `-Zunpretty`, so to respect the `dep-info` flag.

Fixes https://github.com/rust-lang/rust/issues/112898
r? `@oli-obk`
2023-08-06 00:04:52 +00:00
Urgau
8229d8e251 Fix missing dependency file with -Zunpretty 2023-08-04 20:13:40 +02:00
Oli Scherer
29de70da1b Replace the many arguments of EmitterWriter::stderr with builder methods 2023-07-31 07:19:23 +00:00
Oli Scherer
2b444672e1 Use a builder instead of boolean/option arguments 2023-07-25 13:51:15 +00:00
Matthias Krüger
b1d1e99c22
Rollup merge of #113780 - dtolnay:printkindpath, r=b-naber
Support `--print KIND=PATH` command line syntax

As is already done for `--emit KIND=PATH` and `-L KIND=PATH`.

In the discussion of #110785, it was pointed out that `--print KIND=PATH` is nicer than trying to apply the single global `-o` path to `--print`'s output, because in general there can be multiple print requests within a single rustc invocation, and anyway `-o` would already be used for a different meaning in the case of `link-args` and `native-static-libs`.

I am interested in using `--print cfg=PATH` in Buck2. Currently Buck2 works around the lack of support for `--print KIND=PATH` by [indirecting through a Python wrapper script](d43cf3a51a/prelude/rust/tools/get_rustc_cfg.py) to redirect rustc's stdout into the location dictated by the build system.

From skimming Cargo's usages of `--print`, it definitely seems like it would benefit from `--print KIND=PATH` too. Currently it is working around the lack of this by inserting `--crate-name=___ --print=crate-name` so that it can look for a line containing `___` as a delimiter between the 2 other `--print` informations it actually cares about. This is commented as a "HACK" and "abuse". 31eda6f7c3/src/cargo/core/compiler/build_context/target_info.rs (L242) (FYI `@weihanglo` as you dealt with this recently in https://github.com/rust-lang/cargo/pull/11633.)

Mentioning reviewers active in #110785: `@fee1-dead` `@jyn514` `@bjorn3`
2023-07-21 06:52:28 +02:00
David Tolnay
11ae0afc93
Create separate match arms for FileNames and CrateNames
This introduces a bit of code duplication, but we don't have the
build_output_filenames in the CrateName arm and this seems a little
cleaner overall.
2023-07-20 11:04:32 -07:00
David Tolnay
c80cbe4bae
Implement printing to file in codegen_backend.print 2023-07-20 11:04:31 -07:00
David Tolnay
5a60660ff8
Implement printing to file in print_crate_info 2023-07-20 11:04:31 -07:00
David Tolnay
f2e3d3fc63
Move OutFileName writing into rustc_session 2023-07-20 11:04:31 -07:00
David Tolnay
c0dc0c6875
Store individual output file name with every PrintRequest 2023-07-20 11:04:30 -07:00
Esteban Küber
8eb5843a59 On nightly, dump ICE backtraces to disk
Implement rust-lang/compiler-team#578.

When an ICE is encountered on nightly releases, the new rustc panic
handler will also write the contents of the backtrace to disk. If any
`delay_span_bug`s are encountered, their backtrace is also added to the
file. The platform and rustc version will also be collected.
2023-07-19 14:10:07 +00:00
Jubilee
3dee9775a8 Clarify arbitrary constants
First, we reuse the `MAX_FRAMES` constant.

Co-authored-by: erikdesjardins <erikdesjardins@users.noreply.github.com>

Then we choose an arbitrary recursion depth for
the other case. In this case, I used 2d20. Honest.
2023-07-19 00:22:04 -07:00
Jubilee Young
1e65b5b741 Add recursion detection to signal-safe backtrace
This cleans up the formatting of the backtrace considerably,
dodging the fact that a backtrace with recursion normally
emits hundreds of lines. Instead, simply write repeated symbols,
and add how many times the recursion occurred.
Also, it makes it look more like the "normal" backtrace.

Some fine details in the code are important for reducing
the amount of possible panic branches.
2023-07-19 00:19:23 -07:00
Jubilee Young
4fa00c2507 Explain SIGSEGV backtrace handler
...to both compiler contributors and other rustc invokers.
The previous error messaging was extremely unfriendly,
and potentially both confusing and alarming.

The entire modules is extracted into a new file to help
ease of reading, and plenty of comments get layered in.
The design of the messaging is focused on preventing
the overall purpose of the output from being too opaque
in common cases, so users understand why it is there.
There's not an immediate need for it being actionable,
but some suggestions are offered anyways.
2023-07-19 00:15:00 -07:00
jyn
d52eb4f99a Don't require each rustc_interface tool to opt-in to parallel_rustc support
Previously, forgetting to call `interface::set_thread_safe_mode` would cause the following ICE:
```
thread 'rustc' panicked at 'uninitialized dyn_thread_safe mode!', /rustc/dfe0683138de0959b6ab6a039b54d9347f6a6355/compiler/rustc_data_structures/src/sync.rs:74:18
```

This calls `set_thread_safe_mode` in `interface::run_compiler` to avoid requiring it in the caller.

Fixes `tests/run-make-fulldeps/issue-19371` when parallel-compiler is enabled.
2023-07-11 22:55:23 -05:00
Jubilee Young
094cb1a9fb Dynamically size sigaltstk in rustc
rustc installs a signal stack that assumes that
MINSIGSTKSZ is a constant, unchanging value.
Newer hardware undermines that assumption greatly,
with register files larger than MINSIGSTKZ.
Properly handle this so that it is correct on
all supported Linux versions with all CPUs.
2023-07-10 12:05:16 -07:00
Trevor Gross
6a1c10bd85 Add a simple markdown parser for formatting rustc --explain
Currently, the output of `rustc --explain foo` displays the raw markdown in a
pager. This is acceptable, but using actual formatting makes it easier to
understand.

This patch consists of three major components:

1.  A markdown parser. This is an extremely simple non-backtracking recursive
    implementation that requires normalization of the final token stream
2.  A utility to write the token stream to an output buffer
3.  Configuration within rustc_driver_impl to invoke this combination for
    `--explain`. Like the current implementation, it first attempts to print to
    a pager with a fallback colorized terminal, and standard print as a last
    resort.

    If color is disabled, or if the output does not support it, or if printing
    with color fails, it will write the raw markdown (which matches current
    behavior).

    Pagers known to support color are: `less` (with `-r`), `bat` (aka `catbat`),
    and `delta`.

The markdown parser does not support the entire markdown specification, but
should support the following with reasonable accuracy:

-   Headings, including formatting
-   Comments
-   Code, inline and fenced block (no indented block)
-   Strong, emphasis, and strikethrough formatted text
-   Links, anchor, inline, and reference-style
-   Horizontal rules
-   Unordered and ordered list items, including formatting

This parser and writer should be reusable by other systems if ever needed.
2023-07-03 16:04:18 -04:00
许杰友 Jieyou Xu (Joe)
cef812bd95
Provide more context for rustc +nightly -Zunstable-options on stable 2023-06-27 23:23:33 +08:00
Michael Goulet
0710040648 Make sure to include default en-US ftl resources for rustc_error crate 2023-06-23 17:22:07 +00:00
Nicholas Nethercote
5dd7550a08 Avoid Lrc<Box<dyn CodegenBackend>>.
Because `Lrc<Box<T>>` is silly. (Clippy warns about `Rc<Box<T>>` and
`Arc<Box<T>>`, and it would warn here if (a) we used Clippy with rustc,
and (b) Clippy knew about `Lrc`.)
2023-06-22 09:18:09 +10:00