about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2023-10-23Allow `ensure` queries to return `Result<(), ErrorGuaranteed>`Oli Scherer-4/+60
2023-10-22use visibility to check unused imports and delete some stmtsbohan-4/+0
2023-10-21Auto merge of #116922 - Zalathar:unused, r=cjgillotbors-6/+0
coverage: Emit mappings for unused functions without generating stubs For a while I've been annoyed by the fact that generating coverage maps for unused functions involves generating a stub function at the LLVM level. As I suspected, generating that stub function isn't actually necessary, as long as we specifically tell LLVM about the symbol names of all the functions that have coverage mappings but weren't codegenned (due to being unused). --- There is some helper code that gets moved around in the follow-up patches, so look at the first patch to see the most important functional changes. --- `@rustbot` label +A-code-coverage
2023-10-21Rollup merge of #106601 - estebank:match-semi, r=cjgillotMatthias Krüger-0/+1
Suggest `;` after bare `match` expression E0308 Fix #72634.
2023-10-21Make `ty::print::Printer` take `&mut self` instead of `self`Nilstrieb-316/+329
This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
2023-10-21Implement JumpThreading pass.Camille GILLOT-0/+9
2023-10-21coverage: Change query `codegened_and_inlined_items` to a plain functionZalathar-6/+0
This query has a name that sounds general-purpose, but in fact it has coverage-specific semantics, and (fortunately) is only used by coverage code. Because it is only ever called once (from one designated CGU), it doesn't need to be a query, and we can change it to a regular function instead.
2023-10-20Uplift ClauseKind and PredicateKindMichael Goulet-183/+78
2023-10-20Rename `CoroutineKind::Gen` to `::Coroutine`Oli Scherer-7/+11
2023-10-20s/generator/coroutine/Oli Scherer-178/+179
2023-10-20s/Generator/Coroutine/Oli Scherer-186/+186
2023-10-20Adjust importsMichael Goulet-4/+4
2023-10-20Avoid a `track_errors` by bubbling up most errors from `check_well_formed`Oli Scherer-14/+37
2023-10-20Auto merge of #116946 - compiler-errors:movability-and-mutability, r=lcnrbors-7/+1
Uplift movability and mutability, the simple way Just make type_ir a dependency of ast. This can be relaxed later if we want to make the dependency less heavy. Part of rust-lang/types-team#124. r? `@lcnr` or `@jackh726`
2023-10-19Auto merge of #116874 - compiler-errors:elaborator-nits, r=wesleywiserbors-5/+7
Some small elaborator nits Didn't want to fold these into a totally unrelated pr.
2023-10-19Uplift movability and mutability, the simple wayMichael Goulet-7/+1
2023-10-18Some renaming nits for rustc_type_irMichael Goulet-14/+12
2023-10-18Remove unused variant BinderListTyMichael Goulet-1/+0
2023-10-18Auto merge of #116046 - Zalathar:fn-cov-info, r=cjgillotbors-71/+135
coverage: Move most per-function coverage info into `mir::Body` Currently, all of the coverage information collected by the `InstrumentCoverage` pass is smuggled through MIR in the form of individual `StatementKind::Coverage` statements, which must then be reassembled by coverage codegen. That's awkward for a number of reasons: - While some of the coverage statements do care about their specific position in the MIR control-flow graph, many of them don't, and are just tacked onto the function's first BB as metadata carriers. - MIR inlining can result in coverage statements being duplicated, so coverage codegen has to jump through hoops to avoid emitting duplicate mappings. - MIR optimizations that would delete coverage statements need to carefully copy them into the function's first BB so as not to omit them from coverage reports. - The order in which coverage codegen sees coverage statements is dependent on MIR optimizations/inlining, which can cause unnecessary churn in the emitted coverage mappings. - We don't have a good way to annotate MIR-level functions with extra coverage info that doesn't belong in a statement. --- This PR therefore takes most of the per-function coverage info and stores it in a field in `mir::Body` as `Option<Box<FunctionCoverageInfo>>`. (This adds one pointer to the size of `mir::Body`, even when coverage is not enabled.) Coverage statements still need to be injected into MIR in some cases, but only when they actually affect codegen (counters) or are needed to detect code that has been optimized away as unreachable (counters/expressions). --- By the end of this PR, the information stored in `FunctionCoverageInfo` is: - A hash of the function's source code (needed by LLVM's coverage map format) - The number of coverage counters added by coverage instrumentation - A table of coverage expressions, associating each expression ID with its operator (add or subtract) and its two operands - The list of mappings, associating each covered code region with a counter/expression/zero value --- ~~This is built on top of #115301, so I'll rebase and roll a reviewer once that lands.~~ r? `@ghost` `@rustbot` label +A-code-coverage
2023-10-18Auto merge of #116887 - lcnr:alias-ty-constructor, r=compiler-errorsbors-19/+21
`TyCtxt::mk_alias_ty` -> `AliasTy::new`
2023-10-18coverage: Explicitly note that counter/expression IDs are function-localZalathar-0/+10
2023-10-18coverage: Update docs for `StatementKind::Coverage`Zalathar-5/+10
This new description reflects the changes made in this PR, and should hopefully be more useful to non-coverage developers who need to care about coverage statements.
2023-10-18coverage: Store expression data in function coverage infoZalathar-21/+25
Even though expression details are now stored in the info structure, we still need to inject `ExpressionUsed` statements into MIR, because if one is missing during codegen then we know that it was optimized out and we can remap all of its associated code regions to zero.
2023-10-18coverage: Store all of a function's mappings in function coverage infoZalathar-28/+30
Previously, mappings were attached to individual coverage statements in MIR. That necessitated special handling in MIR optimizations to avoid deleting those statements, since otherwise codegen would be unable to reassemble the original list of mappings. With this change, a function's list of mappings is now attached to its MIR body, and survives intact even if individual statements are deleted by optimizations.
2023-10-18AliasTy::new instead of tcx methodlcnr-19/+21
2023-10-18Auto merge of #116885 - aliemjay:rollup-plbeppt, r=aliemjaybors-5/+0
Rollup of 5 pull requests Successful merges: - #116812 (Disable missing_copy_implementations lint on non_exhaustive types) - #116856 (Disable effects in libcore again) - #116865 (Suggest constraining assoc types in more cases) - #116870 (Don't compare host param by name) - #116879 (revert #114586) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-18Rollup merge of #116870 - compiler-errors:host-param-by-name, r=fee1-deadAli MJ Al-Nasrawy-5/+0
Don't compare host param by name Seems sketchy to be searching for `sym::host` by name, especially when we can get the actual index with not very much work. r? fee1-dead
2023-10-18coverage: Collect a function's coverage mappings into a single listZalathar-0/+14
This is an intermediate step towards being able to store all of a function's mappings in function coverage info.
2023-10-18coverage: Rename `Operand` to `CovTerm`Zalathar-7/+9
Later patches in this PR will use `CovTerm` to represent things that are not expression operands.
2023-10-18coverage: Store the number of counters/expressions in function coverage infoZalathar-13/+22
Coverage codegen can now allocate arrays based on the number of counters/expressions originally used by the instrumentor. The existing query that inspects coverage statements is still used for determining the number of counters passed to `llvm.instrprof.increment`. If some high-numbered counters were removed by MIR optimizations, the instrumented binary can potentially use less memory and disk space at runtime.
2023-10-18coverage: Attach an optional `FunctionCoverageInfo` to `mir::Body`Zalathar-2/+20
This allows coverage information to be attached to the function as a whole when appropriate, instead of being smuggled through coverage statements in the function's basic blocks. As an example, this patch moves the `function_source_hash` value out of individual `CoverageKind::Counter` statements and into the per-function info. When synthesizing unused functions for coverage purposes, the absence of this info is taken to indicate that a function was not eligible for coverage and should not be synthesized.
2023-10-18Auto merge of #116815 - Nilstrieb:more-funny-pretty-printers, r=compiler-errorsbors-143/+90
Remove lots of generics from `ty::print` All of these generics mostly resolve to the same thing, which means we can remove them, greatly simplifying the types involved in pretty printing and unlocking another simplification (that is not performed in this PR): Using `&mut self` instead of passing `self` through the return type. cc `@eddyb` you probably know why it's like this, just checking in and making sure I didn't do anything bad r? oli-obk
2023-10-18Make sure that non-pretty-printing usages are using the correct elaboratorMichael Goulet-5/+7
2023-10-18Don't compare host param by nameMichael Goulet-5/+0
2023-10-17Automatically enable cross-crate inlining for small functionsBen Kimock-13/+9
2023-10-18Remove `#![feature(result_option_inspect)]` from the compilerSlanterns-1/+0
2023-10-17Remove `Print::Error`Nilstrieb-22/+11
All printing goes through `fmt::Error` now.
2023-10-17Remove `Printer::Error`Nilstrieb-95/+93
It's always a `fmt::Error` except in some cases where it was `!`, but we're not really winning anything in that case.
2023-10-17Remove `Print::Output`Nilstrieb-27/+19
Now that `Printer` doesn't have subprinters anymore, the output of a printing operation is always the same.
2023-10-17Remove "subprinter" types from `Printer`Nilstrieb-88/+56
These are `Self` in almost all printers except one, which can just store the state as a field instead. This simplifies the printer and allows for further simplifications, for example using `&mut self` instead of passing around the printer.
2023-10-17Auto merge of #116756 - fee1-dead-contrib:dupe-those-bounds, r=oli-obkbors-0/+4
Duplicate `~const` bounds with a non-const one in effects desugaring This should unblock #116058. r? `@oli-obk`
2023-10-16Address review commentsMatthew Jasper-3/+14
Clean up code and add comments. Use InlineConstant to wrap range patterns.
2023-10-16Fix inline const pattern unsafety checking in THIRMatthew Jasper-4/+14
THIR unsafety checking was getting a cycle of function unsafety checking -> building THIR for the function -> evaluating pattern inline constants in the function -> building MIR for the inline constant -> checking unsafety of functions (so that THIR can be stolen) This is fixed by not stealing THIR when generating MIR but instead when unsafety checking. This leaves an issue with pattern inline constants not being unsafety checked because they are evaluated away when generating THIR. To fix that we now represent inline constants in THIR patterns and visit them in THIR unsafety checking.
2023-10-16Auto merge of #114330 - RalfJung:dagling-ptr-deref, r=oli-obkbors-22/+34
don't UB on dangling ptr deref, instead check inbounds on projections This implements https://github.com/rust-lang/reference/pull/1387 in Miri. See that PR for what the change is about. Detecting dangling references in `let x = &...;` is now done by validity checking only, so some tests need to have validity checking enabled. There is no longer inherently a "nodangle" check in evaluating the expression `&*ptr` (aside from the aliasing model). r? `@oli-obk` Based on: - https://github.com/rust-lang/reference/pull/1387 - https://github.com/rust-lang/rust/pull/115524
2023-10-16Auto merge of #116724 - RalfJung:alloc-bytes, r=oli-obkbors-13/+5
interpret: clean up AllocBytes Fixes https://github.com/rust-lang/miri/issues/2836 Nothing has moved here in half a year, so let's just remove these unused stubs -- they need a proper re-design anyway. r? `@oli-obk`
2023-10-15update MIR place semantics UB commentRalf Jung-12/+9
2023-10-15more precise error for 'based on misaligned pointer' caseRalf Jung-8/+18
2023-10-15place evaluation: require the original pointer to be aligned if an access ↵Ralf Jung-2/+9
happens
2023-10-15don't UB on dangling ptr deref, instead check inbounds on projectionsRalf Jung-2/+0
2023-10-15Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstriebbors-30/+71
Format all the let-chains in compiler crates Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped). This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else. I will also add this commit to the ignore list after it has landed. The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree. ``` ~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates ~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif ``` cc `@rust-lang/rustfmt` r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :> cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.