about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2024-01-23Rollup merge of #119766 - oli-obk:split_tait_and_atpit, r=compiler-errorsLeón Orell Valerian Liehr-0/+9
Split tait and impl trait in assoc items logic And simplify the assoc item logic where applicable. This separation shows that it is easier to reason about impl trait in assoc items compared with TAITs. See https://rust-lang.zulipchat.com/#narrow/stream/315482-t-compiler.2Fetc.2Fopaque-types/topic/impl.20trait.20in.20associated.20type for some discussion. The current plan is to try to stabilize impl trait in associated items before TAIT, as they do not have any issues with their defining scopes (see https://github.com/rust-lang/rust/issues/107645 for why this is not a trivial or uncontroversial topic).
2024-01-23Rollup merge of #120270 - compiler-errors:randos, r=lcnrLeón Orell Valerian Liehr-50/+33
A bunch of random modifications r? oli-obk Kitchen sink of changes that I didn't know where to put elsewhere. Documentation tweaks mostly, but also removing some unreachable code and simplifying the pretty printing for closures/coroutines.
2024-01-23const prop nonsense eliminatedOli Scherer-2/+0
2024-01-23Remove track_errors entirelyOli Scherer-3/+12
2024-01-23Random type checker changesMichael Goulet-50/+33
2024-01-23Auto merge of #119044 - RalfJung:intern-without-types, r=oli-obkbors-2/+8
const-eval interning: get rid of type-driven traversal This entirely replaces our const-eval interner, i.e. the code that takes the final result of a constant evaluation from the local memory of the const-eval machine to the global `tcx` memory. The main goal of this change is to ensure that we can detect mutable references that sneak into this final value -- this is something we want to reject for `static` and `const`, and while const-checking performs some static analysis to ensure this, I would be much more comfortable stabilizing const_mut_refs if we had a dynamic check that sanitizes the final value. (This is generally the approach we have been using on const-eval: do a static check to give nice errors upfront, and then do a dynamic check to be really sure that the properties we need for soundness, actually hold.) We can do this now that https://github.com/rust-lang/rust/pull/118324 landed and each pointer comes with a bit (completely independent of its type) storing whether mutation is permitted through this pointer or not. The new interner is a lot simpler than the old one: previously we did a complete type-driven traversal to determine the mutability of all memory we see, and then a second pass to intern any leftover raw pointers. The new interner simply recursively traverses the allocation holding the final result, and all allocations reachable from it (which can be determined from the raw bytes of the result, without knowing anything about types), and ensures they all get interned. The initial allocation is interned as immutable for `const` and pomoted and non-interior-mutable `static`; all other allocations are interned as immutable for `static`, `const`, and promoted. The main subtlety is justifying that those inner allocations may indeed be interned immutably, i.e., that mutating them later would anyway already be UB: - for promoteds, we rely on the analysis that does promotion to ensure that this is sound. - for `const` and `static`, we check that all pointers in the final result that point to things that are new (i.e., part of this const evaluation) are immutable, i.e., were created via `&<expr>` at a non-interior-mutable type. Mutation through immutable pointers is UB so we are free to intern that memory as immutable. Interning raises an error if it encounters a dangling pointer or a mutable pointer that violates the above rules. I also extended our type-driven const validity checks to ensure that `&mut T` in the final value of a const points to mutable memory, at least if `T` is not zero-sized. This catches cases of people turning `&i32` into `&mut i32` (which would still be considered a read-only pointer). Similarly, when these checks encounter an `UnsafeCell`, they are checking that it lives in mutable memory. (Both of these only traverse the newly created values; if those point to other consts/promoteds, the check stops there. But that's okay, we don't have to catch all the UB.) I co-developed this with the stricter interner changes but I can split it out into a separate PR if you prefer. This PR does have the immediate effect of allowing some new code on stable, for instance: ```rust const CONST_RAW: *const Vec<i32> = &Vec::new() as *const _; ``` Previously that code got rejected since the type-based interner didn't know what to do with that pointer. It's a raw pointer, we cannot trust its type. The new interner does not care about types so it sees no issue with this code; there's an immutable pointer pointing to some read-only memory (storing a `Vec<i32>`), all is good. Accepting this code pretty much commits us to non-type-based interning, but I think that's the better strategy anyway. This PR also leads to slightly worse error messages when the final value of a const contains a dangling reference. Previously we would complete interning and then the type-based validation would detect this dangling reference and show a nice error saying where in the value (i.e., in which field) the dangling reference is located. However, the new interner cannot distinguish dangling references from dangling raw pointers, so it must throw an error when it encounters either of them. It doesn't have an understanding of the value structure so all it can say is "somewhere in this constant there's a dangling pointer". (Later parts of the compiler don't like dangling pointers/references so we have to reject them either during interning or during validation.) This could potentially be improved by doing validation before interning, but that's a larger change that I have not attempted yet. (It's also subtle since we do want validation to use the final mutability bits of all involved allocations, and currently it is interning that marks a bunch of allocations as immutable -- that would have to still happen before validation.) `@rust-lang/wg-const-eval` I hope you are okay with this plan. :) `@rust-lang/lang` paging you in since this accepts new code on stable as explained above. Please let me know if you think FCP is necessary.
2024-01-23Auto merge of #120017 - nnethercote:lint-api, r=oli-obkbors-22/+22
Fix naming in the lint API Methods for emit lints are named very inconsistently. This PR fixes that up. r? `@compiler-errors`
2024-01-22Rollup merge of #120233 - oli-obk:revert_trait_obj_upcast_stabilization, r=lcnrMatthias Krüger-0/+1
Revert stabilization of trait_upcasting feature Reverts #118133 This reverts commit 6d2b84b3ed7848fd91b8d6151d4451b3103ed816, reversing changes made to 73bc12199ea8c7651ed98b069c0dd6b0bb5fabcf. The feature has a soundness bug: * #120222 It is unclear to me whether we'll actually want to destabilize, but I thought it was still prudent to open the PR for easy destabilization once we get there.
2024-01-22Rollup merge of #120216 - nnethercote:fix-trimmed_def_paths-assertion, ↵Matthias Krüger-2/+0
r=compiler-errors Fix a `trimmed_def_paths` assertion failure. `RegionHighlightMode::force_print_trimmed_def_path` can call `trimmed_def_paths` even when `tcx.sess.opts.trimmed_def_paths` is false. Based on the `force` in the method name, it seems this is deliberate, so I have removed the assertion. Fixes #120035. r? `@compiler-errors`
2024-01-22Rollup merge of #120143 - ↵Matthias Krüger-0/+50
compiler-errors:consolidate-instance-resolve-for-coroutines, r=oli-obk Consolidate logic around resolving built-in coroutine trait impls Deduplicates a lot of code. Requires defining a new lang item for `Coroutine::resume` for consistency, but it seems not harmful at worst, and potentially later useful at best. r? oli-obk
2024-01-23Rename `struct_lint_level` as `lint_level`.Nicholas Nethercote-9/+9
2024-01-23Rename `TyCtxt::emit_spanned_lint` as `TyCtxt::emit_node_span_lint`.Nicholas Nethercote-2/+2
2024-01-23Rename `TyCtxt::emit_lint` as `TyCtxt::emit_node_lint`.Nicholas Nethercote-2/+2
2024-01-23Rename `TyCtxt::struct_span_lint_hir` as `TyCtxt::node_span_lint`.Nicholas Nethercote-5/+5
2024-01-23Rename `TyCtxt::struct_lint_node` as `TyCtxt::node_lint`.Nicholas Nethercote-3/+3
2024-01-23Rename `LintContext::lookup` as `LintContext::opt_span_lint`.Nicholas Nethercote-1/+1
2024-01-22Do not normalize closure signature when building FnOnce shimMichael Goulet-10/+8
2024-01-22Add a simpler and more targetted code path for impl trait in assoc itemsOli Scherer-0/+9
2024-01-22Revert "Auto merge of #118133 - Urgau:stabilize_trait_upcasting, r=WaffleLapkin"Oli Scherer-0/+1
This reverts commit 6d2b84b3ed7848fd91b8d6151d4451b3103ed816, reversing changes made to 73bc12199ea8c7651ed98b069c0dd6b0bb5fabcf.
2024-01-22Auto merge of #120080 - cuviper:128-align-packed, r=nikicbors-16/+13
Pack u128 in the compiler to mitigate new alignment This is based on #116672, adding a new `#[repr(packed(8))]` wrapper on `u128` to avoid changing any of the compiler's size assertions. This is needed in two places: * `SwitchTargets`, otherwise its `SmallVec<[u128; 1]>` gets padded up to 32 bytes. * `LitKind::Int`, so that entire `enum` can stay 24 bytes. * This change definitely has far-reaching effects though, since it's public.
2024-01-22Auto merge of #120226 - matthiaskrgr:rollup-9xwx0si, r=matthiaskrgrbors-2/+5
Rollup of 9 pull requests Successful merges: - #118714 ( Explanation that fields are being used when deriving `(Partial)Ord` on enums) - #119710 (Improve `let_underscore_lock`) - #119726 (Tweak Library Integer Division Docs) - #119746 (rustdoc: hide modals when resizing the sidebar) - #119986 (Fix error counting) - #120194 (Shorten `#[must_use]` Diagnostic Message for `Option::is_none`) - #120200 (Correct the anchor of an URL in an error message) - #120203 (Replace `#!/bin/bash` with `#!/usr/bin/env bash` in rust-installer tests) - #120212 (Give nnethercote more reviews) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-22const-eval interner: from-scratch rewrite using mutability information from ↵Ralf Jung-2/+8
provenance rather than types
2024-01-22Fix a `trimmed_def_paths` assertion failure.Nicholas Nethercote-2/+0
`RegionHighlightMode::force_print_trimmed_def_path` can call `trimmed_def_paths` even when `tcx.sess.opts.trimmed_def_paths` is false. Based on the `force` in the method name, it seems this is deliberate, so I have removed the assertion. Fixes #120035.
2024-01-22Tweak error counting.Nicholas Nethercote-2/+5
We have several methods indicating the presence of errors, lint errors, and delayed bugs. I find it frustrating that it's very unclear which one you should use in any particular spot. This commit attempts to instill a basic principle of "use the least general one possible", because that reflects reality in practice -- `has_errors` is the least general one and has by far the most uses (esp. via `abort_if_errors`). Specifics: - Add some comments giving some usage guidelines. - Prefer `has_errors` to comparing `err_count` to zero. - Remove `has_errors_or_span_delayed_bugs` because it's a weird one: in the cases where we need to count delayed bugs, we should really be counting lint errors as well. - Rename `is_compilation_going_to_fail` as `has_errors_or_lint_errors_or_span_delayed_bugs`, for consistency with `has_errors` and `has_errors_or_lint_errors`. - Change a few other `has_errors_or_lint_errors` calls to `has_errors`, as per the "least general" principle. This didn't turn out to be as neat as I hoped when I started, but I think it's still an improvement.
2024-01-21Rollup merge of #120128 - oli-obk:smir_internal_lift, r=celinvalMatthias Krüger-3/+24
Make stable_mir::with_tables sound See the first commit for the actual soundness fix. The rest is just fallout from that and is entirely safe code. Includes most of #120120 The major difference to #120120 is that we don't need an unsafe trait, as we can now rely on the type system (the only unsafe part, and the actual source of the unsoundness was in `with_tables`) r? `@celinval`
2024-01-20Auto merge of #119821 - oli-obk:reveal_all_const_evals, r=lcnrbors-2/+2
Always use RevealAll for const eval queries implements what is described in https://github.com/rust-lang/rust/pull/116803#discussion_r1364089471 Using `UserFacing` for const eval does not make sense anymore, unless we significantly change things like avoiding revealing opaque types. New tests are copied from https://github.com/rust-lang/rust/pull/101478
2024-01-19Pack the u128 in LitKind::IntJosh Stone-1/+1
2024-01-19Pack the u128 in SwitchTargetsJosh Stone-15/+12
2024-01-20Auto merge of #116672 - maurer:128-align, r=nikicbors-3/+9
LLVM 18 x86 data layout update With https://reviews.llvm.org/D86310 LLVM now has i128 aligned to 16-bytes on x86 based platforms. This will be in LLVM-18. This patch updates all our spec targets to be 16-byte aligned, and removes the alignment when speaking to older LLVM. This results in Rust overaligning things relative to LLVM on older LLVMs. This implements MCP https://github.com/rust-lang/compiler-team/issues/683. See #54341
2024-01-19Consolidate logic around resolving built-in coroutine trait implsMichael Goulet-0/+50
2024-01-19Always use RevealAll for const eval queriesOli Scherer-2/+2
2024-01-19LLVM 18 x86 data layout updateMatthew Maurer-3/+9
With https://reviews.llvm.org/D86310 LLVM now has i128 aligned to 16-bytes on x86 based platforms. This will be in LLVM-18. This patch updates all our spec targets to be 16-byte aligned, and removes the alignment when speaking to older LLVM. This results in Rust overaligning things relative to LLVM on older LLVMs. This alignment change was discussed in rust-lang/compiler-team#683 See #54341 for additional information about why this is happening and where this will be useful in the future. This *does not* stabilize `i128`/`u128` for FFI.
2024-01-19Fix `Stable` trait and its impls to work with the new `with_tables`Oli Scherer-3/+24
2024-01-19Auto merge of #120112 - matthiaskrgr:rollup-48o3919, r=matthiaskrgrbors-18/+40
Rollup of 9 pull requests Successful merges: - #119582 (bootstrap: handle vendored sources when remapping crate paths) - #119730 (docs: fix typos) - #119828 (Improved collapse_debuginfo attribute, added command-line flag) - #119869 (replace `track_errors` usages with bubbling up `ErrorGuaranteed`) - #120037 (Remove `next_root_ty_var`) - #120094 (tests/ui/asm/inline-syntax: adapt for LLVM 18) - #120096 (Set RUSTC_BOOTSTRAP=1 consistently) - #120101 (change `.unwrap()` to `?` on write where `fmt::Result` is returned) - #120102 (Fix typo in munmap_partial.rs) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-18Modify GenericArg and Term structs to use strict provenance rulesKamalesh Palanisamy-18/+56
2024-01-19Auto merge of #120006 - cjgillot:no-hir-owner, r=wesleywiserbors-71/+35
Get rid of the hir_owner query. This query was meant as a firewall between `hir_owner_nodes` which is supposed to change often, and the queries that only depend on the item signature. That firewall was inefficient, leaking the contents of the HIR body through `HirId`s. `hir_owner` incurs a significant cost, as we need to hash HIR twice in multiple modes. This PR proposes to remove it, and simplify the hashing scheme. For the future, `def_kind`, `def_span`... are much more efficient for incremental decoupling, and should be preferred.
2024-01-18Rollup merge of #120101 - mj10021:issue-120090-fix, r=WaffleLapkinMatthias Krüger-2/+2
change `.unwrap()` to `?` on write where `fmt::Result` is returned Fixes #120090 which points out that some of the `.unwrap()`s in `rustc_middle/src/mir/pretty.rs` are likely meant to be `?`s
2024-01-18Rollup merge of #119869 - oli-obk:track_errors2, r=matthewjasperMatthias Krüger-14/+37
replace `track_errors` usages with bubbling up `ErrorGuaranteed` more of the same as https://github.com/rust-lang/rust/pull/117449 (removing `track_errors`)
2024-01-18Rollup merge of #119828 - azhogin:azhogin/collapse_debuginfo_improved_attr, ↵Matthias Krüger-2/+1
r=petrochenkov Improved collapse_debuginfo attribute, added command-line flag Improved attribute collapse_debuginfo with variants: `#[collapse_debuginfo=(no|external|yes)]`. Added command-line flag for default behaviour. Work-in-progress: will add more tests. cc https://github.com/rust-lang/rust/issues/100758
2024-01-18Auto merge of #120089 - matthiaskrgr:rollup-xyfqrb5, r=matthiaskrgrbors-57/+30
Rollup of 8 pull requests Successful merges: - #119172 (Detect `NulInCStr` error earlier.) - #119833 (Make tcx optional from StableMIR run macro and extend it to accept closures) - #119967 (Add `PatKind::Err` to AST/HIR) - #119978 (Move async closure parameters into the resultant closure's future eagerly) - #120021 (don't store const var origins for known vars) - #120038 (Don't create a separate "basename" when naming and opening a MIR dump file) - #120057 (Don't ICE when deducing future output if other errors already occurred) - #120073 (Remove spastorino from users_on_vacation) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-18change unwrap to `?` on write where result is returnedJames Dietz-2/+2
2024-01-18Auto merge of #118553 - jackh726:lint-implied-bounds, r=lcnrbors-2/+15
error on incorrect implied bounds in wfcheck except for Bevy dependents Rebase of #109763 Additionally, special cases Bevy `ParamSet` types to not trigger the lint. This is tracked in #119956. Fixes #109628
2024-01-18Rollup merge of #120038 - Zalathar:dump-path, r=WaffleLapkinMatthias Krüger-38/+20
Don't create a separate "basename" when naming and opening a MIR dump file These functions were split up by #77080, in order to support passing the dump file's “basename” (filename without extension) to the implementation of `-Zdump-mir-spanview`, so that it could be used as a page title. That flag has since been removed (#119566), so now there's no particular reason for this code to handle the basename separately from the filename or full path. This PR therefore restores things to (roughly) how they were before #77080.
2024-01-18Rollup merge of #120021 - lcnr:const-var-value, r=compiler-errorsMatthias Krüger-19/+10
don't store const var origins for known vars r? types
2024-01-17Correctly handle normalization in implied boundsAli MJ Al-Nasrawy-2/+15
Special-case Bevy dependents to not error
2024-01-17Improved collapse_debuginfo attribute, added command-line flag (no|external|yes)Andrew Zhogin-2/+1
2024-01-17Use FnOnceOutput instead of FnOnce where expectedOli Scherer-1/+1
2024-01-17Make crate_inherent_impls fallible and stop using `track_errors` for itOli Scherer-12/+33
2024-01-17Make crate_inherent_impls_overlap_check bubble up its errorsOli Scherer-1/+2
2024-01-17Move `check_mod_impl_wf` query call out of track_errors and bubble errors up ↵Oli Scherer-1/+2
instead.