Skip to content

Commit 80ea67b

Browse files
committed
Use package access control for BinaryInstructionDecoder
This is a preparation for a future internal breakpoint instruction, for which we need `visitUnknown` of `BinaryInstructionDecoder` to be available in the `WasmKit` module. Bumped `swift-tools-version` to 6.0 to get proper support for `package` in SwiftPM enabled.
1 parent 89c2c78 commit 80ea67b

File tree

5 files changed

+49
-45
lines changed

5 files changed

+49
-45
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version:6.0
22

33
import PackageDescription
44

Sources/WasmKit/Execution/Function.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ struct InternalFunction: Equatable, Hashable {
124124
_storage = bitPattern
125125
}
126126

127+
/// Returns `true` if the function is defined as a Wasm function in its original module.
128+
/// Returns `false` if the function is implemented by the host.
127129
var isWasm: Bool {
128130
_storage & 0b1 == 0
129131
}
@@ -241,7 +243,7 @@ struct WasmFunctionEntity {
241243
switch code {
242244
case .uncompiled(let code):
243245
return try compile(store: store, code: code)
244-
case .compiled(let iseq):
246+
case .compiled(let iseq), .compiledAndPatchable(_, let iseq):
245247
return iseq
246248
}
247249
}
@@ -281,7 +283,8 @@ extension EntityHandle<WasmFunctionEntity> {
281283
$0.code = .compiled(iseq)
282284
return iseq
283285
}
284-
case .compiled(let iseq): return iseq
286+
case .compiled(let iseq), .compiledAndPatchable(_, let iseq):
287+
return iseq
285288
}
286289
}
287290
}
@@ -313,6 +316,7 @@ struct InstructionSequence {
313316
enum CodeBody {
314317
case uncompiled(InternalUncompiledCode)
315318
case compiled(InstructionSequence)
319+
case compiledAndPatchable(InternalUncompiledCode, InstructionSequence)
316320
}
317321

318322
extension Reference {

Sources/WasmParser/BinaryInstructionDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import WasmTypes
66

77
@usableFromInline
8-
protocol BinaryInstructionDecoder {
8+
package protocol BinaryInstructionDecoder {
99
/// Claim the next byte to be decoded
1010
@inlinable func claimNextByte() throws -> UInt8
1111
/// Visit unknown instruction

Sources/WasmParser/WasmParser.swift

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -606,23 +606,23 @@ extension Parser: BinaryInstructionDecoder {
606606
return 0
607607
}
608608

609-
@inlinable func visitUnknown(_ opcode: [UInt8]) throws {
609+
@inlinable package func visitUnknown(_ opcode: [UInt8]) throws {
610610
throw makeError(.illegalOpcode(opcode))
611611
}
612612

613-
@inlinable mutating func visitBlock() throws -> BlockType { try parseResultType() }
614-
@inlinable mutating func visitLoop() throws -> BlockType { try parseResultType() }
615-
@inlinable mutating func visitIf() throws -> BlockType { try parseResultType() }
616-
@inlinable mutating func visitBr() throws -> UInt32 { try parseUnsigned() }
617-
@inlinable mutating func visitBrIf() throws -> UInt32 { try parseUnsigned() }
618-
@inlinable mutating func visitBrTable() throws -> BrTable {
613+
@inlinable package mutating func visitBlock() throws -> BlockType { try parseResultType() }
614+
@inlinable package mutating func visitLoop() throws -> BlockType { try parseResultType() }
615+
@inlinable package mutating func visitIf() throws -> BlockType { try parseResultType() }
616+
@inlinable package mutating func visitBr() throws -> UInt32 { try parseUnsigned() }
617+
@inlinable package mutating func visitBrIf() throws -> UInt32 { try parseUnsigned() }
618+
@inlinable package mutating func visitBrTable() throws -> BrTable {
619619
let labelIndices: [UInt32] = try parseVector { try parseUnsigned() }
620620
let labelIndex: UInt32 = try parseUnsigned()
621621
return BrTable(labelIndices: labelIndices, defaultIndex: labelIndex)
622622
}
623-
@inlinable mutating func visitCall() throws -> UInt32 { try parseUnsigned() }
623+
@inlinable package mutating func visitCall() throws -> UInt32 { try parseUnsigned() }
624624

625-
@inlinable mutating func visitCallIndirect() throws -> (typeIndex: UInt32, tableIndex: UInt32) {
625+
@inlinable package mutating func visitCallIndirect() throws -> (typeIndex: UInt32, tableIndex: UInt32) {
626626
let typeIndex: TypeIndex = try parseUnsigned()
627627
if try !features.contains(.referenceTypes) && stream.peek() != 0 {
628628
// Check that reserved byte is zero when reference-types is disabled
@@ -632,115 +632,115 @@ extension Parser: BinaryInstructionDecoder {
632632
return (typeIndex, tableIndex)
633633
}
634634

635-
@inlinable mutating func visitReturnCall() throws -> UInt32 {
635+
@inlinable package mutating func visitReturnCall() throws -> UInt32 {
636636
try parseUnsigned()
637637
}
638638

639-
@inlinable mutating func visitReturnCallIndirect() throws -> (typeIndex: UInt32, tableIndex: UInt32) {
639+
@inlinable package mutating func visitReturnCallIndirect() throws -> (typeIndex: UInt32, tableIndex: UInt32) {
640640
let typeIndex: TypeIndex = try parseUnsigned()
641641
let tableIndex: TableIndex = try parseUnsigned()
642642
return (typeIndex, tableIndex)
643643
}
644644

645-
@inlinable mutating func visitTypedSelect() throws -> WasmTypes.ValueType {
645+
@inlinable package mutating func visitTypedSelect() throws -> WasmTypes.ValueType {
646646
let results = try parseVector { try parseValueType() }
647647
guard results.count == 1 else {
648648
throw makeError(.invalidResultArity(expected: 1, actual: results.count))
649649
}
650650
return results[0]
651651
}
652652

653-
@inlinable mutating func visitLocalGet() throws -> UInt32 { try parseUnsigned() }
654-
@inlinable mutating func visitLocalSet() throws -> UInt32 { try parseUnsigned() }
655-
@inlinable mutating func visitLocalTee() throws -> UInt32 { try parseUnsigned() }
656-
@inlinable mutating func visitGlobalGet() throws -> UInt32 { try parseUnsigned() }
657-
@inlinable mutating func visitGlobalSet() throws -> UInt32 { try parseUnsigned() }
658-
@inlinable mutating func visitLoad(_: Instruction.Load) throws -> MemArg { try parseMemarg() }
659-
@inlinable mutating func visitStore(_: Instruction.Store) throws -> MemArg { try parseMemarg() }
660-
@inlinable mutating func visitMemorySize() throws -> UInt32 {
653+
@inlinable package mutating func visitLocalGet() throws -> UInt32 { try parseUnsigned() }
654+
@inlinable package mutating func visitLocalSet() throws -> UInt32 { try parseUnsigned() }
655+
@inlinable package mutating func visitLocalTee() throws -> UInt32 { try parseUnsigned() }
656+
@inlinable package mutating func visitGlobalGet() throws -> UInt32 { try parseUnsigned() }
657+
@inlinable package mutating func visitGlobalSet() throws -> UInt32 { try parseUnsigned() }
658+
@inlinable package mutating func visitLoad(_: Instruction.Load) throws -> MemArg { try parseMemarg() }
659+
@inlinable package mutating func visitStore(_: Instruction.Store) throws -> MemArg { try parseMemarg() }
660+
@inlinable package mutating func visitMemorySize() throws -> UInt32 {
661661
try parseMemoryIndex()
662662
}
663-
@inlinable mutating func visitMemoryGrow() throws -> UInt32 {
663+
@inlinable package mutating func visitMemoryGrow() throws -> UInt32 {
664664
try parseMemoryIndex()
665665
}
666-
@inlinable mutating func visitI32Const() throws -> Int32 {
666+
@inlinable package mutating func visitI32Const() throws -> Int32 {
667667
let n: UInt32 = try parseInteger()
668668
return Int32(bitPattern: n)
669669
}
670-
@inlinable mutating func visitI64Const() throws -> Int64 {
670+
@inlinable package mutating func visitI64Const() throws -> Int64 {
671671
let n: UInt64 = try parseInteger()
672672
return Int64(bitPattern: n)
673673
}
674-
@inlinable mutating func visitF32Const() throws -> IEEE754.Float32 {
674+
@inlinable package mutating func visitF32Const() throws -> IEEE754.Float32 {
675675
let n = try parseFloat()
676676
return IEEE754.Float32(bitPattern: n)
677677
}
678-
@inlinable mutating func visitF64Const() throws -> IEEE754.Float64 {
678+
@inlinable package mutating func visitF64Const() throws -> IEEE754.Float64 {
679679
let n = try parseDouble()
680680
return IEEE754.Float64(bitPattern: n)
681681
}
682-
@inlinable mutating func visitRefNull() throws -> WasmTypes.ReferenceType {
682+
@inlinable package mutating func visitRefNull() throws -> WasmTypes.ReferenceType {
683683
let type = try parseValueType()
684684
guard case let .ref(refType) = type else {
685685
throw makeError(.expectedRefType(actual: type))
686686
}
687687
return refType
688688
}
689689

690-
@inlinable mutating func visitRefFunc() throws -> UInt32 { try parseUnsigned() }
691-
@inlinable mutating func visitMemoryInit() throws -> UInt32 {
690+
@inlinable package mutating func visitRefFunc() throws -> UInt32 { try parseUnsigned() }
691+
@inlinable package mutating func visitMemoryInit() throws -> UInt32 {
692692
let dataIndex: DataIndex = try parseUnsigned()
693693
_ = try parseMemoryIndex()
694694
return dataIndex
695695
}
696696

697-
@inlinable mutating func visitDataDrop() throws -> UInt32 {
697+
@inlinable package mutating func visitDataDrop() throws -> UInt32 {
698698
try parseUnsigned()
699699
}
700700

701-
@inlinable mutating func visitMemoryCopy() throws -> (dstMem: UInt32, srcMem: UInt32) {
701+
@inlinable package mutating func visitMemoryCopy() throws -> (dstMem: UInt32, srcMem: UInt32) {
702702
_ = try parseMemoryIndex()
703703
_ = try parseMemoryIndex()
704704
return (0, 0)
705705
}
706706

707-
@inlinable mutating func visitMemoryFill() throws -> UInt32 {
707+
@inlinable package mutating func visitMemoryFill() throws -> UInt32 {
708708
let zero = try stream.consumeAny()
709709
guard zero == 0x00 else {
710710
throw makeError(.zeroExpected(actual: zero))
711711
}
712712
return 0
713713
}
714714

715-
@inlinable mutating func visitTableInit() throws -> (elemIndex: UInt32, table: UInt32) {
715+
@inlinable package mutating func visitTableInit() throws -> (elemIndex: UInt32, table: UInt32) {
716716
let elementIndex: ElementIndex = try parseUnsigned()
717717
let tableIndex: TableIndex = try parseUnsigned()
718718
return (elementIndex, tableIndex)
719719
}
720-
@inlinable mutating func visitElemDrop() throws -> UInt32 {
720+
@inlinable package mutating func visitElemDrop() throws -> UInt32 {
721721
try parseUnsigned()
722722
}
723-
@inlinable mutating func visitTableCopy() throws -> (dstTable: UInt32, srcTable: UInt32) {
723+
@inlinable package mutating func visitTableCopy() throws -> (dstTable: UInt32, srcTable: UInt32) {
724724
let destination: TableIndex = try parseUnsigned()
725725
let source: TableIndex = try parseUnsigned()
726726
return (destination, source)
727727
}
728-
@inlinable mutating func visitTableFill() throws -> UInt32 {
728+
@inlinable package mutating func visitTableFill() throws -> UInt32 {
729729
try parseUnsigned()
730730
}
731-
@inlinable mutating func visitTableGet() throws -> UInt32 {
731+
@inlinable package mutating func visitTableGet() throws -> UInt32 {
732732
try parseUnsigned()
733733
}
734-
@inlinable mutating func visitTableSet() throws -> UInt32 {
734+
@inlinable package mutating func visitTableSet() throws -> UInt32 {
735735
try parseUnsigned()
736736
}
737-
@inlinable mutating func visitTableGrow() throws -> UInt32 {
737+
@inlinable package mutating func visitTableGrow() throws -> UInt32 {
738738
try parseUnsigned()
739739
}
740-
@inlinable mutating func visitTableSize() throws -> UInt32 {
740+
@inlinable package mutating func visitTableSize() throws -> UInt32 {
741741
try parseUnsigned()
742742
}
743-
@inlinable func claimNextByte() throws -> UInt8 {
743+
@inlinable package func claimNextByte() throws -> UInt8 {
744744
return try stream.consumeAny()
745745
}
746746

Utilities/Sources/WasmGen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ enum WasmGen {
524524
import WasmTypes
525525
526526
@usableFromInline
527-
protocol BinaryInstructionDecoder {
527+
package protocol BinaryInstructionDecoder {
528528
/// Claim the next byte to be decoded
529529
@inlinable func claimNextByte() throws -> UInt8
530530
/// Visit unknown instruction

0 commit comments

Comments
 (0)