Skip to content

[un-revert] Replace per-save-point array snapshots with an undo trail - #881

Merged
natecook1000 merged 5 commits into
mainfrom
savepoint-simplify-attempt-2
Sep 29, 2026
Merged

natecook1000 merged 5 commits into
mainfrom
savepoint-simplify-attempt-2

Conversation

@natecook1000

Copy link
Copy Markdown
Member

Second attempt at landing #870, which simplifies the SavePoint type and logs register mutations in an UndoableArray, rather than relying on copy-on-write for the registers during backtracking. Updated from the original to include a proper import that was missed without the MemberImportVisibility flag, and some additional performance tuning.

Creating a save point previously copied the four mutable register arrays
(ints, positions, values, and storedCaptures) to enable restoration
during backtracking. This led to a large amount of reference counting
traffic and copy-on-write of the original register arrays whenever they
were updated.

This change moves the restoration data from using full copies of each
array in every save point, to tracking a log of the changes to each array
in the processor itself and only storing the current state of the logs
in each save point. This allows `SavePoint` to be a trivial type (almost)
and removes all the copy-on-write traffic. Backtracking now uses the
tracking logs to unwind the registers to the specific previous state.

This change also includes a minor refactor, moving the `storedCaptures`
array to the `Registers` struct, alongside the other mutable registers.
signalFailure only calls `undo(to:)`, which rewinds a register's
log, but doesn't touch its values or add to the log.
@natecook1000

Copy link
Copy Markdown
Member Author

@swift-ci Please test Linux platform

@natecook1000

Copy link
Copy Markdown
Member Author

Checked that the macOS build worked with the import _RegexParser change here: swiftlang/swift#92622

@natecook1000
natecook1000 merged commit 2d0b2db into main Sep 29, 2026
24 checks passed
@natecook1000
natecook1000 deleted the savepoint-simplify-attempt-2 branch September 29, 2026 22:24
AnthonyLatsis added a commit that referenced this pull request Sep 30, 2026
…do trail (#881)"

This reverts commit 2d0b2db.

The commit broke Windows PR testing.
AnthonyLatsis added a commit that referenced this pull request Sep 30, 2026
Revert "[un-revert] Replace per-save-point array snapshots with an undo trail (#881)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant