summary refs log tree commit diff
path: root/src/librustc_mir/monomorphize
AgeCommit message (Collapse)AuthorLines
2020-07-10Change how compiler-builtins gets many CGUsAlex Crichton-8/+1
This commit intends to fix an accidental regression from #70846. The goal of #70846 was to build compiler-builtins with a maximal number of CGUs to ensure that each module in the source corresponds to an object file. This high degree of control for compiler-builtins is desirable to ensure that there's at most one exported symbol per CGU, ideally enabling compiler-builtins to not conflict with the system libgcc as often. In #70846, however, only part of the compiler understands that compiler-builtins is built with many CGUs. The rest of the compiler thinks it's building with `sess.codegen_units()`. Notably the calculation of `sess.lto()` consults `sess.codegen_units()`, which when there's only one CGU it disables ThinLTO. This means that compiler-builtins is built without ThinLTO, which is quite harmful to performance! This is the root of the cause from #73135 where intrinsics were found to not be inlining trivial functions. The fix applied in this commit is to remove the special-casing of compiler-builtins in the compiler. Instead the build system is now responsible for special-casing compiler-builtins. It doesn't know exactly how many CGUs will be needed but it passes a large number that is assumed to be much greater than the number of source-level modules needed. After reading the various locations in the compiler source, this seemed like the best solution rather than adding more and more special casing in the compiler for compiler-builtins. Closes #73135
2020-06-26Fix link error with #[thread_local] introduced by #71192Amanieu d'Antras-0/+8
2020-06-01Auto merge of #71192 - oli-obk:eager_alloc_id_canonicalization, r=wesleywiserbors-0/+1
Make TLS accesses explicit in MIR r? @rust-lang/wg-mir-opt cc @RalfJung @vakaras for miri thread locals cc @bjorn3 for cranelift fixes #70685
2020-05-30Rollup merge of #72540 - davidtwco:issue-67552-mono-collector-comparison, ↵Ralf Jung-2/+2
r=varkor mir: adjust conditional in recursion limit check Fixes #67552. This PR adjusts the condition used in the recursion limit check of the monomorphization collector, from `>` to `>=`. In #67552, the test case had infinite indirect recursion, repeating a handful of functions (from the perspective of the monomorphization collector): `rec` -> `identity` -> `Iterator::count` -> `Iterator::fold` -> `Iterator::next` -> `rec`. During this process, `resolve_associated_item` was invoked for `Iterator::fold` (during the construction of an `Instance`), and ICE'd due to substitutions needing inference. However, previous iterations of this recursion would have called this function for `Iterator::fold` - and did! - and succeeded in doing so (trivially checkable from debug logging, `()` is present where `_` is in the substs of the failing execution). The expected outcome of this test case would be a recursion limit error (which is present when the `identity` fn indirection is removed), and the recursion depth of `rec` is increasing (other functions finish collecting their neighbours and thus have their recursion depths reset). When the ICE occurs, the recursion depth of `rec` is 256 (which matches the recursion limit), which suggests perhaps that a different part of the compiler is using a `>=` comparison and returning a different result on this recursion rather than what it returned in every previous recursion, thus stopping the monomorphization collector from reporting an error on the next recursion, where `recursion_depth_of_rec > 256` would have been true. With grep and some educated guesses, we can determine that the recursion limit check at line 818 in `src/librustc_trait_selection/traits/project.rs` is the other check that is using a different comparison. Modifying either comparison to be `>` or `>=` respectively will fix the error, but changing the monomorphization collector produces the nicer error.
2020-05-30Rollup merge of #72521 - Amanieu:fix-72484, r=petrochenkovRalf Jung-2/+9
Properly handle InlineAsmOperand::SymFn when collecting monomorphized items Fixes #72484
2020-05-30Make TLS accesses explicit in MIROliver Scherer-0/+1
2020-05-28standardize limit comparisons with `Limit` typeDavid Wood-2/+2
This commit introduces a `Limit` type which is used to ensure that all comparisons against limits within the compiler are consistent (which can result in ICEs if they aren't). Signed-off-by: David Wood <david@davidtw.co>
2020-05-28mir: adjust conditional in recursion limit checkDavid Wood-1/+1
This commit adjusts the condition used in the recursion limit check of the monomorphization collector, from `>` to `>=`. In #67552, the test case had infinite indirect recursion, repeating a handful of functions (from the perspective of the monomorphization collector): `rec` -> `identity` -> `Iterator::count` -> `Iterator::fold` -> `Iterator::next` -> `rec`. During this process, `resolve_associated_item` was invoked for `Iterator::fold` (during the construction of an `Instance`), and ICE'd due to substitutions needing inference. However, previous iterations of this recursion would have called this function for `Iterator::fold` - and did! - and succeeded in doing so (trivially checkable from debug logging, `()` is present where `_` is in the substs of the failing execution). The expected outcome of this test case would be a recursion limit error (which is present when the `identity` fn indirection is removed), and the recursion depth of `rec` is increasing (other functions finish collecting their neighbours and thus have their recursion depths reset). When the ICE occurs, the recursion depth of `rec` is 256 (which matches the recursion limit), which suggests perhaps that a different part of the compiler is using a `>=` comparison and returning a different result on this recursion rather than what it returned in every previous recursion, thus stopping the monomorphization collector from reporting an error on the next recursion, where `recursion_depth_of_rec > 256` would have been true. With grep and some educated guesses, we can determine that the recursion limit check at line 818 in `src/librustc_trait_selection/traits/project.rs` is the other check that is using a different comparison. Modifying either comparison to be `>` or `>=` respectively will fix the error, but changing the monomorphization collector produces the nicer error. Signed-off-by: David Wood <david@davidtw.co>
2020-05-24Properly handle InlineAsmOperand::SymFn when collecting monomorphized itemsAmanieu d'Antras-2/+9
Fixes #72484
2020-05-23iterate List by valueBastian Kauschke-1/+1
2020-05-22Use `OnceCell` instead of `Once`Dylan MacKenzie-3/+2
2020-05-18Add asm! to MIRAmanieu d'Antras-1/+2
2020-05-15Remove lang_items\(\).*\.unwrap\(\)Nathan Corbyn-1/+3
2020-05-13use `require_lang_item` over `unwrap`.Bastian Kauschke-4/+2
2020-05-08Create a convenience wrapper for `get_global_alloc(id).unwrap()`Oliver Scherer-5/+4
2020-05-08Simplify the `tcx.alloc_map` APIOliver Scherer-2/+1
2020-05-02Move ensure_sufficient_stack to data_structuresSimonas Kazlauskas-2/+2
We anticipate this to have uses in all sorts of crates and keeping it in `rustc_data_structures` enables access to it from more locations without necessarily pulling in the large `librustc` crate.
2020-05-02Prevent stack overflow for deeply recursive codeOliver Scherer-2/+6
2020-04-27Change return type of `entry_fn` query to return a `LocalDefId`marmeladema-2/+2
2020-04-24Remove `Option` from the return type of `def_kind`.Eduard-Mihai Burtescu-1/+1
2020-04-23Address comments from reviewmarmeladema-1/+2
2020-04-23Modify `as_local_hir_id` to return a bare `HirId`marmeladema-3/+1
2020-04-23Modify `as_local_hir_id` to accept a `LocalDefId` instead of a `DefId`marmeladema-1/+3
2020-04-23librustc_middle: return LocalDefId instead of DefId in local_def_idmarmeladema-14/+14
2020-04-22Rollup merge of #71401 - spastorino:remove-visit-place-base, r=wesleywiserDylan DPC-1/+1
visit_place_base is just visit_local r? @wesleywiser
2020-04-22Rollup merge of #70970 - eddyb:trait-vs-impl-mismatch, r=oli-obkDylan DPC-6/+11
Detect mistyped associated consts in `Instance::resolve`. *Based on #71049 to prevent redundant/misleading downstream errors.* Fixes #70942 by refusing to resolve an associated `const` if it doesn't have the same type in the `impl` that it does in the `trait` (which we assume had errored, and `delay_span_bug` guards against bugs).
2020-04-21visit_place_base is just visit_localSantiago Pastorino-1/+1
2020-04-19Dogfood more or_patterns in the compilerJosh Stone-2/+1
2020-04-18Detect mistyped associated consts in `Instance::resolve`.Eduard-Mihai Burtescu-6/+11
2020-04-17Auto merge of #71049 - eddyb:const-err, r=oli-obkbors-1/+2
Add `ConstKind::Error` and convert `ErrorHandled::Reported` to it. By replicating the `ty::Error` approach to encoding "an error has occurred", all of the mechanisms that skip redundant/downstream errors are engaged and help out (see the reduction in test output). This PR also adds `ErrorHandled::Linted` for the lint case because using `ErrorHandled::Reported` *without* having emitted an error that is *guaranteed* to stop compilation, is incorrect now. r? @oli-obk cc @rust-lang/wg-const-eval @varkor @yodaldevoid
2020-04-16mir/interpret: only use `ErrorHandled::Reported` for `ErrorReported`.Eduard-Mihai Burtescu-1/+2
2020-04-16don't clone types that are copy (clippy::clone_on_copy)Matthias Krüger-1/+1
2020-04-11Auto merge of #70161 - cjgillot:query-arena, r=nikomatsakisbors-9/+9
Allocate some query results on an arena This avoids a cloning few `Lrc` and `Vec`s in the queries.
2020-04-07Rollup merge of #70846 - tmiasko:compiler-builtins-codegen-units, r=alexcrichtonDylan DPC-1/+8
Keep codegen units unmerged when building compiler builtins Make it possible to control how mono items are partitioned into code generation units, when compiling the compiler builtins, by retaining the original partitioning. Helps with #48625, #61063, #67960, #70489. r? @alexcrichton
2020-04-06ty: switch `Ty::walk` from `Ty` to `GenericArg`.Eduard-Mihai Burtescu-9/+12
2020-04-06Keep codegen units unmerged when building compiler builtinsTomasz Miąsko-1/+8
2020-04-05Remove Arcs in queries.Camille GILLOT-9/+9
2020-04-03Auto merge of #70156 - michaelwoerister:incr-cgus, r=nikomatsakisbors-24/+60
Make the rustc respect the `-C codegen-units` flag in incremental mode. This PR implements (the as of yet unapproved) major change proposal at https://github.com/rust-lang/compiler-team/issues/245. See the description there for background and rationale. The changes are pretty straightforward and should be easy to rebase if the proposal gets accepted at some point. r? @nikomatsakis cc @pnkfelix
2020-04-02direct imports for langitem stuffMazdak Farrokhzad-1/+1
2020-03-31Make the rustc respect the `-C codegen-units` flag in incremental mode.Michael Woerister-24/+60
Before this commit `-C codegen-units` would just get silently be ignored if `-C incremental` was specified too. After this commit one can control the number of codegen units generated during incremental compilation. The default is rather high at 256, so most crates won't see a difference unless explicitly opting into a lower count.
2020-03-30Use if let instead of match when only matching a single variant ↵Matthias Krüger-6/+3
(clippy::single_match) Makes code more compact and reduces nestig.
2020-03-30rustc -> rustc_middle part 3 (rustfmt)Mazdak Farrokhzad-10/+10
2020-03-30rustc -> rustc_middle part 2Mazdak Farrokhzad-21/+21
2020-03-29Use `&` to do deref coercion for `ReadOnlyBodyAndCache`Dylan MacKenzie-1/+1
2020-03-29Make `Visitor::visit_body` take a simple `Body`Dylan MacKenzie-1/+1
2020-03-22remove redundant closures (clippy::redundant_closure)Matthias Krüger-1/+1
2020-03-20remove redundant returns (clippy::needless_return)Matthias Krüger-1/+1
2020-03-20Rollup merge of #69935 - davidtwco:issue-69925, r=eddybYuki Okushi-62/+40
codegen/mir: support polymorphic `InstanceDef`s cc #69925 This PR modifies the use of `subst_and_normalize_erasing_regions` on parts of the MIR bodies returned from `instance_mir`, so that `InstanceDef::CloneShim` and `InstanceDef::DropGlue` (where there is a type) do not perform substitutions. This avoids double substitutions and enables polymorphic `InstanceDef`s. r? @eddyb cc @nikomatsakis
2020-03-18Rollup merge of #69920 - Centril:hir-cleanup, r=ZoxcMazdak Farrokhzad-1/+1
Remove some imports to the rustc crate - When we have `NestedVisitorMap::None`, we use `type Map = dyn intravisit::Map<'v>;` instead of the actual map. This doesn't actually result in dynamic dispatch (in the future we may want to use an associated type default to simplify the code). - Use `rustc_session::` imports instead of `rustc::{session, lint}`. r? @Zoxc
2020-03-16Rollup merge of #69989 - petrochenkov:nolegacy, r=eddyb,matthewjasperDylan DPC-2/+2
resolve/hygiene: `macro_rules` are not "legacy" The "modern" vs "legacy" naming was introduced by jseyfried during initial implementation of macros 2.0. At this point it's clear that `macro_rules` are not going anywhere and won't be deprecated in the near future. So this PR changes the naming "legacy" (when it implies "macro_rules") to "macro_rules". This should also help people reading this code because it's wasn't obvious that "legacy" actually meant "macro_rules" in these contexts. The most contentious renaming here is probably ``` fn modern -> fn normalize_to_macros_2_0 fn modern_and_legacy -> fn normalize_to_macro_rules ``` Other alternatives that I could think of are `normalize_to_opaque`/`normalize_to_semitransparent`, or `strip_non_opaque`/`strip_transparent`, but they seemed less intuitive. The documentation to these functions can be found in `symbol.rs`. r? @matthewjasper