Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

want int64 rather than Optional(int64) when dict.get(key, default_int64) and dict value type is int64 #9473

Open
dlee992 opened this issue Feb 29, 2024 · 1 comment · May be fixed by #9481

Comments

@dlee992
Copy link
Contributor

dlee992 commented Feb 29, 2024

Coming from gitter discussion (https://matrix.to/#/!gFwSEpcuaweltInwDW:gitter.im/$GQbCOdu6zbw3baQZM2CSSAm2xfw2bvWkgf3MImzOPlk?via=gitter.im&via=matrix.org&via=tryp.io), a test case:

from os import environ

environ["NUMBA_CHROME_TRACE"] = "5.json"
# environ["NUMBA_DUMP_LLVM"] = "1"
environ["NUMBA_DEBUG_TYPEINFER"] = "1"

from numba import njit
from numba.core import types
from numba.typed import Dict


@njit
def goo():
    d = Dict.empty(types.int64, value_type=types.int64)
    d[0] = 0
    v = d.get(2, 0)
    return v

print(goo())

The root cause is the @intrinsic _dict_lookup will forcily generate Optional for the return value at

        out = context.make_optional_none(builder, td.value_type)

A potential fix is that let _dict_lookup knows the default_value type, and choose using Optional or not based on that.

I'm not sure if doing this violates Python semantics, I feel not?

@sklam
Copy link
Member

sklam commented Mar 4, 2024

Should be doable. Patches welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants