Compiler error message readability

I think the readability of the error messages can be improved.

Here’s an example error message.

Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:38:15: error: cannot implicitly convert 'IntLiteral[0]' value to 'DType'
        res = 0
              ^
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:54:24: error: cannot implicitly convert 'SIMD[dtype, __init__[::Origin[::Bool(IntTuple(1), IntTuple(1
)).size()]' value to 'DType'
    res = intersection / union
          ~~~~~~~~~~~~~^~~~~~~
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:111:70: error: invalid call to 'iou': argument #0 cannot be converted from 'LayoutTensor[dtype, _compute_tile_layout[*::Int]().__getitem__(0),
 MutableAnyOrigin, layout_int_type=_get_layout_type(corners_layout, AddressSpace(0)), linear_idx_type=_get_index_type(corners_layout, AddressSpace(0)), masked=_tile_is_masked[::Layout,*::I
nt]()]' to 'LayoutTensor[dtype, _compute_tile_layout[*::Int]().__getitem__(0), MutableAnyOrigin]'
                var overlap = iou[dtype, first.layout, second.layout](
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:112:21: note: types parameters include unfolded expression at parser time; try rebinding to a consistent type?
                    first, second
                    ^
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:22:4: note: function declared here
fn iou[
   ^
/home/marius/dev/nms.mojo/.magic/envs/default/bin/mojo: error: failed to parse the provided Mojo source module

We do need to know the full absolute path of the root though do we really need every time? Maybe yes, I’m admittedly naive. How about just once?

Additionally, the compiler does know the entry point and the file being compiled. Can we simplify and left align for easier readability?

Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
~/nms.mojo/operations/nms.mojo:38:15: error: cannot implicitly convert 'IntLiteral[0]' value to 'DType'
        res = 0
              ^
~/nms.mojo/test_correctness.mojo:18:
~/nms.mojo/operations/nms.mojo:54:24: error: cannot implicitly convert 'SIMD[dtype, __init__[::Origin[::Bool(IntTuple(1), IntTuple(1
)).size()]' value to 'DType'
    res = intersection / union
          ~~~~~~~~~~~~~^~~~~~~
~/nms.mojo/test_correctness.mojo:18:
~/nms.mojo/operations/nms.mojo:111:70: error: invalid call to 'iou': argument #0 cannot be converted from 'LayoutTensor[dtype, _compute_tile_layout[*::Int]().__getitem__(0),
 MutableAnyOrigin, layout_int_type=_get_layout_type(corners_layout, AddressSpace(0)), linear_idx_type=_get_index_type(corners_layout, AddressSpace(0)), masked=_tile_is_masked[::Layout,*::I
nt]()]' to 'LayoutTensor[dtype, _compute_tile_layout[*::Int]().__getitem__(0), MutableAnyOrigin]'
                var overlap = iou[dtype, first.layout, second.layout](
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
~/nms.mojo/test_correctness.mojo:18:
~/nms.mojo/operations/nms.mojo:112:21: note: types parameters include unfolded expression at parser time; try rebinding to a consistent type?
                    first, second
                    ^
~/nms.mojo/test_correctness.mojo:18:
~/nms.mojo/operations/nms.mojo:22:4: note: function declared here
fn iou[
   ^
~/nms.mojo/.magic/envs/default/bin/mojo: error: failed to parse the provided Mojo source module

Specifically, the ~/entrypoint/ is the same number of characters so our eye can easily read down and across.

I get that this is a bigger ask than a forum post though I think there’s a bit of bit shaving here :wink: that would improve the tooling experience.

@denis

2 Likes