-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Fix assertion failure on nested tuple identity #1947
Conversation
bd5ac19
to
94c7300
Compare
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'm not sure I get the logic of determining reachability by considering the contents of both sides.
If we determine that the TK_IS
needs the __is
method, (ie subtype_kind_overlap
contains SUBTYPE_KIND_TUPLE
), then I think we should only mark the method as reachable on the left hand side type, and all types it contains recursively. We should ignore completely the right hand side type.
The reachability logic here should match the genident one, especially the box_is_box
and gen_is_tuple_fun
methods
src/libponyc/reach/reach.c
Outdated
|
||
if(!is_known(l_type) && !is_known(r_type)) | ||
{ | ||
pony_assert(r_child == NULL); |
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.
Tuples could have different length, in which case this asserts (or segfaults)
#1946
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'll fix that.
reach_type_t* sub; | ||
size_t i = HASHMAP_BEGIN; | ||
|
||
while((sub = reach_type_cache_next(&t->subtypes, &i)) != NULL) |
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.
Doesn't add_rmethod
already take care of adding it to all subtypes ?
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.
It does, but it doesn't handle the case of a tuple subtype that should add __is
to its members.
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.
Indeed, thanks
@plietar The For example, consider this case: a: ((U8, U16) | (U16, U16))
b: ((U8, U16) | None)
a is b Here, both If we were to determine the reachability of |
if(!is_known(type)) | ||
static void reachable_digestof_type(reach_t* r, ast_t* type, pass_opt_t* opt) | ||
{ | ||
if(ast_id(type) == TK_TUPLETYPE) |
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.
Shouldn't this case call add_rmethod
as well ?
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.
No, we only need __digestof
when using digestof
on an abstract type (i.e. not a tuple) with boxed subtypes.
What I meant here is that when generating the Therefore we should only recurse considering the left hand side type, ignoring the right one. Additionally right now we generate the |
94c7300
to
ef8f359
Compare
I do think that recursing on every subtype of the left hand side type is unnecessary and marks too many types. Recursing on types which are subtypes of both the left hand side type and the right hand side type marks every needed type and no unneeded type. I expect that we'll have to change that logic in order to fix #1950 but for now I think it's fine. I'll fix the |
ef8f359
to
92e7b68
Compare
This fixes a bug introduced in 9b9c084 caused by the `__is` method of a tuple nested in another tuple not being reached.
92e7b68
to
5c7dfaa
Compare
Conflicts fixed, merging. |
This fixes a bug introduced in 9b9c084 caused by the
__is
method of a tuple nested in another tuple not being reached.This should only get a changelog entry if we do a new release before merging this, since the bug exists only in the unreleased version.