Skip to content

Commit

Permalink
Merge pull request rust-lang#278 from solson/unions
Browse files Browse the repository at this point in the history
Process untagged unions
  • Loading branch information
eddyb authored Aug 2, 2017
2 parents 7700bd0 + f8c61da commit cf318b1
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 73 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ script:
- |
# and run all tests with full mir
MIRI_SYSROOT=~/.xargo/HOST cargo test
- |
# test that the rustc_tests binary compiles
cd rustc_tests &&
cargo build &&
cd ..
notifications:
email:
on_success: never
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ rustc_miri = { path = "src/librustc_mir" }
compiletest_rs = "0.2.6"

[workspace]
exclude = ["xargo", "cargo-miri-test"]
exclude = ["xargo", "cargo-miri-test", "rustc_tests"]
6 changes: 6 additions & 0 deletions miri/fn_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
}

"syscall" => {
// TODO: read `syscall` ids like `sysconf` ids and
// figure out some way to actually process some of them
//
// libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)
// is called if a `HashMap` is created the regular way.
match self.value_to_primval(args[0], usize)?.to_u64()? {
318 |
511 => return Err(EvalError::Unimplemented("miri does not support random number generators".to_owned())),
id => return Err(EvalError::Unimplemented(format!("miri does not support syscall id {}", id))),
}
Expand Down
122 changes: 59 additions & 63 deletions rustc_tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rustc_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"]

[dependencies]
miri = { path = "../miri" }
miri = { path = ".." }
8 changes: 2 additions & 6 deletions rustc_tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,7 @@ fn main() {
args.push(Path::new(&std::env::var("HOME").unwrap()).join(".xargo").join("HOST").display().to_string());
}

// we run the optimization passes inside miri
// if we ran them twice we'd get funny failures due to borrowck ElaborateDrops only working on
// unoptimized MIR
// FIXME: add an after-mir-passes hook to rustc driver
args.push("-Zmir-opt-level=0".to_owned());
args.push("-Zmir-opt-level=3".to_owned());
// for auxilary builds in unit tests
args.push("-Zalways-encode-mir".to_owned());

Expand Down Expand Up @@ -218,7 +214,7 @@ fn main() {
}
}
}
let stderr = std::io::stderr();:{MetaItemKind, NestedMetaItemKind, self};
let stderr = std::io::stderr();
let mut stderr = stderr.lock();
writeln!(stderr, "{} success, {} no mir, {} crate not found, {} failed, \
{} C fn, {} ABI, {} unsupported, {} intrinsic",
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
let variant_def = adt_def.struct_variant();
use rustc::ty::layout::Layout::*;
match *self.type_layout(ty)? {
UntaggedUnion { ref variants } =>
Ok(TyAndPacked { ty: variant_def.fields[field_index].ty(self.tcx, substs), packed: variants.packed }),
Univariant { ref variant, .. } =>
Ok(TyAndPacked { ty: variant_def.fields[field_index].ty(self.tcx, substs), packed: variant.packed }),
_ => Err(EvalError::Unimplemented(format!("get_field_ty can't handle struct type: {:?}, {:?}", ty, ty.sty))),
Expand Down Expand Up @@ -988,8 +990,9 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
StructWrappedNullablePointer { ref nonnull, .. } => {
Ok(nonnull.offsets[field_index])
}
UntaggedUnion { .. } => Ok(Size::from_bytes(0)),
_ => {
let msg = format!("can't handle type: {:?}, with layout: {:?}", ty, layout);
let msg = format!("get_field_offset: can't handle type: {:?}, with layout: {:?}", ty, layout);
Err(EvalError::Unimplemented(msg))
}
}
Expand All @@ -1006,8 +1009,9 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
Vector { count , .. } |
Array { count, .. } => Ok(count),
Scalar { .. } => Ok(0),
UntaggedUnion { .. } => Ok(1),
_ => {
let msg = format!("can't handle type: {:?}, with layout: {:?}", ty, layout);
let msg = format!("get_field_count: can't handle type: {:?}, with layout: {:?}", ty, layout);
Err(EvalError::Unimplemented(msg))
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/run-pass-fullmir/unsized-tuple-impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(unsized_tuple_coercion)]

fn main() {
let x : &(i32, i32, [i32]) = &(0, 1, [2, 3]);
let y : &(i32, i32, [i32]) = &(0, 1, [2, 3, 4]);
let mut a = [y, x];
a.sort();
assert_eq!(a, [x, y]);

assert_eq!(&format!("{:?}", a), "[(0, 1, [2, 3]), (0, 1, [2, 3, 4])]");
}

0 comments on commit cf318b1

Please sign in to comment.