about summary refs log tree commit diff
path: root/compiler/rustc_interface/src/interface.rs
AgeCommit message (Collapse)AuthorLines
2023-03-31Improve `with_source_map`.Nicholas Nethercote-1/+1
Rename `with_source_map` as `set_source_map`. Because `with` functions (e.g. `with_session_globals`, `scoped_tls::ScopedKey::with`) are for *getting* a value for the duration of a closure, and `set` functions (e.g. `set_session_globals_then` `scoped_tls::ScopedKey::with`) are for *setting* a value for the duration of a closure. Also fix up the comment, which is wrong: - The bit about `TyCtxt` is wrong. - `span_debug1` doesn't exist any more. - There's only one level of fallback, not two. (This is effectively a follow-up to the changes in #93936.) Also add a comment explaining that `SessionGlobals::source_map` should only be used when absolutely necessary.
2023-02-22errors: generate typed identifiers in each crateDavid Wood-0/+2
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-14Remove BoxedResolverOli Scherer-1/+0
2023-01-16Move compiler input and ouput paths into sessionOli Scherer-22/+10
2023-01-16Group some commonly passed together values into a structOli Scherer-27/+17
2023-01-16Remove redundant `input_path` field from `Config`Oli Scherer-4/+1
2023-01-05Fix `uninlined_format_args` for some compiler cratesnils-4/+2
Convert all the crates that have had their diagnostic migration completed (except save_analysis because that will be deleted soon and apfloat because of the licensing problem).
2022-11-28Rename `NestedMetaItem::[Ll]iteral` as `NestedMetaItem::[Ll]it`.Nicholas Nethercote-1/+1
We already use a mix of `Literal` and `Lit`. The latter is better because it is shorter without causing any ambiguity.
2022-11-16Use `as_deref` in compiler (but only where it makes sense)Maybe Waffle-1/+1
2022-10-19Add a comment to `Compiler`.Nicholas Nethercote-1/+4
It took me a while to work this out.
2022-10-19Apply `Lrc` later to `sess` and `codegen_backend`.Nicholas Nethercote-7/+3
This avoids the need for a degenerate `Lrc::get_mut` call.
2022-10-19Inline and remove `create_compiler_and_run`.Nicholas Nethercote-53/+51
It has a single call site.
2022-10-19Reduce visibility of some functions.Nicholas Nethercote-1/+1
2022-10-18Remove `RunCompiler::emitter`.Nicholas Nethercote-3/+1
It's no longer used.
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-1/+1
by module
2022-08-31Fix a bunch of typoDezhi Wu-2/+2
This PR will fix some typos detected by [typos]. I only picked the ones I was sure were spelling errors to fix, mostly in the comments. [typos]: https://github.com/crate-ci/typos
2022-08-12Adjust cfgsMark Rousskov-1/+1
2022-07-27lint: add bad opt access internal lintDavid Wood-0/+2
Some command-line options accessible through `sess.opts` are best accessed through wrapper functions on `Session`, `TyCtxt` or otherwise, rather than through field access on the option struct in the `Session`. Adds a new lint which triggers on those options that should be accessed through a wrapper function so that this is prohibited. Options are annotated with a new attribute `rustc_lint_opt_deny_field_access` which can specify the error message (i.e. "use this other function instead") to be emitted. A simpler alternative would be to simply rename the options in the option type so that it is clear they should not be used, however this doesn't prevent uses, just discourages them. Another alternative would be to make the option fields private, and adding accessor functions on the option types, however the wrapper functions sometimes rely on additional state from `Session` or `TyCtxt` which wouldn't be available in an function on the option type, so the accessor would simply make the field available and its use would be discouraged too. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-13Rename `debugging_opts` to `unstable_opts`Joshua Nelson-2/+2
This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`). Rename it to be more clear.
2022-03-03Add support for values() with --check-cfgLoïc BRANSTETT-0/+3
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-2/+2
2022-02-25Auto merge of #93368 - eddyb:diagbld-guarantee, r=estebankbors-4/+4
rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission". That is, `DiagnosticBuilder` is now generic over the return type of `.emit()`, so we'll now have: * `DiagnosticBuilder<ErrorReported>` for error (incl. fatal/bug) diagnostics * can only be created via a `const L: Level`-generic constructor, that limits allowed variants via a `where` clause, so not even `rustc_errors` can accidentally bypass this limitation * asserts `diagnostic.is_error()` on emission, just in case the construction restriction was bypassed (e.g. by replacing the whole `Diagnostic` inside `DiagnosticBuilder`) * `.emit()` returns `ErrorReported`, as a "proof" token that `.emit()` was called (though note that this isn't a real guarantee until after completing the work on #69426) * `DiagnosticBuilder<()>` for everything else (warnings, notes, etc.) * can also be obtained from other `DiagnosticBuilder`s by calling `.forget_guarantee()` This PR is a companion to other ongoing work, namely: * #69426 and it's ongoing implementation: #93222 the API changes in this PR are needed to get statically-checked "only errors produce `ErrorReported` from `.emit()`", but doesn't itself provide any really strong guarantees without those other `ErrorReported` changes * #93244 would make the choices of API changes (esp. naming) in this PR fit better overall In order to be able to let `.emit()` return anything trustable, several changes had to be made: * `Diagnostic`'s `level` field is now private to `rustc_errors`, to disallow arbitrary "downgrade"s from "some kind of error" to "warning" (or anything else that doesn't cause compilation to fail) * it's still possible to replace the whole `Diagnostic` inside the `DiagnosticBuilder`, sadly, that's harder to fix, but it's unlikely enough that we can paper over it with asserts on `.emit()` * `.cancel()` now consumes `DiagnosticBuilder`, preventing `.emit()` calls on a cancelled diagnostic * it's also now done internally, through `DiagnosticBuilder`-private state, instead of having a `Level::Cancelled` variant that can be read (or worse, written) by the user * this removes a hazard of calling `.cancel()` on an error then continuing to attach details to it, and even expect to be able to `.emit()` it * warnings were switched to *only* `can_emit_warnings` on emission (instead of pre-cancelling early) * `struct_dummy` was removed (as it relied on a pre-`Cancelled` `Diagnostic`) * since `.emit()` doesn't consume the `DiagnosticBuilder` <sub>(I tried and gave up, it's much more work than this PR)</sub>, we have to make `.emit()` idempotent wrt the guarantees it returns * thankfully, `err.emit(); err.emit();` can return `ErrorReported` both times, as the second `.emit()` call has no side-effects *only* because the first one did do the appropriate emission * `&mut Diagnostic` is now used in a lot of function signatures, which used to take `&mut DiagnosticBuilder` (in the interest of not having to make those functions generic) * the APIs were already mostly identical, allowing for low-effort porting to this new setup * only some of the suggestion methods needed some rework, to have the extra `DiagnosticBuilder` functionality on the `Diagnostic` methods themselves (that change is also present in #93259) * `.emit()`/`.cancel()` aren't available, but IMO calling them from an "error decorator/annotator" function isn't a good practice, and can lead to strange behavior (from the caller's perspective) * `.downgrade_to_delayed_bug()` was added, letting you convert any `.is_error()` diagnostic into a `delay_span_bug` one (which works because in both cases the guarantees available are the same) This PR should ideally be reviewed commit-by-commit, since there is a lot of fallout in each. r? `@estebank` cc `@Manishearth` `@nikomatsakis` `@mark-i-m`
2022-02-23Continue improvements on the --check-cfg implementationLoïc BRANSTETT-9/+5
- Test the combinations of --check-cfg with partial values() and --cfg - Test that we detect unexpected value when none are expected
2022-02-23rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.Eduard-Mihai Burtescu-4/+4
2022-02-22Improve CheckCfg internal representationLoïc BRANSTETT-6/+16
2022-02-18Rollup merge of #93915 - Urgau:rfc-3013, r=petrochenkovMatthias Krüger-2/+89
Implement --check-cfg option (RFC 3013), take 2 This pull-request implement RFC 3013: Checking conditional compilation at compile time (https://github.com/rust-lang/rfcs/pull/3013) and is based on the previous attempt https://github.com/rust-lang/rust/pull/89346 by `@mwkmwkmwk` that was closed due to inactivity. I have address all the review comments from the previous attempt and added some more tests. cc https://github.com/rust-lang/rust/issues/82450 r? `@petrochenkov`
2022-02-16Implement --check-cfg option (RFC 3013)Loïc BRANSTETT-2/+89
Co-authored-by: Urgau <lolo.branstett@numericable.fr> Co-authored-by: Marcelina Kościelnicka <mwk@0x04.net>
2022-02-13Remove Config::stderrbjorn3-7/+1
1. It captured stdout and not stderr 2. It isn't used anywhere 3. All error messages should go to the DiagnosticOutput instead 4. It modifies thread local state
2022-02-12Move setup_callbacks call to create_compiler_and_runbjorn3-1/+3
This ensures that it is called even when run_in_thread_pool_with_globals is avoided and reduces code duplication between the parallel and non-parallel version of run_in_thread_pool_with_globals
2022-02-03clippy::perf fixesMatthias Krüger-1/+1
single_char_pattern and to_string_in_format_args
2022-01-16Limit scope of the hint about escaping.Ivor Wanders-4/+10
2022-01-12Improve error message for cfg arguments.Ivor Wanders-1/+4
This provides the user with a helpful error message in case a key="value" message was specified but couldn't be parsed.
2022-01-01Emit an error for `--cfg=)`Jakub Kądziołka-19/+19
Fixes #73026 See also: #64467, #89468 The issue stems from a `FatalError` being silently raised in `panictry_buffer`. Normally this is not a problem, because `panictry_buffer` emits the causes of the error, but they are not themselves fatal, so they get filtered out by the silent emitter. To fix this, we use a parser entrypoint which doesn't use `panictry_buffer`, and we handle the error ourselves.
2021-11-07Made temps-dir an unstable option.Tor Hovland-2/+3
2021-11-02Added the --temps-dir option.Tor Hovland-1/+14
2021-10-25Avoid a branch on key being local for queries that use the same local and ↵bjorn3-2/+2
extern providers
2021-10-23Rollup merge of #89468 - FabianWolff:issue-89358, r=jackh726Matthias Krüger-1/+4
Report fatal lexer errors in `--cfg` command line arguments Fixes #89358. The erroneous behavior was apparently introduced by `@Mark-Simulacrum` in https://github.com/rust-lang/rust/commit/a678e3191197f145451c97c6cc884e15cae38186; the idea is to silence individual parser errors and instead emit one catch-all error message after parsing. However, for the example in #89358, a fatal lexer error is created here: https://github.com/rust-lang/rust/blob/edebf77e0090195bf80c0d8cda821e1bf9d03053/compiler/rustc_parse/src/lexer/mod.rs#L340-L349 This fatal error aborts the compilation, and so the call to `new_parser_from_source_str()` never returns and the catch-all error message is never emitted. I have therefore changed the `SilentEmitter` to silence only non-fatal errors; with my changes, for the rustc invocation described in #89358: ```sh rustc --cfg "abc\"" ``` I get the following output: ``` error[E0765]: unterminated double quote string | = note: this error occurred on the command line: `--cfg=abc"` ```
2021-10-02Report fatal lexer errors in `--cfg` command line argumentsFabian Wolff-1/+4
2021-10-01Fix clippy lintsGuillaume Gomez-7/+1
2021-07-18Move OnDiskCache to rustc_query_impl.Camille GILLOT-1/+2
2021-07-08Rework SESSION_GLOBALS API to prevent overwriting itGuillaume Gomez-1/+1
2021-03-15Change the `.unwrap` to `.expect` with a helpful messagehyd-dev-1/+5
2021-03-15Add `rustc_interface::interface::Config::parse_sess_created`hyd-dev-1/+8
2021-02-19Move try_print_query_stack to rustc_interface.Camille GILLOT-1/+22
2020-12-22Add some intra-doc links to compiler docsJoshua Nelson-1/+2
2020-12-01Fix `unknown-crate` when using self-profile with rustdocJoshua Nelson-3/+0
... by removing a duplicate `crate_name` field in `interface::Config`, making it clear that rustdoc should be passing it to `config::Options` instead.
2020-11-24Add method to get the register_lints function from the compilerflip1995-0/+3
2020-09-27Add option to pass a custom codegen backend from a driverbjorn3-0/+5
2020-08-30mv compiler to compiler/mark-0/+209