about summary refs log tree commit diff
path: root/compiler/rustc_const_eval
AgeCommit message (Collapse)AuthorLines
2021-11-06Stabilize `const_raw_ptr_deref` for `*const T`Jacob Pratt-7/+13
This stabilizes dereferencing immutable raw pointers in const contexts. It does not stabilize `*mut T` dereferencing. This is placed behind the `const_raw_mut_ptr_deref` feature gate.
2021-11-06use matches!() macro in more placesMatthias Krüger-24/+13
2021-11-05Remove `Candidate::source_info`Tomasz Miąsko-7/+1
2021-11-05Refactor single variant `Candidate` enum into a structTomasz Miąsko-95/+82
`Candidate` enum has only a single `Ref` variant. Refactor it into a struct and reduce overall indentation of the code by two levels. No functional changes.
2021-11-03`addr_of!` grants mutable access, maybe?Tomasz Miąsko-6/+5
The exact set of permissions granted when forming a raw reference is currently undecided https://github.com/rust-lang/rust/issues/56604. To avoid presupposing any particular outcome, adjust the const qualification to be compatible with decision where raw reference constructed from `addr_of!` grants mutable access.
2021-11-03Remove `MaybeMutBorrowedLocals`Tomasz Miąsko-0/+9
2021-11-03Implement `clone_from` for `State`Tomasz Miąsko-1/+14
Data flow engine uses `clone_from` for domain values. Providing an implementation of `clone_from` will avoid some intermediate memory allocations.
2021-10-31Remove unnecessary `Option` from `promote_candidate` return typeTomasz Miąsko-11/+5
2021-10-29Auto merge of #90373 - tmiasko:union-qualification, r=oli-obkbors-1/+14
Use type based qualification for unions Union field access is currently qualified based on the qualification of a value previously assigned to the union. At the same time, every union access transmutes the content of the union, which might result in a different qualification. For example, consider constants A and B as defined below, under the current rules neither contains interior mutability, since a value used in the initial assignment did not contain `UnsafeCell` constructor. ```rust #![feature(untagged_unions)] union U { i: u32, c: std::cell::Cell<u32> } const A: U = U { i: 0 }; const B: std::cell::Cell<u32> = unsafe { U { i: 0 }.c }; ``` To avoid the issue, the changes here propose to consider the content of a union as opaque and use type based qualification for union types. Fixes #90268. `@rust-lang/wg-const-eval`
2021-10-29Auto merge of #90214 - tmiasko:indirect-mutation-qualif, ↵bors-63/+157
r=ecstatic-morse,oli-obk Consider indirect mutation during const qualification dataflow Previously a local would be qualified if either one of two separate data flow computations indicated so. First determined if a local could contain the qualif, but ignored any forms of indirect mutation. Second determined if a local could be mutably borrowed (and so indirectly mutated), but which in turn ignored the qualif. The end result was incorrect because the effect of indirect mutation was effectivelly ignored in the all but the final stage of computation. In the new implementation the indirect mutation is directly incorporated into the qualif data flow. The local variable becomes immediately qualified once it is mutably borrowed and borrowed place type can contain the qualif. In general we will now reject additional programs, program that were prevously unintentionally accepted. There are also some cases which are now accepted but were previously rejected, because previous implementation didn't consider whether borrowed place could have the qualif under the consideration. Fixes #90124. r? `@ecstatic-morse`
2021-10-28Revert "Add rustc lint, warning when iterating over hashmaps"Mark Rousskov-1/+0
2021-10-28Use type based qualification for unionsTomasz Miąsko-1/+14
Union field access is currently qualified based on the qualification of a value previously assigned to the union. At the same time, every union access transmutes the content of the union, which might result in a different qualification. For example, consider constants A and B as defined below, under the current rules neither contains interior mutability, since a value used in the initial assignment did not contain `UnsafeCell` constructor. ```rust #![feature(untagged_unions)] union U { i: u32, c: std::cell::Cell<u32> } const A: U = U { i: 0 }; const B: std::cell::Cell<u32> = unsafe { U { i: 0 }.c }; ``` To avoid the issue, the changes here propose to consider the content of a union as opaque and use type based qualification for union types.
2021-10-27Remove `is_const_fn` in `find_mir_or_eval_fn`Gary Guo-9/+3
2021-10-26Consider indirect mutation during const qualification dataflowTomasz Miąsko-63/+157
Previously a local would be qualified if either one of two separate data flow computations indicated so. First determined if a local could contain the qualif, but ignored any forms of indirect mutation. Second determined if a local could be mutably borrowed (and so indirectly mutated), but which in turn ignored the qualif. The end result was incorrect because the effect of indirect mutation was effectivelly ignored in the all but the final stage of computation. In the new implementation the indirect mutation is directly incorporated into the qualif data flow. The local variable becomes immediately qualified once it is mutably borrowed and borrowed place type can contain the qualif. In general we will now reject additional programs, program that were prevously unintentionally accepted. There are also some cases which are now accepted but were previously rejected, because previous implementation didn't consider whether borrowed place could have the qualif under the consideration.
2021-10-25Clean up special function const checksGary Guo-77/+41
Mark them as const and `#[rustc_do_not_const_check]` instead of hard-coding them in const-eval checks.
2021-10-24Rollup merge of #89558 - lcnr:query-stable-lint, r=estebankMatthias Krüger-0/+1
Add rustc lint, warning when iterating over hashmaps r? rust-lang/wg-incr-comp
2021-10-23Auto merge of #90203 - matthiaskrgr:rollup-v215wew, r=matthiaskrgrbors-1/+10
Rollup of 5 pull requests Successful merges: - #85833 (Scrape code examples from examples/ directory for Rustdoc) - #88041 (Make all proc-macro back-compat lints deny-by-default) - #89829 (Consider types appearing in const expressions to be invariant) - #90168 (Reset qualifs when a storage of a local ends) - #90198 (Add caveat about changing parallelism and function call overhead) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-10-23Rollup merge of #90168 - tmiasko:const-qualif-storage, r=matthewjasperMatthias Krüger-1/+10
Reset qualifs when a storage of a local ends Reset qualifs when a storage of a local ends to ensure that the local qualifs are affected by the state from previous loop iterations only if the local is kept alive. The change should be forward compatible with a stricter handling of indirect assignments, since storage dead invalidates all existing pointers to the local.
2021-10-23Auto merge of #90104 - spastorino:coherence-for-negative-trait, r=nikomatsakisbors-0/+2
Implement coherence checks for negative trait impls The main purpose of this PR is to be able to [move Error trait to core](https://github.com/rust-lang/project-error-handling/issues/3). This feature is necessary to handle the following from impl on box. ```rust impl From<&str> for Box<dyn Error> { ... } ``` Without having negative traits affect coherence moving the error trait into `core` and moving that `From` impl to `alloc` will cause the from impl to no longer compiler because of a potential future incompatibility. The compiler indicates that `&str` _could_ introduce an `Error` impl in the future, and thus prevents the `From` impl in `alloc` that would cause overlap with `From<E: Error> for Box<dyn Error>`. Adding `impl !Error for &str {}` with the negative trait coherence feature will disable this error by encoding a stability guarantee that `&str` will never implement `Error`, making the `From` impl compile. We would have this in `alloc`: ```rust impl From<&str> for Box<dyn Error> {} // A impl<E> From<E> for Box<dyn Error> where E: Error {} // B ``` and this in `core`: ```rust trait Error {} impl !Error for &str {} ``` r? `@nikomatsakis` This PR was built on top of `@yaahc` PR #85764. Language team proposal: to https://github.com/rust-lang/lang-team/issues/96
2021-10-23Reset qualifs when a storage of a local endsTomasz Miąsko-1/+10
to ensure that the local qualifs are affected by the state from previous loop iterations only if the local is kept alive. The change should be forward compatible with a stricter handling of indirect assignments, since storage dead invalidates all existing pointers to the local.
2021-10-23Rollup merge of #89920 - hudson-ayers:location-detail-control, r=davidtwcoMatthias Krüger-4/+11
Implement -Z location-detail flag This PR implements the `-Z location-detail` flag as described in https://github.com/rust-lang/rfcs/pull/2091 . `-Z location-detail=val` controls what location details are tracked when using `caller_location`. This allows users to control what location details are printed as part of panic messages, by allowing them to exclude any combination of filenames, line numbers, and column numbers. This option is intended to provide users with a way to mitigate the size impact of `#[track_caller]`. Some measurements of the savings of this approach on an embedded binary can be found here: https://github.com/rust-lang/rust/issues/70579#issuecomment-942556822 . Closes #70580 (unless people want to leave that open as a place for discussion of further improvements). This is my first real PR to rust, so any help correcting mistakes / understanding side effects / improving my tests is appreciated :) I have one question: RFC 2091 specified this as a debugging option (I think that is what -Z implies?). Does that mean this can never be stabilized without a separate MCP? If so, do I need to submit an MCP now, or is the initial RFC specifying this option sufficient for this to be merged as is, and then an MCP would be needed for eventual stabilization?
2021-10-22Rollup merge of #90069 - tmiasko:promoted-const-qualif, r=oli-obkYuki Okushi-2/+9
Fix const qualification when executed after promotion The const qualification was so far performed before the promotion and the implementation assumed that it will never encounter a promoted. With `const_precise_live_drops` feature, checking for live drops is delayed until after drop elaboration, which in turn runs after promotion. so the assumption is no longer true. When evaluating `NeedsNonConstDrop` it is now possible to encounter promoteds. Use type base qualification for the promoted. It is a sound approximation in general, and in the specific case of promoteds and `NeedsNonConstDrop` it is precise. Fixes #89938.
2021-10-21Configure saved panic locations based on location-detail flagHudson Ayers-4/+11
2021-10-21Verify that only NeedsNonConstDrop expects promotedsTomasz Miąsko-4/+10
2021-10-21Rollup merge of #90071 - cjgillot:no-blocks, r=oli-obkYuki Okushi-3/+2
Remove hir::map::blocks and use FnKind instead The principal tool is `FnLikeNode`, which is not often used and can be easily implemented using `rustc_hir::intravisit::FnKind`.
2021-10-20Remove `box_alloc` from `Machine` trait.Gary Guo-14/+1
2021-10-20Remove NullOp::BoxGary Guo-7/+0
2021-10-20Add polarity to TraitPredicateSantiago Pastorino-0/+2
2021-10-19Replace FnLikeNode by FnKind.Camille GILLOT-3/+2
2021-10-20Rollup merge of #88860 - nbdd0121:panic, r=m-ou-seYuki Okushi-4/+1
Deduplicate panic_fmt std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.
2021-10-19Auto merge of #89933 - est31:let_else, r=michaelwoeristerbors-3/+2
Adopt let_else across the compiler This performs a substitution of code following the pattern: ``` let <id> = if let <pat> = ... { identity } else { ... : ! }; ``` To simplify it to: ``` let <pat> = ... { identity } else { ... : ! }; ``` By adopting the `let_else` feature (cc #87335). The PR also updates the syn crate because the currently used version of the crate doesn't support `let_else` syntax yet. Note: Generally I'm the person who *removes* usages of unstable features from the compiler, not adds more usages of them, but in this instance I think it hopefully helps the feature get stabilized sooner and in a better state. I have written a [comment](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205) on the tracking issue about my experience and what I feel could be improved before stabilization of `let_else`.
2021-10-19Deduplicate panic_fmtGary Guo-4/+1
std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.
2021-10-19Fix const qualification when executed after promotionTomasz Miąsko-2/+3
The const qualification was so far performed before the promotion and the implementation assumed that it will never encounter a promoted. With `const_precise_live_drops` feature, checking for live drops is delayed until after drop elaboration, which in turn runs after promotion. so the assumption is no longer true. When evaluating `NeedsNonConstDrop` it is now possible to encounter promoteds. Use type base qualification for the promoted. It is a sound approximation in general, and in the specific case of promoteds and `NeedsNonConstDrop` it is precise.
2021-10-18Do not promote values with const drop that need to be droppedTomasz Miąsko-5/+57
Changes from #88558 allowed using `~const Drop` in constants by introducing a new `NeedsNonConstDrop` qualif. The new qualif was also used for promotion purposes, and allowed promotion to happen for values that needs to be dropped but which do have a const drop impl. Since for promoted the drop implementation is never executed, this lead to observable change in behaviour. For example: ```rust struct Panic(); impl const Drop for Panic { fn drop(&mut self) { panic!(); } } fn main() { let _ = &Panic(); } ``` Restore the use of `NeedsDrop` qualif during promotion to avoid the issue.
2021-10-18Rename `needs_drop` to `needs_non_const_drop`Tomasz Miąsko-14/+14
2021-10-17Auto merge of #89514 - davidtwco:polymorphize-shims-and-predicates, r=lcnrbors-1/+2
polymorphization: shims and predicates Supersedes #75737 and #75414. This pull request includes up some changes to polymorphization which hadn't landed previously and gets stage2 bootstrapping and the test suite passing when polymorphization is enabled. There are still issues with `type_id` and polymorphization to investigate but this should get polymorphization in a reasonable state to work on. - #75737 and #75414 both worked but were blocked on having the rest of the test suite pass (with polymorphization enabled) with and without the PRs. It makes more sense to just land these so that the changes are in. - #75737's changes remove the restriction of `InstanceDef::Item` on polymorphization, so that shims can now be polymorphized. This won't have much of an effect until polymorphization's analysis is more advanced, but it doesn't hurt. - #75414's changes remove all logic which marks parameters as used based on their presence in predicates - given #75675, this will enable more polymorphization and avoid the symbol clashes that predicate logic previously sidestepped. - Polymorphization now explicitly checks (and skips) foreign items, this is necessary for stage2 bootstrapping to work when polymorphization is enabled. - The conditional determining the emission of a note adding context to a post-monomorphization error has been modified. Polymorphization results in `optimized_mir` running for shims during collection where that wouldn't happen previously, some errors are emitted during `optimized_mir` and these were considered post-monomorphization errors with the existing logic (more errors and shims have a `DefId` coming from the std crate, not the local crate), adding a note that resulted in tests failing. It isn't particularly feasible to change where polymorphization runs or prevent it from using `optimized_mir`, so it seemed more reasonable to not change the conditional. - `characteristic_def_id_of_type` was being invoked during partitioning for self types of impl blocks which had projections that depended on the value of unused generic parameters of a function - this caused a ICE in a debuginfo test. If partitioning is enabled and the instance needs substitution then this is skipped. That test still fails for me locally, but not with an ICE, but it fails in a fresh checkout too, so 🤷‍♂️. r? `@lcnr`
2021-10-16Adopt let_else across the compilerest31-3/+2
This performs a substitution of code following the pattern: let <id> = if let <pat> = ... { identity } else { ... : ! }; To simplify it to: let <pat> = ... { identity } else { ... : ! }; By adopting the let_else feature.
2021-10-15allow `potential_query_instability` everywherelcnr-0/+1
2021-10-15Rollup merge of #89894 - camsteffen:unused-deps, r=Mark-SimulacrumMatthias Krüger-2/+0
Remove unused dependencies from rustc_const_eval
2021-10-15Rollup merge of #89859 - RalfJung:write-discriminant, r=oli-obkMatthias Krüger-1/+15
add dedicated error variant for writing the discriminant of an uninhabited enum variant This is conceptually different from hitting an `Unreachable` terminator. Also add some sanity check making sure we don't write discriminants of things that do not have discriminants. r? ``@oli-obk``
2021-10-14Remove unused dependencies from rustc_const_evalCameron Steffen-2/+0
2021-10-14add dedicated error variant for writing the discriminant of an uninhabited ↵Ralf Jung-1/+15
enum variant
2021-10-14Fix const stabilityDeadbeef-2/+5
2021-10-12Add const_eval_select intrinsicDeadbeef-29/+62
2021-10-08Auto merge of #89619 - michaelwoerister:incr-vtables, r=nagisabors-1/+1
Turn vtable_allocation() into a query This PR removes the untracked vtable-const-allocation cache from the `tcx` and turns the `vtable_allocation()` method into a query. The change is pretty straightforward and should be backportable without too much effort. Fixes https://github.com/rust-lang/rust/issues/89598.
2021-10-07Turn tcx.vtable_allocation() into a query.Michael Woerister-1/+1
2021-10-05Auto merge of #89266 - cjgillot:session-ich, r=michaelwoeristerbors-1/+2
Move ICH to rustc_query_system Based on https://github.com/rust-lang/rust/pull/89183 The StableHashingContext does not need to be in rustc_middle. This PR moves it to rustc_query_system. This will avoid a dependency between rustc_ast_lowering and rustc_middle in https://github.com/rust-lang/rust/pull/89124.
2021-10-04Rollup merge of #89482 - hkmatsumoto:patch-diagnostics, r=joshtriplettManish Goregaokar-1/+1
Follow the diagnostic output style guide Detected by #89455.
2021-10-04Rollup merge of #89508 - jhpratt:stabilize-const_panic, r=joshtriplettJubilee-19/+0
Stabilize `const_panic` Closes #51999 FCP completed in #89006 ```@rustbot``` label +A-const-eval +A-const-fn +T-lang cc ```@oli-obk``` for review (not `r?`'ing as not on lang team)
2021-10-04Stabilize `const_panic`Jacob Pratt-19/+0