Skip to content

Commit

Permalink
Remove the unused callstack
Browse files Browse the repository at this point in the history
  • Loading branch information
milseman committed Dec 19, 2024
1 parent b0653e2 commit 2929df2
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 43 deletions.
13 changes: 1 addition & 12 deletions Sources/_StringProcessing/Engine/Backtracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -85,7 +77,6 @@ extension Processor {
pos: currentPosition,
quantifiedRange: nil,
isScalarSemantics: false,
stackEnd: .init(callStack.count),
captureEnds: storedCaptures,
intRegisters: registers.ints,
posRegisters: registers.positions)
Expand All @@ -99,7 +90,6 @@ extension Processor {
pos: nil,
quantifiedRange: nil,
isScalarSemantics: false,
stackEnd: .init(callStack.count),
captureEnds: storedCaptures,
intRegisters: registers.ints,
posRegisters: registers.positions)
Expand All @@ -114,7 +104,6 @@ extension Processor {
pos: nil,
quantifiedRange: range,
isScalarSemantics: isScalarSemantics,
stackEnd: .init(callStack.count),
captureEnds: storedCaptures,
intRegisters: registers.ints,
posRegisters: registers.positions)
Expand Down
15 changes: 3 additions & 12 deletions Sources/_StringProcessing/Engine/Processor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ struct Processor {

var savePoints: [SavePoint] = []

var callStack: [InstructionAddress] = []

var storedCaptures: Array<_StoredCapture>

var state: State = .inProgress
Expand Down Expand Up @@ -146,9 +144,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()
Expand All @@ -167,7 +162,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
Expand Down Expand Up @@ -383,10 +377,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]
Expand All @@ -398,17 +391,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

Expand Down
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/Engine/Tracing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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 }

Expand Down
10 changes: 0 additions & 10 deletions Sources/_StringProcessing/Utility/Traced.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -158,7 +149,6 @@ extension TracedProcessor {

func formatTrace() -> String {
var result = "\n--- cycle \(cycleCount) ---\n"
result += formatCallStack()
result += formatSavePoints()
result += formatRegisters()
result += formatInput()
Expand Down
5 changes: 0 additions & 5 deletions Sources/_StringProcessing/Utility/TypedInt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -111,7 +107,6 @@ enum _PositionStackAddress {}
typealias SavePointStackAddress = TypedInt<_SavePointAddress>
enum _SavePointAddress {}


// MARK: - Registers

/// The register number for a stored element
Expand Down

0 comments on commit 2929df2

Please sign in to comment.