Skip to content

Commit ba8bd6f

Browse files
authored
Throw type errors immediately (#202)
The goal here is better error messages. Before we would defer type errors in an effort to collect many errors and show them to the user.
1 parent 3ddbe3a commit ba8bd6f

File tree

9 files changed

+234
-433
lines changed

9 files changed

+234
-433
lines changed

examples/jagged_dense_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def jagged_dense_add_2d(
4343
result : dense + jagged, shape (num_rows, N).
4444
"""
4545
num_rows = y.size(0)
46-
assert (*x_offsets.size(),) == (num_rows + 1,)
46+
assert x_offsets.size(0) == num_rows + 1
4747
out = torch.zeros_like(y)
4848
for tile0 in hl.tile(num_rows):
4949
starts = x_offsets[tile0]

helion/_compiler/error_reporting.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
from __future__ import annotations
22

3-
from collections import defaultdict
43
import functools
54
import re
65
import sys
76
from typing import TYPE_CHECKING
87

9-
from .. import exc
108
from ..exc import Base
119
from ..exc import BaseError
1210
from ..exc import BaseWarning
@@ -16,8 +14,6 @@
1614
from collections.abc import Callable
1715
from collections.abc import Sequence
1816

19-
from .source_location import SourceLocation
20-
from .type_propagation import TypeNotAllowedOnDevice
2117
from helion.runtime.settings import Settings
2218

2319
ErrorOrWarning = BaseError | BaseWarning
@@ -39,9 +35,6 @@ def __init__(self, settings: Settings) -> None:
3935
self.errors: list[BaseError] = []
4036
self.warnings: list[BaseWarning] = []
4137
self.ignores: tuple[type[BaseWarning], ...] = tuple(settings.ignore_warnings)
42-
self.type_errors: dict[SourceLocation, list[exc.TypePropagationError]] = (
43-
defaultdict(list)
44-
)
4538
self.printed_warning = 0
4639

4740
def add(self, e: Base | type[Base]) -> None:
@@ -61,18 +54,6 @@ def add(self, e: Base | type[Base]) -> None:
6154
else:
6255
raise TypeError(f"expected error or warning, got {type(e)}")
6356

64-
def add_type_error(self, type_info: TypeNotAllowedOnDevice) -> None:
65-
"""
66-
Add a type error to the list of type errors and to the errors list if it's the first occurrence.
67-
68-
:param type_info: The TypeNotAllowedOnDevice object containing information about the type error.
69-
"""
70-
locations = type_info.locations
71-
similar_errors = self.type_errors[locations[0]]
72-
similar_errors.append(e := exc.TypePropagationError(type_info, similar_errors))
73-
if len(similar_errors) == 1:
74-
self.add(e)
75-
7657
def ignore(self, e: type[BaseWarning]) -> None:
7758
"""
7859
Add a warning type to the ignore list.

0 commit comments

Comments
 (0)