Skip to content

Remove the unused callstack #790

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

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions Sources/_StringProcessing/Engine/Backtracking.swift
Original file line number Diff line number Diff line change
@@ -21,13 +21,6 @@ extension Processor {
// points. We should try to separate out the concerns better.
var isScalarSemantics: Bool

// The end of the call stack, so we can slice it off
// when failing inside a call.
//
// NOTE: Alternatively, also place return addresses on the
// save point stack
var stackEnd: CallStackAddress

// FIXME: Save minimal info (e.g. stack position and
// perhaps current start)
var captureEnds: [_StoredCapture]
@@ -41,12 +34,11 @@ extension Processor {
var destructure: (
pc: InstructionAddress,
pos: Position?,
stackEnd: CallStackAddress,
captureEnds: [_StoredCapture],
intRegisters: [Int],
PositionRegister: [Input.Index]
) {
return (pc, pos, stackEnd, captureEnds, intRegisters, posRegisters)
return (pc, pos, captureEnds, intRegisters, posRegisters)
}

// Whether this save point is quantified, meaning it has a range of
@@ -85,7 +77,6 @@ extension Processor {
pos: currentPosition,
quantifiedRange: nil,
isScalarSemantics: false,
stackEnd: .init(callStack.count),
captureEnds: storedCaptures,
intRegisters: registers.ints,
posRegisters: registers.positions)
@@ -99,7 +90,6 @@ extension Processor {
pos: nil,
quantifiedRange: nil,
isScalarSemantics: false,
stackEnd: .init(callStack.count),
captureEnds: storedCaptures,
intRegisters: registers.ints,
posRegisters: registers.positions)
@@ -114,7 +104,6 @@ extension Processor {
pos: nil,
quantifiedRange: range,
isScalarSemantics: isScalarSemantics,
stackEnd: .init(callStack.count),
captureEnds: storedCaptures,
intRegisters: registers.ints,
posRegisters: registers.positions)
15 changes: 3 additions & 12 deletions Sources/_StringProcessing/Engine/Processor.swift
Original file line number Diff line number Diff line change
@@ -81,8 +81,6 @@ struct Processor {

var savePoints: [SavePoint] = []

var callStack: [InstructionAddress] = []

var storedCaptures: Array<_StoredCapture>

var state: State = .inProgress
@@ -142,9 +140,6 @@ extension Processor {
if !self.savePoints.isEmpty {
self.savePoints.removeAll(keepingCapacity: true)
}
if !self.callStack.isEmpty {
self.callStack.removeAll(keepingCapacity: true)
}

for idx in storedCaptures.indices {
storedCaptures[idx] = .init()
@@ -163,7 +158,6 @@ extension Processor {
_checkInvariants()
guard self.controller == Controller(pc: 0),
self.savePoints.isEmpty,
self.callStack.isEmpty,
self.storedCaptures.allSatisfy({ $0.range == nil }),
self.state == .inProgress,
self.failureReason == nil
@@ -361,10 +355,9 @@ extension Processor {
state = .fail
return
}
let (pc, pos, stackEnd, capEnds, intRegisters, posRegisters): (
let (pc, pos, capEnds, intRegisters, posRegisters): (
pc: InstructionAddress,
pos: Position?,
stackEnd: CallStackAddress,
captureEnds: [_StoredCapture],
intRegisters: [Int],
PositionRegister: [Input.Index]
@@ -376,17 +369,15 @@ extension Processor {
// pos instead of removing it
if savePoints[idx].isQuantified {
savePoints[idx].takePositionFromQuantifiedRange(input)
(pc, pos, stackEnd, capEnds, intRegisters, posRegisters) = savePoints[idx].destructure
(pc, pos, capEnds, intRegisters, posRegisters) = savePoints[idx].destructure
} else {
(pc, pos, stackEnd, capEnds, intRegisters, posRegisters) = savePoints.removeLast().destructure
(pc, pos, capEnds, intRegisters, posRegisters) = savePoints.removeLast().destructure
}

assert(stackEnd.rawValue <= callStack.count)
assert(capEnds.count == storedCaptures.count)

controller.pc = pc
currentPosition = pos ?? currentPosition
callStack.removeLast(callStack.count - stackEnd.rawValue)
registers.ints = intRegisters
registers.positions = posRegisters

2 changes: 1 addition & 1 deletion Sources/_StringProcessing/Engine/Tracing.swift
Original file line number Diff line number Diff line change
@@ -128,7 +128,7 @@ extension Processor.SavePoint {
}
}
return """
pc: \(self.pc), pos: \(posStr), stackEnd: \(stackEnd)
pc: \(self.pc), pos: \(posStr)
"""
}
}
3 changes: 0 additions & 3 deletions Sources/_StringProcessing/Utility/Protocols.swift
Original file line number Diff line number Diff line change
@@ -34,9 +34,6 @@ protocol ProcessorProtocol {
var isAcceptState: Bool { get }
var isFailState: Bool { get }

// Provide to get call stack formatting, default empty
var callStack: Array<InstructionAddress> { get }

// Provide to get save point formatting, default empty
var savePoints: Array<SavePoint> { get }

10 changes: 0 additions & 10 deletions Sources/_StringProcessing/Utility/Traced.swift
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ protocol Traced {

protocol TracedProcessor: ProcessorProtocol, Traced {
// Empty defaulted
func formatCallStack() -> String // empty default
func formatSavePoints() -> String // empty default
func formatRegisters() -> String // empty default

@@ -52,14 +51,6 @@ extension TracedProcessor {
if isTracingEnabled { printTrace() }
}

// Helpers for the conformers
func formatCallStack() -> String {
if !callStack.isEmpty {
return "call stack: \(callStack)\n"
}
return ""
}

func formatSavePoints() -> String {
if !savePoints.isEmpty {
var result = "save points:\n"
@@ -158,7 +149,6 @@ extension TracedProcessor {

func formatTrace() -> String {
var result = "\n--- cycle \(cycleCount) ---\n"
result += formatCallStack()
result += formatSavePoints()
result += formatRegisters()
result += formatInput()
5 changes: 0 additions & 5 deletions Sources/_StringProcessing/Utility/TypedInt.swift
Original file line number Diff line number Diff line change
@@ -99,10 +99,6 @@ enum _Distance {}
typealias InstructionAddress = TypedInt<_InstructionAddress>
enum _InstructionAddress {}

/// A position in the call stack, i.e. for save point restores
typealias CallStackAddress = TypedInt<_CallStackAddress>
enum _CallStackAddress {}

/// A position in a position stack, i.e. for NFA simulation
typealias PositionStackAddress = TypedInt<_PositionStackAddress>
enum _PositionStackAddress {}
@@ -111,7 +107,6 @@ enum _PositionStackAddress {}
typealias SavePointStackAddress = TypedInt<_SavePointAddress>
enum _SavePointAddress {}


// MARK: - Registers

/// The register number for a stored element