Commit graph

1124 commits

Author SHA1 Message Date
Camille GILLOT
e9e1900af7 Use () for plugin_registrar_fn. 2021-05-12 13:58:43 +02:00
Camille GILLOT
829a9d33a9 Use () for entry_fn. 2021-05-12 13:58:42 +02:00
Camille GILLOT
601453a2ac Use () for HIR queries. 2021-05-12 13:58:42 +02:00
Camille GILLOT
3a729915da Use () in reachable_set. 2021-05-12 13:58:42 +02:00
Camille GILLOT
85a14d70bb Use () in dependency_formats. 2021-05-12 13:58:41 +02:00
bors
ac923d94f8 Auto merge of #83610 - bjorn3:driver_cleanup, r=cjgillot
rustc_driver cleanup

Best reviewed one commit at a time.
2021-05-12 08:38:03 +00:00
Aaron Hill
f916b0474a
Implement span quoting for proc-macros
This PR implements span quoting, allowing proc-macros to produce spans
pointing *into their own crate*. This is used by the unstable
`proc_macro::quote!` macro, allowing us to get error messages like this:

```
error[E0412]: cannot find type `MissingType` in this scope
  --> $DIR/auxiliary/span-from-proc-macro.rs:37:20
   |
LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream {
   | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]`
...
LL |             field: MissingType
   |                    ^^^^^^^^^^^ not found in this scope
   |
  ::: $DIR/span-from-proc-macro.rs:8:1
   |
LL | #[error_from_attribute]
   | ----------------------- in this macro invocation
```

Here, `MissingType` occurs inside the implementation of the proc-macro
`#[error_from_attribute]`. Previosuly, this would always result in a
span pointing at `#[error_from_attribute]`

This will make many proc-macro-related error message much more useful -
when a proc-macro generates code containing an error, users will get an
error message pointing directly at that code (within the macro
definition), instead of always getting a span pointing at the macro
invocation site.

This is implemented as follows:
* When a proc-macro crate is being *compiled*, it causes the `quote!`
  macro to get run. This saves all of the sapns in the input to `quote!`
  into the metadata of *the proc-macro-crate* (which we are currently
  compiling). The `quote!` macro then expands to a call to
  `proc_macro::Span::recover_proc_macro_span(id)`, where `id` is an
opaque identifier for the span in the crate metadata.
* When the same proc-macro crate is *run* (e.g. it is loaded from disk
  and invoked by some consumer crate), the call to
`proc_macro::Span::recover_proc_macro_span` causes us to load the span
from the proc-macro crate's metadata. The proc-macro then produces a
`TokenStream` containing a `Span` pointing into the proc-macro crate
itself.

The recursive nature of 'quote!' can be difficult to understand at
first. The file `src/test/ui/proc-macro/quote-debug.stdout` shows
the output of the `quote!` macro, which should make this eaier to
understand.

This PR also supports custom quoting spans in custom quote macros (e.g.
the `quote` crate). All span quoting goes through the
`proc_macro::quote_span` method, which can be called by a custom quote
macro to perform span quoting. An example of this usage is provided in
`src/test/ui/proc-macro/auxiliary/custom-quote.rs`

Custom quoting currently has a few limitations:

In order to quote a span, we need to generate a call to
`proc_macro::Span::recover_proc_macro_span`. However, proc-macros
support renaming the `proc_macro` crate, so we can't simply hardcode
this path. Previously, the `quote_span` method used the path
`crate::Span` - however, this only works when it is called by the
builtin `quote!` macro in the same crate. To support being called from
arbitrary crates, we need access to the name of the `proc_macro` crate
to generate a path. This PR adds an additional argument to `quote_span`
to specify the name of the `proc_macro` crate. Howver, this feels kind
of hacky, and we may want to change this before stabilizing anything
quote-related.

Additionally, using `quote_span` currently requires enabling the
`proc_macro_internals` feature. The builtin `quote!` macro
has an `#[allow_internal_unstable]` attribute, but this won't work for
custom quote implementations. This will likely require some additional
tricks to apply `allow_internal_unstable` to the span of
`proc_macro::Span::recover_proc_macro_span`.
2021-05-12 00:51:31 -04:00
Yuki Okushi
c4c654f422
Rollup merge of #85187 - FabianWolff:issue-84976, r=jackh726
Use .name_str() to format primitive types in error messages

This pull request fixes #84976. The problem described there is caused by this code
506e75cbf8/compiler/rustc_middle/src/ty/error.rs (L161-L166)
using `Debug` formatting (`{:?}`), while the proper solution is to call `name_str()` of `ty::IntTy`, `ty::UintTy` and `ty::FloatTy`, respectively.
2021-05-12 07:18:04 +09:00
Yuki Okushi
649b385471
Rollup merge of #85018 - hi-rustin:rustin-patch-84637, r=estebank
shrinking the deprecated method span

close https://github.com/rust-lang/rust/issues/84637
2021-05-12 07:18:00 +09:00
Fabian Wolff
f740923b8c Use .name_str() to format primitive types in error messages 2021-05-11 18:12:36 +02:00
b-naber
e4d9bc66f6 improve diagnosts for GATs 2021-05-11 14:09:46 +02:00
Yuki Okushi
5fc898782c
Rollup merge of #84777 - jyn514:rustdoc-parallel, r=Mark-Simulacrum
Apply `--cfg parallel_compiler` when documenting

This also reverts commit 9823c2cc70 working around the bug.

Fixes https://github.com/rust-lang/rust/issues/82301.
2021-05-11 09:28:03 +09:00
bors
d29289c509 Auto merge of #84507 - crlf0710:codegen_nonlocal_main_wrapper, r=nagisa
Add primary marker on codegen unit and generate main wrapper on primary codegen.

This is the codegen part of changes extracted from #84062.

This add a marker called `primary` on each codegen units, where exactly one codegen unit will be `primary = true` at a time. This specific codegen unit will take charge of generating `main` wrapper when `main` is imported from a foreign crate after the implementation of RFC 1260.

cc #28937

I'm not sure who should i ask for review for codegen changes, so feel free to reassign.
r? `@nagisa`
2021-05-10 00:42:31 +00:00
bors
ca82264ec7 Auto merge of #85065 - Mark-Simulacrum:preds-no-alloc, r=jackh726
Avoid predecessors having Drop impls

Should be a simple win - but let's make sure with perf.
2021-05-09 19:01:05 +00:00
Charles Lew
89a67051a7 Add primary marker on codegen unit to take charge of main_wrapper for non-local cases. 2021-05-09 10:52:03 +08:00
Mark Rousskov
0367e24f94 Avoid predecessors having Drop impls 2021-05-07 22:44:08 -04:00
hi-rustin
7c5bc204fa Address comments 2021-05-08 09:02:22 +08:00
bors
abf3ec5b33 Auto merge of #85057 - Dylan-DPC:rollup-efaseq2, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #76808 (Improve diagnostics for functions in `struct` definitions)
 - #84887 (Remove SpanInterner::get)
 - #85034 (fix null pointer error messages)
 - #85038 (Don't stop running rustdoc-gui tests at first failure)
 - #85044 (Use `path.exists()` instead of `fs::metadata(path).is_ok()`)
 - #85052 (rustdoc: Link to the docs on namespaces when an unknown disambiguator is found)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-05-08 00:37:38 +00:00
Camille GILLOT
1891da0378 Hash attributes as part of the crate hash. 2021-05-07 21:42:42 +02:00
Ralf Jung
4dddc3818e fix null pointer error messages 2021-05-07 15:13:23 +02:00
Yuki Okushi
47050275f4
Rollup merge of #84972 - RalfJung:null-ptr-msg, r=oli-obk
CTFE inbounds-error-messages tweak

* use CheckInAllocMsg::PointerArithmeticTest for ptr_offset error
* nicer errors for some null pointer cases

r? `@oli-obk`
2021-05-07 15:20:29 +09:00
hi-rustin
f6dd332820 shrinking the deprecated method span 2021-05-07 10:41:04 +08:00
Ralf Jung
abdba81d03 use CheckInAllocMsg::PointerArithmeticTest for ptr_offset error 2021-05-06 10:39:35 +02:00
Luqman Aden
db555e1284 Implement RFC 2951: Native link modifiers
This commit implements both the native linking modifiers infrastructure
as well as an initial attempt at the individual modifiers from the RFC.
It also introduces a feature flag for the general syntax along with
individual feature flags for each modifier.
2021-05-05 16:04:25 -07:00
Ralf Jung
2c7bf41b97
Rollup merge of #84903 - hyd-dev:dead-check-in-alloc-msg, r=RalfJung
Remove `rustc_middle::mir::interpret::CheckInAllocMsg::NullPointerTest`

Removing it per https://github.com/rust-lang/rust/pull/84842#discussion_r625589674: it's a dead enum variant.

Note that `PointerArithmeticTest` also seems dead:
```
$ rg -F PointerArithmeticTest -C5
compiler/rustc_middle/src/mir/interpret/error.rs
169-
170-/// Details of why a pointer had to be in-bounds.
171-#[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
172-pub enum CheckInAllocMsg {
173-    MemoryAccessTest,
174:    PointerArithmeticTest,
175-    InboundsTest,
176-}
177-
178-impl fmt::Display for CheckInAllocMsg {
179-    /// When this is printed as an error the context looks like this
--
182-        write!(
183-            f,
184-            "{}",
185-            match *self {
186-                CheckInAllocMsg::MemoryAccessTest => "memory access",
187:                CheckInAllocMsg::PointerArithmeticTest => "pointer arithmetic",
188-                CheckInAllocMsg::InboundsTest => "inbounds test",
189-            }
190-        )
191-    }
192-}
```
Not sure if that is also desirable to be removed, however.
2021-05-05 17:52:28 +02:00
hyd-dev
ee7a6c6acc
Remove rustc_middle::mir::interpret::CheckInAllocMsg::NullPointerTest 2021-05-04 18:27:02 +08:00
bors
7a0f1781d0 Auto merge of #83213 - rylev:update-lints-to-errors, r=nikomatsakis
Update BARE_TRAIT_OBJECT and ELLIPSIS_INCLUSIVE_RANGE_PATTERNS to errors in Rust 2021

This addresses https://github.com/rust-lang/rust/pull/81244 by updating two lints to errors in the Rust 2021 edition.

r? `@estebank`
2021-05-04 08:09:23 +00:00
bors
0309953232 Auto merge of #84833 - Mark-Simulacrum:thread-local-consts, r=varkor
"const" initialized thread locals in rustc

This appears to give a slight speedup on many of our benchmarks.
2021-05-04 03:14:32 +00:00
bors
14f863c443 Auto merge of #84472 - Aaron1011:conservative-paramenv-and, r=lcnr
Be more conservative about discarding caller_bound in `ParamEnv::and`
2021-05-04 00:48:42 +00:00
Brent Kerby
6679f5ceb1 Change 'NULL' to 'null' 2021-05-02 17:46:00 -06:00
Mark Rousskov
5065144d6d Use new thread-local const-init
Let's see if this gives us any speedup - some of the TLS state modified in this
commit *is* pretty heavily accessed, so we can hope!
2021-05-02 14:06:07 -04:00
bjorn3
4a6cfc6788 Don't arena allocate Definitions 2021-05-02 18:00:20 +02:00
bjorn3
0447f91e10 Let load_query_result_cache take a &DefPathTable
This allows removing a confusing mem::replace in create_global_ctxt
2021-05-02 18:00:20 +02:00
Dylan DPC
4198d0a87c
Rollup merge of #84392 - dario23:fmt-assert-args-pub, r=varkor,RalfJung
Make AssertKind::fmt_assert_args public
2021-05-02 17:00:22 +02:00
Chris Pardy
d19c46870f add docstrings and add issue to FIXMEs 2021-05-01 19:01:06 -04:00
Chris Pardy
08c4fbcea7 Closure capture borrow diagnostics for disjoint captures 2021-05-01 19:01:05 -04:00
Aaron Hill
91daf705b4
Make TypeFoldable::is_global() false when fresh tys/consts are present
This ensures that `ParamEnv::and` preserves the original `caller_bounds`
when we have a value containing fresh tys/consts. This ensures that when
we cache a `SelectionCandidate`, the cache key (a `ParamEnvAnd`)
contains all of the information that influenced the computation of our
result (e.g. we may end up choosing a `ParamCandidate`)
2021-05-01 16:58:33 -04:00
bors
6e2a34474b Auto merge of #83114 - cjgillot:hop, r=eddyb
Move HIR parenting information out of hir_owner

Split out of #82681.

The parent of a HIR node and its content are currently bundled together, but are rarely used together.
This PR separates both information in two distinct queries for HIR owners.
This reduces incremental invalidation for HIR items that appear within a function body when this body (and the local ids) changes.
2021-05-01 18:03:25 +00:00
Joshua Nelson
1da4445109 Apply --cfg parallel_compiler when documenting
This also reverts commit 9823c2cc70
working around the bug.
2021-05-01 00:25:11 -04:00
bors
8a9fa3682d Auto merge of #84719 - Mark-Simulacrum:reduce-query-impl, r=davidtwco
Move iter_results to dyn FnMut rather than a generic

This means that we're no longer generating the iteration/locking code for each invocation site of iter_results, rather just once per query (roughly), which seems much better: this is a 15% win in instruction counts when compiling the rustc_query_impl crate. The code where this is used also is pretty cold, I suspect; the old solution didn't fully monomorphize either.
2021-04-30 22:21:07 +00:00
bors
bcd696d722 Auto merge of #84401 - crlf0710:impl_main_by_path, r=petrochenkov
Implement RFC 1260 with feature_name `imported_main`.

This is the second extraction part of #84062 plus additional adjustments.
This (mostly) implements RFC 1260.

However there's still one test case failure in the extern crate case. Maybe `LocalDefId` doesn't work here? I'm not sure.

cc https://github.com/rust-lang/rust/issues/28937
r? `@petrochenkov`
2021-04-30 06:59:37 +00:00
Jack Huey
26a4f461d7
Rollup merge of #84682 - jackh726:transitive_bounds_rebind, r=nikomatsakis
Don't rebind in `transitive_bounds_that_define_assoc_type`

Fixes #83737
Fixes #84604

Also fixes another issue that I don't have a test for, popped up in [zulip](https://rust-lang.zulipchat.com/#narrow/stream/144729-wg-traits/topic/Duplicate.20symbol.20error.20.2384604/near/236570445)

r? `````@nikomatsakis`````
2021-04-29 19:27:22 -04:00
Mark Rousskov
a1d7367429 Move iter_results to dyn FnMut rather than a generic
This means that we're no longer generating the iteration/locking code for each
invocation site of iter_results, rather just once per query.

This is a 15% win in instruction counts when compiling the rustc_query_impl crate.
2021-04-29 17:26:46 -04:00
Camille GILLOT
d794cb0d4f Introduce a hir_owner_parent query. 2021-04-29 21:36:56 +02:00
Camille GILLOT
18bffdb10e Move parenting info to index_hir. 2021-04-29 21:36:55 +02:00
Camille GILLOT
99d3798b6c Do not compute entry parent when not required. 2021-04-29 21:36:55 +02:00
Camille GILLOT
2d341e1e28 Remove parent_node. 2021-04-29 21:36:55 +02:00
Camille GILLOT
323f5b2ac9 Split crate_hash from index_hir. 2021-04-29 21:36:48 +02:00
bors
814a560072 Auto merge of #84233 - jyn514:track-path-prefix, r=michaelwoerister
Add TRACKED_NO_CRATE_HASH and use it for `--remap-path-prefix`

I verified locally that this fixes https://github.com/rust-lang/rust/issues/66955.

r? `@Aaron1011` (feel free to reassign)
2021-04-29 14:57:17 +00:00
Charles Lew
d261df4a72 Implement RFC 1260 with feature_name imported_main. 2021-04-29 08:35:08 +08:00