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

suspicious code in Array #754

Closed
wishfoundry opened this Issue Nov 16, 2016 · 9 comments

Comments

Projects
None yet
6 participants
@wishfoundry

wishfoundry commented Nov 16, 2016

I noticed this line

var slot = new createNode(a.height - 1, 0);

in:
https://github.com/elm-lang/core/blob/master/src/Native/Array.js#L730

createNode() is the factory here, it should not be new'ed up itself

I'm entirely sure where this will manifest though. If the being appended are balanced it probably can't reach this code.

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Nov 16, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Nov 16, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@wishfoundry

This comment has been minimized.

Show comment
Hide comment
@wishfoundry

wishfoundry Nov 16, 2016

actually this looks like the source of the problem in #474

wishfoundry commented Nov 16, 2016

actually this looks like the source of the problem in #474

@turboMaCk

This comment has been minimized.

Show comment
Hide comment
@turboMaCk

turboMaCk Nov 28, 2016

Contributor

+1

Contributor

turboMaCk commented Nov 28, 2016

+1

@mgold

This comment has been minimized.

Show comment
Hide comment
@mgold

mgold Nov 29, 2016

Contributor

Great detective work, but it won't be needed: there's a fully-Elm version of Array in the final stages of testing.

Contributor

mgold commented Nov 29, 2016

Great detective work, but it won't be needed: there's a fully-Elm version of Array in the final stages of testing.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Nov 30, 2016

Member

I'm interested in this fix in the meantime. That new stuff needs a performance review, and if this is an easy fix, it won't hurt!

So can someone do a PR with the change and a test that demonstrates what it fixes?

Member

evancz commented Nov 30, 2016

I'm interested in this fix in the meantime. That new stuff needs a performance review, and if this is an easy fix, it won't hurt!

So can someone do a PR with the change and a test that demonstrates what it fixes?

@lukewestby

This comment has been minimized.

Show comment
Hide comment
@lukewestby

lukewestby Nov 30, 2016

Member

@wishfoundry how did you demonstrate that this is the cause of the issue in #474? i'm setting a breakpoint at that line while running the examples from that issue and the line in question isn't being reached.

while the use of new is semantically incorrect here, it doesn't change the behavior of pure functions like createNode.

screen shot 2016-11-29 at 6 51 24 pm

Member

lukewestby commented Nov 30, 2016

@wishfoundry how did you demonstrate that this is the cause of the issue in #474? i'm setting a breakpoint at that line while running the examples from that issue and the line in question isn't being reached.

while the use of new is semantically incorrect here, it doesn't change the behavior of pure functions like createNode.

screen shot 2016-11-29 at 6 51 24 pm

@wishfoundry

This comment has been minimized.

Show comment
Hide comment
@wishfoundry

wishfoundry Nov 30, 2016

@lukewestby newing up a function can prevent it from returning a value:

screen shot 2016-11-29 at 9 26 31 pm

I discovered the bug while attempting to port the rrb code to plain js, during a battery of performance comps against other immutable libs.
The rrb version would fail on any tests with lengths > 32, < 1024. I removed the "new", and they ran again. but I'm still a little unclear the exact reason. but if there is still a future in the current Array code, I'll update here as soon as I get a few moment to rerun them

wishfoundry commented Nov 30, 2016

@lukewestby newing up a function can prevent it from returning a value:

screen shot 2016-11-29 at 9 26 31 pm

I discovered the bug while attempting to port the rrb code to plain js, during a battery of performance comps against other immutable libs.
The rrb version would fail on any tests with lengths > 32, < 1024. I removed the "new", and they ran again. but I'm still a little unclear the exact reason. but if there is still a future in the current Array code, I'll update here as soon as I get a few moment to rerun them

@wishfoundry

This comment has been minimized.

Show comment
Hide comment
@wishfoundry

wishfoundry Jan 20, 2017

Finally got it. the issue has to do with the final balancing act done in:

https://github.com/elm-lang/core/blob/master/src/Native/Array.js#L644

assumes that both are never leaves, which isn't always true due to RRBs unbalanced nature. We just need to add a node.height != 0 check in here. (PR to follow)

wishfoundry commented Jan 20, 2017

Finally got it. the issue has to do with the final balancing act done in:

https://github.com/elm-lang/core/blob/master/src/Native/Array.js#L644

assumes that both are never leaves, which isn't always true due to RRBs unbalanced nature. We just need to add a node.height != 0 check in here. (PR to follow)

@wishfoundry

This comment has been minimized.

Show comment
Hide comment
@wishfoundry

wishfoundry Jan 24, 2017

after looking further through this code, I've come to realize it too many issues to quickly repair.

I'm going to see if I can help out with the new HAMT version instead of working on this.

wishfoundry commented Jan 24, 2017

after looking further through this code, I've come to realize it too many issues to quickly repair.

I'm going to see if I can help out with the new HAMT version instead of working on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment