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
|
|
@ -16,7 +16,7 @@ Runtime type reflection
|
|||
|
||||
#[allow(missing_doc)];
|
||||
|
||||
use unstable::intrinsics::{Opaque, TyDesc, TyVisitor};
|
||||
use unstable::intrinsics::{Disr, Opaque, TyDesc, TyVisitor};
|
||||
use libc::c_void;
|
||||
use mem;
|
||||
use unstable::raw;
|
||||
|
|
@ -396,7 +396,7 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<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);
|
||||
|
|
@ -407,7 +407,7 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<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,
|
||||
|
|
@ -426,7 +426,7 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<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,
|
||||
|
|
@ -437,7 +437,7 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<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;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ use reflect::{MovePtr, align};
|
|||
use str::StrSlice;
|
||||
use to_str::ToStr;
|
||||
use vec::OwnedVector;
|
||||
use unstable::intrinsics::{Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc};
|
||||
use unstable::intrinsics::{Disr, Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc};
|
||||
use unstable::raw;
|
||||
|
||||
/// Representations
|
||||
|
|
@ -92,7 +92,7 @@ num_repr!(f64, "f64")
|
|||
// New implementation using reflect::MovePtr
|
||||
|
||||
enum VariantState {
|
||||
SearchingFor(int),
|
||||
SearchingFor(Disr),
|
||||
Matched,
|
||||
AlreadyFound
|
||||
}
|
||||
|
|
@ -473,7 +473,7 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
|
|||
|
||||
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 {
|
||||
let disr = unsafe {
|
||||
|
|
@ -484,7 +484,7 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
|
|||
}
|
||||
|
||||
fn visit_enter_enum_variant(&mut self, _variant: uint,
|
||||
disr_val: int,
|
||||
disr_val: Disr,
|
||||
n_fields: uint,
|
||||
name: &str) -> bool {
|
||||
let mut write = false;
|
||||
|
|
@ -531,7 +531,7 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
|
|||
}
|
||||
|
||||
fn visit_leave_enum_variant(&mut self, _variant: uint,
|
||||
_disr_val: int,
|
||||
_disr_val: Disr,
|
||||
n_fields: uint,
|
||||
_name: &str) -> bool {
|
||||
match self.var_stk[self.var_stk.len() - 1] {
|
||||
|
|
@ -547,7 +547,7 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
|
|||
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -75,6 +75,11 @@ pub struct TyDesc {
|
|||
#[cfg(not(test))]
|
||||
pub enum Opaque { }
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub type Disr = int;
|
||||
#[cfg(not(stage0))]
|
||||
pub type Disr = u64;
|
||||
|
||||
#[lang="ty_visitor"]
|
||||
#[cfg(not(test))]
|
||||
pub trait TyVisitor {
|
||||
|
|
@ -140,19 +145,19 @@ pub trait TyVisitor {
|
|||
sz: uint, align: uint) -> bool;
|
||||
|
||||
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;
|
||||
fn visit_enter_enum_variant(&mut self, variant: uint,
|
||||
disr_val: int,
|
||||
disr_val: Disr,
|
||||
n_fields: uint,
|
||||
name: &str) -> bool;
|
||||
fn visit_enum_variant_field(&mut self, i: uint, offset: uint, inner: *TyDesc) -> bool;
|
||||
fn visit_leave_enum_variant(&mut self, variant: uint,
|
||||
disr_val: int,
|
||||
disr_val: Disr,
|
||||
n_fields: uint,
|
||||
name: &str) -> bool;
|
||||
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;
|
||||
|
||||
fn visit_enter_fn(&mut self, purity: uint, proto: uint,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue