[FRONTEND] better stringification (#394)

- Don't override `self.args` in `CompilationError`, and show the line number and column in error messages. This causes it to generate an easier-to-read backtrace.
- Better `__str__` on `TensorWrapper`, `dtype`, and `block`.
This commit is contained in:
Madeleine Thompson
2021-12-17 20:11:45 -08:00
committed by GitHub
parent 4e93b41c52
commit fa62b4a8f6
3 changed files with 20 additions and 5 deletions

View File

@@ -521,10 +521,10 @@ class LoadedBinary:
class CompilationError(Exception):
def __init__(self, src, node):
self.message = '\n'.join(src.split('\n')[:node.lineno])
self.message = f'at {node.lineno}:{node.col_offset}:\n'
self.message += '\n'.join(src.split('\n')[:node.lineno])
self.message += '\n' + ' ' * node.col_offset + '^'
super().__init__(self.message)
self.args = (src, node)
class OutOfResources(Exception):
@@ -1085,6 +1085,9 @@ class TensorWrapper:
def data_ptr(self):
return self.base.data_ptr()
def __str__(self) -> str:
return f'TensorWrapper[{self.dtype}]({self.base})'
def reinterpret(tensor, dtype):
return TensorWrapper(tensor, dtype)