about summary refs log tree commit diff
path: root/src/librustc_mir
AgeCommit message (Collapse)AuthorLines
2020-08-01Auto merge of #74726 - oli-obk:tracing, r=Mark-Simulacrumbors-3/+2
Move from `log` to `tracing` The only visible change is that we now get timestamps in our logs: ``` Jul 24 18:41:01.065 TRACE rustc_mir::transform::const_prop: skipping replace of Rvalue::Use(const () because it is already a const Jul 24 18:41:01.065 TRACE rustc_mir::transform::const_prop: propagated into _2 Jul 24 18:41:01.065 TRACE rustc_mir::transform::const_prop: visit_constant: const () ``` This PR was explicitly designed to be as low-impact as possible. We can now move to using the name `tracing` insteads of `log` on a crate-by-crate basis and use any of the other tracing features where desirable. As far as I can tell this will allow tools to seamlessly keep working (since they are using `rustc_driver::init_log...`). This is the first half of step 1 of the accepted `tracing` MCP (https://github.com/rust-lang/compiler-team/issues/331)
2020-08-01Rollup merge of #74983 - oli-obk:mir_opt_goto_chain, r=ecstatic-morseManish Goregaokar-26/+43
Replace a recursive algorithm with an iterative one and a stack. fixes #74931
2020-08-01Replace a recursive algorithm with an iterative one and a stack.Oliver Scherer-26/+43
2020-08-01Auto merge of #74945 - dingxiangfei2009:promote-static-ref-deref, r=oli-obkbors-2/+40
[mir] Special treatment for dereferencing a borrow to a static definition Fix #70584. As suggested by @oli-obk in this [comment](https://github.com/rust-lang/rust/issues/70584#issuecomment-626009260), one can chase the definition of the local variable being de-referenced and check if it is a true static variable. If that is the case, `validate_place` will admit the promotion. This is my first time to contribute to `rustc`, and I have two questions. 1. A generalization to some extent is applied to decide if the promotion is possible in the static context. In case that there are more projection operations preceding the de-referencing, `validate_place` recursively decent into inner projection operations. I have put thoughts into its correctness but I am not totally sure about it. 2. I have a hard time to find a good place for the test case. This patch has to do with MIR, but this test case would look out of place compared to other tests in `src/test/ui/mir` or `src/test/ui/borrowck` because it does not generate errors while others do. It is tentatively placed in `src/test/ui/statics` for now. Thank you for any comments and suggestions!
2020-08-01Auto merge of #74717 - ↵bors-20/+91
davidtwco:issue-74636-polymorphized-closures-inherited-params, r=oli-obk mir: add `used_generic_parameters_needs_subst` Fixes #74636. This PR adds a `used_generic_parameters_needs_subst` helper function which checks whether a type needs substitution, but only for parameters that the `unused_generic_params` query considers used. This is used in the MIR interpreter to make the check for some pointer casts and for reflection intrinsics more precise. I've opened this as a draft PR because this might not be the approach we want to fix this issue and we have to decide what to do about the reflection case. r? @eddyb cc @lcnr @wesleywiser
2020-08-01Rollup merge of #74984 - RalfJung:miri-unwind-top, r=oli-obkYuki Okushi-0/+4
Miri: fix ICE when unwinding past topmost stack frame Fixes https://github.com/rust-lang/miri/issues/1389
2020-07-31Move from `log` to `tracing`Oliver Scherer-3/+2
2020-07-31Miri: fix ICE when unwinding past topmost stack frameRalf Jung-0/+4
2020-07-31Auto merge of #65989 - Aaron1011:fix/normalize-param-env, r=nikomatsakisbors-5/+5
Normalize all opaque types when converting ParamEnv to Reveal::All When we normalize a type using a ParamEnv with a reveal mode of RevealMode::All, we will normalize opaque types to their underlying types (e.g. `type MyOpaque = impl Foo` -> `StructThatImplsFoo`). However, the ParamEnv may still have predicates referring to the un-normalized opaque type (e.g. `<T as MyTrait<MyOpaque>>`). This can cause trait projection to fail, since a type containing normalized opaque types will not match up with the un-normalized type in the `ParamEnv`. To fix this, we now explicitly normalize all opaque types in caller_bounds of a `ParamEnv` when changing its mode to `RevealMode::All`. This ensures that all predicatse will refer to the underlying types of any opaque types involved, allowing them to be matched up properly during projection. To reflect the fact that normalization is occuring, `ParamEnv::with_reveal_all` is renamed to `ParamEnv::with_reveal_all_normalized` Fixes #65918
2020-07-31interp: needs_subst -> ensure_monomorphic_enoughDavid Wood-20/+91
This commit adds a `ensure_monomorphic_enough` utility function which checks whether a type needs substitution, but only for parameters that the `unused_generic_params` query considers used. `ensure_monomorphic_enough` is then used throughout interpret where `needs_subst` checks previously existed (in particular, for some pointer casts and for reflection intrinsics more precise). Signed-off-by: David Wood <david@davidtw.co>
2020-07-31rustfmtDing Xiang Fei-1/+3
2020-07-31Remove a trailing spaceDing Xiang Fei-1/+1
2020-07-31Add comments to explain the test case and the special treatmentDing Xiang Fei-1/+13
2020-07-30Special treatment for dereferencing a borrow to a static definitionDing Xiang Fei-2/+26
2020-07-30Auto merge of #74930 - ecstatic-morse:const-size-align-of-val, r=oli-obkbors-0/+15
Make `mem::size_of_val` and `mem::align_of_val` unstably const Implements #46571 but does not stabilize it. I wanted this while working on something today. The only reason not to immediately stabilize are concerns around [custom DSTs](https://github.com/rust-lang/rust/issues/46571#issuecomment-387669352). That proposal has made zero progress in the last two years and const eval is rich enough to support pretty much any user-defined `len` function as long as nightly features are allowed (`raw_ptr_deref`). Currently, this raises a `const_err` lint when passed an `extern type`. r? @oli-obk cc @rust-lang/wg-const-eval
2020-07-30Auto merge of #74876 - oli-obk:lumberjack_disable, r=RalfJungbors-132/+178
Replace all uses of `log::log_enabled` with `Debug` printers cc @RalfJung this touches a bunch of logging in the miri engine. There are some visual changes, mainly that in several cases we stop prepending lines with the module path and just have a newline.
2020-07-29Make `{align,size}_of_val` `const`Dylan MacKenzie-0/+15
2020-07-29Auto merge of #74733 - richkadel:llvm-coverage-map-gen-5, r=tmandrybors-94/+124
Fixed coverage map issues; better aligned with LLVM APIs Found some problems with the coverage map encoding when testing with more than one counter per function. While debugging, I realized some better ways to structure the Rust implementation of the coverage mapping generator. I refactored somewhat, resulting in less code overall, expanded coverage of LLVM Coverage Map capabilities, and much closer alignment with LLVM data structures, APIs, and naming. This should be easier to follow and easier to maintain. r? @tmandry Rust compiler MCP rust-lang/compiler-team#278 Relevant issue: #34701 - Implement support for LLVMs code coverage instrumentation
2020-07-29Move mir-opt tests to toplevelXavier Denis-2/+9
2020-07-29add crate name to mir dumpsXavier Denis-1/+2
2020-07-28Refactor MIR coverage instrumentationRich Kadel-88/+118
Lays a better foundation for injecting more counters in each function.
2020-07-28Replace write-to-vec hack by introducing a display renderer for allocationsOliver Scherer-26/+32
2020-07-28Replace all uses of `log::log_enabled` with `Debug` printersOliver Scherer-113/+153
2020-07-27Auto merge of #73503 - lcnr:forall-predicate-what-and-why-2, r=nikomatsakisbors-43/+38
convert higher ranked `Predicate`s to `PredicateKind::ForAll` implements step 2 of https://github.com/rust-lang/compiler-team/issues/285 r? @nikomatsakis
2020-07-27cleanupBastian Kauschke-8/+7
2020-07-27introduce PredicateAtomBastian Kauschke-18/+17
2020-07-27this might be unqualified, but at least it's now quantifiedBastian Kauschke-2/+2
2020-07-27split ignore_qualifiersBastian Kauschke-3/+3
2020-07-27reviewBastian Kauschke-1/+0
2020-07-27`PredicateKint` -> `PredicateKind`, the beginning of the endBastian Kauschke-11/+13
2020-07-27progressBastian Kauschke-13/+9
2020-07-27convert trivial predicatesBastian Kauschke-7/+7
2020-07-27Auto merge of #74775 - RalfJung:miri-alloc-ids, r=oli-obkbors-116/+100
Miri: replace canonical_alloc_id mechanism by extern_static_alloc_id We only have to call `extern_static_alloc_id` when a `Pointer` is "imported" from the `tcx` to the machine, not on each access. Also drop the old hook for TLS handling, it is not needed any more. The Miri side of this is at https://github.com/rust-lang/miri/pull/1489. Fixes https://github.com/rust-lang/rust/issues/71194 r? @oli-obk
2020-07-27rename eval_const_to_op -> const_to_opRalf Jung-12/+8
2020-07-26typos + fmtRalf Jung-10/+10
2020-07-26move getting the initial value of a static into helper functionRalf Jung-12/+19
2020-07-26Miri: replace canonical_alloc_id mechanism by extern_static_alloc_id which ↵Ralf Jung-93/+74
is called only when a pointer is 'imported' into the machine
2020-07-26Auto merge of #74664 - pnadon:Miri-rename-undef-uninit, r=RalfJungbors-30/+30
Miri rename undef uninit Renamed parts of code within the `librustc_middle/mir/interpret/` directory. Related issue [#71193](https://github.com/rust-lang/rust/issues/71193)
2020-07-25Miri: rename "undef" to "uninit"Philippe Nadon-12/+12
renamed Allocation::check_defined_and_ptr to Allocation::check_init_and_ptr renamed Allocation::check_defined_and_ptr to Allocation::check_init_and_ptr in src/librustc_middle/mir/interpret/allocation.rs renamed Allocation::is_defined and Allocation::check_defined, fixed documentation renamed Allocation::is_defined and Allocation::check_defined to is_init and check_init respectively. Fixed documentation so it correctly refers to "initialization" instead of "defined"-ness renamed Allocation::mark_definedness renamed Allocation::mark_definedness to Allocation::mark_init Renamed new_state parameter in Allocation::mark_init Renamed new_state to is_init, as the latter is more descriptive. renamed functions in AllocationDefinedness renamed AllocationDefinedness::all_bytes_undef and AllocationDefinedness::mark_compressed_undef_range to no_bytes_init and mark_compressed_init_range respectively. renamed AllocationDefinedness to InitMaskCompressed renamed Immediate::to_scalar_or_undef renamed to to_scalar_or_uninit fixed comment references to "undef" Changed comments referring to "undef" and "definedness" to "initialization" and "initialization state" in src/librustc_mir/interpret/memory.rs and src/librustc_middle/mir/interpret/allocation.rs changed references to "undef" in comments and a variable Changed some comments referring to "undef" to use "uninitialized" instead. Also changed a variable from "undef_end" to "uninit_end". All changes were made within src/librustc_middle/mir/interpret/allocation.rs. Changed more comments referring to undef Changed comments to use "uninitialized" instead of "undef" in src/librustc_middle/mir/interpret/allocation.rs.
2020-07-25Fixed coverage map issues; better aligned with LLVM APIsRich Kadel-8/+8
Found some problems with the coverage map encoding when testing with more than one counter per function. While debugging, I realized some better ways to structure the Rust implementation of the coverage mapping generator. I refactored somewhat, resulting in less code overall, expanded coverage of LLVM Coverage Map capabilities, and much closer alignment with LLVM data structures, APIs, and naming. This should be easier to follow and easier to maintain.
2020-07-24Auto merge of #74681 - RalfJung:miri-extern-fn, r=oli-obkbors-1/+4
Miri: use extern fn to expose interpreter operations to program; fix leak checker on Windows This PR realizes an idea that @oli-obk has been suggesting for a while: to use Miri-specific `extern` functions to provide some extra capabilities to the program. Initially, we have two of these methods, which libstd itself needs: * `miri_start_panic`, which replaces the intrinsic of the same name (mostly for consistency, to avoid having multiple mechanisms for Miri-specific functionality). * `miri_static_root`, which adds an allocation to a list of static "roots" that Miri considers as not having leaked (including all memory reachable through them). This is needed for https://github.com/rust-lang/miri/issues/1302. We use `extern` functions instead of intrinsics for this so that user code can more easily call these Miri hoolks -- e.g. `miri_static_root` should be useful for https://github.com/rust-lang/miri/issues/1318. The Miri side of this is at https://github.com/rust-lang/miri/pull/1485. r? @oli-obk
2020-07-24Auto merge of #74507 - lcnr:const-prop-into-op, r=oli-obkbors-62/+50
add `visit_operand` to const prop r? @oli-obk
2020-07-24Rollup merge of #74661 - SNCPlay42:lifetime-names-refactor, r=estebankManish Goregaokar-89/+92
Refactor `region_name`: add `RegionNameHighlight` This PR does not change any diagnostics itself, rather it enables further code changes, but I would like to get approval for the refactoring first before making use of it. In `rustc_mir::borrow_check::diagnostics::region_name`, there is code that allows for, when giving a synthesized name like `'1` to an anonymous lifetime, pointing at e.g. the exact '`&`' that introduces the lifetime. This PR decouples that code from the specific case of arguments, adding a new enum `RegionNameHighlight`, enabling future changes to use it in other places. This allows: * We could change the other `AnonRegionFrom*` variants to use `RegionNameHighlight` to precisely point at where lifetimes are introduced in other locations when they have type annotations, e.g. a closure return `|...| -> &i32`. * Because of how async functions are lowered this affects async functions as well, see #74072 * for #74597, we could add a second, optional `RegionNameHighlight` to the `AnonRegionFromArgument` variant that highlights a lifetime in the return type of a function when, due to elision, this is the same as the argument lifetime. * in https://github.com/rust-lang/rust/issues/74497#issuecomment-6606229707 I noticed that a diagnostic was trying to introduce a lifetime `'2` in the opaque type `impl std::future::Future`. The code for the case of arguments has [code to handle cases like this](https://github.com/rust-lang/rust/blob/bbebe7351fcd29af1eb9a35e315369b15887ea09/src/librustc_mir/borrow_check/diagnostics/region_name.rs#L365) but not the others. This refactoring would allow the same code path to handle this. * It might be appropriate to add another variant of `RegionNameHighlight` to say something like `lifetime '1 appears in the opaque type impl std::future::Future`. These are quite a few changes so I thought I would make sure the refactoring is OK before I start making changes that rely on it. :)
2020-07-24Rollup merge of #74491 - xldenis:constant-binop-opt, r=oli-obkManish Goregaokar-21/+85
Optimize away BitAnd and BitOr when possible This PR lets `const_prop` optimize away `a | true == true` , `a & false == false` and `a * 0 = 0`. While I was writing this I've realized that constant propagation misses a lot of opportunities. For example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=2a4b45e772f214210a36749b27223bb0 Constant propagation doesn't seem to... propagate constants, additionally the way constant propagation is currently setup makes it tricky to add cases like `a | false == a`. I tried to organize `eval_rvalue_with_identities` to make the pattern of the optimizations easier to see but it still obscurs what should be a simple peephole optmization. cc @oli-obk
2020-07-23slightly adapt const propBastian Kauschke-7/+7
2020-07-23on Windows, use miri_static_root for TLS dtorsRalf Jung-1/+4
2020-07-22renamed ScalarMaybeUninit::not_undef to check_initPhilippe Nadon-19/+19
Renamed the function ScalarMaybeUninit::not_undef to ScalarMaybeUninit::check_init in the file src/librustc_middle/mir/interpret/value.rs, to reflect changes in terminology used. Related issue rust-lang#71193
2020-07-23Auto merge of #74662 - Manishearth:rollup-jdt7t71, r=Manishearthbors-2/+10
Rollup of 9 pull requests Successful merges: - #73783 (Detect when `'static` obligation might come from an `impl`) - #73868 (Advertise correct stable version for const control flow) - #74460 (rustdoc: Always warn when linking from public to private items) - #74538 (Guard against non-monomorphized type_id intrinsic call) - #74541 (Add the aarch64-apple-darwin target ) - #74600 (Enable perf try builder) - #74618 (Do not ICE on assoc type with bad placeholder) - #74631 (rustc_target: Add a target spec option for disabling `--eh-frame-hdr`) - #74643 (build: Remove unnecessary `cargo:rerun-if-env-changed` annotations) Failed merges: r? @ghost
2020-07-22Rollup merge of #74538 - nbdd0121:issue-73976, r=lcnrManish Goregaokar-2/+10
Guard against non-monomorphized type_id intrinsic call This PR checks whether the type is sufficient monomorphized when calling type_id or type_name intrinsics. If the type is not sufficiently monomorphized, e.g. used in a pattern, the code will be rejected. Fixes #73976
2020-07-23rename arguments to highlight_if_we_can_match_hir_tySNCPlay42-7/+6