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

fix #33954, recursion through field types in is_derived_type #34223

Merged
merged 1 commit into from
Jan 2, 2020

Conversation

JeffBezanson
Copy link
Sponsor Member

I'm not fully sure how best to address this. But, I assume looking through field types in is_derived_type can't be that important, since we don't do it for any non-bits types. So I just tried something simple and limited the depth of recursion that can happen via that path.

fix #33954

src/datatype.c Outdated
@@ -523,6 +525,7 @@ void jl_compute_field_offsets(jl_datatype_t *st)
//else if (st->layout->fielddesc_type != 0) // GC only implements support for this
// isinlinealloc = 0;
isinlinealloc = 0;
isbitstype = 0;
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

we just asserted this was zero on the previous line

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Yes I have a fix for this.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

It seemed like there might be a case above where we did set not-inlinealloc (from references-name), but don’t simultaneously also set not-isbitstype

@vtjnash
Copy link
Sponsor Member

vtjnash commented Dec 31, 2019

can't be that important

I agree. Let's just delete it then—I don't think it's even correct as written (except perhaps for the trivial case of maxdepth=1). I think it was supposed to permit cases like this:
f(x) = x isa X ? f(x.x) : other
Where you're recursing into yourself over the fields of an object, but they happen to all be trivial things like Ptr{T} or Dual{Complex{T}}. However, in that case, this function (is_derived_type) would only be allowed to look at the fields of the declared type object, and should not be permitted to look inside the fields of any parameters.

src/datatype.c Outdated
@@ -306,6 +306,8 @@ static int references_name(jl_value_t *p, jl_typename_t *name) JL_NOTSAFEPOINT
if (jl_is_datatype(p)) {
if (((jl_datatype_t*)p)->name == name)
return 1;
if (((jl_datatype_t*)p)->layout && (jl_datatype_nfields(p) == 0 || ((jl_datatype_t*)p)->isbitstype))
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I’m not sure we’ve always computed layout yet. In theory, this can eventually be changed to search the declared type structure (wrapper) for a use of the TypeVar as the direct field type (or as a Union) and cached on the TypeName

@JeffBezanson JeffBezanson merged commit 8b57f64 into master Jan 2, 2020
@JeffBezanson JeffBezanson deleted the jb/fix33954 branch January 2, 2020 22:03
KristofferC pushed a commit that referenced this pull request Jan 8, 2020
@KristofferC KristofferC mentioned this pull request Jan 8, 2020
28 tasks
BioTurboNick pushed a commit to BioTurboNick/julia that referenced this pull request Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference kind:bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler throws internal stack overflow error when plotting with Makie on Julia master
3 participants