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
Implement literal dictionaries and lists. #5946
Conversation
From out-of-band discussion:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done a first pass review. There are a few more details I want to look at.
479b425 is failing with:
think literal dictionary unification is probably wrong |
#5946 (comment) is fixed by b17f841 on wards. |
@sklam this still has over-specialisation issues but is probably in a position where it's close enough to working to be reviewable! Thanks. |
The new changes are looking good. Feature-wise, it will address the use-cases for https://gist.github.com/sklam/4f08128860485485c7b3dbd2c9149e07. I did notice that it is difficult to search for the added feature in the current doc. We should probably address this separately. I will want to have another look at the specific details in the new |
@lower_cast(types.DictType, types.DictType) | ||
def cast_DictType_DictType(context, builder, fromty, toty, val): | ||
# should have been picked up by typing | ||
return val |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
untested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think it's left over from trying to make literal dictionary types gracefully degrade, removed in 120ffce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out it is needed: https://dev.azure.com/numba/numba/_build/results?buildId=6009&view=logs&j=12ecc1d6-2964-5850-b419-89f950957853&t=abce8f77-76e0-5291-fb7e-5ca9f390cd04&l=9914 IIRC typed.Dict
uses the list dtype and not its initial value, but the initial value is part of the type, so casts such as the one failing won't work without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot cast DictType[int32,int32]<iv={4: 2}> to DictType[int32,int32]<iv={1: 3}>:
why is that allowed? should it be unified to one without initial_value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this stems from two problems:
- No attempt at unification in the cast impl
numba/numba/typed/typedobjectutils.py
Lines 23 to 35 in e043ee7
@intrinsic def _cast(typingctx, val, typ): """Cast *val* to *typ* """ def codegen(context, builder, signature, args): [val, typ] = args context.nrt.incref(builder, signature.return_type, val) return val # Using implicit casting in argument types casted = typ.instance_type _sentry_safe_cast(val, casted) sig = casted(casted, typ) return sig, codegen DictType
will only unify with anotherDictType
if the other is "imprecise"numba/numba/core/types/containers.py
Lines 636 to 643 in e043ee7
def unify(self, typingctx, other): """ Unify this with the *other* dictionary. """ # If other is dict if isinstance(other, DictType): if not other.is_precise(): return self
smoking at |
This reverts commit 120ffce.
Update: confirmed that all failed tests are entry-point tests due to llvmlite version pinning; thus this PR has essentially passed our smoketest. |
As title.
Permits compilation of things like:
WIP, opened for CI.