about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
AgeCommit message (Collapse)AuthorLines
2024-02-08Add a new debug_assertions instrinsic (compiler)Ben Kimock-0/+1
And in clippy
2024-02-08Auto merge of #120767 - matthiaskrgr:rollup-0k8ib1c, r=matthiaskrgrbors-73/+67
Rollup of 9 pull requests Successful merges: - #119592 (resolve: Unload speculatively resolved crates before freezing cstore) - #120103 (Make it so that async-fn-in-trait is compatible with a concrete future in implementation) - #120206 (hir: Make sure all `HirId`s have corresponding HIR `Node`s) - #120214 (match lowering: consistently lower bindings deepest-first) - #120688 (GVN: also turn moves into copies with projections) - #120702 (docs: also check the inline stmt during redundant link check) - #120727 (exhaustiveness: Prefer "`0..MAX` not covered" to "`_` not covered") - #120734 (Add `SubdiagnosticMessageOp` as a trait alias.) - #120739 (improve pretty printing for associated items in trait objects) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-08Make `RegionName` `Copy` by (transitively) interning the few string variantsAmanda Stjerna-13/+13
2024-02-08Taint borrowck results without running any borrowck if the MIR body was ↵Oli Scherer-4/+5
already tainted
2024-02-07hir: Remove `fn opt_hir_id` and `fn opt_span`Vadim Petrochenkov-72/+65
2024-02-07hir: Make sure all `HirId`s have corresponding HIR `Node`sVadim Petrochenkov-1/+2
2024-02-06Fix incorrect suggestion for uninitialize binding in destructuring patternclubby789-1/+6
2024-02-06Rollup merge of #120513 - compiler-errors:normalize-regions-for-nll, r=lcnrMatthias Krüger-51/+142
Normalize type outlives obligations in NLL for new solver Normalize the type outlives assumptions and obligations in MIR borrowck. This should fix any of the lazy-norm-related MIR borrowck problems. Also some cleanups from last PR: 1. Normalize obligations in a loop in lexical region resolution 2. Use `deeply_normalize_with_skipped_universes` in lexical resolution since we may have, e.g. `for<'a> Alias<'a>: 'b`. r? lcnr
2024-02-06A drive-by rewrite of give_region_a_name()Amanda Stjerna-17/+21
This rewrite makes the cache-updating nature of the function slightly clearer, using the Entry API into the hash table for region names to capture the update-insert nature of the method. May be marginally more efficient since it only runtime-borrows the map once, but in this context the performance impact is almost certainly completely negligible.
2024-02-06More comments, final tweaksMichael Goulet-2/+14
2024-02-06Bless tests, add commentsMichael Goulet-3/+7
2024-02-06Construct body for by-move coroutine closure outputMichael Goulet-0/+1
2024-02-06Teach typeck/borrowck/solvers how to deal with async closuresMichael Goulet-22/+143
2024-02-06Add CoroutineClosure to TyKind, AggregateKind, UpvarArgsMichael Goulet-8/+39
2024-02-06Make async closures directly lower to ClosureKind::CoroutineClosureMichael Goulet-13/+29
2024-02-06Invert diagnostic lints.Nicholas Nethercote-59/+26
That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.
2024-02-03Rollup merge of #120592 - trevyn:cleanup-to-string, r=NilstriebMatthias Krüger-2/+2
Remove unnecessary `.to_string()`/`.as_str()`s
2024-02-03Rollup merge of #120573 - nnethercote:rm-BorrowckErrors-tainted_by_errors, ↵Matthias Krüger-84/+86
r=oli-obk Remove `BorrowckErrors::tainted_by_errors` This PR removes one of the `tainted_by_errors` occurrences, replacing it with direct use of `ErrorGuaranteed`. r? `@oli-obk`
2024-02-02Remove unnecessary `.to_string()`/`.as_str()`strevyn-2/+2
2024-02-02Remove dead args from functionsMichael Goulet-41/+3
2024-02-03Improve a local variable name.Nicholas Nethercote-2/+2
2024-02-02Normalize the whole PolyTypeOutlivesPredicate, more simplificationsMichael Goulet-52/+49
2024-02-02Don't hang when there's an infinite loop of outlives obligationsMichael Goulet-57/+76
2024-02-02Normalize type outlives obligations in NLLMichael Goulet-50/+125
2024-02-02Rename `BorrowckErrors` as `BorrowckDiags`.Nicholas Nethercote-26/+26
And some related things. Because it can hold non-error diagnostics.
2024-02-02Remove `BorrowckErrors::tainted_by_errors`.Nicholas Nethercote-59/+66
`BorrowckErrors` stores a mix of error and non-error diags in `buffered`. As a result, it downgrades `DiagnosticBuilder`s to `Diagnostic`s, losing the emission guarantees, and so has to use a `tainted_by_errors` field to record whether an error has occurred. This commit splits `buffered` into `buffered_errors` and `buffered_non_errors`, keeping them as `DiagnosticBuilder`s and preserving the emission guarantees. This also requires fixing a bunch of incorrect lifetimes on `DiagnosticBuilder` use points.
2024-02-02Remove `BorrowckErrors::set_tainted_by_errors`.Nicholas Nethercote-5/+0
It has no effect. Note that `infcx.set_tainted_by_errors()` is still called, so taintedness is still being propagated.
2024-02-02Rename `buffer_non_error_diag` as `buffer_non_error`.Nicholas Nethercote-5/+5
To match `buffer_error`.
2024-01-30Auto merge of #119101 - compiler-errors:outlives, r=lcnrbors-9/+28
Normalize region obligation in lexical region resolution with next-gen solver This normalizes region obligations when we `resolve_regions`, since they may be unnormalized with deferred projection equality. It's pretty hard to add tests that exercise this without also triggering MIR borrowck errors (because we don't normalize there yet). I've added one test with two revisions that should test that we both 1. normalize region obligations in the param env, and 2. normalize registered region obligations during lexical region resolution.
2024-01-30Rollup merge of #120488 - nnethercote:diag-lifetimes, r=oli-obkGuillaume Gomez-1/+1
Diagnostic lifetimes cleanups Some diagnostic simplifications. r? `@oli-obk`
2024-01-30Remove the lifetime from `DiagnosticArgValue`.Nicholas Nethercote-1/+1
Because it's almost always static. This makes `impl IntoDiagnosticArg for DiagnosticArgValue` trivial, which is nice. There are a few diagnostics constructed in `compiler/rustc_mir_build/src/check_unsafety.rs` and `compiler/rustc_mir_transform/src/errors.rs` that now need symbols converted to `String` with `to_string` instead of `&str` with `as_str`, but that' no big deal, and worth it for the simplifications elsewhere.
2024-01-30Apply suggestions from reviewMichael Goulet-10/+28
2024-01-30Normalize caller boundsMichael Goulet-1/+2
2024-01-29Rollup merge of #120390 - matthewjasper:inline-constant-pat-mir, r=davidtwcoDylan DPC-8/+56
Borrow check inline const patterns Add type annotations to MIR so that borrowck can pass constraints from inline constants in patterns to the containing function. Also enables some inline constant pattern tests that were fixed by the THIR unsafeck stabilization. cc #76001
2024-01-29Borrow check inline const patternsMatthew Jasper-8/+56
Add type annotations to MIR so that borrowck can pass constraints from inline constants in patterns to the containing function.
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-6/+8
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
2024-01-25Remove unused featuresclubby789-3/+0
2024-01-23Auto merge of #116152 - cjgillot:unchunck, r=nnethercotebors-3/+3
Only use dense bitsets in dataflow analyses When a dataflow state has the size close to the number of locals, we should prefer a dense bitset, like we already store locals in a dense vector. Other occurrences of `ChunkedBitSet` need to be justified by the size of the dataflow state.
2024-01-22Remove uses of HybridBitSet.Camille GILLOT-3/+3
2024-01-23Rename `TyCtxt::emit_spanned_lint` as `TyCtxt::emit_node_span_lint`.Nicholas Nethercote-1/+1
2024-01-20Auto merge of #120003 - Mark-Simulacrum:opt-promoted, r=davidtwcobors-30/+87
perf: Don't track specific live points for promoteds We don't query this information out of the promoted (it's basically a single "unit" regardless of the complexity within it) and this saves on re-initializing the SparseIntervalMatrix's backing IndexVec with mostly empty rows for all of the leading regions in the function. Typical promoteds will only contain a few regions that need up be uplifted, while the parent function can have thousands. For a simple function repeating println!("Hello world"); 50,000 times this reduces compile times from 90 to 15 seconds in debug mode. The previous implementations re-initialization led to an overall roughly n^2 runtime as each promoted initialized slots for ~n regions, now we scale closer to linearly (5000 hello worlds takes 1.1 seconds). cc https://github.com/rust-lang/rust/issues/50994, https://github.com/rust-lang/rust/issues/86244
2024-01-20Rollup merge of #120155 - compiler-errors:no-erased-when-promoting, r=aliemjayMatthias Krüger-5/+9
Don't use `ReErased` to detect type test promotion failed Using `ReErased` here is convenient because it implicitly stores the state that we are explicitly recording with the `failed` variable now, but I also think it adds a tiny bit of complexity that is not worth it. r? `@aliemjay`
2024-01-20Don't use ReErased to detect type test promotion failedMichael Goulet-5/+9
2024-01-19perf: Don't track specific live points for promotedsMark Rousskov-30/+87
We don't query this information out of the promoted (it's basically a single "unit" regardless of the complexity within it) and this saves on re-initializing the SparseIntervalMatrix's backing IndexVec with mostly empty rows for all of the leading regions in the function. Typical promoteds will only contain a few regions that need up be uplifted, while the parent function can have thousands. For a simple function repeating println!("Hello world"); 50,000 times this reduces compile times from 90 to 15 seconds in debug mode. The previous implementations re-initialization led to an overall roughly n^2 runtime as each promoted initialized slots for ~n regions, now we scale closer to linearly (5000 hello worlds takes 1.1 seconds).
2024-01-19Rollup merge of #120126 - sjwang05:issue-102269, r=compiler-errorsMatthias Krüger-7/+90
Suggest `.swap()` when encountering conflicting borrows from `mem::swap` on a slice This PR modifies the existing suggestion by matching on `[ProjectionElem::Deref, ProjectionElem::Index(_)]` instead of just `[ProjectionElem::Index(_)]`, which caused us to miss many cases. Additionally, it adds a more specific, machine-applicable suggestion in the case we determine `mem::swap` was used to swap elements in a slice. Closes #102269
2024-01-19Suggest .swap() instead of mem::swap() in more casessjwang05-7/+92
2024-01-17Rollup merge of #115291 - cjgillot:dest-prop-save, r=JakobDegenMatthias Krüger-114/+32
Save liveness results for DestinationPropagation `DestinationPropagation` needs to verify that merge candidates do not conflict with each other. This is done by verifying that a local is not live when its counterpart is written to. To get the liveness information, the pass runs `MaybeLiveLocals` dataflow analysis repeatedly, once for each propagation round. This is quite costly, and the main driver for the perf impact on `ucd` and `diesel`. (See https://github.com/rust-lang/rust/pull/115105#issuecomment-1689205908) In order to mitigate this cost, this PR proposes to save the result of the analysis into a `SparseIntervalMatrix`, and mirror merges of locals into that matrix: `liveness(destination) := liveness(destination) union liveness(source)`. <details> <summary>Proof</summary> We denote by `'` all the quantities of the transformed program. Let $\varphi$ be a mapping of locals, which maps `source` to `destination`, and is identity otherwise. The exact liveness set after a statement is $out'(statement)$, and the proposed liveness set is $\varphi(out(statement))$. Consider a statement. Suppose that the output state verifies $out' \subset phi(out)$. We want to prove that $in' \subset \varphi(in)$ where $in = (out - kill) \cup gen$, and conclude by induction. We have 2 cases: either that statement is kept with locals renumbered by $\varphi$, or it is a tautological assignment and it removed. 1. If the statement is kept: the gen-set and the kill-set of $statement' = \varphi(statement)$ are $gen' = \varphi(gen)$ and $kill' = \varphi(kill)$ exactly. From soundness requirement 3, $\varphi(in)$ is disjoint from $\varphi(kill)$. This implies that $\varphi(out - kill)$ is disjoint from $\varphi(kill)$, and so $\varphi(out - kill) = \varphi(out) - \varphi(kill)$. Then $\varphi(in) = (\varphi(out) - \varphi(kill)) \cup \varphi(gen) = (\varphi(out) - kill') \cup gen'$. We can conclude that $out' \subset \varphi(out) \implies in' \subset \varphi(in)$. 2. If the statement is removed. As $\varphi(statement)$ is a tautological assignment, we know that $\varphi(gen) = \varphi(kill) = \\{ destination \\}$, while $gen' = kill' = \emptyset$. So $\varphi(in) = \varphi(out) \cup \\{ destination \\}$. Then $in' = out' \subset out \subset \varphi(in)$. By recursion, we can conclude by that $in' \subset \varphi(in)$ everywhere. </details> This approximate liveness results is only suboptimal if there are locals that fully disappear from the CFG due to an assignment cycle. These cases are quite unlikely, so we do not bother with them. This change allows to reduce the perf impact of DestinationPropagation by half on diesel and ucd (https://github.com/rust-lang/rust/pull/115105#issuecomment-1694701904). cc ````@JakobDegen````
2024-01-17Auto merge of #120019 - lcnr:fn-wf, r=BoxyUwUbors-1/+34
fix fn/const items implied bounds and wf check (rebase) A rebase of #104098, see that PR for discussion. This is pretty much entirely the work of `@aliemjay.` I received his permission for this rebase. --- These are two distinct changes (edit: actually three, see below): 1. Wf-check all fn item args. This is a soundness fix. Fixes #104005 2. Use implied bounds from impl header in borrowck of associated functions/consts. This strictly accepts more code and helps to mitigate the impact of other breaking changes. Fixes #98852 Fixes #102611 The first is a breaking change and will likely have a big impact without the the second one. See the first commit for how it breaks libstd. Landing the second one without the first will allow more incorrect code to pass. For example an exploit of #104005 would be as simple as: ```rust use core::fmt::Display; trait ExtendLt<Witness> { fn extend(self) -> Box<dyn Display>; } impl<T: Display> ExtendLt<&'static T> for T { fn extend(self) -> Box<dyn Display> { Box::new(self) } } fn main() { let val = (&String::new()).extend(); println!("{val}"); } ``` The third change is to to check WF of user type annotations before normalizing them (fixes #104764, fixes #104763). It is mutually dependent on the second change above: an attempt to land it separately in #104746 caused several crater regressions that can all be mitigated by using the implied from the impl header. It is also necessary for the soundness of associated consts that use the implied bounds of impl header. See #104763 and how the third commit fixes the soundness issue in `tests/ui/wf/wf-associated-const.rs` that was introduces by the previous commit. r? types
2024-01-16Auto merge of #116520 - Enselic:large-copy-into-fn, r=oli-obkbors-12/+18
large_assignments: Lint on specific large args passed to functions Requires lowering function call arg spans down to MIR, which is done in the second commit. Part of #83518 Also see * https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/arg.20Spans.20for.20TerminatorKind.3A.3ACall.3F * https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/move_size_limit.20lint r? `@oli-obk` (E-mentor)
2024-01-16Rollup merge of #119969 - compiler-errors:simplify-closure-env-ty, r=oli-obkMatthias Krüger-1/+5
Simplify `closure_env_ty` and `closure_env_param` Random cleanup that I found when working on async closures. This makes it easier to separate the latter into a new tykind.