Skip to content

Commit

Permalink
Tag asserts 6.2 (#17060)
Browse files Browse the repository at this point in the history
In preparation to minor client release 6.2.0
  • Loading branch information
dannimad authored Aug 29, 2023
1 parent fd9baea commit 607786b
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 89 deletions.
2 changes: 1 addition & 1 deletion experimental/dds/tree2/src/core/forest/editableForest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function initializeForest(
forest: IEditableForest,
content: readonly ITreeCursorSynchronous[],
): void {
assert(forest.isEmpty, "forest must be empty");
assert(forest.isEmpty, 0x747 /* forest must be empty */);
const insert: Delta.Insert = { type: Delta.MarkType.Insert, content };
forest.applyDelta(new Map([[rootFieldKey, [insert]]]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export abstract class ProxyTarget<T extends Anchor | FieldAnchor> {
if (this.lazyCursor.state !== ITreeSubscriptionCursorState.Current) {
assert(
this.lazyCursor.state === ITreeSubscriptionCursorState.Cleared,
"Unset cursor should be in cleared state",
0x749 /* Unset cursor should be in cleared state */,
);
assert(
this.anchor !== undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export class FieldProxyTarget extends ProxyTarget<FieldAnchor> implements Editab
const parentAnchorNode = this.context.forest.anchors.locate(parentAnchor);

// As the "parentAnchor === undefined" case is handled above, parentAnchorNode should exist.
assert(parentAnchorNode !== undefined, "parentAnchorNode must exist.");
assert(parentAnchorNode !== undefined, 0x748 /* parentAnchorNode must exist. */);
return treeStatusFromPath(parentAnchorNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ function rebaseMarkList<TNodeChange>(
if (markEmptiesCells(baseMark)) {
assert(isDetachMark(baseMark), 0x709 /* Only detach marks should empty cells */);
const detachId = getDetachCellId(baseMark, baseIntention);
assert(detachId.revision !== undefined, "Detach ID should have a revision");
assert(detachId.revision !== undefined, 0x74a /* Detach ID should have a revision */);
addLineageToRecipients(lineageRecipients, detachId.revision, detachId.localId, length);
}

if (areInputCellsEmpty(rebasedMark)) {
if (markEmptiesCells(baseMark)) {
assert(isDetachMark(baseMark), "Only detaches empty cells");
assert(isDetachMark(baseMark), 0x74b /* Only detaches empty cells */);
if (baseMark.type === "MoveOut" || baseMark.detachIdOverride === undefined) {
setMarkAdjacentCells(rebasedMark, detachBlock);
}
Expand All @@ -189,7 +189,7 @@ function rebaseMarkList<TNodeChange>(
if (detachId.revision === baseIntention) {
addIdRange(detachBlock, { id: baseMark.id, count: baseMark.count });
} else {
assert(detachId.revision !== undefined, "Detach ID should have revision");
assert(detachId.revision !== undefined, 0x74c /* Detach ID should have revision */);
lineageEntries.push({
revision: detachId.revision,
id: detachId.localId,
Expand Down Expand Up @@ -788,8 +788,11 @@ function getLineageHolder(mark: Mark<unknown>): HasLineage {
}

function setMarkAdjacentCells(mark: Mark<unknown>, adjacentCells: IdRange[]): void {
assert(mark.cellId !== undefined, "Can only set adjacent cells on a mark with cell ID");
assert(mark.cellId.adjacentCells === undefined, "Should not overwrite adjacentCells");
assert(
mark.cellId !== undefined,
0x74d /* Can only set adjacent cells on a mark with cell ID */,
);
assert(mark.cellId.adjacentCells === undefined, 0x74e /* Should not overwrite adjacentCells */);
mark.cellId.adjacentCells = adjacentCells;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export function sequenceFieldToDelta<TNodeChange>(
const changes = getEffectiveNodeChanges(mark);
const cellDeltas = cellDeltaFromMark(mark, revision, idAllocator, changes === undefined);
if (changes !== undefined) {
assert(cellDeltas.length === 1, "Invalid nested changes on non length-1 mark");
assert(
cellDeltas.length === 1,
0x74f /* Invalid nested changes on non length-1 mark */,
);
const fullDelta = withChildModifications(changes, cellDeltas[0], deltaFromChild);
out.push(fullDelta);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function getOutputCellId(
revision: RevisionTag | undefined,
): CellId | undefined {
if (markEmptiesCells(mark)) {
assert(isDetachMark(mark), "Only detaches can empty cells");
assert(isDetachMark(mark), 0x750 /* Only detaches can empty cells */);
return getDetachCellId(mark, revision);
} else if (markFillsCells(mark)) {
return undefined;
Expand Down
6 changes: 3 additions & 3 deletions experimental/dds/tree2/src/shared-tree-core/editManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ export class EditManager<
const trunkSize = getPathFromBase(this.trunk.getHead(), this.trunkBase).length;
assert(
this.sequenceMap.size === trunkSize + 1,
"The size of the sequenceMap must have one element more than the trunk",
0x744 /* The size of the sequenceMap must have one element more than the trunk */,
);
assert(
this.trunkMetadata.size === trunkSize,
"The size of the trunkMetadata must be the same as the trunk",
0x745 /* The size of the trunkMetadata must be the same as the trunk */,
);
}
}
Expand Down Expand Up @@ -610,7 +610,7 @@ export class EditManager<
: searchBy;

const commit = this.sequenceMap.getPairOrNextLower(sequenceId);
assert(commit !== undefined, "sequence id has been evicted");
assert(commit !== undefined, 0x746 /* sequence id has been evicted */);
return commit;
}

Expand Down
2 changes: 1 addition & 1 deletion experimental/dds/tree2/src/shared-tree/schematizedTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function initializeContent(
schema: TypedSchemaCollection,
setInitialTree: () => void,
): void {
assert(schemaDataIsEmpty(storedSchema), "cannot initialize after a schema is set");
assert(schemaDataIsEmpty(storedSchema), 0x743 /* cannot initialize after a schema is set */);

const rootSchema = schema.rootFieldSchema;
const rootKind = rootSchema.kind.identifier;
Expand Down
2 changes: 1 addition & 1 deletion packages/dds/merge-tree/src/mergeTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ export class MergeTree {
if (marker !== undefined) {
assert(
marker.isLeaf() && Marker.is(marker),
"Object returned is not a valid marker",
0x751 /* Object returned is not a valid marker */,
);
foundMarker = marker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ export class AppendOnlySortedMap<K, V> {
let prev: readonly [K, unknown] | undefined;
for (const kv of this.entries()) {
if (prev !== undefined) {
assert(this.comparator(kv[0], prev[0]) > 0, "Keys in map must be sorted.");
assert(
this.comparator(kv[0], prev[0]) > 0,
0x752 /* Keys in map must be sorted. */,
);
}
prev = kv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class FinalSpace {
lastCluster === undefined ||
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
newCluster.baseFinalId === lastCluster.baseFinalId + lastCluster.capacity,
"Cluster insert to final_space is out of order.",
0x753 /* Cluster insert to final_space is out of order. */,
);
this.clusterList.push(newCluster);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {
// As policy, the first session is always the local session. Preserve this invariant
// during deserialization.
const firstSession = localSessionIdOrDeserialized.sessions().next();
assert(!firstSession.done, "First session must be present.");
assert(!firstSession.done, 0x754 /* First session must be present. */);
this.localSession = firstSession.value;
this.localSessionId = stableIdFromNumericUuid(
this.localSession.sessionUuid,
Expand Down Expand Up @@ -218,7 +218,7 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {
return;
}

assert(range.ids.count > 0, "Malformed ID Range.");
assert(range.ids.count > 0, 0x755 /* Malformed ID Range. */);
const { sessionId, ids } = range;
const { count, firstGenCount } = ids;
const session = this.sessions.getOrCreate(sessionId);
Expand Down Expand Up @@ -254,7 +254,10 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {
// The last cluster in the sessions chain is the last cluster globally, so it can be expanded.
lastCluster.capacity += newClaimedFinalCount;
lastCluster.count += count;
assert(!this.sessions.clusterCollides(lastCluster), "Cluster collision detected.");
assert(
!this.sessions.clusterCollides(lastCluster),
0x756 /* Cluster collision detected. */,
);
if (isLocal) {
this.logger?.sendTelemetryEvent({
eventName: "RuntimeIdCompressor:ClusterExpansion",
Expand Down Expand Up @@ -289,7 +292,7 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {
this.telemetryLocalIdCount = 0;
}

assert(!session.isEmpty(), "Empty sessions should not be created.");
assert(!session.isEmpty(), 0x757 /* Empty sessions should not be created. */);
}

private addEmptyCluster(session: Session, capacity: number): IdCluster {
Expand All @@ -298,7 +301,7 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {
capacity,
0,
);
assert(!this.sessions.clusterCollides(newCluster), "Cluster collision detected.");
assert(!this.sessions.clusterCollides(newCluster), 0x758 /* Cluster collision detected. */);
this.finalSpace.addCluster(newCluster);
return newCluster;
}
Expand Down Expand Up @@ -379,7 +382,10 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {
if (alignedGenCount > lastFinalizedGenCount) {
// should be an eager final id generated by the local session
if (containingCluster.session === this.localSession) {
assert(!this.normalizer.contains(alignedLocal), "Normalizer out of sync.");
assert(
!this.normalizer.contains(alignedLocal),
0x759 /* Normalizer out of sync. */,
);
} else {
throw new Error("Unknown ID");
}
Expand Down Expand Up @@ -432,7 +438,7 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {
} else {
assert(
genCountFromLocalId(alignedLocal) <= this.localGenCount,
"Clusters out of sync.",
0x75a /* Clusters out of sync. */,
);
// Id is an eager final
return getAlignedFinal(containingCluster, alignedLocal) as
Expand Down Expand Up @@ -513,7 +519,7 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {
}
}

assert(index === totalSize, "Serialized size was incorrectly calculated.");
assert(index === totalSize, 0x75b /* Serialized size was incorrectly calculated. */);
this.logger?.sendTelemetryEvent({
eventName: "RuntimeIdCompressor:SerializedIdCompressorSize",
size: serializedFloat.byteLength,
Expand All @@ -540,7 +546,7 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {
bufferUint: new BigUint64Array(buffer),
};
const version = readNumber(index);
assert(version === currentWrittenVersion, "Unknown serialized version.");
assert(version === currentWrittenVersion, 0x75c /* Unknown serialized version. */);
const hasLocalState = readBoolean(index);
const clusterCapacity = readNumber(index);
const sessionCount = readNumber(index);
Expand All @@ -551,12 +557,15 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {
const sessions: [NumericUuid, Session][] = [];
if (!hasLocalState) {
// If !hasLocalState, there won't be a serialized local session ID so insert one at the beginning
assert(sessionId !== undefined, "Local session ID is undefined.");
assert(sessionId !== undefined, 0x75d /* Local session ID is undefined. */);
const localSessionNumeric = numericUuidFromStableId(sessionId);
sessions.push([localSessionNumeric, new Session(localSessionNumeric)]);
sessionOffset = 1;
} else {
assert(sessionId === undefined, "Local state should not exist in serialized form.");
assert(
sessionId === undefined,
0x75e /* Local state should not exist in serialized form. */,
);
}

for (let i = 0; i < sessionCount; i++) {
Expand Down Expand Up @@ -595,7 +604,7 @@ export class IdCompressor implements IIdCompressor, IIdCompressorCore {

assert(
index.index === index.bufferFloat.length,
"Failed to read entire serialized compressor.",
0x75f /* Failed to read entire serialized compressor. */,
);
return compressor;
}
Expand Down
11 changes: 7 additions & 4 deletions packages/runtime/container-runtime/src/id-compressor/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export class Sessions {
return existing;
}
const session = new Session(sessionId);
assert(this.uuidSpace.set(session.sessionUuid, session), "Duplicate session in map.");
assert(
this.uuidSpace.set(session.sessionUuid, session),
0x760 /* Duplicate session in map. */,
);
this.sessionCache.set(sessionId, session);
return session;
}
Expand Down Expand Up @@ -111,7 +114,7 @@ export class Sessions {
}

const [_, session] = closestMatch;
assert(session !== owningSession, "Failed to attempt to detect collisions.");
assert(session !== owningSession, 0x761 /* Failed to attempt to detect collisions. */);
const lastCluster = session.getLastCluster();
if (lastCluster === undefined) {
// If the closest session is empty (the local session), then it is guaranteed (probabilistically) that there are no
Expand All @@ -138,7 +141,7 @@ export class Sessions {
}
assert(
session === firstSessionThis,
"The only non-empty session must be the local session.",
0x762 /* The only non-empty session must be the local session. */,
);
} else if (!session.equals(otherSession)) {
return false;
Expand Down Expand Up @@ -367,7 +370,7 @@ export function getAlignedLocal(
): LocalCompressedId {
assert(
finalWithin >= cluster.baseFinalId && finalWithin <= lastAllocatedFinal(cluster),
"Supplied ID is not within the cluster.",
0x763 /* Supplied ID is not within the cluster. */,
);
const finalDelta = finalWithin - cluster.baseFinalId;
return (cluster.baseLocalId - finalDelta) as LocalCompressedId;
Expand Down
Loading

0 comments on commit 607786b

Please sign in to comment.