Skip to content

Commit 050d0e6

Browse files
committed
Add a depth counter to llvm::type_to_str to work around infinite llvm types.
1 parent 47afb33 commit 050d0e6

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/librustc/lib/llvm.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -2149,12 +2149,17 @@ impl TypeNames {
21492149
self.named_types.find_equiv(&s).map_consume(|x| Type::from_ref(*x))
21502150
}
21512151

2152-
pub fn type_to_str(&self, ty: Type) -> ~str {
2152+
// We have a depth count, because we seem to make infinite types.
2153+
pub fn type_to_str_depth(&self, ty: Type, depth: int) -> ~str {
21532154
match self.find_name(&ty) {
21542155
option::Some(name) => return name.to_owned(),
21552156
None => ()
21562157
}
21572158

2159+
if depth == 0 {
2160+
return ~"###";
2161+
}
2162+
21582163
unsafe {
21592164
let kind = ty.kind();
21602165

@@ -2176,31 +2181,36 @@ impl TypeNames {
21762181
Function => {
21772182
let out_ty = ty.return_type();
21782183
let args = ty.func_params();
2179-
let args = args.map(|&ty| self.type_to_str(ty)).connect(", ");
2180-
let out_ty = self.type_to_str(out_ty);
2184+
let args =
2185+
args.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
2186+
let out_ty = self.type_to_str_depth(out_ty, depth-1);
21812187
fmt!("fn(%s) -> %s", args, out_ty)
21822188
}
21832189
Struct => {
21842190
let tys = ty.field_types();
2185-
let tys = tys.map(|&ty| self.type_to_str(ty)).connect(", ");
2191+
let tys = tys.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
21862192
fmt!("{%s}", tys)
21872193
}
21882194
Array => {
21892195
let el_ty = ty.element_type();
2190-
let el_ty = self.type_to_str(el_ty);
2196+
let el_ty = self.type_to_str_depth(el_ty, depth-1);
21912197
let len = ty.array_length();
21922198
fmt!("[%s x %u]", el_ty, len)
21932199
}
21942200
Pointer => {
21952201
let el_ty = ty.element_type();
2196-
let el_ty = self.type_to_str(el_ty);
2202+
let el_ty = self.type_to_str_depth(el_ty, depth-1);
21972203
fmt!("*%s", el_ty)
21982204
}
21992205
_ => fail!("Unknown Type Kind (%u)", kind as uint)
22002206
}
22012207
}
22022208
}
22032209

2210+
pub fn type_to_str(&self, ty: Type) -> ~str {
2211+
self.type_to_str_depth(ty, 30)
2212+
}
2213+
22042214
pub fn val_to_str(&self, val: ValueRef) -> ~str {
22052215
unsafe {
22062216
let ty = Type::from_ref(llvm::LLVMTypeOf(val));

0 commit comments

Comments
 (0)