Commit Graph

568 Commits

Author SHA1 Message Date
Oliver 'ker' Schneider
b2d476eb38 type_size now returns None for unsized types 2016-11-11 13:07:41 +01:00
Oliver 'ker' Schneider
921f5af1fe ensure that integers cast to pointers will never point at a valid alloc, not even the zst alloc 2016-11-10 19:20:11 +01:00
Scott Olson
2d4301ea7e Simplify cast_ptr. 2016-11-06 22:30:56 -08:00
Scott Olson
a8d90ff12e Update for changes in rustc. 2016-11-06 22:25:54 -08:00
Scott Olson
33b1676bda Merge pull request #75 from oli-obk/master
implement more drop stuff
2016-11-06 01:29:14 -08:00
Oliver Schneider
9c85e203c5 remove leftover match 2016-11-05 17:09:37 +01:00
Paul Lietar
86062ef930 Read discriminant as a signed integer if specified by layout.
This ensures it gets sign extended correctly.

Fixes #78
2016-11-05 15:41:19 +00:00
Oliver Schneider
b6c7d76562 address nits 2016-11-05 13:02:29 +01:00
Oliver Schneider
392123552a
fix a bug error message 2016-11-04 17:55:06 +01:00
Oliver Schneider
53f1118517
remove needless allocations 2016-11-04 17:55:06 +01:00
Oliver Schneider
07c752cc82
fix the block processing for the drop_in_place intrinsic 2016-11-04 17:55:06 +01:00
Oliver Schneider
893f16389e
run drop on array elements 2016-11-04 17:34:33 +01:00
Oliver Schneider
5ef7924aa9
call drop for all elements of an owned slice 2016-11-04 16:51:43 +01:00
Oliver Schneider
c4c8764f53
generate a drop method pointer in the vtable and process it 2016-11-04 16:38:04 +01:00
Oliver Schneider
bd6e52d831
fix the drop_in_place intrinsic for fat pointers 2016-11-04 16:37:12 +01:00
Oliver Schneider
0420c27c8e
fix drop ordering and forward fat pointer extras to fields
this doesn't yet use the fat pointer extras
2016-11-04 15:55:05 +01:00
Oliver Schneider
859b7049c8
add method to ensure that a Value::ByRef is now a Value::ByVal* 2016-11-04 15:49:51 +01:00
Oliver Schneider
8003c570d8
don't panic on pointer to value comparison in primvals 2016-11-04 15:49:14 +01:00
Oliver Schneider
b12e7224af
move method to function so it can be used in map iterators without borrowing self 2016-11-04 15:48:45 +01:00
Oliver Schneider
73d7f1d41b
implement drop for NonZero optimized enums 2016-11-04 09:34:54 +01:00
Oliver Schneider
bd25230882
nit: move if let into match 2016-11-04 09:15:31 +01:00
Oliver Schneider
2a35b3e322
call user defined drop impls 2016-11-03 17:32:37 +01:00
Oliver Schneider
1e0d5b817d
implement a bunch of intrinsics 2016-11-03 17:32:06 +01:00
Oliver Schneider
50fd0765b5
call drop "glue" for enums 2016-11-03 15:55:09 +01:00
Oliver Schneider
b90cc77bac
basic struct and tuple drop "glue" 2016-11-03 15:22:39 +01:00
Oliver Schneider
feefb66ebd
recursively drop Box<Box<...Box<T>...>> 2016-11-03 13:30:54 +01:00
Oliver Schneider
a1acd9405d
don't allocate on drop calls 2016-11-03 13:27:35 +01:00
Oliver Schneider
a9b984d21e
don't always allocate for the uninit intrinsic 2016-11-03 13:13:47 +01:00
Oliver Schneider
92f6874ead
enable code sharing between global and local access 2016-11-03 12:52:13 +01:00
Oliver Schneider
bf73e7581e
don't always allocate during init intrinsic processing 2016-11-03 12:31:04 +01:00
Oliver Schneider
b3bf730513
don't panic on invalid primval types, report an error instead 2016-11-03 12:30:41 +01:00
Oliver Schneider
19c44dab05
rustup to rustc 1.14.0-nightly (7c69b0d5a 2016-11-01) 2016-11-03 10:38:08 +01:00
bluss
277a1ee869 rustup to rustc 1.14.0-nightly (3f4408347 2016-10-27) 2016-11-01 23:26:04 +01:00
Oliver Schneider
073f91654c
don't force allocate for most Unsize casts
only Arc<T> -> Arc<Trait> unsize casts are left
2016-10-21 15:18:12 +02:00
Oliver Schneider
9af5a0a420
don't force allocate for UnsafeFnPointer casts 2016-10-21 14:55:49 +02:00
Oliver Schneider
eb08a2e646
don't force allocate for ReifyFnPointer casts 2016-10-21 14:54:37 +02:00
Oliver Schneider
512f344a3b
don't force allocate for Misc casts 2016-10-21 13:56:38 +02:00
Scott Olson
7f3cb7fdb8 Merge pull request #68 from oli-obk/master
priroda requirements + static impl
2016-10-21 04:08:20 -06:00
Oliver Schneider
edc6b93b85
adjust some comments referencing locals 2016-10-21 12:03:34 +02:00
Oliver Schneider
9d0b903d9d
remove GlobalKind 2016-10-21 11:54:38 +02:00
Oliver Schneider
e82e6132ec
preemptively change some assertions into errors 2016-10-21 11:51:24 +02:00
Oliver Schneider
2f81729e76
rename more [Ss]tatic* to [Gg]lobal* 2016-10-21 11:48:56 +02:00
Oliver Schneider
d3b3c56b07
rename statics/Constant/ConstantId/ConstantKind to [gG]lobal* 2016-10-21 11:39:39 +02:00
Oliver Schneider
f6bbea0f08
choose better function and argument names 2016-10-21 11:24:10 +02:00
Oliver Schneider
9e9586da95
constant ids are Copy now 2016-10-21 11:21:52 +02:00
Scott Olson
e7bcf35f8a Simplify PrimValKind and remove a horrible hack.
This takes the `AllocId` out of PrimValKind, replacing it with a
`relocation` field on `PrimVal`, which is closer to an earlier design
for `PrimVal` I discussed with @eddyb.

This commit prepares the code for removing the `PrimValKind` from
`PrimVal` and making them more pure bitbags. The only code dealing with
`PrimValKind` will be code making decisions like "what kind of operation
do I need to do on these bits", like operators and casting. Transmutes
of `PrimVal`s will become true no-ops, not even adjusting a `kind`
field.

This commit also removes my horrible `value_to_primval` hack that made
an allocation for every `ByVal` passed in, so it could use `read_value`
to get a `PrimVal` with the right kind. Now I just compute the
`PrimValKind` from the `Ty` and re-tag the `PrimVal`.

The code got slightly messier in some areas here, but I think a _lot_ of
code will simplify in obvious ways once I remove the `kind` field from
`PrimVal`.

Gosh, if my commit messages aren't turning into essays these days.
2016-10-21 03:17:53 -06:00
Oliver Schneider
f81c4ac91b
more priroda requirements 2016-10-21 10:45:01 +02:00
Oliver Schneider
b8842b25e8
yield a miri error instead of panicking on uninitialized statics 2016-10-21 10:44:48 +02:00
Oliver Schneider
a75e7f7686
don't allocate statics unless a reference to them is created 2016-10-21 10:32:27 +02:00
Oliver Schneider
bef879083e
split eval_and_read_lvalue into two functions 2016-10-21 10:31:13 +02:00
Oliver Schneider
24be49f7dd
add a 'tcx lifetime to Lvalue in preparation for statics 2016-10-21 10:29:56 +02:00
Oliver Schneider
ed679c3d23
make some pieces public that are required by priroda 2016-10-20 13:10:22 +02:00
Scott Olson
330be7766f Represent PrimVals as "bitbags".
Now instead of holding a native type based on the tag, all PrimVals
store a u64 (the `bits`), along with a `kind` corresponding to the
variant as it would be in the old PrimVal representation.

This commit makes no major optimizations and attempts to not change any
behaviour. There will be commits to follow that make use of this
representation to eliminate unnecessary allocation hacks like in
`value_to_primval`.

A number of places could be even more cleaned up after this commit,
particularly in `cast.rs`.
2016-10-20 04:42:19 -06:00
Scott Olson
d6b4e1aba6 Expand on "uninit" FIXME. 2016-10-19 20:27:35 -06:00
Scott Olson
e807f0c405 Fix local dump check. 2016-10-18 23:24:30 -06:00
Scott Olson
1e93f64e15 Clean up read_value. 2016-10-18 22:31:21 -06:00
Scott Olson
4da533729b Dump local values on Lvalue creation. 2016-10-18 21:51:36 -06:00
Scott Olson
9e363952c0 Dump local values when they are read. 2016-10-18 21:45:48 -06:00
Scott Olson
39bb1254d1 Fix write_value of ByVal into a ByRef.
Previously, you could perform the following, if you assume we could make
`Cell<i32>` into a primitive. (Alternately, you could achieve this with
unsafe code):

    x = Cell::new(12);
    y = &x;

    // Miri locals array:
    //   x = ByRef(alloc123);
    //   y = ByVal(Ptr(alloc123));
    //
    // Miri allocations:
    //   alloc123: [12, 0, 0, 0]

    x.set(42);

    // Miri locals array:
    //   x = ByVal(I32(42));
    //   y = ByVal(Ptr(alloc123));
    //
    // Miri allocations:
    //   alloc123: [12, 0, 0, 0]

Notice how `y` still refers to the allocation that used to represent
`x`. But now `x` was changed to `42` and `y` is still looking at memory
containing `12`.

Now, instead, we keep `x` as a `ByRef` and write the `42` constant into
it.

Unit test to follow in the next commit.
2016-10-18 21:02:37 -06:00
Scott Olson
f5c0a24bb0 Make locals debug printing configurable. 2016-10-16 21:08:45 -06:00
Scott Olson
6503148589 Optimize reads of field projections of ByValPairs.
This helps in the case of field projections of the results of checked
binary operations. E.g.:

    _1 = CheckedAdd(const 1i32, const 2i32);
    assert(!(_1.1: bool), "attempt to add with overflow" -> bb1

Previously, the `_1.1` field projection lvalue would force_allocate `_1`
so it could read the memory in the old-style way. Now checked math with
its assertions will not allocate at all.

The oom2.rs compile-fail test had to be re-written, because the old
version of it no longer allocates _at all_ (yay!), so it would hit the
stack depth limit instead, from recursion.
2016-10-16 19:58:22 -06:00
Scott Olson
701eb3f62b Make locals debug printing smarter. 2016-10-16 17:18:56 -06:00
Scott Olson
7728de3e60 Do not force_allocate checked binop destination. 2016-10-16 17:18:06 -06:00
Scott Olson
3f67c4612c Refactor writing ByValPair to pointers. 2016-10-16 15:31:02 -06:00
Scott Olson
b1094f6c1e Deallocate primval conversion hack allocs.
It's a hack, sure, but it should learn some manners.
2016-10-16 03:21:41 -06:00
Scott Olson
55f2164bcd Do not force_allocate Deref base.
This makes `eval_lvalue` a bit less DRY for now, but it will be easier
to remove force_allocate in more places piecewise.
2016-10-16 02:57:59 -06:00
Scott Olson
e4f5b4b39a Do not force_allocate Ref destination. 2016-10-16 02:12:46 -06:00
Scott Olson
c1b97f1440 Pass thin self ptr to virtual calls. 2016-10-16 02:12:26 -06:00
Scott Olson
268bf9c185 Do not force_allocate CEnum destination. 2016-10-16 00:41:25 -06:00
Scott Olson
abf3e048ad Do not force_allocate Box destination. 2016-10-16 00:12:27 -06:00
Scott Olson
197e89bbb0 Refactor alloc_ptr. 2016-10-16 00:12:11 -06:00
Scott Olson
754dcc401d Do not force_allocate SwitchInt discrs. 2016-10-15 23:59:01 -06:00
Scott Olson
49e6c57ef9 Do not pre-allocate local variables.
Thanks to the `Value` locals refactoring, now primitive locals (ints,
floats, chars, bools, and the like) will not require `Allocation`s at
all, and locals that are never initialized at all because of conditional
control flow won't be wasting memory.
2016-10-15 23:31:42 -06:00
Scott Olson
6c463b7562 Hold an Lvalue for the return pointer in a frame.
Previously ReturnPointer was just the first slot in the locals array,
which had type `Vec<Pointer>`. But after my recent refactoring, locals
is `Vec<Value>` and it became increasingly hacky to pull a pointer out
of the first slot to be the value. Besides, that hack wouldn't allow
ReturnPointer to ever be an `Lvalue::Local`, referring directly to a
local on a higher stack frame.

Now ReturnPointer has no presence in the locals array, instead being
upgraded to its own field on `Frame`.

This introduces a couple of new hacks, detailed by some of my FIXME
comments, so that I could get the tests passing again and commit. More
commits coming soon should clean up these hacks without much trouble,
and overall I feel that the code is converging on a cleaner, more
efficient design.
2016-10-15 19:48:30 -06:00
Scott Olson
00ae07be07 Update for changes in rustc. 2016-10-14 22:59:50 -06:00
Scott Olson
65d3be0084 Add support for local Values in Lvalue.
The new `Lvalue` has an additional form, `Lvalue::Local`, with the old
form being `Lvalue::Ptr`. In an upcoming commit, we will start producing
the new form for locals, and enable reading and writing of primitive
locals without ever touching `Memory`.

Statics should be able to get a similar treatment, where primitive
statics can be stored and accessed without touching `Memory`.
2016-10-14 22:13:11 -06:00
Scott Olson
3d6dbb89dd Fix some long lines. 2016-10-14 03:52:23 -06:00
Scott Olson
8143a05812 Implement atomic_{load,store}. 2016-10-14 03:49:02 -06:00
Scott Olson
5f65ee2713 Refactor in preparation for Value locals.
Turning locals into `Vec<Value>` will allow writing `PrimVal` results
directly into the locals array without creating `memory::Allocation`s
for every local.

This will entail passing around a generalized kind of `Lvalue` instead
of `Pointer`s for the destinations of operations. Replacing `Pointer`
with `Lvalue` is mostly done with this commit, but expanding `Lvalue`
will come later.

This commit turns every local from `Pointer` into `Value::ByRef(ptr)`.
Locals which are `Value::ByVal(prim_val)` will come in a later commit.
2016-10-14 03:31:45 -06:00
Scott Olson
911e46fb0e Update for changes in rustc. 2016-10-03 20:45:50 -06:00
Oliver Schneider
de38015e47 rustup 2016-10-01 15:33:07 +02:00
Oliver Schneider
c9914cd3ae
fix enum variants with multiple fields 2016-09-30 10:45:52 +02:00
Oliver Schneider
8c666b30ed
remove some debug output 2016-09-30 10:45:13 +02:00
Oliver Schneider
18c8c852e4
factor out shared code 2016-09-29 16:42:01 +02:00
Oliver Schneider
f1c5bf2281
fix intrinsics and implement more of them 2016-09-29 15:58:26 +02:00
Scott Olson
870bb4d862 Reword inline assembly error. 2016-09-28 11:48:43 -06:00
Oliver Schneider
787feaad4b
allow tuple field indexing into anonymous tuples 2016-09-28 18:22:53 +02:00
Oliver Schneider
51abf19e12
don't panic on asm! 2016-09-28 18:22:25 +02:00
Oliver Schneider
1c18f6ddfa
implement slice patterns 2016-09-28 18:22:09 +02:00
Oliver Schneider
f1f6205145
we can get the Session from the TyCtxt 2016-09-27 18:06:51 +02:00
Oliver Schneider
5b89f3fb94
implement Arc<T> -> Arc<Trait> unsizing 2016-09-27 18:01:33 +02:00
Oliver Schneider
f4516e738b
be able to find statics in other crates 2016-09-27 17:02:04 +02:00
Oliver Schneider
db8185e439
print stacktrace when miri can't find the MIR for something 2016-09-27 17:01:06 +02:00
Oliver Schneider
69aeaea01f
rustup 2016-09-27 16:59:48 +02:00
Oliver Schneider
d6f1ba89ce
fix matching on chars
fixes #63
2016-09-27 11:10:25 +02:00
Oliver Schneider
7e29392ac4
fix warnings 2016-09-27 10:39:14 +02:00
Oliver Schneider
055c1b14f7
remove FIXME cleared up in the PR 2016-09-27 10:36:44 +02:00
Oliver Schneider
7b70f4fe2c
typecheck write_value for ByValPair 2016-09-27 10:33:47 +02:00
Oliver Schneider
d2d73a908d
reintroduce Lvalue and LvalueExtra 2016-09-27 10:14:53 +02:00
Oliver Schneider
5d1080d0ca
refactor Lvalue and PrimVal::{SlicePtr, VtablePtr} into Value::ByValPair 2016-09-26 17:49:30 +02:00