if (stack.has(obj)) {
writer.writeByte(CIRCULAR)
return
}
Does this mean that if a nested object holds a reference to itself, it will produce the same hash as if it held a reference to any of the objects it is nested in?
Any circular reference to an ancestor on the stack turns into the same CIRCULAR byte, so two structures with identical shape but whose cycle points to different ancestors in the nesting chain produce the same hash.
This will be fixed in the next patch, which will encode the distance to the referenced ancestor instead of a flat marker, so self-reference and reference-to-parent will stop colliding. Note that every existing hash will change as a result, breaking any persisted hash (acceptable since this is pre-1.0). I could also bump the marker byte so new hashes can't accidentally collide with old ones, though the old ones remain broken either way.
Yes.
Any circular reference to an ancestor on the stack turns into the same CIRCULAR byte, so two structures with identical shape but whose cycle points to different ancestors in the nesting chain produce the same hash.
This will be fixed in the next patch, which will encode the distance to the referenced ancestor instead of a flat marker, so self-reference and reference-to-parent will stop colliding. Note that every existing hash will change as a result, breaking any persisted hash (acceptable since this is pre-1.0). I could also bump the marker byte so new hashes can't accidentally collide with old ones, though the old ones remain broken either way.