Skip to content

Could the error message for missing imports be made clearer? #125

@rajuptvs

Description

@rajuptvs

When running the example below, Mojo raises an error that can be confusing at first glance. The root cause was a missing import, but the error message did not make that clear.

from testing import assert_equal
from gpu.host import DeviceContext
# ANCHOR: dot_product_layout_tensor
from gpu import thread_idx, block_idx, block_dim, barrier
from layout import Layout, LayoutTensor

alias TPB = 8
alias SIZE = 8
alias BLOCKS_PER_GRID = (1, 1)
alias THREADS_PER_BLOCK = (TPB, 1)
alias dtype = DType.float32
alias layout = Layout.row_major(SIZE)
alias out_layout = Layout.row_major(1)

fn dot_product[
    in_layout: Layout, out_layout: Layout
](
    output: LayoutTensor[mut=True, dtype, out_layout],
    a: LayoutTensor[mut=True, dtype, in_layout],
    b: LayoutTensor[mut=True, dtype, in_layout],
    size: UInt,
):
    # FILL ME IN (roughly 13 lines)
    shared = LayoutTensor[
        dtype,
        Layout.row_major(TPB),
        MutableAnyOrigin,
        address_space = AddressSpace.SHARED,
    ].stack_allocation()
/home/raju/personal/mojo-gpu-puzzles/problems/p12/p12_layout_tensor.mojo:31:37: error: 'AddressSpace' value has no attribute 'SHARED'
        address_space = AddressSpace.SHARED,
                        ~~~~~~~~~~~~^

Initially, I assumed it was an issue with the AddressSpace type or its attributes.
However, after checking other puzzles, I realized it was simply a missing import.
In Python, a similar situation would produce something like:

NameError: name 'AddressSpace' is not defined

This would immediately hint that the symbol wasn’t imported or defined.

Was wondering if this kind of error message could be improved in the future — or maybe this isn’t really a big deal and is just part of Mojo’s current design philosophy?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions