88 Commits

Author SHA1 Message Date
bors
22e6099330 Auto merge of #74717 - 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-01 02:48:34 +00:00
David Wood
59e621c196
interp: needs_subst -> ensure_monomorphic_enough
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-31 16:36:42 +01:00
Philippe Nadon
55984b65ce renamed ScalarMaybeUninit::not_undef to check_init
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-22 22:58:11 -06:00
David Wood
2989fea88a
mir: unused_generic_params query
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-20 19:35:30 +01:00
Ralf Jung
2210abea71 keep root_span and tcx together 2020-06-14 15:06:16 +02:00
Ralf Jung
dc6ffaebd5 make miri InterpCx TyCtxtAt a TyCtxt, and separately remember the root span of the evaluation 2020-06-12 09:43:53 +02:00
Ralf Jung
8998c7afe8 try_validation: handle multi-branching, and use macro for most remaining manual throw_validation_failure sites 2020-05-06 13:30:54 +02:00
Ralf Jung
441419a923 properly catch invalid-drop-fn errors 2020-05-06 11:31:05 +02:00
Vytautas Astrauskas
c53210c550 Make the necessary changes to support concurrency in Miri. 2020-04-15 09:25:21 -07:00
Mazdak Farrokhzad
124144704f nix rustc_target::abi::* reexport in ty::layout 2020-04-02 13:40:43 +02:00
Mazdak Farrokhzad
0cb9e36090 rustc -> rustc_middle part 2 2020-03-30 07:16:56 +02:00
Ralf Jung
b7db7320ad go back to infix ops for Size 2020-03-25 15:53:53 +01:00
Ralf Jung
d7e2650db2 miri: avoid a bunch of casts by offering usized-based field indexing 2020-03-25 15:53:52 +01:00
Ralf Jung
1ddbdc6269 use checked casts and arithmetic in Miri engine 2020-03-25 15:53:52 +01:00
Aaron Hill
336b902f66
Use Instance.ty_env instead of Instance.monomorphic_ty in interpreter 2020-01-05 18:09:57 -05:00
Aaron Hill
33caf0b61f
Rename Instance.ty to Instance.monomorphic_ty 2020-01-05 14:59:40 -05:00
Mark Rousskov
a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Ralf Jung
b2392aa2fc dont ICE in case of invalid drop fn 2019-12-12 15:23:27 +01:00
Ralf Jung
cde17d9158 Add From instances for Pointer -> ScalarMaybeUndef and Pointer -> Immediate 2019-12-02 08:55:42 +01:00
Alexander Regueiro
51cb60cd3f Aggregation of drive-by cosmetic changes. 2019-11-21 18:50:38 +00:00
Aaron Hill
b4545a4ad6
Update 2019-11-11 15:14:38 -05:00
Aaron Hill
8df4248c71
Some cleanup 2019-11-11 15:14:33 -05:00
Ralf Jung
15ec8f7c52 rename Memory::get methods to get_raw to indicate their unchecked nature 2019-11-08 09:20:30 +01:00
Ralf Jung
0f3e596c1d miri: detect too large dynamically sized objects 2019-08-30 07:44:51 +02:00
Oliver Scherer
7dff647d23 Ensure miri can do bit ops on pointer values 2019-08-24 02:23:56 +02:00
Eduard-Mihai Burtescu
ceabe0dc54 rustc_mir: disallow non-monomorphic vtables. 2019-08-19 18:57:09 +03:00
Eduard-Mihai Burtescu
b4f217ed7b rustc_mir: remove wrong calls to subst_from_frame_and_normalize_erasing_regions. 2019-08-19 18:55:19 +03:00
Ralf Jung
d4196a7673 start cleaning up subst mess
fix an ICE

fix method name
2019-08-19 18:55:18 +03:00
Saleem Jaffer
69daf844da adding throw_ and err_ macros for InterpError 2019-07-30 15:25:12 +05:30
Saleem Jaffer
2a33fbff22 addding an interp_error module 2019-07-30 13:18:36 +05:30
Saleem Jaffer
307798aa38 fixing fallout due to InterpError refactor 2019-07-29 13:35:09 +05:30
Ralf Jung
842bbd2764 make Memory::get_fn take a Scalar like most of the Memory API surface 2019-07-04 10:38:54 +02:00
Ralf Jung
1297a274a3 Add basic support for "other" kinds of values for function pointers, determined by the machine instance.
So far, however, calling such a function will fail.
2019-07-04 10:38:54 +02:00
Ralf Jung
fc918a395a rename InterpretCx -> InterpCx
That's more consistent with InterpResult and InterpError.
2019-06-27 13:23:34 +02:00
Ralf Jung
9492038ae9 make code more symmetric 2019-06-23 18:06:11 +02:00
Ralf Jung
c50b9d197f Centralize bounds, alignment and NULL checking for memory accesses in one function: memory.check_ptr_access
That function also takes care of converting a Scalar to a Pointer, should that be needed.  Not all accesses need that though: if the access has size 0, None is returned.
Everyone accessing memory based on a Scalar should use this method to get the Pointer they need.

All operations on the Allocation work on Pointer inputs and expect all the checks to have happened (and will ICE if the bounds are violated).
The operations on Memory work on Scalar inputs and do the checks themselves.

The only other public method to check pointers is memory.ptr_may_be_null, which is needed in a few places.
With this, we can make all the other methods (tests for a pointer being in-bounds and checking alignment) private helper methods, used to implement the two public methods.
That maks the public API surface much easier to use and harder to mis-use.

While I am at it, this also removes the assumption that the vtable part of a `dyn Trait`-fat-pointer is a `Pointer` (as opposed to a pointer cast to an integer, stored as raw bits).
2019-06-23 15:55:04 +02:00
Eduard-Mihai Burtescu
37799a5552 rustc: replace TyCtxt<'a, 'gcx, 'tcx> with TyCtxt<'tcx, 'gcx, 'tcx>. 2019-06-12 13:38:27 +03:00
Ralf Jung
8f05ff3e33 rename EvalResult -> InterpResult and EvalError -> InterpErrorInfo 2019-06-08 11:39:48 +02:00
Mark Mansi
58bd0ea732 deduplicate ty::Instance constructors 2019-06-02 22:44:51 -05:00
Ralf Jung
2726a91cca cache tag for vtable; fn_alloc's don't have a stack nor tag 2019-06-02 10:21:00 +02:00
flip1995
e1da67e69c
Fix lint findings in librustc_mir 2019-04-28 21:19:27 +02:00
Ralf Jung
19485cc101 Miri: refactor new allocation tagging 2019-04-16 23:35:39 +02:00
bors
2226c09699 Auto merge of #59536 - Zoxc:the-arena, r=eddyb
Introduce an arena type which may be used to allocate a list of types with destructors

You can also specify that you want deserializers for `&'tcx [T]` and `&'tcx T` for a type in the list, which will allocate those using the arena.

Based on https://github.com/rust-lang/rust/pull/59517 and https://github.com/rust-lang/rust/pull/59533. Look at the last commit for the interesting changes.

An alternative to https://github.com/rust-lang/rust/pull/56448. cc @michaelwoerister @eddyb

r? @oli-obk
2019-04-12 06:10:19 +00:00
Ralf Jung
5731945187
Apply suggestions from code review
typos

Co-Authored-By: RalfJung <post@ralfj.de>
2019-04-08 10:29:22 +02:00
Ralf Jung
b00fd57075 implement by-value object safety 2019-04-07 20:04:44 +02:00
John Kåre Alsaker
002c70f2d4 Introduce an arena type which may be used to allocate a list of types with destructors 2019-04-05 00:55:07 +02:00
kenta7777
630d5a4895 renames EvalContext to InterpretCx. 2019-03-26 13:06:15 +09:00
Ralf Jung
e73f96abe7 make OpTy.op private, and ImmTy.imm public instead 2019-02-13 10:14:56 +01:00
Alexander Regueiro
c3e182cf43 rustc: doc comments 2019-02-10 23:42:32 +00:00
Taiki Endo
725af30809 librustc_mir => 2018 2019-02-08 06:28:15 +09:00