Adjust reflection for the possibility of discriminants larger than int.
Not only can discriminants be smaller than int now, but they can be larger than int on 32-bit targets. This has obvious implications for the reflection interface. Without this change, things fail with LLVM assertions when we try to "extend" i64 to i32.
This commit is contained in:
parent
92109b1202
commit
fcfbfde0b7
8 changed files with 44 additions and 40 deletions
|
|
@ -13,13 +13,8 @@ use std::mem;
|
|||
pub fn main() {
|
||||
enum E { V = 0x1717171717171717 }
|
||||
static C: E = V;
|
||||
let expected: u64 = if mem::size_of::<uint>() < 8 {
|
||||
0x17171717
|
||||
} else {
|
||||
0x1717171717171717
|
||||
};
|
||||
assert_eq!(expected, V as u64);
|
||||
assert_eq!(expected, C as u64);
|
||||
assert_eq!(V as u64, 0x1717171717171717u64);
|
||||
assert_eq!(C as u64, 0x1717171717171717u64);
|
||||
assert_eq!(format!("{:?}", V), ~"V");
|
||||
assert_eq!(format!("{:?}", C), ~"V");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
use std::libc::c_void;
|
||||
use std::ptr;
|
||||
use std::mem;
|
||||
use std::unstable::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Opaque};
|
||||
use std::unstable::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Disr, Opaque};
|
||||
use std::unstable::raw::Vec;
|
||||
|
||||
#[doc = "High-level interfaces to `std::unstable::intrinsics::visit_ty` reflection system."]
|
||||
|
|
@ -380,7 +380,7 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
|
|||
}
|
||||
|
||||
fn visit_enter_enum(&mut self, n_variants: uint,
|
||||
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
get_disr: extern unsafe fn(ptr: *Opaque) -> Disr,
|
||||
sz: uint, align: uint)
|
||||
-> bool {
|
||||
self.align(align);
|
||||
|
|
@ -389,7 +389,7 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
|
|||
}
|
||||
|
||||
fn visit_enter_enum_variant(&mut self, variant: uint,
|
||||
disr_val: int,
|
||||
disr_val: Disr,
|
||||
n_fields: uint,
|
||||
name: &str) -> bool {
|
||||
if ! self.inner.visit_enter_enum_variant(variant, disr_val,
|
||||
|
|
@ -405,7 +405,7 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
|
|||
}
|
||||
|
||||
fn visit_leave_enum_variant(&mut self, variant: uint,
|
||||
disr_val: int,
|
||||
disr_val: Disr,
|
||||
n_fields: uint,
|
||||
name: &str) -> bool {
|
||||
if ! self.inner.visit_leave_enum_variant(variant, disr_val,
|
||||
|
|
@ -416,7 +416,7 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
|
|||
}
|
||||
|
||||
fn visit_leave_enum(&mut self, n_variants: uint,
|
||||
get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
get_disr: extern unsafe fn(ptr: *Opaque) -> Disr,
|
||||
sz: uint, align: uint)
|
||||
-> bool {
|
||||
if ! self.inner.visit_leave_enum(n_variants, get_disr, sz, align) { return false; }
|
||||
|
|
@ -578,24 +578,24 @@ impl TyVisitor for my_visitor {
|
|||
_sz: uint, _align: uint) -> bool { true }
|
||||
|
||||
fn visit_enter_enum(&mut self, _n_variants: uint,
|
||||
_get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
_get_disr: extern unsafe fn(ptr: *Opaque) -> Disr,
|
||||
_sz: uint, _align: uint) -> bool {
|
||||
// FIXME (#3732): this needs to rewind between enum variants, or something.
|
||||
true
|
||||
}
|
||||
fn visit_enter_enum_variant(&mut self, _variant: uint,
|
||||
_disr_val: int,
|
||||
_disr_val: Disr,
|
||||
_n_fields: uint,
|
||||
_name: &str) -> bool { true }
|
||||
fn visit_enum_variant_field(&mut self, _i: uint, _offset: uint, inner: *TyDesc) -> bool {
|
||||
self.visit_inner(inner)
|
||||
}
|
||||
fn visit_leave_enum_variant(&mut self, _variant: uint,
|
||||
_disr_val: int,
|
||||
_disr_val: Disr,
|
||||
_n_fields: uint,
|
||||
_name: &str) -> bool { true }
|
||||
fn visit_leave_enum(&mut self, _n_variants: uint,
|
||||
_get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
_get_disr: extern unsafe fn(ptr: *Opaque) -> Disr,
|
||||
_sz: uint, _align: uint) -> bool { true }
|
||||
|
||||
fn visit_enter_fn(&mut self, _purity: uint, _proto: uint,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#[feature(managed_boxes)];
|
||||
|
||||
use std::unstable::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Opaque};
|
||||
use std::unstable::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Disr, Opaque};
|
||||
|
||||
struct MyVisitor {
|
||||
types: @mut ~[~str],
|
||||
|
|
@ -114,22 +114,22 @@ impl TyVisitor for MyVisitor {
|
|||
_sz: uint, _align: uint) -> bool { true }
|
||||
|
||||
fn visit_enter_enum(&mut self, _n_variants: uint,
|
||||
_get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
_get_disr: extern unsafe fn(ptr: *Opaque) -> Disr,
|
||||
_sz: uint, _align: uint) -> bool { true }
|
||||
fn visit_enter_enum_variant(&mut self,
|
||||
_variant: uint,
|
||||
_disr_val: int,
|
||||
_disr_val: Disr,
|
||||
_n_fields: uint,
|
||||
_name: &str) -> bool { true }
|
||||
fn visit_enum_variant_field(&mut self, _i: uint, _offset: uint, _inner: *TyDesc) -> bool { true }
|
||||
fn visit_leave_enum_variant(&mut self,
|
||||
_variant: uint,
|
||||
_disr_val: int,
|
||||
_disr_val: Disr,
|
||||
_n_fields: uint,
|
||||
_name: &str) -> bool { true }
|
||||
fn visit_leave_enum(&mut self,
|
||||
_n_variants: uint,
|
||||
_get_disr: extern unsafe fn(ptr: *Opaque) -> int,
|
||||
_get_disr: extern unsafe fn(ptr: *Opaque) -> Disr,
|
||||
_sz: uint, _align: uint) -> bool { true }
|
||||
|
||||
fn visit_enter_fn(&mut self, _purity: uint, _proto: uint,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue