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 list concat overwriting #3167

Merged
merged 3 commits into from
Jul 1, 2024

Conversation

peterebden
Copy link
Member

Fixes #3166

Looks like this is due to the slices overwriting since on append they both think they have extra capacity, but are in fact sharing it. A pure Go example: https://go.dev/play/p/pLl6MlMr3V4

This fixes this particular case; I don't think there are others at present, we seem to construct lists with capacity equal to their final size in other instances.

Copy link
Contributor

@samwestmoreland samwestmoreland left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for the fix 😄

Copy link

@HartBlanc HartBlanc left a comment

Choose a reason for hiding this comment

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

Do we need to apply the slices.Clip to the pyFrozenList case a few lines above too?

@@ -363,7 +364,7 @@ func (l pyList) Operator(operator Operator, operand pyObject) pyObject {
}
panic("Cannot add list and " + operand.Type())
}
return append(l, l2...)
return slices.Clip(append(l, l2...))

Choose a reason for hiding this comment

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

Do we need to apply this change to the pyFrozenList case a few lines above too?

Copy link
Member Author

Choose a reason for hiding this comment

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

can't hurt, thanks!

@peterebden peterebden merged commit d76609c into thought-machine:master Jul 1, 2024
14 checks passed
@peterebden peterebden deleted the list-concat-bug branch July 1, 2024 09:21
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.

List concatenation bug
4 participants