about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
AgeCommit message (Collapse)AuthorLines
2024-11-12Rollup merge of #132541 - RalfJung:const-stable-extern-crate, r=compiler-errorsMatthias Krüger-96/+103
Proper support for cross-crate recursive const stability checks ~~Stacked on top of https://github.com/rust-lang/rust/pull/132492; only the last three commits are new.~~ In a crate without `staged_api` but with `-Zforce-unstable-if-unmarked`, we now subject all functions marked with `#[rustc_const_stable_indirect]` to recursive const stability checks. We require an opt-in so that by default, a crate can be built with `-Zforce-unstable-if-unmarked` and use nightly features as usual. This property is recorded in the crate metadata so when a `staged_api` crate calls such a function, it sees the `#[rustc_const_stable_indirect]` and allows it to be exposed on stable. This, finally, will let us expose `const fn` from hashbrown on stable. The second commit makes const stability more like regular stability: via `check_missing_const_stability`, we ensure that all publicly reachable functions have a const stability attribute -- both in `staged_api` crates and `-Zforce-unstable-if-unmarked` crates. To achieve this, we move around the stability computation so that const stability is computed after regular stability is done. This lets us access the final result of the regular stability computation, which we use so that `const fn` can inherit the regular stability (but only if that is "unstable"). Fortunately, this lets us get rid of an `Option` in `ConstStability`. This is the last PR that I have planned in this series. r? `@compiler-errors`
2024-11-11Add #[rustc_as_ptr] attributegavincrawford-0/+3
2024-11-11Auto merge of #127589 - notriddle:notriddle/search-sem-3, r=GuillaumeGomezbors-2/+32
rustdoc-search: simplify rules for generics and type params **Heads up!**: This PR is a follow-up that depends on #124544. It adds 12dc24f46007f82b93ed85614347a42d47580afa, a change to the filtering behavior, and 9900ea48b566656fb12b5fcbd0a1b20aaa96e5ca, a minor ranking tweak. Part of https://github.com/rust-lang/rust-project-goals/issues/112 This PR overturns https://github.com/rust-lang/rust/pull/109802 ## Preview * no results: [`Box<[A]> -> Vec<B>`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3/std/index.html?search=Box%3C%5BA%5D%3E%20-%3E%20Vec%3CB%3E) * results: [`Box<[A]> -> Vec<A>`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3/std/index.html?search=Box%3C%5BA%5D%3E%20-%3E%20Vec%3CA%3E) * [`T -> U`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3/std/index.html?search=T%20-%3E%20U) * [`Cx -> TyCtxt`](http://notriddle.com/rustdoc-html-demo-12/search-sem-3-compiler/rustdoc/index.html?search=Cx%20-%3E%20TyCtxt) ![image](https://github.com/user-attachments/assets/015ae28c-7469-4f7f-be03-157d28d7ec97) ## Description This commit is a response to feedback on the displayed type signatures results, by making generics act stricter. - Order within generics is significant. This means `Vec<Allocator>` now matches only with a true vector of allocators, instead of matching the second type param. It also makes unboxing within generics stricter, so `Result<A, B>` only matches if `B` is in the error type and `A` is in the success type. The top level of the function search is unaffected. - Generics are only "unboxed" if a type is explicitly opted into it. References and tuples are hardcoded to allow unboxing, and Box, Rc, Arc, Option, Result, and Future are opted in with an unstable attribute. Search result unboxing is the process that allows you to search for `i32 -> str` and get back a function with the type signature `&Future<i32> -> Box<str>`. - Instead of ranking by set overlap, it ranks by the number of items in the type signature. This makes it easier to find single type signatures like transmute. ## Find the discussion on * <https://rust-lang.zulipchat.com/#narrow/stream/393423-t-rustdoc.2Fmeetings/topic/meeting.202024-07-08/near/449965149> * <https://github.com/rust-lang/rust/pull/124544#issuecomment-2204272265> * <https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/deciding.20on.20semantics.20of.20generics.20in.20rustdoc.20search>
2024-11-10ensure that all publicly reachable const fn have const stability infoRalf Jung-96/+98
2024-11-10honor rustc_const_stable_indirect in non-staged_api crate with ↵Ralf Jung-0/+5
-Zforce-unstable-if-unmarked
2024-11-08remove support for rustc_safe_intrinsic attribute; use rustc_intrinsic ↵Ralf Jung-31/+0
functions instead
2024-11-04remove support for extern-block const intrinsicsRalf Jung-15/+0
2024-11-03Rollup merge of #132576 - jdonszelmann:no-attrid-in-stats, r=nnethercoteJubilee-80/+76
remove attribute ids from hir stats (they're simply not needed) Turns out these are simply not needed. Yay! r? `@nnethercote`
2024-11-03remove attribute ids from hir stats (they're simply not needed)Jonathan Dönszelmann-80/+76
2024-11-03Rename the FIXMEs, remove a few that dont matter anymoreMichael Goulet-1/+1
2024-11-02Allow disabling ASan instrumentation for globalsDaniel Bertalan-3/+45
AddressSanitizer adds instrumentation to global variables unless the [`no_sanitize_address`](https://llvm.org/docs/LangRef.html#global-attributes) attribute is set on them. This commit extends the existing `#[no_sanitize(address)]` attribute to set this; previously it only had the desired effect on functions.
2024-10-30Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errorsJubilee-1/+5
Rename `rustc_abi::Abi` to `BackendRepr` Remove the confabulation of `rustc_abi::Abi` with what "ABI" actually means by renaming it to `BackendRepr`, and rename `Abi::Aggregate` to `BackendRepr::Memory`. The type never actually represented how things are passed, as that has to have `PassMode` considered, at minimum, but rather it just is how we represented some things to the backend. This conflation arose because LLVM, the primary backend at the time, would lower certain IR forms using certain ABIs. Even that only somewhat was true, as it broke down when one ventured significantly afield of what is described by the System V AMD64 ABI either by using different architectures, ABI-modifying IR annotations, the same architecture **with different ISA extensions enabled**, or other... unexpected delights. Unfortunately both names are still somewhat of a misnomer right now, as people have written code for years based on this misunderstanding. Still, their original names are even moreso, and for better or worse, this backend code hasn't received as much maintenance as the rest of the compiler, lately. Actually arriving at a correct end-state will simply require us to disentangle a lot of code in order to fix, much of it pointlessly repeated in several places. Thus this is not an "actual fix", just a way to deflect further misunderstandings.
2024-10-30rustdoc-search: simplify rules for generics and type paramsMichael Howell-2/+32
This commit is a response to feedback on the displayed type signatures results, by making generics act stricter. Generics are tightened by making order significant. This means `Vec<Allocator>` now matches only with a true vector of allocators, instead of matching the second type param. It also makes unboxing within generics stricter, so `Result<A, B>` only matches if `B` is in the error type and `A` is in the success type. The top level of the function search is unaffected. Find the discussion on: * <https://rust-lang.zulipchat.com/#narrow/stream/393423-t-rustdoc.2Fmeetings/topic/meeting.202024-07-08/near/449965149> * <https://github.com/rust-lang/rust/pull/124544#issuecomment-2204272265> * <https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/deciding.20on.20semantics.20of.20generics.20in.20rustdoc.20search/near/476841363>
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-1/+5
The initial naming of "Abi" was an awful mistake, conveying wrong ideas about how psABIs worked and even more about what the enum meant. It was only meant to represent the way the value would be described to a codegen backend as it was lowered to that intermediate representation. It was never meant to mean anything about the actual psABI handling! The conflation is because LLVM typically will associate a certain form with a certain ABI, but even that does not hold when the special cases that actually exist arise, plus the IR annotations that modify the ABI. Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename `BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to the persistent misunderstandings, this too is now incorrect: - Scattered ABI-relevant code is entangled with BackendRepr - We do not always pre-compute a correct BackendRepr that reflects how we "actually" want this value to be handled, so we leave the backend interface to also inject various special-cases here - In some cases `BackendRepr::Memory` is a "real" aggregate, but in others it is in fact using memory, and in some cases it is a scalar! Our rustc-to-backend lowering code handles this sort of thing right now. That will eventually be addressed by lifting duplicated lowering code to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-29TypingMode :thinking:lcnr-3/+4
2024-10-29Auto merge of #132277 - workingjubilee:rollup-5e6q6e4, r=workingjubileebors-2/+2
Rollup of 9 pull requests Successful merges: - #130259 (Lower AST node id only once) - #131441 (Add a new trait `proc_macro::ToTokens`) - #132247 (stable_mir: Directly use types from rustc_abi) - #132249 (compiler: Add rustc_abi dependence to the compiler) - #132255 (Add `LayoutData::is_uninhabited` and use it) - #132258 ([rustdoc] Unify variant struct fields margins with struct fields) - #132260 (cg_llvm: Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`) - #132261 (refactor: cleaner check to return None) - #132271 (Updating Fuchsia platform-support documentation) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-28Rollup merge of #132249 - workingjubilee:add-rustc-abi, r=compiler-errorsJubilee-2/+2
compiler: Add rustc_abi dependence to the compiler Depend on rustc_abi in compiler crates that use it indirectly but have not yet taken on that dependency, and are not *significantly* entangled in my other PRs. This leaves an "excise rustc_target" step after the dust settles.
2024-10-28Auto merge of #132145 - RalfJung:stdarch, r=Amanieubors-3/+0
bump stdarch This lets us remove a hack from https://github.com/rust-lang/rust/pull/131349. r? `@Amanieu` try-job: test-various
2024-10-28we can now enable the 'const stable fn must be stable' checkRalf Jung-3/+0
2024-10-28Error on alignments greater than `isize::MAX`asquared31415-1/+52
Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
2024-10-27compiler: Add rustc_abi dependence to the compilerJubilee Young-2/+2
Depend on rustc_abi in compiler crates that use it indirectly but have not yet taken on that dependency, and are not entangled in my other PRs. This leaves an "excise rustc_target" step after the dust settles.
2024-10-27Auto merge of #131284 - ↵bors-1/+1
dingxiangfei2009:rename-smart-ptr-to-coerce-referent, r=compiler-errors Rename macro `SmartPointer` to `CoercePointee` As per resolution #129104 we will rename the macro to better reflect the technical specification of the feature and clarify the communication. - `SmartPointer` is renamed to `CoerceReferent` - `#[pointee]` attribute is renamed to `#[referent]` - `#![feature(derive_smart_pointer)]` gate is renamed to `#![feature(derive_coerce_referent)]`. - Any mention of `SmartPointer` in the file names are renamed accordingly. r? `@compiler-errors` cc `@nikomatsakis` `@Darksonn`
2024-10-26Rollup merge of #132114 - jieyouxu:features-bundle, r=fee1-deadMatthias Krüger-12/+12
Use `Enabled{Lang,Lib}Feature` instead of n-tuples Instead of passing around e.g. `(gate_name, attr_span, stable_since)` 3-tuples for enabled lang features or `(gate_name, attr_span)` 2-tuples for enabled lib features, use `Enabled{Lang,Lib}Feature` structs with named fields. Also did some minor code-golfing of involved iterator chains to hopefully make them easier to follow. Follow-up to https://github.com/rust-lang/rust/pull/132098#issuecomment-2434523431 cc `@RalfJung.`
2024-10-25tcx.is_const_fn doesn't work the way it is described, remove itRalf Jung-5/+5
Then we can rename the _raw functions to drop their suffix, and instead explicitly use is_stable_const_fn for the few cases where that is really what you want.
2024-10-25add a HACK to allow stdarch migrationRalf Jung-0/+3
2024-10-25Re-do recursive const stability checksRalf Jung-32/+94
Fundamentally, we have *three* disjoint categories of functions: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, several holes in recursive const stability checking are being closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to *not* be `rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required.
2024-10-25Introduce `Enabled{Lang,Lib}Feature`许杰友 Jieyou Xu (Joe)-12/+12
Instead of passing around random n-tuples of e.g. `(gate_name, attr_sp, since)`.
2024-10-24rustdoc: Extend fake_variadic to "wrapped" tuplesTau Gärtli-6/+18
This allows impls such as `impl QueryData for OneOf<(T,)>` to be displayed as variadic: `impl QueryData for OneOf<(T₁, T₂, …, Tₙ)>`. See question on zulip: <https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Make.20.60.23.5Bdoc.28fake_variadic.29.5D.60.20more.20useful>
2024-10-24Plumb through param_env to note_type_errMichael Goulet-2/+2
2024-10-24s/SmartPointer/CoerceReferent/gDing Xiang Fei-1/+1
move derive_smart_pointer into removed set
2024-10-23rename lang feature lists to include LANGRalf Jung-3/+3
2024-10-23nightly feature tracking: get rid of the per-feature bool fieldsRalf Jung-11/+11
2024-10-22Auto merge of #132035 - matthiaskrgr:rollup-ty1e4q0, r=matthiaskrgrbors-10/+39
Rollup of 8 pull requests Successful merges: - #125205 (Fixup Windows verbatim paths when used with the `include!` macro) - #131049 (Validate args are correct for `UnevaluatedConst`, `ExistentialTraitRef`/`ExistentialProjection`) - #131549 (Add a note for `?` on a `impl Future<Output = Result<..>>` in sync function) - #131731 (add `TestFloatParse` to `tools.rs` for bootstrap) - #131732 (Add doc(plugins), doc(passes), etc. to INVALID_DOC_ATTRIBUTES) - #132006 (don't stage-off to previous compiler when CI rustc is available) - #132022 (Move `cmp_in_dominator_order` out of graph dominator computation) - #132033 (compiletest: Make `line_directive` return a `DirectiveLine`) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-22Rollup merge of #131732 - m4tx:fix-82824, r=davidtwcoMatthias Krüger-9/+38
Add doc(plugins), doc(passes), etc. to INVALID_DOC_ATTRIBUTES This fixes #82824.
2024-10-22Rollup merge of #131049 - compiler-errors:more-validation, r=spastorinoMatthias Krüger-1/+1
Validate args are correct for `UnevaluatedConst`, `ExistentialTraitRef`/`ExistentialProjection` For the `Existential*` ones, we have to do some adjustment to the args list to deal with the missing `Self` type, so we introduce a `debug_assert_existential_args_compatible` function to the interner as well.
2024-10-22make some rustc_feature internals private, and ensure invariants with debug ↵Ralf Jung-2/+2
assertions
2024-10-22terminology: #[feature] *enables* a feature (instead of "declaring" or ↵Ralf Jung-8/+8
"activating" it)
2024-10-20Auto merge of #131980 - matthiaskrgr:rollup-iy5nw71, r=matthiaskrgrbors-20/+22
Rollup of 5 pull requests Successful merges: - #131814 (`optimize` attribute applied to things other than methods/functions/c…) - #131927 (Check for filecheck directives in files marked `skip-filecheck`) - #131967 (Remove `lower_mono_bounds`) - #131973 (fix(rustdoc-json-types): document rustc-hash feature) - #131976 (feat(rustdoc-json-types): mark simple enums as copy) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-20misapplied optimize attribute throws a compilation error (#128488)ash-20/+22
2024-10-20Stop relying on hashmap iteration for hir stat printingNoratrieb-1/+3
Just because the code says it's OK does not mean that it actually is OK. Nodes with the same total size were not sorted, their order relied on hashmap iteration.
2024-10-15Unify secondary_span and swap_secondary_and_primaryMichael Goulet-1/+0
2024-10-15Add doc(plugins), doc(passes), etc. to INVALID_DOC_ATTRIBUTESMateusz Maćkowski-9/+38
2024-10-15Auto merge of #131724 - matthiaskrgr:rollup-ntgkkk8, r=matthiaskrgrbors-0/+1
Rollup of 7 pull requests Successful merges: - #130608 (Implemented `FromStr` for `CString` and `TryFrom<CString>` for `String`) - #130635 (Add `&pin (mut|const) T` type position sugar) - #130747 (improve error messages for `C-cmse-nonsecure-entry` functions) - #131137 (Add 1.82 release notes) - #131328 (Remove unnecessary sorts in `rustc_hir_analysis`) - #131496 (Stabilise `const_make_ascii`.) - #131706 (Fix two const-hacks) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-15Rollup merge of #130635 - eholk:pin-reborrow-sugar, r=compiler-errorsMatthias Krüger-0/+1
Add `&pin (mut|const) T` type position sugar This adds parser support for `&pin mut T` and `&pin const T` references. These are desugared to `Pin<&mut T>` and `Pin<&T>` in the AST lowering phases. This PR currently includes #130526 since that one is in the commit queue. Only the most recent commits (bd450027eb4a94b814a7dd9c0fa29102e6361149 and following) are new. Tracking: - #130494 r? `@compiler-errors`
2024-10-15Auto merge of #129458 - EnzymeAD:enzyme-frontend, r=jieyouxubors-0/+23
Autodiff Upstreaming - enzyme frontend This is an upstream PR for the `autodiff` rustc_builtin_macro that is part of the autodiff feature. For the full implementation, see: https://github.com/rust-lang/rust/pull/129175 **Content:** It contains a new `#[autodiff(<args>)]` rustc_builtin_macro, as well as a `#[rustc_autodiff]` builtin attribute. The autodiff macro is applied on function `f` and will expand to a second function `df` (name given by user). It will add a dummy body to `df` to make sure it type-checks. The body will later be replaced by enzyme on llvm-ir level, we therefore don't really care about the content. Most of the changes (700 from 1.2k) are in `compiler/rustc_builtin_macros/src/autodiff.rs`, which expand the macro. Nothing except expansion is implemented for now. I have a fallback implementation for relevant functions in case that rustc should be build without autodiff support. The default for now will be off, although we want to flip it later (once everything landed) to on for nightly. For the sake of CI, I have flipped the defaults, I'll revert this before merging. **Dummy function Body:** The first line is an `inline_asm` nop to make inlining less likely (I have additional checks to prevent this in the middle end of rustc. If `f` gets inlined too early, we can't pass it to enzyme and thus can't differentiate it. If `df` gets inlined too early, the call site will just compute this dummy code instead of the derivatives, a correctness issue. The following black_box lines make sure that none of the input arguments is getting optimized away before we replace the body. **Motivation:** The user facing autodiff macro can verify the user input. Then I write it as args to the rustc_attribute, so from here on I can know that these values should be sensible. A rustc_attribute also turned out to be quite nice to attach this information to the corresponding function and carry it till the backend. This is also just an experiment, I expect to adjust the user facing autodiff macro based on user feedback, to improve usability. As a simple example of what this will do, we can see this expansion: From: ``` #[autodiff(df, Reverse, Duplicated, Const, Active)] pub fn f1(x: &[f64], y: f64) -> f64 { unimplemented!() } ``` to ``` #[rustc_autodiff] #[inline(never)] pub fn f1(x: &[f64], y: f64) -> f64 { ::core::panicking::panic("not implemented") } #[rustc_autodiff(Reverse, Duplicated, Const, Active,)] #[inline(never)] pub fn df(x: &[f64], dx: &mut [f64], y: f64, dret: f64) -> f64 { unsafe { asm!("NOP"); }; ::core::hint::black_box(f1(x, y)); ::core::hint::black_box((dx, dret)); ::core::hint::black_box(f1(x, y)) } ``` I will add a few more tests once I figured out why rustc rebuilds every time I touch a test. Tracking: - https://github.com/rust-lang/rust/issues/124509 try-job: dist-x86_64-msvc
2024-10-12Rollup merge of #131567 - ↵Matthias Krüger-0/+27
CastilloDel:reject-unstable-with-accepted-features, r=jieyouxu Emit an error for unstable attributes that reference already stable features Closes https://github.com/rust-lang/rust/issues/129814
2024-10-12Emit an error for unstable attributes that reference already stable featuresCastilloDel-0/+27
Add missing error annotations and .stderr file Acknowledge comments
2024-10-11Single commit implementing the enzyme/autodiff frontendManuel Drehwald-0/+23
Co-authored-by: Lorenz Schmidt <bytesnake@mailbox.org>
2024-10-11Auto merge of #131045 - compiler-errors:remove-unnamed_fields, r=wesleywiserbors-2/+0
Retire the `unnamed_fields` feature for now `#![feature(unnamed_fields)]` was implemented in part in #115131 and #115367, however work on that feature has (afaict) stalled and in the mean time there have been some concerns raised (e.g.[^1][^2]) about whether `unnamed_fields` is worthwhile to have in the language, especially in its current desugaring. Because it represents a compiler implementation burden including a new kind of anonymous ADT and additional complication to field selection, and is quite prone to bugs today, I'm choosing to remove the feature. However, since I'm not one to really write a bunch of words, I'm specifically *not* going to de-RFC this feature. This PR essentially *rolls back* the state of this feature to "RFC accepted but not yet implemented"; however if anyone wants to formally unapprove the RFC from the t-lang side, then please be my guest. I'm just not totally willing to summarize the various language-facing reasons for why this feature is or is not worthwhile, since I'm coming from the compiler side mostly. Fixes #117942 Fixes #121161 Fixes #121263 Fixes #121299 Fixes #121722 Fixes #121799 Fixes #126969 Fixes #131041 Tracking: * https://github.com/rust-lang/rust/issues/49804 [^1]: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Unnamed.20struct.2Funion.20fields [^2]: https://github.com/rust-lang/rust/issues/49804#issuecomment-1972619108
2024-10-07Fix clippy and rustfmt compilationEric Holk-27/+24