Commit Graph

1138 Commits

Author SHA1 Message Date
Ralf Jung
50a9f008f2 CTFE Machine: do not expose Allocation 2021-05-19 16:37:57 +02:00
bors
3e827cc21e Auto merge of #85376 - RalfJung:ptrless-allocs, r=oli-obk
CTFE core engine allocation & memory API improvemenets

This is a first step towards https://github.com/rust-lang/miri/issues/841.
- make `Allocation` API offset-based (no more making up `Pointer`s just to access an `Allocation`)
- make `Memory` API higher-level (combine checking for access and getting access into one operation)

The Miri-side PR is at https://github.com/rust-lang/miri/pull/1804.
r? `@oli-obk`
2021-05-19 10:11:28 +00:00
Ralf Jung
d5ccf68a10 fix mplace_access_checked with forced alignment 2021-05-18 19:33:55 +02:00
Ralf Jung
563ab4a106 add Align::ONE; add methods to access alloc.extra 2021-05-18 19:33:55 +02:00
Ralf Jung
74995c4292 reduce number of allocation lookups during copy 2021-05-18 19:33:55 +02:00
Ralf Jung
46c2286395 CTFE core engine allocation & memory API improvemenets
- make Allocation API offset-based (no more Pointer)
- make Memory API higher-level (combine checking for access and getting access into one operation)
2021-05-18 19:33:55 +02:00
Joshua Nelson
18f6922d8c Address review comments
- Simplify boolean expression
- Give an example of invalid syntax
- Remove explanation of why code block is text
2021-05-17 21:31:05 -04:00
Alexis Bourget
b574c67b93 New rustdoc lint to respect -Dwarnings correctly
This adds a new lint to `rustc` that is used in rustdoc when a code
block is empty or cannot be parsed as valid Rust code.

Previously this was unconditionally a warning. As such some
documentation comments were (unknowingly) abusing this to pass despite
the `-Dwarnings` used when compiling `rustc`, this should not be the
case anymore.
2021-05-17 21:31:01 -04:00
Ralf Jung
a28be5cbe8
Rollup merge of #85412 - RalfJung:c_str, r=oli-obk
remove some functions that were only used by Miri

and Miri does not need them any more with https://github.com/rust-lang/miri/pull/1805.

r? ``@oli-obk``
2021-05-17 18:52:17 +02:00
Ralf Jung
af1ac55cbf
Rollup merge of #85408 - RalfJung:alloc-size, r=oli-obk
remove size field from Allocation

This is a part of https://github.com/rust-lang/rust/pull/85376 that can be easily split out.
r? ``@oli-obk``
2021-05-17 18:52:11 +02:00
Ralf Jung
b93753ee21
Rollup merge of #85087 - hyd-dev:lots-of-abis, r=RalfJung
`eval_fn_call`: check the ABI of `body.source`

And stop checking `instance_ty.fn_sig(*self.tcx).abi()`, if the function is not an intrinsic.
Addresses https://github.com/rust-lang/miri/pull/1776#discussion_r615381169.
No idea how to test this without Miri...
2021-05-17 18:51:59 +02:00
hyd-dev
97bc0eefe7
Add a comment for check_abi() 2021-05-17 20:54:31 +08:00
Ralf Jung
cb5533cff2 remove some functions that were only used by Miri 2021-05-17 14:43:16 +02:00
Ralf Jung
7962b5ae45 remove size field from Allocation 2021-05-17 13:30:16 +02:00
bors
44ec846f4e Auto merge of #85353 - jonas-schievink:async-blocks-in-ctfe, r=oli-obk
Allow `async {}` expressions in const contexts

Gated behind a new `const_async_blocks` feature.
2021-05-17 04:53:30 +00:00
bors
3396a383bb Auto merge of #85178 - cjgillot:local-crate, r=oli-obk
Remove CrateNum parameter for queries that only work on local crate

The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea.

Using `()` as query key in those cases avoids having to worry about the validity of the query key.
2021-05-17 01:42:03 +00:00
bors
3f46b82d29 Auto merge of #85332 - RalfJung:ptr-in-str, r=oli-obk
CTFE validation: handle pointers in str

I also finally learned how I can match *some* NOTEs in a ui test without matching all of them, and applied that to some const tests in the 2nd commit where I added NOTE because I did not know what I was doing. I can separate this into its own PR if you prefer.

Fixes https://github.com/rust-lang/rust/issues/83182
r? `@oli-obk`
2021-05-16 09:49:12 +00:00
Jonas Schievink
bd16825767 Allow async {} expressions in const contexts 2021-05-16 02:06:40 +02:00
Ralf Jung
a1507b80c2 handle pointers in str 2021-05-15 15:04:41 +02:00
Guillaume Gomez
cd3d166021
Rollup merge of #85278 - ayushmishra2005:code-refactoring, r=jackh726
Improve match statements
2021-05-15 13:29:55 +02:00
Guillaume Gomez
57aa0d812a
Rollup merge of #85246 - ayushmishra2005:minor-reactoring, r=petrochenkov
Miner code formatting
2021-05-15 13:29:51 +02:00
Guillaume Gomez
e611e64e3a
Rollup merge of #85215 - richkadel:ice-fixes-minus-dead-blocks, r=tmandry
coverage bug fixes and some refactoring

This replaces the relevant commits (2 and 3) from PR #85082, and also corrects an error querying for coverageinfo.

1. `coverageinfo` query needs to use the same MIR as codegen

I ran into an error trying to fix dead block coverage and realized the
`coverageinfo` query is getting a different MIR compared to the
codegenned MIR, which can sometimes be a problem during mapgen.

I changed that query to use the `InstandeDef` (which includes the
generic parameter substitutions, prosibly specific to const params)
instead of the `DefId` (without unknown/default const substitutions).

2. Simplified body_span and filtered span code

  Some code cleanup extracted from future (but unfinished) commit to fix
  coverage in attr macro functions.

3. Spanview needs the relevant body_span used for coverage

The coverage body_span doesn't always match the function body_span.

r? ```@tmandry```
2021-05-15 13:29:49 +02:00
ayushmishra2005
34055a932b Improve match statements 2021-05-14 08:57:33 +05:30
Amanieu d'Antras
40d9da4d8c global_asm! consts do not depend on other items 2021-05-13 22:31:58 +01:00
Amanieu d'Antras
5918ee4317 Add support for const operands and options to global_asm!
On x86, the default syntax is also switched to Intel to match asm!
2021-05-13 22:31:57 +01:00
ayushmishra2005
267450a814 removed compilation error 2021-05-13 10:34:41 +05:30
ayushmishra2005
0cee527869 Miner code formatting 2021-05-13 10:22:17 +05:30
Rich Kadel
aed8ef5a4d coverageinfo query needs to use the same MIR as codegen
I ran into an error trying to fix dead block coverage and realized the
`coverageinfo` query is getting a different MIR compared to the
codegenned MIR, which can sometimes be a problem during mapgen.

I changed that query to use the `InstandeDef` (which includes the
generic parameter substitutions, prosibly specific to const params)
instead of the `DefId` (without unknown/default const substitutions).
2021-05-12 20:27:07 -07:00
Rich Kadel
31f523ff94 Simplified body_span and filtered span code
Some code cleanup extracted from future (but unfinished) commit to fix
coverage in attr macro functions.
2021-05-12 20:12:42 -07:00
Rich Kadel
e354cca696 Spanview needs the relevant body_span used for coverage
The coverage body_span doesn't always match the function body_span.
2021-05-12 20:10:05 -07:00
Ralf Jung
2e8e91ce25 add check that simd_shuffle arguments are constants 2021-05-12 16:15:30 +02:00
Ralf Jung
44a8e8d745 entirely remove rustc_args_required_const attribute 2021-05-12 16:15:27 +02:00
Ralf Jung
22e1778ec0 rustc_args_required_const is no longer a promotion site 2021-05-12 16:14:57 +02:00
Camille GILLOT
0bde3b1f80 Use () for codegen queries. 2021-05-12 13:58:46 +02:00
Camille GILLOT
75f4f6ee4f Use () for mir_keys. 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
3a729915da Use () in reachable_set. 2021-05-12 13:58:42 +02:00
bors
e1ff91f439 Auto merge of #83813 - cbeuw:remap-std, r=michaelwoerister
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths

This PR fixes #73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped.

`RealFileName::Named` introduced in #72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path.

`RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure.

When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host".

`rustc_span::SourceFile`'s fields `unmapped_path` (introduced by #44940) and `name_was_remapped` (introduced by #41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`.

cc `@eddyb` who implemented `/rustc/...` path devirtualisation
2021-05-12 11:05:56 +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
Rich Kadel
bea112ba07 Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements, r=tmandry"
This reverts commit e5f83d24ae, reversing
changes made to ac888e8675.
2021-05-11 12:47:08 -07:00
bors
382f748f23 Auto merge of #85100 - HKalbasi:issue-68049-fix, r=Aaron1011
Fix invalid suggestion of changing impl trait signature

Fix #68049
2021-05-11 07:44:16 +00:00
hamidreza kalbasi
1f20966e90 Fix CI problems 2021-05-11 08:50:43 +04:30
Andy Wang
37dbe868c9
Split span_to_string into span_to_diagnostic/embeddable_string 2021-05-11 00:04:12 +01:00
hamidreza kalbasi
8f5585ac00 remove big match 2021-05-10 05:53:42 +04:30
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
hamidreza kalbasi
48f5f01e8b move logic to a function 2021-05-10 03:31:31 +04:30
hyd-dev
c6ae57cb83
Check the ABI of body.source 2021-05-09 13:39:38 +08: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
hamidreza kalbasi
efc8f65b85 Try to fix issue 68049 2021-05-09 05:26:59 +04:30
Mark Rousskov
0367e24f94 Avoid predecessors having Drop impls 2021-05-07 22:44:08 -04:00