about summary refs log tree commit diff
path: root/compiler/rustc_monomorphize/src
AgeCommit message (Collapse)AuthorLines
2025-02-14Normalize closure instance before eagerly monomorphizing itMichael Goulet-0/+7
2025-02-09Auto merge of #136751 - bjorn3:update_rustfmt, r=Mark-Simulacrumbors-10/+7
Update bootstrap compiler and rustfmt The rustfmt version we previously used formats things differently from what the latest nightly rustfmt does. This causes issues for subtrees that get formatted both in-tree and in their own repo. Updating the rustfmt used in-tree solves those issues. Also bumped the bootstrap compiler as the stage0 update command always updates both at the same time.
2025-02-08Rollup merge of #136706 - workingjubilee:finish-up-rustc-abi-updates, ↵Jubilee-2/+2
r=compiler-errors compiler: mostly-finish `rustc_abi` updates This almost-finishes all the updates in the compiler to use `rustc_abi` and removes some of the reexports of `rustc_abi` items in `rustc_target` that were previously available. r? ```@compiler-errors```
2025-02-08Rustfmtbjorn3-10/+7
2025-02-07compiler: remove rustc_target::abi entirelyJubilee Young-2/+2
2025-02-07Remove Linkage::Appendingbjorn3-1/+0
It can only be used for certain LLVM internal variables like llvm.global_ctors which users are not allowed to define.
2025-02-07Remove Linkage::Privatebjorn3-1/+0
This is the same as Linkage::Internal except that it doesn't emit any symbol. Some backends may not support it and it isn't all that useful anyway.
2025-02-03Auto merge of #136481 - jieyouxu:rollup-w0lnnqb, r=jieyouxubors-2/+2
Rollup of 8 pull requests Successful merges: - #136356 (Docs for f16 and f128: correct a typo and add details) - #136404 (Remove a footgun-y feature / relic of the past from the compiletest DSL) - #136432 (LTA: Actually check where-clauses for well-formedness at the def site) - #136438 (miri: improve error when offset_from preconditions are violated) - #136441 ([`compiletest`-related cleanups 1/7] Cleanup `is_rustdoc` logic and remove a useless path join in rustdoc-json runtest logic) - #136455 (Remove some `Clone` bounds and derives.) - #136464 (Remove hook calling via `TyCtxtAt`.) - #136467 (override default config profile on tarballs) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-03Rollup merge of #136464 - nnethercote:rm-TyCtxtAt-for-hooks, r=oli-obk许杰友 Jieyou Xu (Joe)-2/+2
Remove hook calling via `TyCtxtAt`. All hooks receive a `TyCtxtAt` argument. Currently hooks can be called through `TyCtxtAt` or `TyCtxt`. In the latter case, a `TyCtxtAt` is constructed with a dummy span and passed to the hook. However, in practice hooks are never called through `TyCtxtAt`, and always receive a dummy span. (I confirmed this via code inspection, and double-checked it by temporarily making the `TyCtxtAt` code path panic and running all the tests.) This commit removes all the `TyCtxtAt` machinery for hooks. All hooks now receive `TyCtxt` instead of `TyCtxtAt`. There are two existing hooks that use `TyCtxtAt::span`: `const_caller_location_provider` and `try_destructure_mir_constant_for_user_output`. For both hooks the span is always a dummy span, probably unintentionally. This dummy span use is now explicit. If a non-dummy span is needed for these two hooks it would be easy to add it as an extra argument because hooks are less constrained than queries. r? `@oli-obk`
2025-02-03Auto merge of #136413 - EnzymeAD:fix-autodiff-comptime-regression, r=oli-obkbors-9/+9
fix autodiff compile time regression Tries to fix the regression from https://github.com/rust-lang/rust/pull/133429 Tracking: - https://github.com/rust-lang/rust/issues/124509
2025-02-03Remove hook calling via `TyCtxtAt`.Nicholas Nethercote-2/+2
All hooks receive a `TyCtxtAt` argument. Currently hooks can be called through `TyCtxtAt` or `TyCtxt`. In the latter case, a `TyCtxtAt` is constructed with a dummy span and passed to the hook. However, in practice hooks are never called through `TyCtxtAt`, and always receive a dummy span. (I confirmed this via code inspection, and double-checked it by temporarily making the `TyCtxtAt` code path panic and running all the tests.) This commit removes all the `TyCtxtAt` machinery for hooks. All hooks now receive `TyCtxt` instead of `TyCtxtAt`. There are two existing hooks that use `TyCtxtAt::span`: `const_caller_location_provider` and `try_destructure_mir_constant_for_user_output`. For both hooks the span is always a dummy span, probably unintentionally. This dummy span use is now explicit. If a non-dummy span is needed for these two hooks it would be easy to add it as an extra argument because hooks are less constrained than queries.
2025-02-02run less code if cfg(llvm_enzyme) isn't usedManuel Drehwald-0/+4
2025-02-01test compile time fixesManuel Drehwald-9/+5
2025-02-01Rename `tcx.ensure()` to `tcx.ensure_ok()`Zalathar-1/+1
2025-01-31Auto merge of #134424 - 1c3t3a:null-checks, r=saethlinbors-0/+3
Insert null checks for pointer dereferences when debug assertions are enabled Similar to how the alignment is already checked, this adds a check for null pointer dereferences in debug mode. It is implemented similarly to the alignment check as a `MirPass`. This inserts checks in the same places as the `CheckAlignment` pass and additionally also inserts checks for `Borrows`, so code like ```rust let ptr: *const u32 = std::ptr::null(); let val: &u32 = unsafe { &*ptr }; ``` will have a check inserted on dereference. This is done because null references are UB. The alignment check doesn't cover these places, because in `&(*ptr).field`, the exact requirement is that the final reference must be aligned. This is something to consider further enhancements of the alignment check. For now this is implemented as a separate `MirPass`, to make it easy to disable this check if necessary. This is related to a 2025H1 project goal for better UB checks in debug mode: https://github.com/rust-lang/rust-project-goals/pull/177. r? `@saethlin`
2025-01-31Insert null checks for pointer dereferences when debug assertions are enabledBastian Kersting-0/+3
Similar to how the alignment is already checked, this adds a check for null pointer dereferences in debug mode. It is implemented similarly to the alignment check as a MirPass. This is related to a 2025H1 project goal for better UB checks in debug mode: https://github.com/rust-lang/rust-project-goals/pull/177.
2025-01-31Auto merge of #136332 - jhpratt:rollup-aa69d0e, r=jhprattbors-3/+152
Rollup of 9 pull requests Successful merges: - #132156 (When encountering unexpected closure return type, point at return type/expression) - #133429 (Autodiff Upstreaming - rustc_codegen_ssa, rustc_middle) - #136281 (`rustc_hir_analysis` cleanups) - #136297 (Fix a typo in profile-guided-optimization.md) - #136300 (atomic: extend compare_and_swap migration docs) - #136310 (normalize `*.long-type.txt` paths for compare-mode tests) - #136312 (Disable `overflow_delimited_expr` in edition 2024) - #136313 (Filter out RPITITs when suggesting unconstrained assoc type on too many generics) - #136323 (Fix a typo in conventions.md) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-31Rollup merge of #133429 - EnzymeAD:autodiff-middle, r=oli-obkJacob Pratt-3/+152
Autodiff Upstreaming - rustc_codegen_ssa, rustc_middle This PR should not be merged until the rustc_codegen_llvm part is merged. I will also alter it a little based on what get's shaved off from the cg_llvm PR, and address some of the feedback I received in the other PR (including cleanups). I am putting it already up to 1) Discuss with `@jieyouxu` if there is more work needed to add tests to this and 2) Pray that there is someone reviewing who can tell me why some of my autodiff invocations get lost. Re 1: My test require fat-lto. I also modify the compilation pipeline. So if there are any other llvm-ir tests in the same compilation unit then I will likely break them. Luckily there are two groups who currently have the same fat-lto requirement for their GPU code which I have for my autodiff code and both groups have some plans to enable support for thin-lto. Once either that work pans out, I'll copy it over for this feature. I will also work on not changing the optimization pipeline for functions not differentiated, but that will require some thoughts and engineering, so I think it would be good to be able to run the autodiff tests isolated from the rest for now. Can you guide me here please? For context, here are some of my tests in the samples folder: https://github.com/EnzymeAD/rustbook Re 2: This is a pretty serious issue, since it effectively prevents publishing libraries making use of autodiff: https://github.com/EnzymeAD/rust/issues/173. For some reason my dummy code persists till the end, so the code which calls autodiff, deletes the dummy, and inserts the code to compute the derivative never gets executed. To me it looks like the rustc_autodiff attribute just get's dropped, but I don't know WHY? Any help would be super appreciated, as rustc queries look a bit voodoo to me. Tracking: - https://github.com/rust-lang/rust/issues/124509 r? `@jieyouxu`
2025-01-30Do not treat vtable supertraits as distinct when bound with different bound varsMichael Goulet-4/+10
2025-01-29upstream rustc_codegen_ssa/rustc_middle changes for enzyme/autodiffManuel Drehwald-3/+152
2025-01-29Rollup merge of #136168 - fmease:gci-fix-mono, r=compiler-errorsLeón Orell Valerian Liehr-4/+7
GCI: Don't try to eval / collect mono items inside overly generic free const items Fixes #136156. Thanks for the pointers, errs! There's one (preexisting) thing of note (maybe?). There's a difference between `const _: () = panic!();` and `const _<'a>: () = panic!();`: The former is a pre-mono error, the latter is a post-mono error. For comparison, both `fn _f() { const { panic!() } }` and `fn _f<'a: 'a>() { const { panic!() } }` are post-mono errors. cc `@oli-obk` r? compiler-errors or reassign
2025-01-28GCI: Don't try to collect mono items inside overly generic free const itemsLeón Orell Valerian Liehr-4/+7
2025-01-27Change `collect_and_partition_mono_items` tuple return type to a structOli Scherer-9/+8
2025-01-15Make sure we actually use the right trivial lifetime substs when eagerly ↵Michael Goulet-4/+18
monomorphizing drop for structs
2025-01-14Auto merge of #135313 - compiler-errors:needs-mono, r=BoxyUwUbors-2/+5
Eagerly mono drop for structs with lifetimes That is, use `!generics.requires_monomorphization()` rather than `generics.is_empty()` like the rest of the mono collector code.
2025-01-11Rollup merge of #135314 - compiler-errors:eagerly-mono-closures, r=wesleywiserMatthias Krüger-0/+31
Eagerly collect mono items for non-generic closures This allows users to use `-Zprint-mono-items=eager` to eagerly monomorphize closures and coroutine bodies, in case they want to inspect the LLVM or ASM for those items. `-Zprint-mono-items`, which used to be called `-Zprint-trans-items`, was originally added in https://github.com/rust-lang/rust/pull/30900: > Eager mode is meant to be used in conjunction with incremental compilation > where a stable set of translation items is more important than a minimal > one. Thus, eager mode will instantiate drop-glue for every drop-able type > in the crate, even of no drop call for that type exists (yet). It will > also instantiate default implementations of trait methods, something that > otherwise is only done on demand. Although it remains an unstable option, its purpose has somewhat expanded since then, and as far as I can tell it's generally useful for cases when you want to monomorphize as many items as possible, even if they're unreachable. Specifically, it's useful for debugging since you can look at the codegen'd body of a function, since we don't emit items that are not reachable in monomorphization. And even more specifically, it would be very to monomorphize the coroutine body of an async fn, since those you can't easily call those without a runtime. This PR enables this usecase since we now monomorphize `DefKind::Closure`.
2025-01-10don't collect `#[rustc_force_inline]` in eager modeDavid Wood-4/+6
2025-01-10mir_transform: implement forced inliningDavid Wood-0/+9
Adds `#[rustc_force_inline]` which is similar to always inlining but reports an error if the inlining was not possible, and which always attempts to inline annotated items, regardless of optimisation levels. It can only be applied to free functions to guarantee that the MIR inliner will be able to resolve calls.
2025-01-10Eagerly collect mono items for non-generic closuresMichael Goulet-0/+31
2025-01-10Eagerly mono drop for structs with lifetimesMichael Goulet-2/+5
2025-01-04rustc_intrinsic: support functions without body; they are implicitly marked ↵Ralf Jung-9/+9
as must-be-overridden
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-5/+3
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-16rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structuresJonathan Dönszelmann-2/+3
2024-12-10Implement projection and shim for AFIDTMichael Goulet-1/+4
2024-12-06Remove polymorphizationBen Kimock-378/+10
2024-11-28Share inline(never) generics across cratesMark Rousskov-8/+24
This reduces code sizes and better respects programmer intent when marking inline(never). Previously such a marking was essentially ignored for generic functions, as we'd still inline them in remote crates.
2024-11-23remove remaining references to `Reveal`lcnr-1/+1
2024-11-19move `fn is_item_raw` to `TypingEnv`lcnr-1/+1
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-34/+54
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-17Rollup merge of #133029 - veluca93:abi-checks-tier3, r=workingjubilee许杰友 Jieyou Xu (Joe)-3/+1
ABI checks: add support for some tier3 arches, warn on others. Followup to - https://github.com/rust-lang/rust/pull/132842 - https://github.com/rust-lang/rust/pull/132173 - https://github.com/rust-lang/rust/issues/131800 r? ``@workingjubilee``
2024-11-17Auto merge of #132566 - saethlin:querify-mir-collection, r=cjgillotbors-50/+100
Querify MonoItem collection Factored out of https://github.com/rust-lang/rust/pull/131650. These changes are required for post-mono MIR opts, because the previous implementation would load the MIR for every Instance that we traverse (as well as invoke queries on it). The cost of that would grow massively with post-mono MIR opts because we'll need to load new MIR for every Instance, instead of re-using the `optimized_mir` for every Instance with the same DefId. So the approach here is to add two new queries, `items_of_instance` and `size_estimate`, which contain the specific information about an Instance's MIR that MirUsedCollector and CGU partitioning need, respectively. Caching these significantly increases the size of the query cache, but that's justified by our improved incrementality (I'm sure walking all the MIR for a huge crate scales quite poorly). This also changes `MonoItems` into a type that will retain the traversal order (otherwise we perturb a bunch of diagnostics), and will also eliminate duplicate findings. Eliminating duplicates removes about a quarter of the query cache size growth. The perf improvements in this PR are inflated because rustc-perf uses `-Zincremental-verify-ich`, which makes loading MIR a lot slower because MIR contains a lot of Spans and computing the stable hash of a Span is slow. And the primary goal of this PR is to load less MIR. Some squinting at `collector profile_local perf-record +stage1` runs suggests the magnitude of the improvements in this PR would be decreased by between a third and a half if that flag weren't being used. Though this effect may apply to the regressions too since most are incr-full and this change also causes such builds to encode more Spans.
2024-11-14ABI checks: add support for some tier3 arches, warn on others.Luca Versari-3/+1
2024-11-12ABI checks: add support for tier2 archesLuca Versari-16/+55
See #131800 for the data collection behind this change. Also adds a test that exercise the "empty list of features" path.
2024-11-12Querify MonoItem collectionBen Kimock-50/+100
2024-11-10move all mono-time checks into their own folder, and their own queryRalf Jung-101/+124
2024-11-10Auto merge of #132173 - veluca93:abi_checks, r=RalfJung,compiler-errorsbors-0/+184
Emit warning when calling/declaring functions with unavailable vectors. On some architectures, vector types may have a different ABI depending on whether the relevant target features are enabled. (The ABI when the feature is disabled is often not specified, but LLVM implements some de-facto ABI.) As discussed in rust-lang/lang-team#235, this turns out to very easily lead to unsound code. This commit makes it a post-monomorphization future-incompat warning to declare or call functions using those vector types in a context in which the corresponding target features are disabled, if using an ABI for which the difference is relevant. This ensures that these functions are always called with a consistent ABI. See the [nomination comment](https://github.com/rust-lang/rust/pull/127731#issuecomment-2288558187) for more discussion. Part of #116558 r? RalfJung
2024-11-02compiler: Add rustc_abi to _monomorphizeJubilee Young-1/+1
2024-11-01Emit warning when calling/declaring functions with unavailable vectors.Luca Versari-0/+184
On some architectures, vector types may have a different ABI depending on whether the relevant target features are enabled. (The ABI when the feature is disabled is often not specified, but LLVM implements some de-facto ABI.) As discussed in rust-lang/lang-team#235, this turns out to very easily lead to unsound code. This commit makes it a post-monomorphization future-incompat warning to declare or call functions using those vector types in a context in which the corresponding target features are disabled, if using an ABI for which the difference is relevant. This ensures that these functions are always called with a consistent ABI. See the [nomination comment](https://github.com/rust-lang/rust/pull/127731#issuecomment-2288558187) for more discussion. Part of #116558
2024-10-26Auto merge of #132171 - matthiaskrgr:rollup-tp75ge7, r=matthiaskrgrbors-3/+3
Rollup of 3 pull requests Successful merges: - #132114 (Use `Enabled{Lang,Lib}Feature` instead of n-tuples) - #132163 (Update Fuchsia CI script for package serving) - #132168 (Effects cleanup) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-26Effects cleanupDeadbeef-3/+3
- removed extra bits from predicates queries that are no longer needed in the new system - removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers