Commit Graph

266 Commits

Author SHA1 Message Date
Josh Stone
99f6de759e
Rollup merge of #59430 - kenta7777:rename-evalcontext-to-interpretcx, r=oli-obk
Renames `EvalContext` to `InterpretCx`

This PR renames `EvalContext` to `InterpretCx` in `src/librustc_mir`.
This PR is related to #54395 .
2019-03-27 18:15:36 -07:00
Mazdak Farrokhzad
90c2d641eb
Rollup merge of #59232 - saleemjaffer:mir_place_refactor, r=oli-obk
Merge `Promoted` and `Static` in `mir::Place`

fixes #53848
2019-03-26 09:05:40 +01:00
kenta7777
630d5a4895 renames EvalContext to InterpretCx. 2019-03-26 13:06:15 +09:00
Esteban Küber
8e043950c8 Swap const evaluation lint spans to point at problem in primary span 2019-03-23 13:05:30 -07:00
Saleem Jaffer
752544b284 adding mir::StaticKind enum for static and promoted 2019-03-23 20:18:52 +05:30
Saleem Jaffer
cf2f1bb072 review fixes 2019-03-21 22:13:09 +05:30
Saleem Jaffer
23c87a1f53 fixed all compilation errors 2019-03-18 15:03:30 +05:30
Saleem Jaffer
a837b8a368 cleaner code as per review 2019-03-18 15:03:30 +05:30
Saleem Jaffer
7fb1c22da1 promoted is still left in 2 places 2019-03-18 15:03:29 +05:30
Oliver Scherer
5cd2806621 Revert the LazyConst PR 2019-03-16 21:04:10 +01:00
ljedrz
cd06038b54 HirIdification: replace NodeId method calls 2019-03-07 09:22:43 +01:00
bors
c1d2d83ca3 Auto merge of #58754 - ljedrz:I_hate_NodeIds, r=Zoxc
Remove NodeId from more HIR nodes

The next iteration of HirIdification (#57578).

Removes `NodeId` from:

- [x] `Stmt`
- [x] `Local`
- [x] `Field`
- [x] `AnonConst`
- [x] `TraitItem`
- [x] `ImplItem`
- [x] `TypeBinding`
- [x] `Arg`
- [x] `TraitRef`
- [x] `VisibilityKind`

It will most probably break clippy again; I'd appreciate a **delegate** again if/when it is good to go so I can attach a clippy fix later.

r? @Zoxc
2019-03-01 15:36:13 +00:00
ljedrz
c2e517e0c4 ty: HirIdify some lints 2019-03-01 11:18:49 +01:00
Santiago Pastorino
0f993d5a7a Put Local, Static and Promoted as one Base variant of Place 2019-03-01 05:02:00 +01:00
csmoe
cf11729787 rename Substs to InternalSubsts
Change-Id: I3fa00e999a2ee4eb72db1fdf53a8633b49176a18
2019-02-27 00:39:13 +08:00
bors
ea43c3c688 Auto merge of #58561 - ljedrz:HirIdify_some_nodes, r=Zoxc
Remove NodeId from some HIR nodes

The next iteration of https://github.com/rust-lang/rust/pull/57578.

Removes `NodeId` from:

- [x] `Lifetime`
- [x] `Ty`
- [x] `GenericParam`
- [x] `WhereClause`
- [x] `WhereEqPredicate`
- [x] `MacroDef`
- [x] `Block`
- [x] `Expr`

r? @Zoxc
2019-02-26 06:13:27 +00:00
ljedrz
021a140dcd hir: remove NodeId from Block 2019-02-24 17:09:26 +01:00
Oliver Scherer
4fdeb2da74 Add eval prefix to clarify what the function does 2019-02-16 14:56:07 +01:00
Oliver Scherer
235a6b7d06 Expose const -> op functions that don't allow violiting const eval invariants 2019-02-16 12:32:22 +01:00
Ralf Jung
b376ae6671 make bin_op and unary_op APIs consistently work on ImmTy 2019-02-13 10:14:56 +01:00
Ralf Jung
e73f96abe7 make OpTy.op private, and ImmTy.imm public instead 2019-02-13 10:14:56 +01:00
Ralf Jung
2708946787 pass full InstanceDef to run_passes 2019-02-09 12:11:12 +01:00
Taiki Endo
725af30809 librustc_mir => 2018 2019-02-08 06:28:15 +09:00
Oliver Scherer
f6da141b5f Span fixup 2019-01-22 17:22:30 +01:00
Oliver Scherer
a59eabbc36 Get rid of the fake stack frame 2019-01-22 17:22:29 +01:00
Oliver Scherer
089c4039c6 Pacify tidy 2019-01-01 20:05:02 +01:00
Oliver Scherer
bb9f717a80 const_to_op is now lazy_const_to_op 2019-01-01 20:05:02 +01:00
Oliver Scherer
b903cb9d60 Move the Unevaluated constant arm upwards in the type structure 2019-01-01 20:05:02 +01:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Ralf Jung
81a45e2038 miri: allocation is infallible 2018-12-19 14:11:01 +01:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
John Kåre Alsaker
a70babed03 Use a function to access the Hir map to be able to turn it into a query later 2018-12-06 17:24:36 +01:00
bors
b51632e3f0 Auto merge of #56070 - oli-obk:const_let, r=eddyb
Allow assignments in const contexts

fixes https://github.com/rust-lang/rust/issues/54098
fixes https://github.com/rust-lang/rust/issues/51251
fixes https://github.com/rust-lang/rust/issues/52613
2018-11-26 08:17:36 +00:00
Ralf Jung
ba82f54b04 use RawConst in miri 2018-11-19 22:42:46 +01:00
Ralf Jung
b50c1b243e Make const_eval_raw query return just an AllocId 2018-11-19 22:42:46 +01:00
Oliver Scherer
59eff14120 Also catch static mutation at evaluation time 2018-11-19 16:46:03 +01:00
Oliver Scherer
df10965dc0 Prevent ICE in const-prop array oob check 2018-11-08 20:15:13 +01:00
Ralf Jung
c905497766 miri: binary_op_val -> binary_op_imm 2018-11-05 09:10:48 +01:00
Eduard-Mihai Burtescu
d00d42d079 rustc_target: pass contexts by reference, not value. 2018-11-04 20:33:57 +02:00
Oliver Scherer
e8a22b692a Rename Value to Immediate for miri 2018-11-02 16:56:59 +01:00
Ralf Jung
aaa505af02 remove some unused CTFE error variants 2018-10-28 11:33:33 +01:00
Ralf Jung
02a42382f6 rename env var to control ctfe backtraces, and make it usually show the backtrace delayed
The env var is now RUST_CTFE_BACKTRACE.  Similar to RUST_BACKTRACE, it usually
only prints a backtrace when the error actually surfaces, not when it happens.
This makes a difference when we catch errors.

As per @oli-obk's request, one can set RUST_CTFE_BACKTRACE=immediate to get the
backtrace shown immediately.
2018-10-28 11:33:27 +01:00
David Wood
6208bd8e03
Refactor and add PlaceContext::AscribeUserTy.
This commit refactors `PlaceContext` to split it into four different
smaller enums based on if the context represents a mutating use,
non-mutating use, maybe-mutating use or a non-use (this is based on the
recommendation from @oli-obk on Zulip[1]).

This commit then introduces a `PlaceContext::AscribeUserTy` variant.
`StatementKind::AscribeUserTy` is now correctly mapped to
`PlaceContext::AscribeUserTy` instead of `PlaceContext::Validate`.
`PlaceContext::AscribeUserTy` can also now be correctly categorized as a
non-use which fixes an issue with constant promotion in statics after a
cast introduces a `AscribeUserTy` statement.

[1]: https://rust-lang.zulipchat.com/#narrow/stream/122657-wg-nll/subject/.2355288.20cast.20fails.20to.20promote.20to.20'static/near/136536949
2018-10-27 12:11:37 +02:00
Oliver Schneider
b4ee38ede3 Don't extend hir::Def when there's already a dedicated "function-like" detector 2018-10-25 16:47:35 +02:00
Oliver Schneider
7fdf06cdde Report const eval error inside the query 2018-10-25 16:46:19 +02:00
Ralf Jung
616cb6356f miri engine: also check return type before calling function 2018-10-09 13:08:00 +02:00
Ralf Jung
d62aa3e085 move ScalarMaybeUndef into the miri engine 2018-09-30 13:09:26 +02:00
Ralf Jung
c16336a014 move loop detector constants to the module that uses them; make lifetime order in ConstPropagator consistent with Memory 2018-09-20 11:57:45 +02:00
Ralf Jung
018d128325 rename evaluator -> interpreter to make eddyb happy 2018-09-20 10:36:25 +02:00
Ralf Jung
169f7911e9 move CTFE engine snapshot state out of miri engine into CTFE machine instance 2018-09-20 10:12:21 +02:00
bors
968d95e940 Auto merge of #53903 - GabrielMajeri:opt-miri-array-slice, r=oli-obk
Optimize miri checking of integer array/slices

This pull request implements the optimization described in #53845 (the  `E-easy` part of that issue, not the refactoring). Instead of checking every element of an integral array, we can check the whole memory range at once.

r? @RalfJung
2018-09-08 17:36:09 +00:00
Gabriel Majeri
82cde902c5 Optimize miri checking of integer array/slices
Instead of checking every element, we can check the whole memory
range at once.
2018-09-08 07:13:19 +03:00
Niko Matsakis
5aee959e9f make field always private, add From impls 2018-09-07 11:37:46 -04:00
Ralf Jung
1d498d5a43 make ptr_op finally reponsible for all ops involving pointers; make ValTy constructor private
Also remove public OpTy constructors, but a pub(crate) constructor remains
2018-08-29 08:44:37 +02:00
Ralf Jung
ec056d5188 re-do argument passing one more time to finally be sane 2018-08-29 08:44:37 +02:00
Ralf Jung
506dd7058c fix const_prop detecting unary neg underflows 2018-08-28 19:57:05 +02:00
Ralf Jung
f96208ca5b address nits 2018-08-28 19:57:05 +02:00
Ralf Jung
035c69f658 switch validation to use operand, not mplace
this means we can get rid of the public allocate_op, and make OpTy only
constructible in librustc_mir
2018-08-27 18:12:49 +02:00
Oliver Schneider
bb78426ca8 Allow panicking with string literal messages inside constants 2018-08-22 18:28:57 +02:00
Ralf Jung
ad2de8b4ee miri/CTFE refactor
* Value gets renamed to Operand, so that now interpret::{Place, Operand} are the
  "dynamic" versions of mir::{Place, Operand}.
* Operand and Place share the data for their "stuff is in memory"-base in a new
  type, MemPlace.  This also makes it possible to give some more precise types
  in other areas.  Both Operand and MemPlace have methods available to project
  into fields (and other kinds of projections) without causing further
  allocations.
* The type for "a Scalar or a ScalarPair" is called Value, and again used to
  give some more precise types.
* All of these have versions with an attached layout, so that we can more often
  drag the layout along instead of recomputing it.  This lets us get rid of
  `PlaceExtra::Downcast`.  MPlaceTy and PlaceTy can only be constructed
  in place.rs, making sure the layout is handled properly.
  (The same should eventually be done for ValTy and OpTy.)
* All the high-level functions to write typed memory take a Place, and live in
  place.rs.  All the high-level typed functions to read typed memory take an
  Operand, and live in operands.rs.
2018-08-22 09:06:28 +02:00
Donato Sciarra
82607d2cf3 mv (mod) codemap source_map 2018-08-19 23:01:00 +02:00
Oliver Schneider
afcbc2e90f Remove an overly pedantic and wrong assertion 2018-08-07 18:37:50 +02:00
Oliver Schneider
c53aa2989a Address stylistic review comments and rebase fallout 2018-08-01 15:29:35 +02:00
Oliver Schneider
c6c06854c0 Reintroduce Undef and properly check constant value sizes 2018-08-01 15:29:35 +02:00
Oliver Schneider
9377041de9 Sanity-check all constants 2018-07-29 20:22:15 +02:00
Oliver Schneider
ef5fba0067 Hide some lints which are not quite right the way they are reported to the user 2018-07-25 13:05:05 +02:00
Oliver Schneider
de511438cd Promoteds are statics and statics have a place, not just a value 2018-07-23 09:51:30 +02:00
Oliver Schneider
9329957d32 Const-propagate casts 2018-07-18 18:52:43 +02:00
Oliver Schneider
4d473300a2 Turn the use of erroneous constants into errors again 2018-06-28 11:04:26 +02:00
Oliver Schneider
4eea1a4e5e Don't const propagate the body of constants 2018-06-28 11:04:25 +02:00
Oliver Schneider
4bb9648b27 Merge ConstVal and ConstValue 2018-06-28 11:04:25 +02:00
Oliver Schneider
05994779ea Move everything over from middle::const_val to mir::interpret 2018-06-28 11:02:31 +02:00
Oliver Schneider
6005b0ad2f Move the Lrc outside the error type and name the fields 2018-06-28 11:01:35 +02:00
Oliver Schneider
6f8fe4eaef Eliminate old CTFE's ErrKind 2018-06-28 11:01:35 +02:00
Oliver Schneider
8a74be6684 Add source information the const propagation of places 2018-06-05 20:49:47 +02:00
Oliver Schneider
5c0d1355f2 Refactor the const eval diagnostic API 2018-06-05 20:49:46 +02:00
Fabian Zaiser
589f9a87a8 Propagate uses of constants correctly so that array index checks work 2018-06-05 10:35:44 +02:00
Oliver Schneider
f7eedfab8e Simplify value field access 2018-06-04 14:50:29 +02:00
Oliver Schneider
47f37d67f1 Correctly access ScalarPair fields during const eval 2018-06-02 23:34:25 +02:00
Eduard-Mihai Burtescu
ca1ac6b6fb rustc: rename mir::SourceScopeInfo to mir::SourceScopeLocalData. 2018-05-30 20:30:09 +03:00
Eduard-Mihai Burtescu
85d44c4276 rustc: rename mir::VisibilityScope to mir::SourceScope. 2018-05-30 20:30:09 +03:00
Oliver Schneider
cc60a22b10 Get rid of scalar_size 2018-05-24 20:49:37 +02:00
Oliver Schneider
f82256e473 primval -> scalar rename 2018-05-24 20:49:37 +02:00
Oliver Schneider
64a75ecc80 change Value::Bytes to Value::Bits 2018-05-24 20:49:37 +02:00
Oliver Schneider
ef2177cffc Rename ByVal(Pair) to Scalar(Pair) 2018-05-24 20:47:35 +02:00
Oliver Schneider
1606e137e7 Rename PrimVal to Scalar 2018-05-24 20:47:35 +02:00
varkor
15d2759d90 Rename has_type_parameters to requires_monomorphization 2018-05-15 14:20:19 +01:00
varkor
a9622dc5c6 Fix generics type parameter handling in miri 2018-05-15 14:20:19 +01:00
John Kåre Alsaker
fdd9787777 Introduce ConstValue and use it instead of miri's Value for constant values 2018-05-11 13:01:44 +02:00
Oliver Schneider
01158eaec6
Unify MIR assert messages and const eval errors 2018-04-30 18:29:15 +02:00
Oliver Schneider
cefcf0548e
Merge ConstMathError into EvalErrorKind 2018-04-30 18:18:33 +02:00
Irina Popa
7a5147616b rustc_target: move LayoutOf's type parameter to an associated type. 2018-04-26 16:50:28 +03:00
Oliver Schneider
a406af885d
Only warn on erroneous promoted constants 2018-04-15 15:08:37 +02:00
Oliver Schneider
c0fc6a8b6b
simplify constant value pair field access 2018-03-08 08:35:39 +01:00
Oliver Schneider
b5ace9a906
Unify the const folding errors
before they differed depending on whether optimizations were on or not
2018-03-08 08:35:39 +01:00
Oliver Schneider
3dc7e93db6
Generator assertions are unconditionally triggered 2018-03-08 08:35:38 +01:00
Oliver Schneider
df283df887
Don't use the undefined bytes of PrimVal::Bytes 2018-03-08 08:34:18 +01:00
Oliver Schneider
5b698a1040
Unregress error spans in constant errors 2018-03-08 08:34:17 +01:00
Oliver Schneider
3c663d0607
Tidy fix 2018-03-08 08:34:16 +01:00
Oliver Schneider
8c53d54b98
Update tests 2018-03-08 08:34:16 +01:00
Oliver Schneider
d2f363ba89
Report all errors other than those about insufficient type information 2018-03-08 08:34:15 +01:00
Oliver Schneider
64fbf5d5ad
Compute the ParamEnv only once and use it to call tcx.const_eval 2018-03-08 08:34:15 +01:00
Oliver Schneider
dde68dcfe5
Can only const prop temporaries
Variables might error in branches that are not reachable due to the variable value.
2018-03-08 08:34:15 +01:00
Oliver Schneider
1561b4ad50
Simplify const propagator by removing unused code paths 2018-03-08 08:34:15 +01:00
Oliver Schneider
411fcf58fd
Rename OptimizationFinder and don't propagate any borrows 2018-03-08 08:34:15 +01:00
Oliver Schneider
57ae890265
Simplify const prop checks through PlaceContext 2018-03-08 08:34:15 +01:00
Oliver Schneider
0462d092d2
Figure out const propgatable locals in a single pass 2018-03-08 08:34:14 +01:00
Oliver Schneider
ceb634a732
Update tests 2018-03-08 08:34:14 +01:00
Oliver Schneider
13c0dc56df
Only report bitshift lints on bitshift ops 2018-03-08 08:34:14 +01:00
Oliver Schneider
929a4cece5
Use IndexVec instead of FxHashMap 2018-03-08 08:34:14 +01:00
Oliver Schneider
8c8a433532
Merge const linting pass into const prop 2018-03-08 08:34:14 +01:00
Oliver Schneider
c568807989
Remove single field struct by just using the field 2018-03-08 08:34:13 +01:00
Oliver Schneider
4667346042
Remove the fragile const propagator and just do linting 2018-03-08 08:34:13 +01:00
Oliver Schneider
21554b96af
Fix ICE in const prop 2018-03-08 08:34:13 +01:00
Oliver Schneider
00c95b29bc
Revert all changes to the instcombine pass 2018-03-08 08:34:13 +01:00
Oliver Schneider
54615ec989
Split const prop into its own pass 2018-03-08 08:34:12 +01:00