DynamicArray.subArray creates array with length bound+1 #280
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
Subscript
exception, even though the values in the range [0, 2] are set.Similarly, running this in the REPL:
will cause
arr
to be in an invalid state, so runningDynamicArray.toList arr
orDynamicArray.toVector arr
will raise aSubscript
exception.This is because
subArray
creates 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
truncate
to set the bound reference even when the array size <= 3 * sz. With this change,truncate
can be used to consistently lower the bound of the dynamic array.Related Issue
Motivation and Context
I want to use
DynamicArray.truncate
to lower the bound, and I want to useDynamicArray.bound + 1
as the length of all the set elements in the array. Right nowtruncate
often 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: