Commit Graph

3628 Commits

Author SHA1 Message Date
Mazdak Farrokhzad
0f68ab03c3 separate out an arena for HIR 2020-03-21 22:18:57 +01:00
Dylan DPC
f1ab750083
Rollup merge of #70119 - eddyb:typeck-tables-local-def-id, r=petrochenkov
rustc: use LocalDefId instead of DefId in TypeckTables.

The logic in `TypeckTables`' implementation of `HashStable`, which created `DefId`s by combining a `CrateNum` from a `DefId` and a `DefIndex` from a `LocalDefId`, bothered me a bit.

I don't know how much this matters, but it works so might as well submit it.
2020-03-21 13:06:42 +01:00
Dylan DPC
8deeac153f
Rollup merge of #69910 - cjgillot:polym, r=Zoxc
Avoid query type in generics

There are at the moment roughly 170 queries in librustc.
The way ty::query is structured, a lot of code is duplicated for each query.
I suspect this to be responsible for a part of librustc'c compile time.

This PR reduces the amount of code generic on the query,
replacing it by code generic on the key-value types.

This is split out of #69808,
and should not contain the perf regression.

cc #65031
2020-03-21 13:06:36 +01:00
Mazdak Farrokhzad
569272ac05
Rollup merge of #70092 - eddyb:hir-items-are-just-nodes, r=Zoxc
hir: replace "items" terminology with "nodes" where appropriate.

The newly added `HirOwnerItems` confused me before I realized that "items" there actually referred to HIR nodes, not `hir:Item` or "item-like" (which we should IMO replace with "owner").

I suspect the naming had something to do with `ItemLocalId`'s use of "item".
That is, `ItemLocalId` could be interpreted to mean one of two things:
* `IntraItemNodeId` i.e. `IntraOwnerNodeId`
  * this is IMO correct, and I'd even like to rename it, but I didn't want to throw that into this PR
* `IntraOwnerItemId`
  * this is what `HirOwnerItems` would seem to imply

r? @Zoxc cc @michaelwoerister @nikomatsakis
2020-03-21 08:51:19 +01:00
Mazdak Farrokhzad
a6d0c35e86
Rollup merge of #70089 - eddyb:closure-sig-infer, r=nikomatsakis
rustc_infer: remove InferCtxt::closure_sig as the FnSig is always shallowly known.

That is, `ClosureSubsts` is always created (in `rustc_typeck::check::closure`) with a `FnSig`, as the number of inputs is known, even if they might all have inference types.
The only useful thing `InferCtxt::closure_sig` was doing is resolving an inference variable used just to get the `ty::FnPtr` containing that `FnSig` into `ClosureSubsts`.

The ideal way to solve this would be to add a constructor for `ClosureSubsts`, that combines the parent `Substs`, the closure kind, the signature, and capture types together, but for now I've went with resolving the inference types just after unifying them with the real types.

r? @nikomatsakis
2020-03-21 08:51:18 +01:00
Mazdak Farrokhzad
0b99489a89
Rollup merge of #69965 - mark-i-m:codegen-utils, r=eddyb
Refactorings to get rid of rustc_codegen_utils

r? @eddyb

cc #45276

After this, the only modules left in `rustc_codegen_utils` are
- `link`: a bunch of linking-related functions (many dealing with file names). These are mostly consumed by save analysis, rustc_driver, rustc_interface, and of course codegen. I assume they live here because we don't want a dependency of save analysis on codegen... Perhaps they can be moved to librustc?
- ~`symbol_names` and `symbol_names_test`: honestly it seems odd that `symbol_names_test` is not a submodule of `symbol_names`. It seems like these could honestly live in their own crate or move to librustc. Already name mangling is exported as the `symbol_name` query.~ (move it to its own crate)

I don't mind doing either of the above as part of this PR or a followup if you want.
2020-03-21 08:51:14 +01:00
Mazdak Farrokhzad
9adfb18def
Rollup merge of #67888 - Zoxc:metadata-prefetch, r=matthewjasper
Prefetch some queries used by the metadata encoder

This brings the time for `metadata encoding and writing` for `syntex_syntax` from 1.338s to 0.997s with 6 threads in non-incremental debug mode.

r? @Mark-Simulacrum
2020-03-21 08:51:10 +01:00
Matthias Krüger
ad00e91887 remove redundant returns (clippy::needless_return) 2020-03-20 20:23:03 +01:00
Yuki Okushi
9dc699430f
Rollup merge of #69935 - davidtwco:issue-69925, r=eddyb
codegen/mir: support polymorphic `InstanceDef`s

cc #69925

This PR modifies the use of `subst_and_normalize_erasing_regions` on parts of the MIR bodies returned from `instance_mir`, so that `InstanceDef::CloneShim` and `InstanceDef::DropGlue` (where there is a type) do not perform substitutions. This avoids double substitutions and enables polymorphic `InstanceDef`s.

r? @eddyb
cc @nikomatsakis
2020-03-20 17:02:05 +09:00
Yuki Okushi
3554f2d941
Rollup merge of #69768 - oli-obk:union_field_ice, r=eddyb,RalfJung
Compute the correct layout for variants of uninhabited enums

r? @eddyb
cc @RalfJung

fixes #69191
cc #69763
2020-03-20 17:02:03 +09:00
Mark Mansi
2d75a339ca Refactorings to begin getting rid of rustc_codegen_utils 2020-03-19 23:14:46 -05:00
John Kåre Alsaker
3d59c0ee38 Make the timer more verbose 2020-03-19 15:12:31 +01:00
Eduard-Mihai Burtescu
e8f1dfae64 hir: replace "items" terminology with "nodes" where appropriate. 2020-03-19 14:36:04 +02:00
Eduard-Mihai Burtescu
f8178c7a23 rustc: use LocalDefId instead of DefId in TypeckTables. 2020-03-19 14:25:50 +02:00
Eduard-Mihai Burtescu
16e25f0ea3 rustc: use LocalDefId instead of DefIndex in hir::map::definitions. 2020-03-19 11:16:08 +02:00
Eduard-Mihai Burtescu
f3ec069886 rustc: use LocalDefId instead of DefIndex in HirId. 2020-03-19 11:16:08 +02:00
Eduard-Mihai Burtescu
42b2adfab0 rustc: introduce DefId::as_local(self) -> Option<LocalDefId> and use it. 2020-03-19 11:15:35 +02:00
Eduard-Mihai Burtescu
0c692797d7 rustc: rename DefId::to_local to expect_local and use it instead of LocalDefId::from_def_id. 2020-03-19 11:15:35 +02:00
Eduard-Mihai Burtescu
55ed19fe1b rustc: make LocalDefId's index field public like DefId's is. 2020-03-19 11:15:35 +02:00
Eduard-Mihai Burtescu
e11dd47503 rustc: use LocalDefId instead of DefIndex for query keys. 2020-03-19 11:15:35 +02:00
Mazdak Farrokhzad
ffb3c2cb3d
Rollup merge of #69036 - eddyb:monoshim, r=nikomatsakis
rustc: don't resolve Instances which would produce malformed shims.

There are some `InstanceDef` variants (shims and drop "glue") which contain a `Ty`, and that `Ty` is used in generating the shim MIR. But if that `Ty` mentions any generic parameters, the generated shim would refer to them (but they won't match the `Substs` of the `Instance`), or worse, generating the shim would fail because not enough of the type is known.

Ideally we would always produce a "skeleton" of the type, e.g. `(_, _)` for dropping any tuples with two elements, or `Vec<_>` for dropping any `Vec` value, but that's a lot of work, and they would still not match the `Substs` of the `Instance` as it exists today, so `Instance` would probably need to change.

By making `Instance::resolve` return `None` in the still-generic cases, we get behavior similar to specialization, where a default can only be used if there are no more generic parameters which would allow a more specialized `impl` to match.

<hr/>

This was found while testing the MIR inliner with #68965, because it was trying to inline shims.

cc @rust-lang/wg-mir-opt
2020-03-19 06:57:28 +01:00
Mazdak Farrokhzad
292c538265
Rollup merge of #69920 - Centril:hir-cleanup, r=Zoxc
Remove some imports to the rustc crate

- When we have `NestedVisitorMap::None`, we use `type Map = dyn intravisit::Map<'v>;` instead of the actual map. This doesn't actually result in dynamic dispatch (in the future we may want to use an associated type default to simplify the code).

- Use `rustc_session::` imports instead of `rustc::{session, lint}`.

r? @Zoxc
2020-03-18 18:03:44 +01:00
Mazdak Farrokhzad
252184969b
Rollup merge of #69899 - ecstatic-morse:const-idx-methods, r=oli-obk
Make methods declared by `newtype_index` macro `const`

Crates that use the macro to define an `Idx` type need to enable `#![feature(const_if_match, const_panic)]`.
2020-03-18 18:03:42 +01:00
Mazdak Farrokhzad
4118ff61ec
Rollup merge of #69837 - jonas-schievink:gen-discr-opt, r=tmandry
Use smaller discriminants for generators

Closes https://github.com/rust-lang/rust/issues/69815

I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on)

* [x] Add test with a generator that has exactly 256 total states
* [x] Add test with a generator that has more than 256 states so that it needs to use a u16 discriminant
* [x] Add tests for the size of `Option<[generator]>`
* [x] Add tests for the `discriminant_value` intrinsic in all cases
2020-03-18 18:03:37 +01:00
Mazdak Farrokhzad
3f583fc270
Rollup merge of #69189 - matthewjasper:erase-the-world, r=nikomatsakis
Erase regions in writeback

Regions in `TypeckTables` (except canonicalized user annotations) are now erased. Further, we no longer do lexical region solving on item bodies with `-Zborrowck=mir`.

cc #68261
r? @nikomatsakis
2020-03-18 18:03:35 +01:00
Eduard-Mihai Burtescu
63811bc38f rustc_infer: remove InferCtxt::closure_sig as the FnSig is always shallowly known. 2020-03-18 02:16:01 +02:00
Camille GILLOT
8aa13289b5 Make stuff private. 2020-03-17 20:07:50 +01:00
Dylan MacKenzie
7f5a2841ea Rename from_u32_const -> from_u32 2020-03-17 11:15:40 -07:00
Mazdak Farrokhzad
98295f7908
Rollup merge of #69956 - matthewjasper:fix-region-flags, r=nikomatsakis
Ensure HAS_FREE_LOCAL_NAMES is set for ReFree

This fixes a bug introduced by #69469.
I don't have any ideas on how to reate a regression test for this.
2020-03-17 12:16:18 +01:00
Matthew Jasper
5a9ccc9ce7 Remove free_region_map from TypeckTables
It was unused.
2020-03-17 08:46:56 +00:00
Mazdak Farrokhzad
f118fee02b
Rollup merge of #70049 - oli-obk:param_env_empty_considered_unimplemented, r=eddyb
Fiddle `ParamEnv` through to a place that used to use `ParamEnv::empty` in a buggy manner

cc https://github.com/rust-lang/rust/pull/69981#discussion_r393048924

r? @eddyb
2020-03-17 03:05:20 +01:00
bors
e24252a12c Auto merge of #68970 - matthewjasper:min-spec, r=nikomatsakis
Implement a feature for a sound specialization subset

This implements a new feature (`min_specialization`) that restricts specialization to a subset that is reasonable for the standard library to use.

The plan is to then:

* Update `libcore` and `liballoc` to compile with `min_specialization`.
* Add a lint to forbid use of `feature(specialization)` (and other unsound, type system extending features) in the standard library.
* Fix the soundness issues around `specialization`.
* Remove `min_specialization`

The rest of this is an overview from a comment in this PR

## Basic approach

To enforce this requirement on specializations we take the following approach:
1. Match up the substs for `impl2` so that the implemented trait and self-type match those for `impl1`.
2. Check for any direct use of `'static` in the substs of `impl2`.
3. Check that all of the generic parameters of `impl1` occur at most once in the *unconstrained* substs for `impl2`. A parameter is constrained if its value is completely determined by an associated type projection predicate.
4. Check that all predicates on `impl1` also exist on `impl2` (after matching substs).

## Example

Suppose we have the following always applicable impl:

```rust
impl<T> SpecExtend<T> for std::vec::IntoIter<T> { /* specialized impl */ }
impl<T, I: Iterator<Item=T>> SpecExtend<T> for I { /* default impl */ }
```

We get that the subst for `impl2` are `[T, std::vec::IntoIter<T>]`. `T` is constrained to be `<I as Iterator>::Item`, so we check only `std::vec::IntoIter<T>` for repeated parameters, which it doesn't have. The predicates of `impl1` are only `T: Sized`, which is also a predicate of impl2`. So this specialization is sound.

## Extensions

Unfortunately not all specializations in the standard library are allowed by this. So there are two extensions to these rules that allow specializing on some traits.

### rustc_specialization_trait

If a trait is always applicable, then it's sound to specialize on it. We check trait is always applicable in the same way as impls, except that step 4 is now "all predicates on `impl1` are always applicable". We require that `specialization` or `min_specialization` is enabled to implement these traits.

### rustc_specialization_marker

There are also some specialization on traits with no methods, including the `FusedIterator` trait which is advertised as allowing optimizations. We allow marking marker traits with an unstable attribute that means we ignore them in point 3 of the checks above. This is unsound but we allow it in the short term because it can't cause use after frees with purely safe code in the same way as specializing on traits methods can.

r? @nikomatsakis
cc #31844 #67194
2020-03-16 20:49:26 +00:00
Oliver Scherer
7894509b00 Fiddle ParamEnv through to a place that used to use ParamEnv::empty in a buggy manner 2020-03-16 18:51:55 +01:00
bors
dd67187965 Auto merge of #67133 - oli-obk:it_must_be_a_sign, r=eddyb
Deduplicate pretty printing of constants

r? @eddyb for the pretty printing logic
cc @RalfJung
2020-03-16 16:31:23 +00:00
Dylan DPC
d8dbb3c041
Rollup merge of #70036 - mark-i-m:describe-it-4, r=eddyb
Make article_and_description primarily use def_kind

r? @eddyb

cc @matthewjasper
2020-03-16 13:16:45 +01:00
Dylan DPC
8872d90572
Rollup merge of #69989 - petrochenkov:nolegacy, r=eddyb,matthewjasper
resolve/hygiene: `macro_rules` are not "legacy"

The "modern" vs "legacy" naming was introduced by jseyfried during initial implementation of macros 2.0.
At this point it's clear that `macro_rules` are not going anywhere and won't be deprecated in the near future.
So this PR changes the naming "legacy" (when it implies "macro_rules") to "macro_rules".
This should also help people reading this code because it's wasn't obvious that "legacy" actually meant "macro_rules" in these contexts.

The most contentious renaming here is probably
```
fn modern -> fn normalize_to_macros_2_0
fn modern_and_legacy -> fn normalize_to_macro_rules
```
Other alternatives that I could think of are `normalize_to_opaque`/`normalize_to_semitransparent`, or `strip_non_opaque`/`strip_transparent`, but they seemed less intuitive.
The documentation to these functions can be found in `symbol.rs`.

r? @matthewjasper
2020-03-16 13:16:44 +01:00
Camille GILLOT
5557407fbb Remove QueryState type alias. 2020-03-16 11:06:53 +01:00
Camille GILLOT
3abd4753b7 Make QueryCache parameters associated types. 2020-03-16 11:06:50 +01:00
Camille GILLOT
7309b3cd8b Simplify type aliases. 2020-03-16 10:23:50 +01:00
Camille GILLOT
7d84f4fb16 Offload try_collect_active_jobs. 2020-03-16 10:22:45 +01:00
Camille GILLOT
5dc7c2ed1a Remove Q parameter from try_get_cached. 2020-03-16 09:48:38 +01:00
Camille GILLOT
fa0794db23 Remove Q parameter from JobOwner. 2020-03-16 09:46:27 +01:00
Camille GILLOT
d125bbb12b Remove Q parameter from query stats. 2020-03-16 09:44:39 +01:00
Camille GILLOT
a18aa81bd8 Remove Q parameter from alloc_self_profile_query_strings_for_query_cache. 2020-03-16 09:42:34 +01:00
Camille GILLOT
fa02dca428 Remove Q parameter from QueryCache::lookup. 2020-03-16 09:40:29 +01:00
Camille GILLOT
a0f57e24e3 Unpack type arguments for QueryState. 2020-03-16 09:39:11 +01:00
Camille GILLOT
486a082c58 Unpack type arguments for QueryLookup. 2020-03-16 09:36:28 +01:00
Camille GILLOT
b08943358e Unpack type arguments for QueryStateShard. 2020-03-16 09:34:57 +01:00
Camille GILLOT
1249032aab Move impl of Queries with its definition. 2020-03-16 09:12:31 +01:00
Camille GILLOT
cf238fd057 Inline QueryAccessor::query. 2020-03-16 09:11:30 +01:00