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
Construct Vector without an invalid internal state #8246
Conversation
I'm quite worried that this would mask an underlying logic error rather than just fix the NPE. Why should the absolute value accurately describe what to do? |
I am sorry to reply so late. The following is my opinion. newBlockIndex
= blockIndex - shift
= (endIndex & ~31) - (startIndex & ~((1 << (5 * (depth - 1))) - 1))
>= (endIndex & ~31) - (startIndex & ~31) > 0
//when depth == 2
= (endIndex & ~31) - (startIndex & ~31)
//when depth > 2
> (endIndex & ~31) - (startIndex & ~31)
newFocus
= focus - shift
= focus - (startIndex & ~((1 << (5 * (depth - 1))) - 1)) then s.gotoFreshPosWritable(newFocus, newBlockIndex, newFocus ^ newBlockIndex) the value of def gotoFreshPosWritable0(oldIndex: Int, newIndex: Int, xor: Int): Unit = { // goto block start pos
if (xor < (1 << 5)) { // level = 0
// we're already at the block start
} else if (xor < (1 << 10)) { // level = 1
// ...
} else if (xor < (1 << 15)) { // level = 2
}
//....
} the following test case works well, and the @Test
def constructProperStartIndex(): Unit = {
val a = "A1" +: "A" +: "O" +: Iterator.continually("E").take(2078).foldLeft(Vector.empty[String])((v, e) => v :+ e) :+ "C" :+"C"
val d = "O" +: Iterator.continually("E").take(0) .foldLeft(Vector.empty[String])((v, e) => v :+ e) :+ "C"
val right = a ++ d
assertEquals(2085, right.map(_ => 0).size)
} ahh, could you give me some suggestions? @Ichoran |
@Ichoran can you take a look? |
@szeiger - Unfortunately I'm incredibly busy through the end of the month. Was it @joshlemer who had worked on Vector recently? (Is this already fixed by some other PR? I thought i saw something come through that addressed Vector soundness issues.) |
It may be best to just revert that PR for now, since that one was also responsible for this bug: scala/bug#11600 though that one has existing fixes up for consideration. |
Strike that, update: the bug is not in that commit, the bug has something to do with these changes: #7588 (When I revert that change, the bug is gone) Update: Yeah, the VectorBuilder changes in that commit are not quite right somehow, that's definitely the issue. |
I opened #8410 to revert the VectorBuilder optimization for now. Rescheduling this PR to 2.13.2 to give us some more time to get it right. |
@szeiger should this PR be re-targeted at 2.12.x? |
@lrytz so far as I understand, this is only a bug fix meant to address bugs that appeared in 2.13.0 |
obviated by #8534 |
when i debug vector's add behavior, i found out the reason why scala throw NPE is because the value of variable
newFocus
is negative. So accordingly, the code judges its depth is 0(the actual depth should be 2), which lead to a incorrect start position.Thus i think the value of
newFocus
should be positive all the time, we only need to pay attention to its absolute valueFixes scala/bug#11636