Skip to content

Commit

Permalink
tree: Avoid adding an empty changeset to compositions (#21958)
Browse files Browse the repository at this point in the history
## Description

This PR removes a behavior where ModularChangeFamily, as well as some
test change handlers, would include an empty changeset into the
composition whenever composing an array of changesets. This was done so
that even composing a single changeset would cause a full composition
pass. In the past this was necessary because the composition pass had
the side effect of inlining revision tags. Now that revision tag
inlining is done separately, this pass is unnecessary.
  • Loading branch information
alex-pardes authored Jul 19, 2024
1 parent 50438c3 commit bfbef34
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,12 @@ export class ModularChangeFamily
const { revInfos, maxId } = getRevInfoFromTaggedChanges(changes);
const idState: IdAllocationState = { maxId };

return changes.reduce(
(change1, change2) =>
makeAnonChange(this.composePair(change1, change2, revInfos, idState)),
makeAnonChange({
fieldChanges: new Map(),
nodeChanges: new Map(),
nodeToParent: new Map(),
nodeAliases: new Map(),
crossFieldKeys: newCrossFieldKeyTable(),
}),
if (changes.length === 0) {
return makeModularChangeset();
}

return changes.reduce((change1, change2) =>
makeAnonChange(this.composePair(change1, change2, revInfos, idState)),
).change;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ function rebaseComposedWrapped(
change: TaggedChange<WrappedChangeset>,
...baseChanges: TaggedChange<WrappedChangeset>[]
): WrappedChangeset {
const composed = baseChanges.reduce(
(change1, change2) => makeAnonChange(composeWrapped(change1, change2)),
makeAnonChange(ChangesetWrapper.create(Change.empty())),
);
const composed =
baseChanges.length === 0
? makeAnonChange(ChangesetWrapper.create(Change.empty()))
: baseChanges.reduce((change1, change2) =>
makeAnonChange(composeWrapped(change1, change2)),
);

return rebaseWrapped(change, composed, metadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ export function composeDeep(
): WrappedChange {
const metadata = revisionMetadata ?? defaultRevisionMetadataFromChanges(changes);

return changes.reduce(
(change1, change2) =>
makeAnonChange(
ChangesetWrapper.compose(change1, change2, (c1, c2, composeChild) =>
composePair(c1.change, c2.change, composeChild, metadata, idAllocatorFromMaxId()),
return changes.length === 0
? ChangesetWrapper.create([])
: changes.reduce((change1, change2) =>
makeAnonChange(
ChangesetWrapper.compose(change1, change2, (c1, c2, composeChild) =>
composePair(c1.change, c2.change, composeChild, metadata, idAllocatorFromMaxId()),
),
),
),
makeAnonChange(ChangesetWrapper.create([])),
).change;
).change;
}

export function composeNoVerify(
Expand Down

0 comments on commit bfbef34

Please sign in to comment.