In an interpreter I'm writing I'm often running into Blocked block exceptions. I've been able to solve several of these errors but the problem is always figuring out what exactly I've done to cause the error. Most of the time it seems to come down to some sort of missing assertions that cause the translator to think that there is no way for an operation to succeed, but I just can't find it. For example, I'm currently getting this error: [translation:ERROR] AnnotatorError: [translation:ERROR] [translation:ERROR] Blocked block -- operation cannot succeed [translation:ERROR] [translation:ERROR] v1 = getattr(v0, ('data')) [translation:ERROR] [translation:ERROR] In <FunctionGraph of (clojure.vm.array:18)Array.aget at 0x1019d52d0>: [translation:ERROR] Happened at file /Users/tim/oss/clojure-vm/clojure/vm/array.py line 20 [translation:ERROR] [translation:ERROR] ==> return self.data[idx] [translation:ERROR] [translation:ERROR] Known variable annotations: [translation:ERROR] v0 = SomeInstance(can_be_None=False, classdef=clojure.vm.array.Array) for this class: from clojure.vm.object import Object, type_ids from clojure.vm.primitives import nil class Array(Object): type_id = type_ids.next() def __init__(self, data, meta = nil): self.data = data self.meta = meta def type(self): return self.type_id def aclone(self): return Array(self.data[:], self.meta) def aget(self, idx): assert isinstance(idx, int) return self.data[idx] def aset(self, idx, val): assert isinstance(idx, int) assert isinstance(val, Object) self.data[idx] = val def alength(self): return len(self.data) Of course, the error is wrong, and it must be related to some other part of the code, but I feel like a blind man in the dark trying to find it. Is there any good way to debug these sorts of errors? Timothy
Hi Timothy, On 21 February 2014 15:45, Timothy Baldridge <tbaldridge@gmail.com> wrote:
In an interpreter I'm writing I'm often running into Blocked block exceptions. I've been able to solve several of these errors but the problem is always figuring out what exactly I've done to cause the error. Most of the time it seems to come down to some sort of missing assertions that cause the translator to think that there is no way for an operation to succeed, but I just can't find it.
Welcome to RPython :-( There is no general nice solution to these problems.
[translation:ERROR] v1 = getattr(v0, ('data')) [translation:ERROR] ==> return self.data[idx]
The error is that the class Array has no attribute 'data'. Obviously, you see that it has; but that requires the annotator to have already analyzed its __init__() method in order to know this. Usually, when you get blocked-block errors, you get a whole bunch of them, and only one or two of them actually make sense. In this case, the error above might be caused by another blocked block that prevents annotation from entering Array.__init__(). (Of course there is also the less-likely possibility that you really never see Array.__init__() in your program.) A bientôt, Armin.
participants (2)
-
Armin Rigo
-
Timothy Baldridge