about summary refs log tree commit diff
path: root/compiler/rustc_driver_impl
AgeCommit message (Collapse)AuthorLines
2024-02-15Refactor out a repeating pattern with `get_or_default_sysroot`Maybe Waffle-6/+2
2024-02-14Allow targets to override default codegen backendMaybe Waffle-3/+16
2024-02-09Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwcoMatthias Krüger-2/+0
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-07Remove an `unchecked_claim_error_was_emitted` call.Nicholas Nethercote-7/+8
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-06Invert diagnostic lints.Nicholas Nethercote-2/+0
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-01-29Stop using `String` for error codes.Nicholas Nethercote-31/+28
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-25Remove unused featuresclubby789-2/+0
2024-01-15Replace `TrimmedDefPaths` with a bool.Nicholas Nethercote-2/+2
It's a tri-state enum but the `Always` variant is never used, so a bool is simpler.
2024-01-10Rename `{create,emit}_warning` as `{create,emit}_warn`.Nicholas Nethercote-1/+1
For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`, all of which use an abbreviated form.
2024-01-09Rollup merge of #118680 - djkoloski:shell_argfiles, r=compiler-errorsGuillaume Gomez-16/+92
Add support for shell argfiles Closes https://github.com/rust-lang/compiler-team/issues/684
2024-01-09Rollup merge of #119527 - klensy:ordering, r=compiler-errorsGuillaume Gomez-2/+1
don't reexport atomic::ordering via rustc_data_structures, use std import This looks simpler.
2024-01-08Add support for shell argfilesDavid Koloski-16/+92
2024-01-08Make `DiagnosticBuilder::emit` consuming.Nicholas Nethercote-1/+1
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-06don't reexport atomic::ordering via rustc_data_structures, use std importklensy-2/+1
2024-01-05Rollup merge of #119601 - nnethercote:Emitter-cleanups, r=oli-obkMichael Goulet-1/+1
`Emitter` cleanups Some improvements I found while looking at this code. r? `@oli-obk`
2024-01-05Rename `EmitterWriter` as `HumanEmitter`.Nicholas Nethercote-1/+1
For consistency with other `Emitter` impls, such as `JsonEmitter`, `SilentEmitter`, `SharedEmitter`, etc.
2023-12-28Use Result::flatten in catch_with_exit_codeDaniPopes-2/+2
2023-12-26Auto merge of #119129 - jyn514:verbose, r=compiler-errors,estebankbors-1/+1
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-24Remove more `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-1/+1
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-5/+7
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-23Rename `EarlyDiagCtxt` methods to match `DiagCtxt`.Nicholas Nethercote-13/+12
- `early_error_no_abort` -> `early_err` - `early_error` -> `early_fatal` - `early_struct_error` -> `early_struct_fatal`
2023-12-19rename to verbose-internalsjyn-1/+1
2023-12-18Rename many `DiagCtxt` and `EarlyDiagCtxt` locals.Nicholas Nethercote-32/+32
2023-12-18Rename many `EarlyDiagCtxt` arguments.Nicholas Nethercote-24/+24
2023-12-18Rename `EarlyErrorHandler` as `EarlyDiagCtxt`.Nicholas Nethercote-20/+16
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-4/+7
2023-12-12clippy::complexity fixesMatthias Krüger-3/+1
filter_map_identity needless_bool search_is_some unit_arg map_identity needless_question_mark derivable_impls
2023-12-11Extract exhaustiveness into its own crateNadrieril-0/+2
2023-12-05rustc_driver_impl: Address all `rustc::potential_query_instability` lintsMartin Nordholts-1/+0
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-01Auto merge of #118472 - nnethercote:rustc_session, r=bjorn3bors-1/+1
`rustc_session` cleanups r? `@bjorn3`
2023-11-30Move `MetadataLoader{,Dyn}` to `rustc_metadata`.Nicholas Nethercote-1/+1
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-26Turn write_dep_info into a regular functionbjorn3-6/+2
It has side-effects and as such can't be cached.
2023-11-26Mostly revert "Accept crate name instead of attributes in ↵bjorn3-1/+1
build_output_filenames"
2023-11-26Feed the output filenames into the TyCtxtbjorn3-4/+4
Since the introduction of the crate attribute pre-expansion pass we don't need access to the TyCtxt to compute it.
2023-11-26Serialize OutputFilenames into rmeta filebjorn3-3/+2
This ensures that linking will use the correct crate name even when `#![crate_name = "..."]` is used to specify the crate name.
2023-11-26Accept crate name instead of attributes in build_output_filenamesbjorn3-1/+1
2023-11-26Remove unnecessary dependencies.Nicholas Nethercote-1/+0
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-2/+1
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-26Avoid need for `{D,Subd}iagnosticMessage` imports.Nicholas Nethercote-1/+1
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-26Remove `rustc_error_messages/messages.ftl`.Nicholas Nethercote-1/+0
It's empty, and it doesn't even make sense, because `rustc_error_messages` is a lower-level crate than `rustc_errors`.
2023-11-22Merge `Queries::{ongoing_codegen,linker}`.Nicholas Nethercote-2/+1
There is no real need for them to be separate.
2023-11-22Make `Compiler::{sess,codegen_backend}` public.Nicholas Nethercote-3/+3
And remove the relevant getters on `Compiler` and `Queries`.
2023-11-22Add two useful comments.Nicholas Nethercote-0/+4
2023-11-18Auto merge of #118002 - nnethercote:unify-input-no-input, r=bjorn3bors-109/+80
Unify "input" and "no input" paths in `run_compiler` A follow-up to #117649. r? `@bjorn3`
2023-11-17Rollup merge of #117745 - ouz-a:emit_smir, r=celinvalMatthias Krüger-0/+7
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-18Simplify `run_compiler` control flow.Nicholas Nethercote-72/+54
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-18Factor out two `print_crate_info` calls.Nicholas Nethercote-2/+3
2023-11-18Move `describe_lints` calls.Nicholas Nethercote-9/+9
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-18Merge `interface::run_compiler` calls.Nicholas Nethercote-30/+18
`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-18Rename `early_error_handler` as `default_handler`.Nicholas Nethercote-9/+9
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()`.