Skip to content

Fix overspecialized containers - #6070

Merged
sklam merged 7 commits into
numba:masterfrom
stuartarchibald:wip/fix_overspecialized_containers
Aug 4, 2020
Merged

sklam merged 7 commits into
numba:masterfrom
stuartarchibald:wip/fix_overspecialized_containers

Conversation

@stuartarchibald

Copy link
Copy Markdown
Contributor

No description provided.

@stuartarchibald stuartarchibald added the abandoned PR is abandoned (no reason required) label Aug 4, 2020
@stuartarchibald
stuartarchibald force-pushed the wip/fix_overspecialized_containers branch from 2746db6 to 235df5e Compare August 4, 2020 11:01
Comment thread numba/core/types/containers.py Outdated
siv_none = siv is None
oiv_none = oiv is None
if siv_none and oiv_none:
return DictType(ukey_type, uvalue_type)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ukey_type, uvalue_type are bool
and i think this branch should execute if not siv_none and not oiv_none and the initial value doesn't match

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, this a) has bugs and b) is left over from when I was trying to make it do something else! 965a19b fixes.

@sklam

sklam commented Aug 4, 2020 •

Copy link
Copy Markdown
Member

this example contains unify that would fail:

from numba import njit


@njit
def bar(x):
    o = {1: 2}
    if x:
        o = {2: 3}
    return o

@njit
def foo(x):
    if x:
        d = {3: 4}
    else:
        d = bar(x)
    return d


foo(1)

As title.
@stuartarchibald stuartarchibald changed the title Wip/fix overspecialized containers Fix overspecialized containers Aug 4, 2020
@stuartarchibald stuartarchibald added 3 - Ready for Review and removed abandoned PR is abandoned (no reason required) labels Aug 4, 2020
@stuartarchibald stuartarchibald added this to the Numba 0.51 RC milestone Aug 4, 2020
Comment thread numba/core/analysis.py
query_arg.initial_value is None)
if do_raise:
loc = first_loc[pos]
raise errors.ForceLiteralArg(marked_args, loc=loc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there tests exercising this branch? I can't seem to find it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my test here would trigger it but I am not sure if this is useful to raise ForceLiteralArg:

from numba import njit, literally

@njit
def bar(d):
    return literally(d)

@njit
def inner(d):
    return bar(d)

@njit
def foo(x):
    d = {2: x}
    return inner(d)


r = foo(123)
print(r)

The literal request will never be satisfied it seems.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try e.g. ./runtests.py numba.tests.test_dictobject.TestTypedDictInitialValues.test_homogeneous_and_literal
?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test would pass for me even if the branch is commented out, but it did fail numba.tests.test_dictobject.TestTypedDictInitialValues.test_mutation_not_carried_single_function.
But it seems that it doesn't need to be ForceLiteralArg exception.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ForceLiteralArg would likely be useful if prefer_literal=True

@sklam sklam added 5 - Ready to merge Review and testing done, is ready to merge and removed 3 - Ready for Review labels Aug 4, 2020
@sklam
sklam merged commit 64923dd into numba:master Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to merge Review and testing done, is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants