From cca23a257db3e983cf1cfe644e6b967daf10936d Mon Sep 17 00:00:00 2001 From: Lucian Radu Teodorescu Date: Tue, 7 Oct 2025 22:55:37 +0300 Subject: [PATCH 1/5] Remove `Block.AbsoluteID` Replace its use in Emitter with a simpler structure. --- Sources/IR/BlockID.swift | 45 ---------------------------------------- Sources/IR/Emitter.swift | 16 ++++++++++++-- 2 files changed, 14 insertions(+), 47 deletions(-) diff --git a/Sources/IR/BlockID.swift b/Sources/IR/BlockID.swift index 9e7cbeae9..2de58c905 100644 --- a/Sources/IR/BlockID.swift +++ b/Sources/IR/BlockID.swift @@ -13,11 +13,6 @@ extension Block { self.address = address } - /// Creates an instance with the given address. - public init(_ b: Block.AbsoluteID) { - self.address = b.address - } - /// Creates an instance denoting the block containing `i`. public init(containing i: InstructionID) { self.address = i.block @@ -41,40 +36,6 @@ extension Block { } - /// The absolute ID of a basic block. - public struct AbsoluteID: Hashable { - - /// The ID of the function containing the block. - public var function: Function.ID - - /// The address of the block in the containing function. - public var address: Function.Blocks.Address - - /// Creates an instance with the given properties. - public init(_ function: Function.ID, _ address: Function.Blocks.Address) { - self.function = function - self.address = address - } - - /// Creates an instance with the given properties. - public init(_ function: Function.ID, _ block: Block.ID) { - self.function = function - self.address = block.address - } - - /// The ID of the `index`-th parameter of the block. - public func parameter(_ index: Int) -> Operand { - .parameter(Block.ID(self), index) - } - - /// The operand denoting the result of the instruction at `instructionAddress` in the block - /// identified by `self`. - public func result(at instructionAddress: Block.Instructions.Address) -> Operand { - .register(InstructionID(address, instructionAddress)) - } - - } - } extension Block.ID: CustomStringConvertible { @@ -82,9 +43,3 @@ extension Block.ID: CustomStringConvertible { public var description: String { "b\(address)" } } - -extension Block.AbsoluteID: CustomStringConvertible { - - public var description: String { "b\(address)" } - -} diff --git a/Sources/IR/Emitter.swift b/Sources/IR/Emitter.swift index 157d5ede3..74d48d16e 100644 --- a/Sources/IR/Emitter.swift +++ b/Sources/IR/Emitter.swift @@ -57,7 +57,7 @@ struct Emitter { private var loops = LoopIDs() /// For each block, the state of `frames` where the block was first entered. - private var stackOnEntry: [Block.AbsoluteID: Stack] = [:] + private var stackOnEntry: [BlockInFunction: Stack] = [:] /// Where new instructions are inserted. var insertionPoint: InsertionPoint? @@ -68,6 +68,18 @@ struct Emitter { /// The source code associated with instructions to be inserted. var currentSource: SourceRange + /// The block's ID within its function. + public struct BlockInFunction: Hashable { + + /// The ID of the function containing the block. + public var function: Function.ID + + /// The ID of the block in the function. + public var block: Block.ID + + } + + /// The program being lowered. private var program: TypedProgram { module.program @@ -3592,7 +3604,7 @@ extension Emitter { /// This test is used to ensure that all points branching to a block /// have consistent stack allocations. fileprivate mutating func checkEntryStack(_ b: Block.ID) { - modify(&stackOnEntry[Block.AbsoluteID(insertionFunction!, b)]) { x in + modify(&stackOnEntry[BlockInFunction(function: insertionFunction!, block: b)]) { x in if let y = x { assert(y.hasSameAllocations(as: frames)) } From ba7edfa7903f973164712cb682d4a915433653d1 Mon Sep 17 00:00:00 2001 From: Lucian Radu Teodorescu Date: Fri, 24 Oct 2025 23:20:03 +0300 Subject: [PATCH 2/5] Update some documentation. --- Sources/IR/Emitter.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/IR/Emitter.swift b/Sources/IR/Emitter.swift index 4e70fda0b..e0d19c6ad 100644 --- a/Sources/IR/Emitter.swift +++ b/Sources/IR/Emitter.swift @@ -68,18 +68,17 @@ struct Emitter: Sendable { /// The source code associated with instructions to be inserted. var currentSource: SourceRange - /// The block's ID within its function. + /// The block's ID across functions. public struct BlockInFunction: Hashable { /// The ID of the function containing the block. public var function: Function.ID - /// The ID of the block in the function. + /// The block's ID inside the function. public var block: Block.ID } - /// The program being lowered. private var program: TypedProgram { module.program From 0a56c3b6a8d5f36a44817de8a4ced9d0476f82bf Mon Sep 17 00:00:00 2001 From: Lucian Radu Teodorescu Date: Mon, 27 Oct 2025 22:26:58 +0200 Subject: [PATCH 3/5] Update Sources/IR/Emitter.swift Co-authored-by: Dimi Racordon --- Sources/IR/Emitter.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/IR/Emitter.swift b/Sources/IR/Emitter.swift index e0d19c6ad..3b03a4fe0 100644 --- a/Sources/IR/Emitter.swift +++ b/Sources/IR/Emitter.swift @@ -69,7 +69,7 @@ struct Emitter: Sendable { var currentSource: SourceRange /// The block's ID across functions. - public struct BlockInFunction: Hashable { + public struct BlockAndFunction: Hashable { /// The ID of the function containing the block. public var function: Function.ID From 72e65693e633425bfd5a620a219ad0a1b0b788a1 Mon Sep 17 00:00:00 2001 From: Lucian Radu Teodorescu Date: Mon, 27 Oct 2025 22:43:45 +0200 Subject: [PATCH 4/5] Fix build errors --- Sources/IR/Emitter.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/IR/Emitter.swift b/Sources/IR/Emitter.swift index 3b03a4fe0..eeb01c9e6 100644 --- a/Sources/IR/Emitter.swift +++ b/Sources/IR/Emitter.swift @@ -57,7 +57,7 @@ struct Emitter: Sendable { private var loops = LoopIDs() /// For each block, the state of `frames` where the block was first entered. - private var stackOnEntry: [BlockInFunction: Stack] = [:] + private var stackOnEntry: [BlockAndFunction: Stack] = [:] /// Where new instructions are inserted. var insertionPoint: InsertionPoint? @@ -3603,7 +3603,7 @@ extension Emitter { /// This test is used to ensure that all points branching to a block /// have consistent stack allocations. fileprivate mutating func checkEntryStack(_ b: Block.ID) { - modify(&stackOnEntry[BlockInFunction(function: insertionFunction!, block: b)]) { x in + modify(&stackOnEntry[BlockAndFunction(function: insertionFunction!, block: b)]) { x in if let y = x { assert(y.hasSameAllocations(as: frames)) } From c72377e6611049f9b1eb229868983f0c7683864d Mon Sep 17 00:00:00 2001 From: Ambrus Toth Date: Mon, 27 Oct 2025 21:39:41 +0000 Subject: [PATCH 5/5] Update SPM Build tool --- SPMBuildToolSupport | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SPMBuildToolSupport b/SPMBuildToolSupport index 7c0a5c10c..c270d23a9 160000 --- a/SPMBuildToolSupport +++ b/SPMBuildToolSupport @@ -1 +1 @@ -Subproject commit 7c0a5c10ccacf066163c36e2cfcba65c7a21e956 +Subproject commit c270d23a9c70aa015e09a9c0ea28e36d2801adc4