about summary refs log tree commit diff
path: root/compiler/rustc_middle
AgeCommit message (Collapse)AuthorLines
2022-01-29Rollup merge of #93424 - lcnr:nit, r=spastorinoMatthias Krüger-1/+1
fix nit
2022-01-29Make local_def_id_to_hir_id query directly returh HirIdSantiago Pastorino-8/+10
2022-01-28Make local_def_id_to_hir_id return MaybeOwner<()>Santiago Pastorino-7/+2
2022-01-28Separate hir_owner query into two queries to avoid using extensive data on ↵Santiago Pastorino-16/+29
incr comp most of the time
2022-01-28fix nitlcnr-1/+1
2022-01-28update cfg(bootstrap)sPietro Albini-17/+4
2022-01-27Continue work on assoc const eqkadmin-0/+3
2022-01-27Store def_id_to_hir_id as variant in hir_owner.Camille GILLOT-43/+50
If hir_owner is Owner(_), the LocalDefId is pointing to an owner, so the ItemLocalId is 0. If the HIR node does not exist, we store Phantom. Otherwise, we store the HirId associated to the LocalDefId.
2022-01-27try apply `rustc_pass_by_value` to `Span`lcnr-3/+3
2022-01-26drive-by: use is_const and is_const_if_constMichael Goulet-2/+9
2022-01-26add note suggesting that predicate is satisfied but is not constMichael Goulet-0/+9
2022-01-26Auto merge of #93352 - matthiaskrgr:rollup-5peret4, r=matthiaskrgrbors-6/+64
Rollup of 7 pull requests Successful merges: - #90247 (Improve Duration::try_from_secs_f32/64 accuracy by directly processing exponent and mantissa) - #91861 (Replace iterator-based construction of collections by `Into<T>`) - #92098 (add OpenBSD platform-support page) - #92134 (Add x86_64-pc-windows-msvc linker-plugin-lto instructions) - #92256 (Improve selection errors for `~const` trait bounds) - #92778 (fs: Use readdir() instead of readdir_r() on Linux and Android) - #93338 (Update minifier crate version to 0.0.42) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-26Rollup merge of #92256 - fee1-dead:improve-selection-err, r=oli-obkMatthias Krüger-6/+64
Improve selection errors for `~const` trait bounds
2022-01-26Auto merge of #93301 - spastorino:perf-test-1, r=oli-obkbors-2/+5
Store hir_id_to_def_id in OwnerInfo. This is for perf test purposes only. Related to #89278
2022-01-25Return an indexmap in `all_local_trait_impls` querypierwill-5/+3
The data structure previously used here required Ord. As part of #90317, we do not want DefId to implement Ord.
2022-01-25Auto merge of #93095 - Aaron1011:remove-assoc-ident, r=cjgillotbors-12/+15
Store a `Symbol` instead of an `Ident` in `AssocItem` This is the same idea as #92533, but for `AssocItem` instead of `VariantDef`/`FieldDef`. With this change, we no longer have any uses of `#[stable_hasher(project(...))]`
2022-01-25Store hir_id_to_def_id in OwnerInfo.Camille GILLOT-2/+5
2022-01-26Improve selection errors for `~const` trait boundsDeadbeef-6/+64
2022-01-24Auto merge of #90842 - pierwill:localdefid-indexmap, r=wesleywiserbors-1/+1
Use `indexmap` to avoid sorting `LocalDefId`s See discussion in https://github.com/rust-lang/rust/pull/90408#discussion_r745935459. Related to work on https://github.com/rust-lang/rust/issues/90317.
2022-01-24rustc_errors: remove `allow_suggestions` from `DiagnosticBuilder`.Eduard-Mihai Burtescu-1/+1
2022-01-24Auto merge of #93028 - compiler-errors:const_drop_bounds, r=fee1-deadbors-13/+56
Check `const Drop` impls considering `~const` Bounds This PR adds logic to trait selection to account for `~const` bounds in custom `impl const Drop` for types, elaborates the `const Drop` check in `rustc_const_eval` to check those bounds, and steals some drop linting fixes from #92922, thanks `@DrMeepster.` r? `@fee1-dead` `@oli-obk` <sup>(edit: guess I can't request review from two people, lol)</sup> since each of you wrote and reviewed #88558, respectively. Since the logic here is more complicated than what existed, it's possible that this is a perf regression. But it works correctly with tests, and that makes me happy. Fixes #92881
2022-01-23Rollup merge of #91526 - petrochenkov:earlint, r=cjgillotMatthias Krüger-0/+3
rustc_lint: Some early linting refactorings The first one removes and renames some fields and methods from `EarlyContext`. The second one uses the set of registered tools (for tool attributes and tool lints) in a more centralized way. The third one removes creation of a fake `ast::Crate` from `fn pre_expansion_lint`. Pre-expansion linting is done with per-module granularity on freshly loaded modules, and it previously synthesized an `ast::Crate` to visit non-root modules, now they are visited as modules. The node ID used for pre-expansion linting is also made more precise (the loaded module ID is used).
2022-01-23Auto merge of #93066 - nnethercote:infallible-decoder, r=bjorn3bors-137/+154
Make `Decodable` and `Decoder` infallible. `Decoder` has two impls: - opaque: this impl is already partly infallible, i.e. in some places it currently panics on failure (e.g. if the input is too short, or on a bad `Result` discriminant), and in some places it returns an error (e.g. on a bad `Option` discriminant). The number of places where either happens is surprisingly small, just because the binary representation has very little redundancy and a lot of input reading can occur even on malformed data. - json: this impl is fully fallible, but it's only used (a) for the `.rlink` file production, and there's a `FIXME` comment suggesting it should change to a binary format, and (b) in a few tests in non-fundamental ways. Indeed #85993 is open to remove it entirely. And the top-level places in the compiler that call into decoding just abort on error anyway. So the fallibility is providing little value, and getting rid of it leads to some non-trivial performance improvements. Much of this PR is pretty boring and mechanical. Some notes about a few interesting parts: - The commit removes `Decoder::{Error,error}`. - `InternIteratorElement::intern_with`: the impl for `T` now has the same optimization for small counts that the impl for `Result<T, E>` has, because it's now much hotter. - Decodable impls for SmallVec, LinkedList, VecDeque now all use `collect`, which is nice; the one for `Vec` uses unsafe code, because that gave better perf on some benchmarks. r? `@bjorn3`
2022-01-23rustc_lint: Reuse the set of registered tools from resolverVadim Petrochenkov-0/+3
2022-01-22Use an `indexmap` to avoid sorting `LocalDefId`spierwill-1/+1
Update `indexmap` to 1.8.0. Bless test
2022-01-22Rollup merge of #93147 - nnethercote:interner-cleanups, r=lcnrMatthias Krüger-44/+69
Interner cleanups Improve some code that I have found confusing. r? ```@lcnr```
2022-01-22Address review comments.Nicholas Nethercote-7/+8
2022-01-22Make `Decodable` and `Decoder` infallible.Nicholas Nethercote-136/+152
`Decoder` has two impls: - opaque: this impl is already partly infallible, i.e. in some places it currently panics on failure (e.g. if the input is too short, or on a bad `Result` discriminant), and in some places it returns an error (e.g. on a bad `Option` discriminant). The number of places where either happens is surprisingly small, just because the binary representation has very little redundancy and a lot of input reading can occur even on malformed data. - json: this impl is fully fallible, but it's only used (a) for the `.rlink` file production, and there's a `FIXME` comment suggesting it should change to a binary format, and (b) in a few tests in non-fundamental ways. Indeed #85993 is open to remove it entirely. And the top-level places in the compiler that call into decoding just abort on error anyway. So the fallibility is providing little value, and getting rid of it leads to some non-trivial performance improvements. Much of this commit is pretty boring and mechanical. Some notes about a few interesting parts: - The commit removes `Decoder::{Error,error}`. - `InternIteratorElement::intern_with`: the impl for `T` now has the same optimization for small counts that the impl for `Result<T, E>` has, because it's now much hotter. - Decodable impls for SmallVec, LinkedList, VecDeque now all use `collect`, which is nice; the one for `Vec` uses unsafe code, because that gave better perf on some benchmarks.
2022-01-22Rename `Decoder::read_nil` and `read_unit`.Nicholas Nethercote-1/+1
Because `()` is called "unit" and it makes it match `Encoder::emit_unit`.
2022-01-21Clarify some code relating to interning and types.Nicholas Nethercote-24/+57
I have found this code very confusing at times. This commit clarifies things. In particular, the commit explains the requirements that the `Borrow` impls put on the `Eq` and `Hash` impls, which are non-obvious. And it puts the `Borrow` impls first, since they force `Eq` and `Hash` to have particular forms. The commit also notes `TyS`'s uniqueness requirements.
2022-01-21Auto merge of #93138 - matthiaskrgr:rollup-m8akifd, r=matthiaskrgrbors-7/+12
Rollup of 17 pull requests Successful merges: - #91032 (Introduce drop range tracking to generator interior analysis) - #92856 (Exclude "test" from doc_auto_cfg) - #92860 (Fix errors on blanket impls by ignoring the children of generated impls) - #93038 (Fix star handling in block doc comments) - #93061 (Only suggest adding `!` to expressions that can be macro invocation) - #93067 (rustdoc mobile: fix scroll offset when jumping to internal id) - #93086 (Add tests to ensure that `let_chains` works with `if_let_guard`) - #93087 (Fix src/test/run-make/raw-dylib-alt-calling-convention) - #93091 (⬆ chalk to 0.76.0) - #93094 (src/test/rustdoc-json: Check for `struct_field`s in `variant_tuple_struct.rs`) - #93098 (Show a more informative panic message when `DefPathHash` does not exist) - #93099 (rustdoc: auto create output directory when "--output-format json") - #93102 (Pretty printer algorithm revamp step 3) - #93104 (Support --bless for pp-exact pretty printer tests) - #93114 (update comment for `ensure_monomorphic_enough`) - #93128 (Add script to prevent point releases with same number as existing ones) - #93136 (Backport the 1.58.1 release notes to master) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-21Make stability interning follow the usual pattern.Nicholas Nethercote-20/+12
2022-01-20Rollup merge of #93098 - Aaron1011:def-path-hash-debug, r=oli-obkMatthias Krüger-3/+8
Show a more informative panic message when `DefPathHash` does not exist This should hopefully make it easier to debug incremental compilation bugs like #93096 without affecting performance.
2022-01-20Rollup merge of #93091 - pierwill:chalk-0.76, r=jackh726Matthias Krüger-1/+1
⬆ chalk to 0.76.0 This update contains https://github.com/rust-lang/chalk/pull/740, which is needed for work on #90317.
2022-01-20Rollup merge of #91032 - eholk:generator-drop-tracking, r=nikomatsakisMatthias Krüger-3/+3
Introduce drop range tracking to generator interior analysis This PR addresses cases such as this one from #57478: ```rust struct Foo; impl !Send for Foo {} let _: impl Send = || { let guard = Foo; drop(guard); yield; }; ``` Previously, the `generator_interior` pass would unnecessarily include the type `Foo` in the generator because it was not aware of the behavior of `drop`. We fix this issue by introducing a drop range analysis that finds portions of the code where a value is guaranteed to be dropped. If a value is dropped at all suspend points, then it is no longer included in the generator type. Note that we are using "dropped" in a generic sense to include any case in which a value has been moved. That is, we do not only look at calls to the `drop` function. There are several phases to the drop tracking algorithm, and we'll go into more detail below. 1. Use `ExprUseVisitor` to find values that are consumed and borrowed. 2. `DropRangeVisitor` uses consume and borrow information to gather drop and reinitialization events, as well as build a control flow graph. 3. We then propagate drop and reinitialization information through the CFG until we reach a fix point (see `DropRanges::propagate_to_fixpoint`). 4. When recording a type (see `InteriorVisitor::record`), we check the computed drop ranges to see if that value is definitely dropped at the suspend point. If so, we skip including it in the type. ## 1. Use `ExprUseVisitor` to find values that are consumed and borrowed. We use `ExprUseVisitor` to identify the places where values are consumed. We track both the `hir_id` of the value, and the `hir_id` of the expression that consumes it. For example, in the expression `[Foo]`, the `Foo` is consumed by the array expression, so after the array expression we can consider the `Foo` temporary to be dropped. In this process, we also collect values that are borrowed. The reason is that the MIR transform for generators conservatively assumes anything borrowed is live across a suspend point (see `rustc_mir_transform::generator::locals_live_across_suspend_points`). We match this behavior here as well. ## 2. Gather drop events, reinitialization events, and control flow graph After finding the values of interest, we perform a post-order traversal over the HIR tree to find the points where these values are dropped or reinitialized. We use the post-order index of each event because this is how the existing generator interior analysis refers to the position of suspend points and the scopes of variables. During this traversal, we also record branching and merging information to handle control flow constructs such as `if`, `match`, and `loop`. This is necessary because values may be dropped along some control flow paths but not others. ## 3. Iterate to fixed point The previous pass found the interesting events and locations, but now we need to find the actual ranges where things are dropped. Upon entry, we have a list of nodes ordered by their position in the post-order traversal. Each node has a set of successors. For each node we additionally keep a bitfield with one bit per potentially consumed value. The bit is set if we the value is dropped along all paths entering this node. To compute the drop information, we first reverse the successor edges to find each node's predecessors. Then we iterate through each node, and for each node we set its dropped value bitfield to the intersection of all incoming dropped value bitfields. If any bitfield for any node changes, we re-run the propagation loop again. ## 4. Ignore dropped values across suspend points At this point we have a data structure where we can ask whether a value is guaranteed to be dropped at any post order index for the HIR tree. We use this information in `InteriorVisitor` to check whether a value in question is dropped at a particular suspend point. If it is, we do not include that value's type in the generator type. Note that we had to augment the region scope tree to include all yields in scope, rather than just the last one as we did before. r? `@nikomatsakis`
2022-01-20Rollup merge of #92582 - lcnr:generic-arg-infer, r=BoxyUwUMatthias Krüger-3/+17
improve `_` constants in item signature handling removing the "type" from the error messages does slightly worsen the error messages for types, but figuring out whether the placeholder is for a type or a constant and correctly dealing with that seemed fairly difficult to me so I took the easy way out :sparkles: Imo the error message is still clear enough. r? `@BoxyUwU` cc `@estebank`
2022-01-19Foreign types are trivially dropMichael Goulet-5/+5
- Also rename a trivial_const_drop to match style of other functions in the util module. - Also add a test for `const Drop` that doesn't depend on a `~const` bound. - Also comment a bit why we remove the const bound during dropck impl check.
2022-01-19Show a more informative panic message when `DefPathHash` does not existAaron Hill-3/+8
This should hopefully make it easier to debug incremental compilation bugs like #93096 without affecting performance.
2022-01-19Store a `Symbol` instead of an `Ident` in `AssocItem`Aaron Hill-12/+15
This is the same idea as #92533, but for `AssocItem` instead of `VariantDef`/`FieldDef`. With this change, we no longer have any uses of `#[stable_hasher(project(...))]`
2022-01-19never is trivially const-drop, and add testMichael Goulet-2/+2
2022-01-19⬆ chalk to 0.76.0pierwill-1/+1
2022-01-19Rollup merge of #93077 - lcnr:write_substs, r=oli-obkMatthias Krüger-4/+0
remove `List::is_noop` think that `is_noop` is actually less clear than just using `is_empty`
2022-01-19remove `is_noop`lcnr-4/+0
2022-01-19Rollup merge of #93041 - pierwill:rm-unused-defid-ords, r=cjgillotMatthias Krüger-16/+6
Remove some unused ordering derivations based on `DefId` Like #93018, this removes some unused/unneeded ordering derivations as part of ongoing work on #90317. Here, these changes are aimed at making https://github.com/rust-lang/rust/pull/90749 easier to review, test, and merge. r? `@cjgillot`
2022-01-19Rollup merge of #88642 - c410-f3r:let_chains_2, r=matthewjasperMatthias Krüger-1/+1
Formally implement let chains ## Let chains My longest and hardest contribution since #64010. Thanks to `@Centril` for creating the RFC and special thanks to `@matthewjasper` for helping me since the beginning of this journey. In fact, `@matthewjasper` did much of the complicated MIR stuff so it's true to say that this feature wouldn't be possible without him. Thanks again `@matthewjasper!` With the changes proposed in this PR, it will be possible to chain let expressions along side local variable declarations or ordinary conditional expressions. In other words, do much of what the `if_chain` crate already does. ## Other considerations * `if let guard` and `let ... else` features need special care and should be handled in a following PR. * Irrefutable patterns are allowed within a let chain context * ~~Three Clippy lints were already converted to start dogfooding and help detect possible corner cases~~ cc #53667
2022-01-18Short-circuit some trivially const Drop typesMichael Goulet-0/+36
2022-01-18Formally implement let chainsCaio-1/+1
2022-01-18Track drops across multiple yieldsEric Holk-3/+3
2022-01-18Rollup merge of #93018 - pierwill:rm-unused-ord, r=davidtwcoMatthias Krüger-1/+1
Remove some unused `Ord` derives based on `Span` Remove some `Ord`, `PartialOrd` derivations that rely on underlying ordering of `Span`. These ordering traits appear to be unused right now. If we're going to attempt to remove ordering traits from `Span` as suggested in https://github.com/rust-lang/rust/issues/90317#issuecomment-1013980591, we might want to slowly remove code that depends on this ordering (as opposed to the all-at-once approach in https://github.com/rust-lang/rust/pull/90749 and https://github.com/rust-lang/rust/pull/90408). cc `@tmiasko` `@cjgillot`
2022-01-18Rollup merge of #92780 - b-naber:postpone-const-eval-coherence, r=lcnrMatthias Krüger-9/+12
Directly use ConstValue for single literals in blocks Addresses the minimal repro in https://github.com/rust-lang/rust/issues/92186, but doesn't fix the underlying problem (which would be solved by solving the anon subst problem afaict). I do, however, think that it makes sense in general to treat single literals in anon blocks as const values directly, especially in light of the problem that the issue refers to (anon const evaluation being postponed until infer variables in substs can be resolved, which was introduced by https://github.com/rust-lang/rust/pull/90023), i.e. while we do get warnings for those unnecessary braces, we should try to avoid errors caused by those braces if possible.