DynamicArray.subArray creates array with length bound+1 - #280
Merged
Conversation
JohnReppy
approved these changes
Dec 20, 2023
JohnReppy
left a comment
Contributor
There was a problem hiding this comment.
These changes look good to me.
DynamicArray.subArray creates array with length bound+1
DynamicArray.subArray creates array with length bound+1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Running this in the REPL:
raises a
Subscriptexception, even though the values in the range [0, 2] are set.Similarly, running this in the REPL:
will cause
arrto be in an invalid state, so runningDynamicArray.toList arrorDynamicArray.toVector arrwill raise aSubscriptexception.This is because
subArraycreates an array with the length of the new array bound, even though the comment in the file says that the array should have at least bound+1 elements.I also modified
truncateto set the bound reference even when the array size <= 3 * sz. With this change,truncatecan be used to consistently lower the bound of the dynamic array.Related Issue
Motivation and Context
I want to use
DynamicArray.truncateto lower the bound, and I want to useDynamicArray.bound + 1as the length of all the set elements in the array. Right nowtruncateoften results in an invalid state, and it only lowers the bound in certain cases, which means that the elements from [0, bound] may include zeroed out values.How Has This Been Tested?
I loaded the updated smlnj-lib.cm file into the REPL and ran this: