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

call convert in Base.setfield! #16226

Closed
wants to merge 2 commits into from

Conversation

stevengj
Copy link
Member

@stevengj stevengj commented May 6, 2016

Fixes #16195, following the suggestion of @vtjnash.

@vtjnash
Copy link
Member

vtjnash commented May 6, 2016

this looks correct to me, although I think we also need to delete the corresponding lowering code that was inserting calls to convert. I also think we just need to check that it won't cause any performance regressions since now setfield is not handled by a special tfunc.

@JeffBezanson
Copy link
Member

I think this will definitely be a problem, since the index argument to fieldtype would no longer be a constant.

@stevengj
Copy link
Member Author

stevengj commented May 6, 2016

Don't we just have to make sure it uses Core.setfield! for foo.bar expressions, which are lowered to (top setfield!) right? inference.jl is using Core.setfield! for add_tfunc(setfield!, ...), not Base.setfield!, I think; isn't that enough?

@JeffBezanson
Copy link
Member

Yes I think lowering will need to be changed to call (|.| Core setfield!).

@stevengj
Copy link
Member Author

stevengj commented May 6, 2016

@JeffBezanson, when I replace (top setfield!) with that in julia-syntax.scm, I get ERROR: syntax: unhandled expr (. Core setfield!). What am I missing?

@JeffBezanson
Copy link
Member

Good news --- in the interim I've added a core node and changed the lowering to (core setfield!), so this should work fine now.

@stevengj
Copy link
Member Author

Is there a way restart Travis, or do I need a forced push?

@tkelman
Copy link
Contributor

tkelman commented May 27, 2016

Log in to travis with github auth then you can restart. Travis overwrites logs on restarts, so please save failure logs to a gist before restarting.

Note that this succeeded 3 weeks ago, but I restarted it this morning to see if the merge commit into latest master would still pass. It didn't, so if you rebase this branch I suspect you'll see the same failure locally. Probably a newly added test that this would break.

@stevengj stevengj force-pushed the setfield_convert branch from b1ff106 to 83b09e2 Compare May 27, 2016 19:11
@@ -2238,7 +2238,7 @@ f9534d(x) = (a=(1,2,4,6,7); a[x])
@test try; f9534d() catch ex; (ex::BoundsError).a === (1,2,4,6,7) && ex.i == 7; end
@test try; f9534d(-1) catch ex; (ex::BoundsError).a === (1,2,4,6,7) && ex.i == -1; end
f9534e(x) = (a=IOBuffer(); setfield!(a, x, 3))
@test try; f9534e(-2) catch ex; isa((ex::BoundsError).a,Base.IOBuffer) && ex.i == -2; end
@test try; f9534e(-2) catch ex; (ex::BoundsError).a == Base.IOBuffer && ex.i == -2; end
Copy link
Member Author

@stevengj stevengj May 27, 2016

Choose a reason for hiding this comment

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

I'm not sure why I had to make this change to get the test to pass. @JeffBezanson, has the behavior of Core.setfield! changed to store the type rather than the value in the a field?

Copy link
Member

Choose a reason for hiding this comment

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

No this should not have changed.

Copy link
Member

Choose a reason for hiding this comment

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

I think this means inlining may have changed? I'm not certain that jl_f_getfield and the codegen optimization for that getfield actually throw the same error.

Copy link
Contributor

@yuyichao yuyichao May 28, 2016

Choose a reason for hiding this comment

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

This is probably #16517 Actually probably not... that one is only applicable when the one following the catch is a literal.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the issue is that Core.setfield!(x, i, convert(fieldtype(T, i), v)) is throwing a BoundsError from fieldtype, not from Core.setfield!.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if there is a clean way to fix this.

If we had an isfield(T, i) intrinsic, I could check it explicitly and then throw an error, but we don't have such an intrinsic. I can replace fieldtype(T, i) with try; fieldtype(T, i); catch; Any; end — that works, but is mildly horrifying.

Suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

We could just call Core.setfield! in the test

Copy link
Member Author

Choose a reason for hiding this comment

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

We could, but do we care what kind of BoundsError data is thrown by Base.setfield!?

@vtjnash
Copy link
Member

vtjnash commented Jun 23, 2016

needs another rebase?

@schmrlng
Copy link
Contributor

Bump - as the underlying issue (#16195) here is related to a 0.5 deprecation, should this be added to the 0.5.x milestone?

@stevengj
Copy link
Member Author

Rebased.

@tkelman
Copy link
Contributor

tkelman commented Aug 23, 2016

this may have to queue for a bit

@nanosoldier runbenchmarks(ALL, vs = ":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

@stevengj
Copy link
Member Author

I'm skeptical that the performance regression here is real; setfield! is barely used in Base, and isn't used at all in the sorting code.

@KristofferC
Copy link
Member

The sort functions seem to generally be a bit noisy so nothing to worry about.

@yuyichao
Copy link
Contributor

The BoundsError change sounds like a bug and should be fixed before merging.

@StefanKarpinski
Copy link
Member

The sort functions seem to generally be a bit noisy so nothing to worry about.

I don't recall if we are or not, but we should be using a fixed random sequence since the randomization has a large impact on sort performance. Obviously, it evens out in the long term, but it's unnecessary noise that we're adding only to have to try to remove it with more runs.

@KristofferC
Copy link
Member

Pretty sure everything in BaseBenchmarks fixes the seed for all "random" data.

@jrevels
Copy link
Member

jrevels commented Aug 24, 2016

Pretty sure everything in BaseBenchmarks fixes the seed for all "random" data.

This is the case.

vtjnash added a commit that referenced this pull request Dec 5, 2017
vtjnash added a commit that referenced this pull request Dec 5, 2017
vtjnash added a commit that referenced this pull request Dec 7, 2017
New functions `Base.getproperty` and `Base.setproperty!`
can be overloaded to change the behavior of `x.f` and `x.f = v`,
respectively.

fix #16226 (close #16195)
fix #1974
@vtjnash vtjnash mentioned this pull request Dec 7, 2017
2 tasks
vtjnash added a commit that referenced this pull request Dec 7, 2017
New functions `Base.getproperty` and `Base.setproperty!`
can be overloaded to change the behavior of `x.f` and `x.f = v`,
respectively.

fix #16226 (close #16195)
fix #1974
vtjnash added a commit that referenced this pull request Dec 11, 2017
New functions `Base.getproperty` and `Base.setproperty!`
can be overloaded to change the behavior of `x.f` and `x.f = v`,
respectively.

fix #16226 (close #16195)
fix #1974
vtjnash added a commit that referenced this pull request Dec 15, 2017
New functions `Base.getproperty` and `Base.setproperty!`
can be overloaded to change the behavior of `x.f` and `x.f = v`,
respectively.

fix #16226 (close #16195)
fix #1974
vtjnash added a commit that referenced this pull request Dec 17, 2017
New functions `Base.getproperty` and `Base.setproperty!`
can be overloaded to change the behavior of `x.f` and `x.f = v`,
respectively.

fix #16226 (close #16195)
fix #1974
vtjnash added a commit that referenced this pull request Dec 18, 2017
New functions `Base.getproperty` and `Base.setproperty!`
can be overloaded to change the behavior of `x.p` and `x.p = v`,
respectively.

This forces inference constant propagation through get/setproperty,
since it is very likely this method will yield better information after specializing on the field name
(even if `convert` is too big to make us want to inline the generic version and trigger the heuristic normally).

closes #16195 (and thus also closes #16226)
fix #1974
@stevengj stevengj deleted the setfield_convert branch December 18, 2017 13:17
Keno pushed a commit that referenced this pull request Jun 5, 2024
New functions `Base.getproperty` and `Base.setproperty!`
can be overloaded to change the behavior of `x.p` and `x.p = v`,
respectively.

This forces inference constant propagation through get/setproperty,
since it is very likely this method will yield better information after specializing on the field name
(even if `convert` is too big to make us want to inline the generic version and trigger the heuristic normally).

closes #16195 (and thus also closes #16226)
fix #1974
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants