about summary refs log tree commit diff
path: root/src/librustc_mir/monomorphize
AgeCommit message (Collapse)AuthorLines
2020-08-30mv compiler to compiler/mark-2714/+0
2020-08-25Auto merge of #74275 - wesleywiser:break_up_partitioning_rs, r=pnkfelixbors-1012/+1095
Refactor the partitioning module to make it easier to introduce new algorithms I've split the `librustc_mir::monomorphize::partitioning` module into a few files and introduced a `Partitioner` trait which allows us to decouple the partitioning algorithm from the code which integrates it into the query system. This should allow us to introduce new partitioning algorithms much more easily. I've also gone ahead and added a `-Z` flag to control which algorithm is used (currently there is only the `default`). I left a few comments in places where things might be improved further. r? @pnkfelix cc @rust-lang/wg-incr-comp
2020-08-24hir: consistent use and naming of lang itemsDavid Wood-5/+5
This commit adjusts the naming of various lang items so that they are consistent and don't include prefixes containing the target or "LangItem". In addition, lang item variants are no longer exported from the `lang_items` module. Signed-off-by: David Wood <david@davidtw.co>
2020-08-21Add partitioning -Z option to control which partitioning scheme is usedWesley Wiser-3/+11
2020-08-21Split partitioning.rs into a moduleWesley Wiser-676/+704
2020-08-21Add a CGU partitioning traitWesley Wiser-287/+334
This will allow us to prototype different partitioning schemes without adding a lot of extra conditionals everywhere.
2020-08-17polymorphize: ∃ used param ∈ predicate → all usedDavid Wood-75/+12
This commit modifies polymorphization's handling of predicates so that if any generic parameter is used in a predicate then all parameters in that predicate are used. Signed-off-by: David Wood <david@davidtw.co>
2020-08-14polymorphize: `I` used if `T` used in `I: Foo<T>`David Wood-31/+119
This commit adjusts polymorphization's handling of predicates so that after ensuring that `T` is used in `I: Foo<T>` if `I` is used, it now ensures that `I` is used if `T` is used in `I: Foo<T>`. This is necessary to mark generic parameters that only exist in impl parameters as used - thereby avoiding symbol clashes when using the new mangling scheme. Signed-off-by: David Wood <david@davidtw.co>
2020-08-10polymorphize: constrain unevaluated const handlingDavid Wood-4/+10
This commit constrains the support added for handling unevaluated consts in polymorphization (introduced in #75260) by: - Skipping associated constants as this causes cycle errors. - Skipping promoted constants when they contain `Self` as this ensures `T` is used in constants of the form `<Self as Foo<T>>`. Signed-off-by: David Wood <david@davidtw.co>
2020-08-08Auto merge of #75260 - davidtwco:polymorphization-promoted-substs, r=lcnrbors-13/+32
polymorphize: unevaluated constants This PR makes polymorphization visit the promoted MIR of unevaluated constants with available promoted MIR instead of visiting the substitutions of that constant - which will mark all of the generic parameters as used; in addition polymorphization will now visit non-promoted unevaluated constants rather than visit their substs. r? @lcnr
2020-08-08Eliminate the `SessionGlobals` from `librustc_ast`.Nicholas Nethercote-1/+5
By moving `{known,used}_attrs` from `SessionGlobals` to `Session`. This means they are accessed via the `Session`, rather than via TLS. A few `Attr` methods and `librustc_ast` functions are now methods of `Session`. All of this required passing a `Session` to lots of functions that didn't already have one. Some of these functions also had arguments removed, because those arguments could be accessed directly via the `Session` argument. `contains_feature_attr()` was dead, and is removed. Some functions were moved from `librustc_ast` elsewhere because they now need to access `Session`, which isn't available in that crate. - `entry_point_type()` --> `librustc_builtin_macros` - `global_allocator_spans()` --> `librustc_metadata` - `is_proc_macro_attr()` --> `Session`
2020-08-07polymorphize: non-promoted unevaluated constantsDavid Wood-13/+25
This commit makes polymorphization visit non-promoted unevaluated constants rather than visit their substs directly. Signed-off-by: David Wood <david@davidtw.co>
2020-08-07polymorphize: visit promoted MIRDavid Wood-0/+7
This commit makes polymorphization visited the MIR of unevaluated constants with available promoted MIR instead of visiting the substitutions of that constant - which will mark all of the generic parameters as used. Signed-off-by: David Wood <david@davidtw.co>
2020-08-04metadata: skip empty polymorphization bitsetDavid Wood-0/+7
This commit skips encoding empty polymorphization results - while polymorphization is disabled, this should be every polymorphization result; but when polymorphization is re-enabled, this would help with non-generic functions and those which do use all their parameters (most functions). Signed-off-by: David Wood <david@davidtw.co>
2020-08-04mir: use `FiniteBitSet<u32>` in polymorphizationDavid Wood-8/+8
This commit changes polymorphization to return a `FiniteBitSet<u32>` rather than a `FiniteBitSet<u64>` because most functions do not use anywhere near sixty-four generic parameters so keeping a `u64` around is unnecessary in most cases. Signed-off-by: David Wood <david@davidtw.co>
2020-07-27cleanupBastian Kauschke-8/+7
2020-07-22mir: improve polymorphic constant bugDavid Wood-2/+3
This commit changes the span and content of the "collection encountered polymorphic constant" bug in monomorphization collection to point to the use of the constant rather than the definition. Signed-off-by: David Wood <david@davidtw.co>
2020-07-20index: introduce and use `FiniteBitSet`David Wood-62/+47
This commit introduces a `FiniteBitSet` type which replaces the manual bit manipulation which was being performed in polymorphization. Signed-off-by: David Wood <david@davidtw.co>
2020-07-20mir: use attribute over `-Z polymorphize-errors`David Wood-4/+6
This commit replaces the `-Z polymorphize-errors` debugging flag with a `#[rustc_polymorphize_error]` attribute for use on functions. Signed-off-by: David Wood <david@davidtw.co>
2020-07-20mir: `unused_generic_params` queryDavid Wood-26/+323
This commit implements the `unused_generic_params` query, an initial version of polymorphization which detects when an item does not use generic parameters and is being needlessly monomorphized as a result. Signed-off-by: David Wood <david@davidtw.co>
2020-07-20mir: rename `should_monomorphize_locally`David Wood-13/+12
This commit renames `should_monomorphize_locally` to `should_codegen_locally` which better describes what the function determines once polymorphization is added. Signed-off-by: David Wood <david@davidtw.co>
2020-07-17Generating the coverage mapRich Kadel-2/+2
rustc now generates the coverage map and can support (limited) coverage report generation, at the function level. Example: $ BUILD=$HOME/rust/build/x86_64-unknown-linux-gnu $ $BUILD/stage1/bin/rustc -Zinstrument-coverage \ $HOME/rust/src/test/run-make-fulldeps/instrument-coverage/main.rs $ LLVM_PROFILE_FILE="main.profraw" ./main called $ $BUILD/llvm/bin/llvm-profdata merge -sparse main.profraw -o main.profdata $ $BUILD/llvm/bin/llvm-cov show --instr-profile=main.profdata main 1| 1|pub fn will_be_called() { 2| 1| println!("called"); 3| 1|} 4| | 5| 0|pub fn will_not_be_called() { 6| 0| println!("should not have been called"); 7| 0|} 8| | 9| 1|fn main() { 10| 1| let less = 1; 11| 1| let more = 100; 12| 1| 13| 1| if less < more { 14| 1| will_be_called(); 15| 1| } else { 16| 1| will_not_be_called(); 17| 1| } 18| 1|}
2020-07-15Auto merge of #74113 - lcnr:type-dependent-consts-2, r=eddybbors-7/+8
Support const args in type dependent paths (Take 2) once more, except it is sound this time :smiling_face_with_three_hearts: previously #71154 ----- ```rust #![feature(const_generics)] struct A; impl A { fn foo<const N: usize>(&self) -> usize { N } } struct B; impl B { fn foo<const N: usize>(&self) -> usize { 42 } } fn main() { let a = A; a.foo::<7>(); } ``` When calling `type_of` for generic const arguments, we now use the `TypeckTables` of the surrounding body to get the expected type. This alone causes cycle errors though, as we now have `typeck_tables_of(main)` -> `...` -> `type_of(main_ANON0 := 7)` -> `typeck_tables_of(main)` :zap: (see https://github.com/rust-lang/rust/issues/68400#issuecomment-611760290) To prevent this we must not call `type_of(const_arg)` during `typeck_tables_of`. This is achieved by calling `type_of(param_def_id)` instead. We have to somehow remember the `DefId` of the param through all of typeck, which is done using the struct `ty::WithOptConstParam<DefId>`, which replaces `DefId` where needed and contains an `Option<DefId>` to be able to store the const parameter in case it exists. Queries which are currently cached on disk are split into two variants: `query_name`(cached) and `query_name_(of|for)_const_arg`(not cached), with `query_name_of_const_arg` taking a pair `(did, param_did): (LocalDefId, DefId)`. For some queries a method `query_name_of_opt_const_arg` is added to `TyCtxt` which takes a `ty::WithOptConstParam` and either calls `query_name` or `query_name_of_const_arg` depending on the value of `const_param_did`. r? @eddyb @varkor
2020-07-15InstanceDef::ItemBastian Kauschke-4/+5
2020-07-15const_eval_resolveBastian Kauschke-1/+1
2020-07-15ConstKind::UnevaluatedBastian Kauschke-3/+3
2020-07-15Change `SymbolName::name` to a `&str`.Nicholas Nethercote-1/+1
This eliminates a bunch of `Symbol::intern()` and `Symbol::as_str()` calls, which is good, because they require locking the interner. Note that the unsafety in `from_cycle_error()` is identical to the unsafety on other adjacent impls.
2020-07-05Use for<'tcx> fn pointers in Providers, instead of having Providers<'tcx>.Eduard-Mihai Burtescu-3/+3
2020-06-23Rollup merge of #73601 - Aaron1011:fix/better-mono-overflow-err, ↵Manish Goregaokar-57/+80
r=ecstatic-morse Point at the call span when overflow occurs during monomorphization This improves the output for issue #72577, but there's still more work to be done. Currently, an overflow error during monomorphization results in an error that points at the function we were unable to monomorphize. However, we don't point at the call that caused the monomorphization to happen. In the overflow occurs in a large recursive function, it may be difficult to determine where the issue is. This commit tracks and `Span` information during collection of `MonoItem`s, which is used when emitting an overflow error. `MonoItem` itself is unchanged, so this only affects `src/librustc_mir/monomorphize/collector.rs`
2020-06-22Point at the call spawn when overflow occurs during monomorphizationAaron Hill-57/+80
This improves the output for issue #72577, but there's still more work to be done. Currently, an overflow error during monomorphization results in an error that points at the function we were unable to monomorphize. However, we don't point at the call that caused the monomorphization to happen. In the overflow occurs in a large recursive function, it may be difficult to determine where the issue is. This commit tracks and `Span` information during collection of `MonoItem`s, which is used when emitting an overflow error. `MonoItem` itself is unchanged, so this only affects `src/librustc_mir/monomorphize/collector.rs`
2020-06-21Update src/librustc_mir/monomorphize/collector.rs Youngsuk Kim-1/+1
typo fix Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-06-20Fix typos in doc commentsYoungsuk Kim-3/+3
This commit fixes typos in the doc comments of 'librustc_mir/monomorphize/collector.rs'
2020-06-19Rollup merge of #73136 - alexcrichton:thinlto-compiler-builtins, ↵Ralf Jung-8/+1
r=Mark-Simulacrum Change how compiler-builtins gets many CGUs 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-18Rollup merge of #72814 - RalfJung:mir-visir-terminator, r=oli-obkManish Goregaokar-7/+7
remove visit_terminator_kind from MIR visitor For some reason, we had both `visit_terminator` and `visit_terminator_kind`. In contrast, for `Statement` we just have `visit_statement`. So this cleans things up by removing `visit_terminator_kind` and porting its users to `visit_terminator`.
2020-06-18Auto merge of #73065 - Amanieu:tls-fix, r=oli-obkbors-0/+8
Fix link error with #[thread_local] introduced by #71192 r? @oli-obk
2020-06-16rename location field of Drop terminators to placeRalf Jung-3/+3
2020-06-16remove visit_terminator_kind from MIR visitorRalf Jung-4/+4
2020-06-15Change 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-12Rollup merge of #73033 - Amanieu:asm-tls, r=oli-obkDylan DPC-3/+13
Fix #[thread_local] statics as asm! sym operands The `asm!` RFC specifies that `#[thread_local]` statics may be used as `sym` operands for inline assembly. This also fixes a regression in the handling of `#[thread_local]` during monomorphization which caused link-time errors with multiple codegen units, most likely introduced by #71192. r? @oli-obk
2020-06-09Auto merge of #72114 - anyska:vtable-rename, r=nikomatsakisbors-5/+6
Rename traits::Vtable to ImplSource. Originally suggested by @eddyb. r? @nikomatsakis
2020-06-07rename FalseEdges -> FalseEdgeRalf Jung-1/+1
2020-06-06Fix #[thread_local] statics as asm! sym operandsAmanieu d'Antras-3/+13
2020-06-06Fix link error with #[thread_local] introduced by #71192Amanieu d'Antras-0/+8
2020-06-05Rename traits::ImplSourceImpl to ImplSourceUserDefined.Ana-Maria Mihalache-3/+4
2020-06-05Rename traits::Vtable to ImplSource.Ana-Maria Mihalache-3/+3
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>