about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2024-04-02Auto merge of #123340 - fmease:rustdoc-simplify-auto-trait-impl-synth, ↵bors-40/+22
r=GuillaumeGomez rustdoc: heavily simplify the synthesis of auto trait impls `gd --numstat HEAD~2 HEAD src/librustdoc/clean/auto_trait.rs` **+315 -705** 🟩🟥🟥🟥⬛ --- As outlined in issue #113015, there are currently 3[^1] large separate routines that “clean” `rustc_middle::ty` data types related to generics & predicates to rustdoc data types. Every single one has their own kinds of bugs. While I've patched a lot of bugs in each of the routines in the past, it's about time to unify them. This PR is only the first in a series. It completely **yanks** the custom “bounds cleaning” of mod `auto_trait` and reuses the routines found in mod `simplify`. As alluded to, `simplify` is also flawed but it's still more complete than `auto_trait`'s routines. [See also my review comment over at `tests/rustdoc/synthetic_auto/bounds.rs`](https://github.com/rust-lang/rust/pull/123340#discussion_r1546900539). This is preparatory work for rewriting “bounds cleaning” from scratch in follow-up PRs in order to finally [fix] #113015. Apart from that, I've eliminated all potential sources of *instability* in the rendered output. See also #119597. I'm pretty sure this fixes #119597. This PR does not attempt to fix [any other issues related to synthetic auto trait impls](https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AA-synthetic-impls%20label%3AA-auto-traits). However, it's definitely meant to be a *stepping stone* by making `auto_trait` more contributor-friendly. --- * Replace `FxHash{Map,Set}` with `FxIndex{Map,Set}` to guarantee a stable iteration order * Or as a perf opt, `UnordSet` (a thin wrapper around `FxHashSet`) in cases where we never iterate over the set. * Yes, we do make use of `swap_remove` but that shouldn't matter since all the callers are deterministic. It does make the output less “predictable” but it's still better than before. Ofc, I rely on `rustc_infer` being deterministic. I hope that holds. * Utilizing `clean::simplify` over the custom “bounds cleaning” routines wipes out the last reference to `collect_referenced_late_bound_regions` in rustdoc (`simplify` uses `bound_vars`) which was a source of instability / unpredictability (cc #116388) * Remove the types `RegionTarget` and `RegionDeps` from `librustdoc`. They were duplicates of the identical types found in `rustc`. Just import them from `rustc`. For some reason, they were duplicated when splitting `auto_trait` in two in #49711. * Get rid of the useless “type namespace” `AutoTraitFinder` in `librustdoc` * The struct only held a `DocContext`, it was over-engineered * Turn the associated functions into free ones * Eliminates rightward drift; increases legibility * `rustc` also contains a useless `AutoTraitFinder` struct but I plan on removing that in a follow-up PR * Rename a bunch of methods to be way more descriptive * Eliminate `use super::*;` * Lead to `clean/mod.rs` accumulating a lot of unnecessary imports * Made `auto_traits` less modular * Eliminate a custom `TypeFolder`: We can just use the rustc helper `fold_regions` which does that for us I plan on adding extensive documentation to `librustdoc`'s `auto_trait` in follow-up PRs. I don't want to do that in this PR because further refactoring & bug fix PRs may alter the overall structure of `librustdoc`'s & `rustc`'s `auto_trait` modules to a great degree. I'm slowly digging into the dark details of `rustc`'s `auto_trait` module again and once I have the full picture I will be able to provide proper docs. --- While this PR does indeed touch `rustc`'s `auto_trait` — mostly tiny refactorings — I argue this PR doesn't need any compiler reviewers next to rustdoc ones since that module falls under the purview of rustdoc — it used to be part of `librustdoc` after all (#49711). Sorry for not having split this into more commits. If you'd like me to I can try to split it into more atomic commits retroactively. However, I don't know if that would actually make reviewing easier. I think the best way to review this might just be to place the master version of `auto_trait` on the left of your screen and the patched one on the right, not joking. r? `@GuillaumeGomez` [^1]: Or even 4 depending on the way you're counting.
2024-04-02Auto merge of #123347 - saethlin:only-allow-upstream-llvm-calls, r=Nilstriebbors-2/+14
Only allow compiler_builtins to call LLVM intrinsics, not any link_name function This is another case of accidental reliance on `inline(never)` like I rooted out in https://github.com/rust-lang/rust/pull/118770. Without this PR, attempting to build some large programs with `-Zcross-crate-inline-threshold=yes` with a sysroot also compiled with that flag will result in linker errors like this: ``` = note: /usr/bin/ld: /tmp/cargo-installNrfN4T/x86_64-unknown-linux-gnu/release/deps/libcompiler_builtins-d2a9b69f4e45b883.rlib(compiler_builtins-d2a9b69f4e45b883.compiler_builtins.dbbc6c2ca970faa4-cgu.0.rcgu.o): in function `core::panicking::panic_fmt': /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:72:(.text.unlikely._ZN4core9panicking9panic_fmt17ha407cc99e97c942fE+0x31): undefined reference to `rust_begin_unwind' ``` With `-Zcross-crate-inline-threshold=yes` we can inline `panic_fmt` into `compiler_builtins`. Then we end up with a call to an upstream monomorphization, but one that has a `link_name` set. But unlike LLVM's magic intrinsic names, this link name is going to make it to the linker, and then we have a problem. This logic looks scuffed, but also we're doing this in 4 other places. Don't know if that means it's good or bad. https://github.com/rust-lang/rust/blob/1684a753dbca5d23b2e03568e6fbbb48eb72d0e6/compiler/rustc_codegen_cranelift/src/abi/mod.rs#L386 https://github.com/rust-lang/rust/blob/1684a753dbca5d23b2e03568e6fbbb48eb72d0e6/compiler/rustc_ast_passes/src/feature_gate.rs#L306 https://github.com/rust-lang/rust/blob/1684a753dbca5d23b2e03568e6fbbb48eb72d0e6/compiler/rustc_codegen_ssa/src/codegen_attrs.rs#L609 https://github.com/rust-lang/rust/blob/1684a753dbca5d23b2e03568e6fbbb48eb72d0e6/compiler/rustc_codegen_gcc/src/declare.rs#L170
2024-04-01Fix obligation param and bless testsMichael Goulet-40/+18
2024-04-01Instantiate closure-like bounds with placeholders to deal with binders correctlyMichael Goulet-82/+88
2024-04-01Only allow upstream calls to LLVM intrinsics, not any link_name functionBen Kimock-2/+14
2024-04-02rustdoc: heavily simplify synthesis of auto trait implsLeón Orell Valerian Liehr-11/+4
2024-04-01Auto merge of #123327 - BoxyUwU:param_env_docs_rewrite, r=compiler-errorsbors-5/+10
Update `ParamEnv` docs There is now a wealth of information in the dev guide about `ParamEnv` so we should explicitly link to it from the doc comments. I also added a caution against using `ParamEnv` and removed the comment about it being "suitable for type checking" as you should practically never use `ParamEnv::empty` for type checking r? `@compiler-errors`
2024-04-01Auto merge of #123320 - WaffleLapkin:fixup-never-type-options, r=compiler-errorsbors-5/+5
Fixup parsing of `rustc_never_type_options` attribute #122843 had a copy paste error, which I did not caught when testing. r? `@compiler-errors`
2024-04-01rustdoc: synthetic impls: auto traits: Fx{Hash↦Index}{Map,Set}León Orell Valerian Liehr-29/+18
2024-04-01maybeBoxy-1/+1
2024-04-01Update `ParamEnv` docsBoxy-5/+10
2024-04-01Auto merge of #122046 - Nadrieril:integrate-or-pats2, r=matthewjasperbors-65/+38
match lowering: handle or-patterns one layer at a time `create_or_subcandidates` and `merge_trivial_subcandidates` both call themselves recursively to handle nested or-patterns, which is hard to follow. In this PR I avoid the need for that; we now process a single "layer" of or-patterns at a time. By calling back into `match_candidates`, we only need to expand one layer at a time. Conversely, since we always try to simplify a layer that we just expanded (thanks to https://github.com/rust-lang/rust/pull/123067), we only have to merge one layer at a time. r? `@matthewjasper`
2024-04-01Fixup parsing of `rustc_never_type_options` attributeMaybe Waffle-5/+5
Copy paste error strike again..
2024-04-01Auto merge of #123310 - compiler-errors:nested-static-codegen-attrs, r=oli-obkbors-3/+8
Don't inherit codegen attrs from parent static Putting this up partly for discussion and partly for review. Specifically, in #121644, `@oli-obk` designed a system that creates new static items for representing nested allocations in statics. However, in that PR, oli made it so that these statics inherited the codegen attrs from the parent. This causes problems such as colliding symbols with `#[export_name]` and ICEs with `#[no_mangle]` since these synthetic statics have no `tcx.item_name(..)`. So the question is, is there any case where we *do* want to inherit codegen attrs from the parent? The only one that seems a bit suspicious is the thread-local attribute. And there may be some interesting interactions with the coverage attributes as well... Fixes (after backport) #123274. Fixes #123243. cc #121644. r? `@oli-obk` cc `@nnethercote` `@RalfJung` (reviewers on that pr)
2024-04-01Auto merge of #122663 - beetrees:non-unicode-env-error, r=TaKO8Kibors-21/+40
Fix error message for `env!` when env var is not valid Unicode Currently (without this PR) the `env!` macro emits an ```environment variable `name` not defined at compile time``` error when the environment variable is defined, but not a valid Unicode string. This PR introduces a separate more accurate error message, and a test to verify this behaviour. For reference, before this PR, the new test would have outputted: ``` error: environment variable `NON_UNICODE_VAR` not defined at compile time --> non_unicode_env.rs:2:13 | 2 | let _ = env!("NON_UNICODE_VAR"); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `std::env::var("NON_UNICODE_VAR")` to read the variable at run time = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error ``` whereas with this PR, the test ouputs: ``` error: environment variable `NON_UNICODE_VAR` is not a valid Unicode string --> non_unicode_env.rs:2:13 | 2 | let _ = env!("NON_UNICODE_VAR"); | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error ```
2024-04-01Fix error message for `env!` when env var is not valid Unicodebeetrees-21/+40
2024-04-01Auto merge of #122972 - beetrees:use-align-type, r=fee1-deadbors-19/+30
Use the `Align` type when parsing alignment attributes Use the `Align` type in `rustc_attr::parse_alignment`, removing the need to call `Align::from_bytes(...).unwrap()` later in the compilation process.
2024-03-31Don't inherit codegen attrs from parent staticMichael Goulet-3/+8
2024-04-01Use the `Align` type when parsing alignment attributesbeetrees-19/+30
2024-03-31Auto merge of #121851 - michaelwoerister:mcp-533-effective-vis, r=cjgillotbors-51/+6
Use FxIndexMap instead FxHashMap to stabilize iteration order in EffectiveVisibilities Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).
2024-03-31Rollup merge of #123242 - Nadrieril:require-contiguous-enum-indices, ↵Matthias Krüger-52/+8
r=compiler-errors pattern analysis: Require enum indices to be contiguous We had a cfg-hack to allow rust-analyzer to use non-contiguous indices for its enum variants. Unfortunately this no longer works if r-a uses the in-tree version of the crate. This PR removes the hack, and on the r-a side we'll have to use contiguous indices but that's not too hard. r? `@compiler-errors`
2024-03-31Rollup merge of #123211 - compiler-errors:V, r=estebankMatthias Krüger-21/+32
Stop calling visitors `V` Renames some visitors which currently have the unhelpful name of `V`. It's not self-documenting, and there is no situation where saving a few bytes in source code helps anyone. Stacked on top of #123202 due to conflict.
2024-03-31Auto merge of #123236 - klensy:tracing-tree-bump, r=Mark-Simulacrumbors-2/+2
bump tracing-tree to 0.3 Only change in `tracing-tree` is https://github.com/davidbarsky/tracing-tree/pull/76 * dedupes `tracing-log` * dupes `nu-ansi-term`
2024-03-31Auto merge of #122459 - Nadrieril:sort-eq, r=oli-obkbors-6/+8
match lowering: sort `Eq` candidates in the failure case too This is a slight tweak to MIR gen of matches. Take a match like: ```rust match (s, flag) { ("a", _) if foo() => 1, ("b", true) => 2, ("a", false) => 3, (_, true) => 4, _ => 5, } ``` If we switch on `s == "a"`, the first candidate matches, and we learn almost nothing about the second candidate. So there's a choice: 1. (what we do today) stop sorting candidates, keep the "b" case grouped with everything below. This could allow us to be clever here and test on `flag == true` next. 2. (what this PR does) sort "b" into the failure case. The "b" will be alone (fewer opportunities for picking a good test), but that means the two "a" cases require a single test. Today, we aren't clever in which tests we pick, so this is an unambiguous win. In a future where we pick tests better, idk. Grouping tests as much as possible feels like a generally good strategy. This was proposed in https://github.com/rust-lang/rust/issues/29623 (9 years ago :D)
2024-03-30Auto merge of #123106 - maurer:cfi-closures, r=compiler-errorsbors-35/+94
CFI: Abstract Closures and Coroutines This will abstract coroutines in a moment, it's just abstracting closures for now to show `@rcvalle` This uses the same principal as the methods on traits - figure out the `dyn` type representing the fn trait, instantiate it, and attach that alias set. We're essentially just computing how we would be called in a dynamic context, and attaching that.
2024-03-30CFI: Rewrite closure and coroutine instances to their trait methodMatthew Maurer-32/+81
Similar to methods on a trait object, the most common way to indirectly call a closure or coroutine is through the vtable on the appropriate trait. This uses the same approach as we use for trait methods, after backing out the trait arguments from the type.
2024-03-30CFI: Only encode Coroutine Parent ArgsMatthew Maurer-3/+13
Fixes #122705
2024-03-30Sort `Eq` candidates in the failure case tooNadrieril-6/+8
2024-03-30Auto merge of #123207 - Urgau:improve_ambi_non_null, r=Nadrierilbors-14/+43
Add support for `NonNull`s in the `ambiguous_wide_ptr_comparisions` lint This PR add support for `NonNull` pointers in the `ambiguous_wide_ptr_comparisions` lint. Fixes https://github.com/rust-lang/rust/issues/121264 r? `@Nadrieril` (since you just reviewed #121268, feel free to reassign)
2024-03-30Require enum indices to be contiguousNadrieril-52/+8
2024-03-30Stop calling visitors VMichael Goulet-21/+32
2024-03-30bump tracing-tree to 0.3klensy-2/+2
Only change is https://github.com/davidbarsky/tracing-tree/pull/76 dedupes tracing-log dupes nu-ansi-term
2024-03-30Auto merge of #123230 - matthiaskrgr:rollup-4twuzj4, r=matthiaskrgrbors-73/+97
Rollup of 5 pull requests Successful merges: - #121573 (unix_sigpipe: Add test for SIGPIPE disposition in child processes) - #123170 (Replace regions in const canonical vars' types with `'static` in next-solver canonicalizer) - #123200 (KCFI: Require -C panic=abort) - #123201 (Improve wording in std::any explanation) - #123224 (compiletest: print reason for failing to read tests) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-30Rollup merge of #123200 - maurer:kcfi-abort, r=compiler-errorsMatthias Krüger-0/+11
KCFI: Require -C panic=abort While the KCFI scheme is not incompatible with unwinding, LLVM's `invoke` instruction does not currently support KCFI bundles. While it likely will in the near future, we won't be able to assume that in Rust for a while. We encountered this problem while [turning on closure support](https://github.com/rust-lang/rust/pull/123106#issuecomment-2027436640). r? ``@workingjubilee``
2024-03-30Rollup merge of #123170 - compiler-errors:const-statics, r=lcnrMatthias Krüger-73/+86
Replace regions in const canonical vars' types with `'static` in next-solver canonicalizer We shouldn't ever have non-static regions in consts on stable (or really any regions at all, lol). The test I committed is less minimal than, e.g., https://github.com/rust-lang/rust/issues/123155?notification_referrer_id=NT_kwDOADgQyrMxMDAzNDU4MDI0OTozNjc0MzE0#issuecomment-2025472029 -- however, I believe that it actually portrays the underlying issue here a bit better than that one. In the linked issue, we end up emitting a normalizes-to predicate for a const placeholder because we don't actually unify `false` and `""`. In the test I committed, we emit a normalizes-to predicate as a part of actually solving a negative coherence goal. Fixes #123155 Fixes #118783 r? lcnr
2024-03-30Auto merge of #123214 - compiler-errors:subst, r=estebankbors-129/+87
Assert that ADTs have the right number of args We're doing it for many other types, let's also do ADTs 😇
2024-03-30Auto merge of #123202 - estebank:issue-123009, r=compiler-errorsbors-10/+3
Do not attempt to write `ty::Err` on binding that isn't from current HIR Owner Fix #123009. Follow up to #122119.
2024-03-30Auto merge of #123012 - maurer:cfi-supertraits, r=compiler-errorsbors-10/+14
CFI: Support calling methods on supertraits Automatically adjust `Virtual` calls to supertrait functions to use the supertrait's trait object type as the receiver rather than the child trait. cc `@compiler-errors` - this is the next usage of `trait_object_ty` I intend to have, so I thought it might be relevant while reviewing the existing one.
2024-03-29Stop doing so much to handle subdiagnosticsMichael Goulet-137/+69
2024-03-29Stop removing substs from Adt type in coherenceMichael Goulet-13/+32
2024-03-29Assert that ADTs have the right number of substsMichael Goulet-0/+7
2024-03-29stabilize ptr.is_aligned, move ptr.is_aligned_to to a new feature gateAria Beingessner-2/+2
This is an alternative to #121920
2024-03-29Add support for NonNull in ambiguous_wide_ptr_comparisionsUrgau-14/+43
2024-03-29Do not attempt to write `ty::Err` on binding that isn't from current HIR OwnerEsteban Küber-10/+3
Fix #123009.
2024-03-29Auto merge of #121268 - Urgau:improve_ambi_wide_ptr_cmps, r=Nadrierilbors-29/+50
Add detection of [Partial]Ord methods in the `ambiguous_wide_pointer_comparisons` lint Partially addresses https://github.com/rust-lang/rust/issues/121264 by adding diagnostics items for PartialOrd and Ord methods, detecting such diagnostics items as "binary operation" and suggesting the correct replacement. I also took the opportunity to change the suggestion to use new methods `.cast()` on `*mut T` an d `*const T`.
2024-03-29CFI: Encode Virtual calls as calls through the defining traitMatthew Maurer-10/+14
For example, if `trait Foo: Bar`, and we try to call a method from `Bar` on `dyn Foo`, encode the callsite as passing a `dyn Bar`, not a `dyn Foo`.
2024-03-29KCFI: Require -C panic=abortMatthew Maurer-0/+11
While the KCFI scheme is not incompatible with unwinding, LLVM's `invoke` instruction does not currently support KCFI bundles. While it likely will in the near future, we won't be able to assume that in Rust for a while.
2024-03-29Auto merge of #123194 - matthiaskrgr:rollup-vhdc8hw, r=matthiaskrgrbors-123/+117
Rollup of 4 pull requests Successful merges: - #123176 (Normalize the result of `Fields::ty_with_args`) - #123186 (copy any file from stage0/lib to stage0-sysroot/lib) - #123187 (Forward port 1.77.1 release notes) - #123188 (compiler: fix few unused_peekable and needless_pass_by_ref_mut clippy lints) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-29Add detection of [Partial]Ord methods to the ambiguous wide ptr cmp lintUrgau-29/+43
2024-03-29Add diagnostic items for Ord and PartialOrd methodsUrgau-0/+7