Skip to content

Instantly share code, notes, and snippets.

@glessard
Last active February 3, 2022 16:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save glessard/f0dc4a7c6eff53b67240b1cb886a346d to your computer and use it in GitHub Desktop.
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 12, 0 sdk_version 12, 1, 0
.globl _main
.p2align 2
_main:
.cfi_startproc
mov w0, #0
ret
.cfi_endproc
.private_extern _$sSP17manglednamefinderE1aSiyF
.globl _$sSP17manglednamefinderE1aSiyF
.p2align 2
_$sSP17manglednamefinderE1aSiyF:
.cfi_startproc
sub sp, sp, #112
stp x22, x21, [sp, #64]
stp x20, x19, [sp, #80]
stp x29, x30, [sp, #96]
add x29, sp, #96
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w19, -24
.cfi_offset w20, -32
.cfi_offset w21, -40
.cfi_offset w22, -48
mov x4, x0
mov x5, x1
adrp x7, _$sSiN@GOTPAGE
ldr x7, [x7, _$sSiN@GOTPAGEOFF]
str xzr, [sp, #48]
mov x21, #0
stur x5, [x29, #-40]
str x4, [sp, #48]
mov x3, sp
adrp x8, _$sSP17manglednamefinderE1aSiyFSiSPySiGXEfU_@PAGE
add x8, x8, _$sSP17manglednamefinderE1aSiyFSiSPySiGXEfU_@PAGEOFF
str x8, [sp, #16]
str xzr, [sp, #24]
add x8, sp, #40
mov x0, x7
mov w9, #1
mov x1, x9
adrp x2, _$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TRTA@PAGE
add x2, x2, _$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TRTA@PAGEOFF
mov x6, x7
bl _$sSP17withMemoryRebound2to8capacity_qd_0_qd__m_Siqd_0_SPyqd__GKXEtKr0_lF
cbnz x21, LBB1_2
ldr x0, [sp, #40]
ldp x29, x30, [sp, #96]
ldp x20, x19, [sp, #80]
ldp x22, x21, [sp, #64]
add sp, sp, #112
ret
LBB1_2:
.cfi_endproc
.p2align 2
_$sSP17manglednamefinderE1aSiyFSiSPySiGXEfU_:
.cfi_startproc
sub sp, sp, #16
.cfi_def_cfa_offset 16
str xzr, [sp, #8]
str x0, [sp, #8]
ldr x8, [x0]
adds x8, x8, #1
str x8, [sp]
cset w8, vs
tbnz w8, #0, LBB2_2
ldr x0, [sp]
add sp, sp, #16
ret
LBB2_2:
brk #0x1
.cfi_endproc
.private_extern _$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
.globl _$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
.weak_definition _$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
.p2align 2
_$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR:
.cfi_startproc
sub sp, sp, #64
str x20, [sp, #32]
stp x29, x30, [sp, #48]
add x29, sp, #48
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w20, -32
str x8, [sp]
mov x20, x2
blr x1
str x21, [sp, #8]
str x0, [sp, #16]
mov x8, x21
str x8, [sp, #24]
cbnz x21, LBB3_2
ldr x21, [sp, #8]
ldr x9, [sp]
ldr x8, [sp, #16]
str x8, [x9]
ldp x29, x30, [sp, #48]
ldr x20, [sp, #32]
add sp, sp, #64
ret
LBB3_2:
ldr x21, [sp, #24]
ldp x29, x30, [sp, #48]
ldr x20, [sp, #32]
add sp, sp, #64
ret
.cfi_endproc
.p2align 2
_$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TRTA:
.cfi_startproc
str x20, [sp, #-32]!
stp x29, x30, [sp, #16]
add x29, sp, #16
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w20, -32
mov x9, x20
ldr x1, [x9, #16]
ldr x2, [x9, #24]
bl _$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
ldp x29, x30, [sp, #16]
ldr x20, [sp], #32
ret
.cfi_endproc
.private_extern _$sSp17manglednamefinderE1bSuyF
.globl _$sSp17manglednamefinderE1bSuyF
.p2align 2
_$sSp17manglednamefinderE1bSuyF:
.cfi_startproc
sub sp, sp, #112
stp x22, x21, [sp, #64]
stp x20, x19, [sp, #80]
stp x29, x30, [sp, #96]
add x29, sp, #96
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w19, -24
.cfi_offset w20, -32
.cfi_offset w21, -40
.cfi_offset w22, -48
mov x4, x0
mov x5, x1
adrp x7, _$sSuN@GOTPAGE
ldr x7, [x7, _$sSuN@GOTPAGEOFF]
str xzr, [sp, #48]
mov x21, #0
stur x5, [x29, #-40]
str x4, [sp, #48]
mov x3, sp
adrp x8, _$sSp17manglednamefinderE1bSuyFSuSpySuGXEfU_@PAGE
add x8, x8, _$sSp17manglednamefinderE1bSuyFSuSpySuGXEfU_@PAGEOFF
str x8, [sp, #16]
str xzr, [sp, #24]
add x8, sp, #40
mov x0, x7
mov w9, #1
mov x1, x9
adrp x2, _$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TRTA@PAGE
add x2, x2, _$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TRTA@PAGEOFF
mov x6, x7
bl _$sSp17withMemoryRebound2to8capacity_qd_0_qd__m_Siqd_0_Spyqd__GKXEtKr0_lF
cbnz x21, LBB5_2
ldr x0, [sp, #40]
ldp x29, x30, [sp, #96]
ldp x20, x19, [sp, #80]
ldp x22, x21, [sp, #64]
add sp, sp, #112
ret
LBB5_2:
.cfi_endproc
.p2align 2
_$sSp17manglednamefinderE1bSuyFSuSpySuGXEfU_:
.cfi_startproc
sub sp, sp, #16
.cfi_def_cfa_offset 16
str xzr, [sp, #8]
str x0, [sp, #8]
ldr x8, [x0]
adds x8, x8, #1
str x8, [sp]
cset w8, hs
tbnz w8, #0, LBB6_2
ldr x0, [sp]
add sp, sp, #16
ret
LBB6_2:
brk #0x1
.cfi_endproc
.private_extern _$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TR
.globl _$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TR
.weak_definition _$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TR
.p2align 2
_$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TR:
.cfi_startproc
sub sp, sp, #64
str x20, [sp, #32]
stp x29, x30, [sp, #48]
add x29, sp, #48
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w20, -32
str x8, [sp]
mov x20, x2
blr x1
str x21, [sp, #8]
str x0, [sp, #16]
mov x8, x21
str x8, [sp, #24]
cbnz x21, LBB7_2
ldr x21, [sp, #8]
ldr x9, [sp]
ldr x8, [sp, #16]
str x8, [x9]
ldp x29, x30, [sp, #48]
ldr x20, [sp, #32]
add sp, sp, #64
ret
LBB7_2:
ldr x21, [sp, #24]
ldp x29, x30, [sp, #48]
ldr x20, [sp, #32]
add sp, sp, #64
ret
.cfi_endproc
.p2align 2
_$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TRTA:
.cfi_startproc
str x20, [sp, #-32]!
stp x29, x30, [sp, #16]
add x29, sp, #16
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w20, -32
mov x9, x20
ldr x1, [x9, #16]
ldr x2, [x9, #24]
bl _$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TR
ldp x29, x30, [sp, #16]
ldr x20, [sp], #32
ret
.cfi_endproc
.private_extern _$sSR17manglednamefinderE1cSiyF
.globl _$sSR17manglednamefinderE1cSiyF
.p2align 2
_$sSR17manglednamefinderE1cSiyF:
.cfi_startproc
sub sp, sp, #112
stp x22, x21, [sp, #64]
stp x20, x19, [sp, #80]
stp x29, x30, [sp, #96]
add x29, sp, #96
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w19, -24
.cfi_offset w20, -32
.cfi_offset w21, -40
.cfi_offset w22, -48
mov x3, x0
mov x4, x1
mov x5, x2
adrp x7, _$sSiN@GOTPAGE
ldr x7, [x7, _$sSiN@GOTPAGEOFF]
str xzr, [sp, #40]
str xzr, [sp, #48]
mov x21, #0
stur x5, [x29, #-40]
str x3, [sp, #40]
str x4, [sp, #48]
mov x2, sp
adrp x8, _$sSR17manglednamefinderE1cSiyFSiSRySiGXEfU_@PAGE
add x8, x8, _$sSR17manglednamefinderE1cSiyFSiSRySiGXEfU_@PAGEOFF
str x8, [sp, #16]
str xzr, [sp, #24]
add x8, sp, #32
mov x0, x7
adrp x1, _$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TRTA@PAGE
add x1, x1, _$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TRTA@PAGEOFF
mov x6, x7
bl _$sSR17withMemoryRebound2to_qd_0_qd__m_qd_0_SRyqd__GKXEtKr0_lF
cbnz x21, LBB9_2
ldr x0, [sp, #32]
ldp x29, x30, [sp, #96]
ldp x20, x19, [sp, #80]
ldp x22, x21, [sp, #64]
add sp, sp, #112
ret
LBB9_2:
.cfi_endproc
.p2align 2
_$sSR17manglednamefinderE1cSiyFSiSRySiGXEfU_:
.cfi_startproc
sub sp, sp, #64
stp x29, x30, [sp, #48]
add x29, sp, #48
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
str x0, [sp, #8]
mov x2, x1
ldr x1, [sp, #8]
stur xzr, [x29, #-16]
stur xzr, [x29, #-8]
stur x1, [x29, #-16]
stur x2, [x29, #-8]
add x8, sp, #24
mov x0, #0
adrp x3, _$sSiN@GOTPAGE
ldr x3, [x3, _$sSiN@GOTPAGEOFF]
bl _$sSRyxSicig
ldr x8, [sp, #24]
adds x8, x8, #1
str x8, [sp, #16]
cset w8, vs
tbnz w8, #0, LBB10_2
ldr x0, [sp, #16]
ldp x29, x30, [sp, #48]
add sp, sp, #64
ret
LBB10_2:
brk #0x1
.cfi_endproc
.private_extern _$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
.globl _$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
.weak_definition _$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
.p2align 2
_$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR:
.cfi_startproc
sub sp, sp, #64
str x20, [sp, #32]
stp x29, x30, [sp, #48]
add x29, sp, #48
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w20, -32
str x8, [sp]
mov x20, x3
blr x2
str x21, [sp, #8]
str x0, [sp, #16]
mov x8, x21
str x8, [sp, #24]
cbnz x21, LBB11_2
ldr x21, [sp, #8]
ldr x9, [sp]
ldr x8, [sp, #16]
str x8, [x9]
ldp x29, x30, [sp, #48]
ldr x20, [sp, #32]
add sp, sp, #64
ret
LBB11_2:
ldr x21, [sp, #24]
ldp x29, x30, [sp, #48]
ldr x20, [sp, #32]
add sp, sp, #64
ret
.cfi_endproc
.p2align 2
_$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TRTA:
.cfi_startproc
str x20, [sp, #-32]!
stp x29, x30, [sp, #16]
add x29, sp, #16
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w20, -32
mov x9, x20
ldr x2, [x9, #16]
ldr x3, [x9, #24]
bl _$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
ldp x29, x30, [sp, #16]
ldr x20, [sp], #32
ret
.cfi_endproc
.private_extern _$sSr17manglednamefinderE1dSiyF
.globl _$sSr17manglednamefinderE1dSiyF
.p2align 2
_$sSr17manglednamefinderE1dSiyF:
.cfi_startproc
sub sp, sp, #112
stp x22, x21, [sp, #64]
stp x20, x19, [sp, #80]
stp x29, x30, [sp, #96]
add x29, sp, #96
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w19, -24
.cfi_offset w20, -32
.cfi_offset w21, -40
.cfi_offset w22, -48
mov x3, x0
mov x4, x1
mov x5, x2
adrp x7, _$sSiN@GOTPAGE
ldr x7, [x7, _$sSiN@GOTPAGEOFF]
str xzr, [sp, #40]
str xzr, [sp, #48]
mov x21, #0
stur x5, [x29, #-40]
str x3, [sp, #40]
str x4, [sp, #48]
mov x2, sp
adrp x8, _$sSr17manglednamefinderE1dSiyFSiSrySiGXEfU_@PAGE
add x8, x8, _$sSr17manglednamefinderE1dSiyFSiSrySiGXEfU_@PAGEOFF
str x8, [sp, #16]
str xzr, [sp, #24]
add x8, sp, #32
mov x0, x7
adrp x1, _$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TRTA@PAGE
add x1, x1, _$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TRTA@PAGEOFF
mov x6, x7
bl _$sSr17withMemoryRebound2to_qd_0_qd__m_qd_0_Sryqd__GKXEtKr0_lF
cbnz x21, LBB13_2
ldr x0, [sp, #32]
ldp x29, x30, [sp, #96]
ldp x20, x19, [sp, #80]
ldp x22, x21, [sp, #64]
add sp, sp, #112
ret
LBB13_2:
.cfi_endproc
.p2align 2
_$sSr17manglednamefinderE1dSiyFSiSrySiGXEfU_:
.cfi_startproc
sub sp, sp, #64
stp x29, x30, [sp, #48]
add x29, sp, #48
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
str x0, [sp, #8]
mov x2, x1
ldr x1, [sp, #8]
stur xzr, [x29, #-16]
stur xzr, [x29, #-8]
stur x1, [x29, #-16]
stur x2, [x29, #-8]
add x8, sp, #24
mov x0, #0
adrp x3, _$sSiN@GOTPAGE
ldr x3, [x3, _$sSiN@GOTPAGEOFF]
bl _$sSryxSicig
ldr x8, [sp, #24]
adds x8, x8, #1
str x8, [sp, #16]
cset w8, vs
tbnz w8, #0, LBB14_2
ldr x0, [sp, #16]
ldp x29, x30, [sp, #48]
add sp, sp, #64
ret
LBB14_2:
brk #0x1
.cfi_endproc
.private_extern _$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
.globl _$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
.weak_definition _$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
.p2align 2
_$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR:
.cfi_startproc
sub sp, sp, #64
str x20, [sp, #32]
stp x29, x30, [sp, #48]
add x29, sp, #48
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w20, -32
str x8, [sp]
mov x20, x3
blr x2
str x21, [sp, #8]
str x0, [sp, #16]
mov x8, x21
str x8, [sp, #24]
cbnz x21, LBB15_2
ldr x21, [sp, #8]
ldr x9, [sp]
ldr x8, [sp, #16]
str x8, [x9]
ldp x29, x30, [sp, #48]
ldr x20, [sp, #32]
add sp, sp, #64
ret
LBB15_2:
ldr x21, [sp, #24]
ldp x29, x30, [sp, #48]
ldr x20, [sp, #32]
add sp, sp, #64
ret
.cfi_endproc
.p2align 2
_$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TRTA:
.cfi_startproc
str x20, [sp, #-32]!
stp x29, x30, [sp, #16]
add x29, sp, #16
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w20, -32
mov x9, x20
ldr x2, [x9, #16]
ldr x3, [x9, #24]
bl _$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR
ldp x29, x30, [sp, #16]
ldr x20, [sp], #32
ret
.cfi_endproc
.section __TEXT,__swift5_entry,regular,no_dead_strip
.p2align 2
l_entry_point:
.long _main-l_entry_point
.private_extern ___swift_reflection_version
.section __TEXT,__const
.globl ___swift_reflection_version
.weak_definition ___swift_reflection_version
.p2align 1
___swift_reflection_version:
.short 3
.no_dead_strip _main
.no_dead_strip l_entry_point
.no_dead_strip ___swift_reflection_version
.linker_option "-lswiftSwiftOnoneSupport"
.linker_option "-lswiftCore"
.linker_option "-lswift_Concurrency"
.linker_option "-lobjc"
.section __DATA,__objc_imageinfo,regular,no_dead_strip
L_OBJC_IMAGE_INFO:
.long 0
.long 84215616
.subsections_via_symbols
sil_stage canonical
import Builtin
import Swift
import SwiftShims
extension UnsafePointer {
func a() -> Int
}
extension UnsafeMutablePointer {
func b() -> UInt
}
extension UnsafeBufferPointer {
func c() -> Int
}
extension UnsafeMutableBufferPointer {
func d() -> Int
}
// main
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
%2 = integer_literal $Builtin.Int32, 0 // user: %3
%3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4
return %3 : $Int32 // id: %4
} // end sil function 'main'
// UnsafePointer.a()
sil hidden @$sSP17manglednamefinderE1aSiyF : $@convention(method) <Pointee> (UnsafePointer<Pointee>) -> Int {
// %0 "self" // users: %15, %1
bb0(%0 : $UnsafePointer<Pointee>):
debug_value %0 : $UnsafePointer<Pointee>, let, name "self", argno 1 // id: %1
%2 = alloc_stack $Int // users: %18, %19, %15
%3 = metatype $@thin Int.Type
%4 = metatype $@thick Int.Type // user: %15
%5 = integer_literal $Builtin.Int64, 1 // user: %6
%6 = struct $Int (%5 : $Builtin.Int64) // user: %15
// function_ref closure #1 in UnsafePointer.a()
%7 = function_ref @$sSP17manglednamefinderE1aSiyFSiSPySiGXEfU_ : $@convention(thin) (UnsafePointer<Int>) -> Int // user: %8
%8 = convert_function %7 : $@convention(thin) (UnsafePointer<Int>) -> Int to $@convention(thin) @noescape (UnsafePointer<Int>) -> Int // user: %9
%9 = thin_to_thick_function %8 : $@convention(thin) @noescape (UnsafePointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafePointer<Int>) -> Int // user: %10
%10 = convert_function %9 : $@noescape @callee_guaranteed (UnsafePointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error) // user: %12
// function_ref thunk for @callee_guaranteed (@unowned UnsafePointer<Int>) -> (@unowned Int, @error @owned Error)
%11 = function_ref @$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafePointer<Int>, @noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // user: %12
%12 = partial_apply [callee_guaranteed] [on_stack] %11(%10) : $@convention(thin) (UnsafePointer<Int>, @noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // users: %17, %13
%13 = convert_function %12 : $@noescape @callee_guaranteed (UnsafePointer<Int>) -> (@out Int, @error Error) to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // user: %15
// function_ref UnsafePointer.withMemoryRebound<A, B>(to:capacity:_:)
%14 = function_ref @$sSP17withMemoryRebound2to8capacity_qd_0_qd__m_Siqd_0_SPyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafePointer<τ_0_0>) -> (@out τ_1_1, @error Error) // user: %15
try_apply %14<Pointee, Int, Int>(%2, %4, %6, %13, %0) : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafePointer<τ_0_0>) -> (@out τ_1_1, @error Error), normal bb1, error bb2 // id: %15
bb1(%16 : $()): // Preds: bb0
dealloc_stack %12 : $@noescape @callee_guaranteed (UnsafePointer<Int>) -> (@out Int, @error Error) // id: %17
%18 = load %2 : $*Int // user: %20
dealloc_stack %2 : $*Int // id: %19
return %18 : $Int // id: %20
bb2(%21 : $Error): // Preds: bb0
unreachable // id: %22
} // end sil function '$sSP17manglednamefinderE1aSiyF'
// Int.init(_builtinIntegerLiteral:)
sil public_external [transparent] @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int {
// %0 // user: %2
bb0(%0 : $Builtin.IntLiteral, %1 : $@thin Int.Type):
%2 = builtin "s_to_s_checked_trunc_IntLiteral_Int64"(%0 : $Builtin.IntLiteral) : $(Builtin.Int64, Builtin.Int1) // user: %3
%3 = tuple_extract %2 : $(Builtin.Int64, Builtin.Int1), 0 // user: %4
%4 = struct $Int (%3 : $Builtin.Int64) // user: %5
return %4 : $Int // id: %5
} // end sil function '$sSi22_builtinIntegerLiteralSiBI_tcfC'
// closure #1 in UnsafePointer.a()
sil private @$sSP17manglednamefinderE1aSiyFSiSPySiGXEfU_ : $@convention(thin) (UnsafePointer<Int>) -> Int {
// %0 "$0" // users: %2, %1
bb0(%0 : $UnsafePointer<Int>):
debug_value %0 : $UnsafePointer<Int>, let, name "$0", argno 1 // id: %1
%2 = struct_extract %0 : $UnsafePointer<Int>, #UnsafePointer._rawValue // user: %3
%3 = pointer_to_address %2 : $Builtin.RawPointer to [strict] $*Int // user: %4
%4 = begin_access [read] [unsafe] %3 : $*Int // users: %5, %6
%5 = load %4 : $*Int // user: %8
end_access %4 : $*Int // id: %6
%7 = integer_literal $Builtin.Int64, 1 // user: %10
%8 = struct_extract %5 : $Int, #Int._value // user: %10
%9 = integer_literal $Builtin.Int1, -1 // user: %10
%10 = builtin "sadd_with_overflow_Int64"(%8 : $Builtin.Int64, %7 : $Builtin.Int64, %9 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1) // users: %12, %11
%11 = tuple_extract %10 : $(Builtin.Int64, Builtin.Int1), 0 // user: %14
%12 = tuple_extract %10 : $(Builtin.Int64, Builtin.Int1), 1 // user: %13
cond_fail %12 : $Builtin.Int1, "arithmetic overflow" // id: %13
%14 = struct $Int (%11 : $Builtin.Int64) // user: %15
return %14 : $Int // id: %15
} // end sil function '$sSP17manglednamefinderE1aSiyFSiSPySiGXEfU_'
// UnsafePointer.pointee.unsafeAddressor
sil public_external [transparent] @$sSP7pointeexvlu : $@convention(method) <Pointee> (UnsafePointer<Pointee>) -> UnsafePointer<Pointee> {
// %0 // user: %1
bb0(%0 : $UnsafePointer<Pointee>):
return %0 : $UnsafePointer<Pointee> // id: %1
} // end sil function '$sSP7pointeexvlu'
// static Int.+ infix(_:_:)
sil public_external [transparent] @$sSi1poiyS2i_SitFZ : $@convention(method) (Int, Int, @thin Int.Type) -> Int {
// %0 // user: %3
// %1 // user: %4
bb0(%0 : $Int, %1 : $Int, %2 : $@thin Int.Type):
%3 = struct_extract %0 : $Int, #Int._value // user: %6
%4 = struct_extract %1 : $Int, #Int._value // user: %6
%5 = integer_literal $Builtin.Int1, -1 // user: %6
%6 = builtin "sadd_with_overflow_Int64"(%3 : $Builtin.Int64, %4 : $Builtin.Int64, %5 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1) // users: %8, %7
%7 = tuple_extract %6 : $(Builtin.Int64, Builtin.Int1), 0 // user: %10
%8 = tuple_extract %6 : $(Builtin.Int64, Builtin.Int1), 1 // user: %9
cond_fail %8 : $Builtin.Int1, "arithmetic overflow" // id: %9
%10 = struct $Int (%7 : $Builtin.Int64) // user: %11
return %10 : $Int // id: %11
} // end sil function '$sSi1poiyS2i_SitFZ'
// thunk for @callee_guaranteed (@unowned UnsafePointer<Int>) -> (@unowned Int, @error @owned Error)
sil shared [transparent] [reabstraction_thunk] @$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafePointer<Int>, @noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) {
// %0 // user: %5
// %1 // user: %3
// %2 // user: %3
bb0(%0 : $*Int, %1 : $UnsafePointer<Int>, %2 : $@noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error)):
try_apply %2(%1) : $@noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error), normal bb1, error bb2 // id: %3
// %4 // user: %5
bb1(%4 : $Int): // Preds: bb0
store %4 to %0 : $*Int // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
// %8 // user: %9
bb2(%8 : $Error): // Preds: bb0
throw %8 : $Error // id: %9
} // end sil function '$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR'
// UnsafePointer.withMemoryRebound<A, B>(to:capacity:_:)
sil @$sSP17withMemoryRebound2to8capacity_qd_0_qd__m_Siqd_0_SPyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafePointer<τ_0_0>) -> (@out τ_1_1, @error Error)
// UnsafeMutablePointer.b()
sil hidden @$sSp17manglednamefinderE1bSuyF : $@convention(method) <Pointee> (UnsafeMutablePointer<Pointee>) -> UInt {
// %0 "self" // users: %15, %1
bb0(%0 : $UnsafeMutablePointer<Pointee>):
debug_value %0 : $UnsafeMutablePointer<Pointee>, let, name "self", argno 1 // id: %1
%2 = alloc_stack $UInt // users: %18, %19, %15
%3 = metatype $@thin UInt.Type
%4 = metatype $@thick UInt.Type // user: %15
%5 = integer_literal $Builtin.Int64, 1 // user: %6
%6 = struct $Int (%5 : $Builtin.Int64) // user: %15
// function_ref closure #1 in UnsafeMutablePointer.b()
%7 = function_ref @$sSp17manglednamefinderE1bSuyFSuSpySuGXEfU_ : $@convention(thin) (UnsafeMutablePointer<UInt>) -> UInt // user: %8
%8 = convert_function %7 : $@convention(thin) (UnsafeMutablePointer<UInt>) -> UInt to $@convention(thin) @noescape (UnsafeMutablePointer<UInt>) -> UInt // user: %9
%9 = thin_to_thick_function %8 : $@convention(thin) @noescape (UnsafeMutablePointer<UInt>) -> UInt to $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> UInt // user: %10
%10 = convert_function %9 : $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> UInt to $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error) // user: %12
// function_ref thunk for @callee_guaranteed (@unowned UnsafeMutablePointer<UInt>) -> (@unowned UInt, @error @owned Error)
%11 = function_ref @$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TR : $@convention(thin) (UnsafeMutablePointer<UInt>, @noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error)) -> (@out UInt, @error Error) // user: %12
%12 = partial_apply [callee_guaranteed] [on_stack] %11(%10) : $@convention(thin) (UnsafeMutablePointer<UInt>, @noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error)) -> (@out UInt, @error Error) // users: %17, %13
%13 = convert_function %12 : $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (@out UInt, @error Error) to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutablePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <UInt, UInt> // user: %15
// function_ref UnsafeMutablePointer.withMemoryRebound<A, B>(to:capacity:_:)
%14 = function_ref @$sSp17withMemoryRebound2to8capacity_qd_0_qd__m_Siqd_0_Spyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutablePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutablePointer<τ_0_0>) -> (@out τ_1_1, @error Error) // user: %15
try_apply %14<Pointee, UInt, UInt>(%2, %4, %6, %13, %0) : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutablePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutablePointer<τ_0_0>) -> (@out τ_1_1, @error Error), normal bb1, error bb2 // id: %15
bb1(%16 : $()): // Preds: bb0
dealloc_stack %12 : $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (@out UInt, @error Error) // id: %17
%18 = load %2 : $*UInt // user: %20
dealloc_stack %2 : $*UInt // id: %19
return %18 : $UInt // id: %20
bb2(%21 : $Error): // Preds: bb0
unreachable // id: %22
} // end sil function '$sSp17manglednamefinderE1bSuyF'
// closure #1 in UnsafeMutablePointer.b()
sil private @$sSp17manglednamefinderE1bSuyFSuSpySuGXEfU_ : $@convention(thin) (UnsafeMutablePointer<UInt>) -> UInt {
// %0 "$0" // users: %2, %1
bb0(%0 : $UnsafeMutablePointer<UInt>):
debug_value %0 : $UnsafeMutablePointer<UInt>, let, name "$0", argno 1 // id: %1
%2 = struct_extract %0 : $UnsafeMutablePointer<UInt>, #UnsafeMutablePointer._rawValue // user: %3
%3 = pointer_to_address %2 : $Builtin.RawPointer to [strict] $*UInt // user: %4
%4 = begin_access [read] [unsafe] %3 : $*UInt // users: %5, %6
%5 = load %4 : $*UInt // user: %8
end_access %4 : $*UInt // id: %6
%7 = integer_literal $Builtin.Int64, 1 // user: %10
%8 = struct_extract %5 : $UInt, #UInt._value // user: %10
%9 = integer_literal $Builtin.Int1, -1 // user: %10
%10 = builtin "uadd_with_overflow_Int64"(%8 : $Builtin.Int64, %7 : $Builtin.Int64, %9 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1) // users: %12, %11
%11 = tuple_extract %10 : $(Builtin.Int64, Builtin.Int1), 0 // user: %14
%12 = tuple_extract %10 : $(Builtin.Int64, Builtin.Int1), 1 // user: %13
cond_fail %12 : $Builtin.Int1, "arithmetic overflow" // id: %13
%14 = struct $UInt (%11 : $Builtin.Int64) // user: %15
return %14 : $UInt // id: %15
} // end sil function '$sSp17manglednamefinderE1bSuyFSuSpySuGXEfU_'
// UnsafeMutablePointer.pointee.unsafeAddressor
sil public_external [transparent] @$sSp7pointeexvlu : $@convention(method) <Pointee> (UnsafeMutablePointer<Pointee>) -> UnsafePointer<Pointee> {
// %0 // user: %1
bb0(%0 : $UnsafeMutablePointer<Pointee>):
%1 = struct_extract %0 : $UnsafeMutablePointer<Pointee>, #UnsafeMutablePointer._rawValue // user: %2
%2 = struct $UnsafePointer<Pointee> (%1 : $Builtin.RawPointer) // user: %3
return %2 : $UnsafePointer<Pointee> // id: %3
} // end sil function '$sSp7pointeexvlu'
// UInt.init(_builtinIntegerLiteral:)
sil public_external [transparent] @$sSu22_builtinIntegerLiteralSuBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin UInt.Type) -> UInt {
// %0 // user: %2
bb0(%0 : $Builtin.IntLiteral, %1 : $@thin UInt.Type):
%2 = builtin "s_to_u_checked_trunc_IntLiteral_Int64"(%0 : $Builtin.IntLiteral) : $(Builtin.Int64, Builtin.Int1) // user: %3
%3 = tuple_extract %2 : $(Builtin.Int64, Builtin.Int1), 0 // user: %4
%4 = struct $UInt (%3 : $Builtin.Int64) // user: %5
return %4 : $UInt // id: %5
} // end sil function '$sSu22_builtinIntegerLiteralSuBI_tcfC'
// static UInt.+ infix(_:_:)
sil public_external [transparent] @$sSu1poiyS2u_SutFZ : $@convention(method) (UInt, UInt, @thin UInt.Type) -> UInt {
// %0 // user: %3
// %1 // user: %4
bb0(%0 : $UInt, %1 : $UInt, %2 : $@thin UInt.Type):
%3 = struct_extract %0 : $UInt, #UInt._value // user: %6
%4 = struct_extract %1 : $UInt, #UInt._value // user: %6
%5 = integer_literal $Builtin.Int1, -1 // user: %6
%6 = builtin "uadd_with_overflow_Int64"(%3 : $Builtin.Int64, %4 : $Builtin.Int64, %5 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1) // users: %8, %7
%7 = tuple_extract %6 : $(Builtin.Int64, Builtin.Int1), 0 // user: %10
%8 = tuple_extract %6 : $(Builtin.Int64, Builtin.Int1), 1 // user: %9
cond_fail %8 : $Builtin.Int1, "arithmetic overflow" // id: %9
%10 = struct $UInt (%7 : $Builtin.Int64) // user: %11
return %10 : $UInt // id: %11
} // end sil function '$sSu1poiyS2u_SutFZ'
// thunk for @callee_guaranteed (@unowned UnsafeMutablePointer<UInt>) -> (@unowned UInt, @error @owned Error)
sil shared [transparent] [reabstraction_thunk] @$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TR : $@convention(thin) (UnsafeMutablePointer<UInt>, @noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error)) -> (@out UInt, @error Error) {
// %0 // user: %5
// %1 // user: %3
// %2 // user: %3
bb0(%0 : $*UInt, %1 : $UnsafeMutablePointer<UInt>, %2 : $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error)):
try_apply %2(%1) : $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error), normal bb1, error bb2 // id: %3
// %4 // user: %5
bb1(%4 : $UInt): // Preds: bb0
store %4 to %0 : $*UInt // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
// %8 // user: %9
bb2(%8 : $Error): // Preds: bb0
throw %8 : $Error // id: %9
} // end sil function '$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TR'
// UnsafeMutablePointer.withMemoryRebound<A, B>(to:capacity:_:)
sil @$sSp17withMemoryRebound2to8capacity_qd_0_qd__m_Siqd_0_Spyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutablePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutablePointer<τ_0_0>) -> (@out τ_1_1, @error Error)
// UnsafeBufferPointer.c()
sil hidden @$sSR17manglednamefinderE1cSiyF : $@convention(method) <Element> (UnsafeBufferPointer<Element>) -> Int {
// %0 "self" // users: %13, %1
bb0(%0 : $UnsafeBufferPointer<Element>):
debug_value %0 : $UnsafeBufferPointer<Element>, let, name "self", argno 1 // id: %1
%2 = alloc_stack $Int // users: %16, %17, %13
%3 = metatype $@thin Int.Type
%4 = metatype $@thick Int.Type // user: %13
// function_ref closure #1 in UnsafeBufferPointer.c()
%5 = function_ref @$sSR17manglednamefinderE1cSiyFSiSRySiGXEfU_ : $@convention(thin) (UnsafeBufferPointer<Int>) -> Int // user: %6
%6 = convert_function %5 : $@convention(thin) (UnsafeBufferPointer<Int>) -> Int to $@convention(thin) @noescape (UnsafeBufferPointer<Int>) -> Int // user: %7
%7 = thin_to_thick_function %6 : $@convention(thin) @noescape (UnsafeBufferPointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> Int // user: %8
%8 = convert_function %7 : $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error) // user: %10
// function_ref thunk for @callee_guaranteed (@unowned UnsafeBufferPointer<Int>) -> (@unowned Int, @error @owned Error)
%9 = function_ref @$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafeBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // user: %10
%10 = partial_apply [callee_guaranteed] [on_stack] %9(%8) : $@convention(thin) (UnsafeBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // users: %15, %11
%11 = convert_function %10 : $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (@out Int, @error Error) to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // user: %13
// function_ref UnsafeBufferPointer.withMemoryRebound<A, B>(to:_:)
%12 = function_ref @$sSR17withMemoryRebound2to_qd_0_qd__m_qd_0_SRyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error) // user: %13
try_apply %12<Element, Int, Int>(%2, %4, %11, %0) : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error), normal bb1, error bb2 // id: %13
bb1(%14 : $()): // Preds: bb0
dealloc_stack %10 : $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (@out Int, @error Error) // id: %15
%16 = load %2 : $*Int // user: %18
dealloc_stack %2 : $*Int // id: %17
return %16 : $Int // id: %18
bb2(%19 : $Error): // Preds: bb0
unreachable // id: %20
} // end sil function '$sSR17manglednamefinderE1cSiyF'
// closure #1 in UnsafeBufferPointer.c()
sil private @$sSR17manglednamefinderE1cSiyFSiSRySiGXEfU_ : $@convention(thin) (UnsafeBufferPointer<Int>) -> Int {
// %0 "$0" // users: %6, %1
bb0(%0 : $UnsafeBufferPointer<Int>):
debug_value %0 : $UnsafeBufferPointer<Int>, let, name "$0", argno 1 // id: %1
%2 = integer_literal $Builtin.Int64, 0 // user: %3
%3 = struct $Int (%2 : $Builtin.Int64) // user: %6
%4 = alloc_stack $Int // users: %7, %16, %6
// function_ref UnsafeBufferPointer.subscript.getter
%5 = function_ref @$sSRyxSicig : $@convention(method) <τ_0_0> (Int, UnsafeBufferPointer<τ_0_0>) -> @out τ_0_0 // user: %6
%6 = apply %5<Int>(%4, %3, %0) : $@convention(method) <τ_0_0> (Int, UnsafeBufferPointer<τ_0_0>) -> @out τ_0_0
%7 = load %4 : $*Int // user: %9
%8 = integer_literal $Builtin.Int64, 1 // user: %11
%9 = struct_extract %7 : $Int, #Int._value // user: %11
%10 = integer_literal $Builtin.Int1, -1 // user: %11
%11 = builtin "sadd_with_overflow_Int64"(%9 : $Builtin.Int64, %8 : $Builtin.Int64, %10 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1) // users: %13, %12
%12 = tuple_extract %11 : $(Builtin.Int64, Builtin.Int1), 0 // user: %15
%13 = tuple_extract %11 : $(Builtin.Int64, Builtin.Int1), 1 // user: %14
cond_fail %13 : $Builtin.Int1, "arithmetic overflow" // id: %14
%15 = struct $Int (%12 : $Builtin.Int64) // user: %17
dealloc_stack %4 : $*Int // id: %16
return %15 : $Int // id: %17
} // end sil function '$sSR17manglednamefinderE1cSiyFSiSRySiGXEfU_'
// UnsafeBufferPointer.subscript.getter
sil @$sSRyxSicig : $@convention(method) <τ_0_0> (Int, UnsafeBufferPointer<τ_0_0>) -> @out τ_0_0
// thunk for @callee_guaranteed (@unowned UnsafeBufferPointer<Int>) -> (@unowned Int, @error @owned Error)
sil shared [transparent] [reabstraction_thunk] @$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafeBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) {
// %0 // user: %5
// %1 // user: %3
// %2 // user: %3
bb0(%0 : $*Int, %1 : $UnsafeBufferPointer<Int>, %2 : $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error)):
try_apply %2(%1) : $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error), normal bb1, error bb2 // id: %3
// %4 // user: %5
bb1(%4 : $Int): // Preds: bb0
store %4 to %0 : $*Int // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
// %8 // user: %9
bb2(%8 : $Error): // Preds: bb0
throw %8 : $Error // id: %9
} // end sil function '$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR'
// UnsafeBufferPointer.withMemoryRebound<A, B>(to:_:)
sil @$sSR17withMemoryRebound2to_qd_0_qd__m_qd_0_SRyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error)
// UnsafeMutableBufferPointer.d()
sil hidden @$sSr17manglednamefinderE1dSiyF : $@convention(method) <Element> (UnsafeMutableBufferPointer<Element>) -> Int {
// %0 "self" // users: %13, %1
bb0(%0 : $UnsafeMutableBufferPointer<Element>):
debug_value %0 : $UnsafeMutableBufferPointer<Element>, let, name "self", argno 1 // id: %1
%2 = alloc_stack $Int // users: %16, %17, %13
%3 = metatype $@thin Int.Type
%4 = metatype $@thick Int.Type // user: %13
// function_ref closure #1 in UnsafeMutableBufferPointer.d()
%5 = function_ref @$sSr17manglednamefinderE1dSiyFSiSrySiGXEfU_ : $@convention(thin) (UnsafeMutableBufferPointer<Int>) -> Int // user: %6
%6 = convert_function %5 : $@convention(thin) (UnsafeMutableBufferPointer<Int>) -> Int to $@convention(thin) @noescape (UnsafeMutableBufferPointer<Int>) -> Int // user: %7
%7 = thin_to_thick_function %6 : $@convention(thin) @noescape (UnsafeMutableBufferPointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> Int // user: %8
%8 = convert_function %7 : $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error) // user: %10
// function_ref thunk for @callee_guaranteed (@unowned UnsafeMutableBufferPointer<Int>) -> (@unowned Int, @error @owned Error)
%9 = function_ref @$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafeMutableBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // user: %10
%10 = partial_apply [callee_guaranteed] [on_stack] %9(%8) : $@convention(thin) (UnsafeMutableBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // users: %15, %11
%11 = convert_function %10 : $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (@out Int, @error Error) to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // user: %13
// function_ref UnsafeMutableBufferPointer.withMemoryRebound<A, B>(to:_:)
%12 = function_ref @$sSr17withMemoryRebound2to_qd_0_qd__m_qd_0_Sryqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error) // user: %13
try_apply %12<Element, Int, Int>(%2, %4, %11, %0) : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error), normal bb1, error bb2 // id: %13
bb1(%14 : $()): // Preds: bb0
dealloc_stack %10 : $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (@out Int, @error Error) // id: %15
%16 = load %2 : $*Int // user: %18
dealloc_stack %2 : $*Int // id: %17
return %16 : $Int // id: %18
bb2(%19 : $Error): // Preds: bb0
unreachable // id: %20
} // end sil function '$sSr17manglednamefinderE1dSiyF'
// closure #1 in UnsafeMutableBufferPointer.d()
sil private @$sSr17manglednamefinderE1dSiyFSiSrySiGXEfU_ : $@convention(thin) (UnsafeMutableBufferPointer<Int>) -> Int {
// %0 "$0" // users: %6, %1
bb0(%0 : $UnsafeMutableBufferPointer<Int>):
debug_value %0 : $UnsafeMutableBufferPointer<Int>, let, name "$0", argno 1 // id: %1
%2 = integer_literal $Builtin.Int64, 0 // user: %3
%3 = struct $Int (%2 : $Builtin.Int64) // user: %6
%4 = alloc_stack $Int // users: %7, %16, %6
// function_ref UnsafeMutableBufferPointer.subscript.getter
%5 = function_ref @$sSryxSicig : $@convention(method) <τ_0_0> (Int, UnsafeMutableBufferPointer<τ_0_0>) -> @out τ_0_0 // user: %6
%6 = apply %5<Int>(%4, %3, %0) : $@convention(method) <τ_0_0> (Int, UnsafeMutableBufferPointer<τ_0_0>) -> @out τ_0_0
%7 = load %4 : $*Int // user: %9
%8 = integer_literal $Builtin.Int64, 1 // user: %11
%9 = struct_extract %7 : $Int, #Int._value // user: %11
%10 = integer_literal $Builtin.Int1, -1 // user: %11
%11 = builtin "sadd_with_overflow_Int64"(%9 : $Builtin.Int64, %8 : $Builtin.Int64, %10 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1) // users: %13, %12
%12 = tuple_extract %11 : $(Builtin.Int64, Builtin.Int1), 0 // user: %15
%13 = tuple_extract %11 : $(Builtin.Int64, Builtin.Int1), 1 // user: %14
cond_fail %13 : $Builtin.Int1, "arithmetic overflow" // id: %14
%15 = struct $Int (%12 : $Builtin.Int64) // user: %17
dealloc_stack %4 : $*Int // id: %16
return %15 : $Int // id: %17
} // end sil function '$sSr17manglednamefinderE1dSiyFSiSrySiGXEfU_'
// UnsafeMutableBufferPointer.subscript.getter
sil @$sSryxSicig : $@convention(method) <τ_0_0> (Int, UnsafeMutableBufferPointer<τ_0_0>) -> @out τ_0_0
// thunk for @callee_guaranteed (@unowned UnsafeMutableBufferPointer<Int>) -> (@unowned Int, @error @owned Error)
sil shared [transparent] [reabstraction_thunk] @$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafeMutableBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) {
// %0 // user: %5
// %1 // user: %3
// %2 // user: %3
bb0(%0 : $*Int, %1 : $UnsafeMutableBufferPointer<Int>, %2 : $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error)):
try_apply %2(%1) : $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error), normal bb1, error bb2 // id: %3
// %4 // user: %5
bb1(%4 : $Int): // Preds: bb0
store %4 to %0 : $*Int // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
// %8 // user: %9
bb2(%8 : $Error): // Preds: bb0
throw %8 : $Error // id: %9
} // end sil function '$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR'
// UnsafeMutableBufferPointer.withMemoryRebound<A, B>(to:_:)
sil @$sSr17withMemoryRebound2to_qd_0_qd__m_qd_0_Sryqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error)
// Mappings from '#fileID' to '#filePath':
// 'manglednamefinder/manglednamefinder.swift' => 'manglednamefinder.swift'
sil_stage raw
import Builtin
import Swift
import SwiftShims
extension UnsafePointer {
func a() -> Int
}
extension UnsafeMutablePointer {
func b() -> UInt
}
extension UnsafeBufferPointer {
func c() -> Int
}
extension UnsafeMutableBufferPointer {
func d() -> Int
}
// main
sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
%2 = integer_literal $Builtin.Int32, 0 // user: %3
%3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4
return %3 : $Int32 // id: %4
} // end sil function 'main'
// UnsafePointer.a()
sil hidden [ossa] @$sSP17manglednamefinderE1aSiyF : $@convention(method) <Pointee> (UnsafePointer<Pointee>) -> Int {
// %0 "self" // users: %19, %1
bb0(%0 : $UnsafePointer<Pointee>):
debug_value %0 : $UnsafePointer<Pointee>, let, name "self", argno 1 // id: %1
%2 = alloc_stack $Int // users: %22, %21, %19
%3 = metatype $@thin Int.Type
%4 = metatype $@thick Int.Type // user: %19
%5 = integer_literal $Builtin.IntLiteral, 1 // user: %8
%6 = metatype $@thin Int.Type // user: %8
// function_ref Int.init(_builtinIntegerLiteral:)
%7 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %8
%8 = apply %7(%5, %6) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %19
// function_ref closure #1 in UnsafePointer.a()
%9 = function_ref @$sSP17manglednamefinderE1aSiyFSiSPySiGXEfU_ : $@convention(thin) (UnsafePointer<Int>) -> Int // user: %10
%10 = convert_function %9 : $@convention(thin) (UnsafePointer<Int>) -> Int to $@convention(thin) @noescape (UnsafePointer<Int>) -> Int // user: %11
%11 = thin_to_thick_function %10 : $@convention(thin) @noescape (UnsafePointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafePointer<Int>) -> Int // user: %12
%12 = convert_function %11 : $@noescape @callee_guaranteed (UnsafePointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error) // user: %14
// function_ref thunk for @callee_guaranteed (@unowned UnsafePointer<Int>) -> (@unowned Int, @error @owned Error)
%13 = function_ref @$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafePointer<Int>, @noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // user: %14
%14 = partial_apply [callee_guaranteed] %13(%12) : $@convention(thin) (UnsafePointer<Int>, @noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // user: %15
%15 = convert_function %14 : $@callee_guaranteed (UnsafePointer<Int>) -> (@out Int, @error Error) to $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // users: %17, %16
%16 = convert_escape_to_noescape [not_guaranteed] %15 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // user: %19
destroy_value %15 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // id: %17
// function_ref UnsafePointer.withMemoryRebound<A, B>(to:capacity:_:)
%18 = function_ref @$sSP17withMemoryRebound2to8capacity_qd_0_qd__m_Siqd_0_SPyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafePointer<τ_0_0>) -> (@out τ_1_1, @error Error) // user: %19
try_apply %18<Pointee, Int, Int>(%2, %4, %8, %16, %0) : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafePointer<τ_0_0>) -> (@out τ_1_1, @error Error), normal bb1, error bb2 // id: %19
bb1(%20 : $()): // Preds: bb0
%21 = load [trivial] %2 : $*Int // user: %23
dealloc_stack %2 : $*Int // id: %22
return %21 : $Int // id: %23
bb2(%24 : @owned $Error): // Preds: bb0
unreachable // id: %25
} // end sil function '$sSP17manglednamefinderE1aSiyF'
// Int.init(_builtinIntegerLiteral:)
sil [transparent] [serialized] @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
// closure #1 in UnsafePointer.a()
sil private [ossa] @$sSP17manglednamefinderE1aSiyFSiSPySiGXEfU_ : $@convention(thin) (UnsafePointer<Int>) -> Int {
// %0 "$0" // users: %4, %1
bb0(%0 : $UnsafePointer<Int>):
debug_value %0 : $UnsafePointer<Int>, let, name "$0", argno 1 // id: %1
%2 = metatype $@thin Int.Type // user: %15
// function_ref UnsafePointer.pointee.unsafeAddressor
%3 = function_ref @$sSP7pointeexvlu : $@convention(method) <τ_0_0> (UnsafePointer<τ_0_0>) -> UnsafePointer<τ_0_0> // user: %4
%4 = apply %3<Int>(%0) : $@convention(method) <τ_0_0> (UnsafePointer<τ_0_0>) -> UnsafePointer<τ_0_0> // user: %5
%5 = struct_extract %4 : $UnsafePointer<Int>, #UnsafePointer._rawValue // user: %6
%6 = pointer_to_address %5 : $Builtin.RawPointer to [strict] $*Int // user: %7
%7 = begin_access [read] [unsafe] %6 : $*Int // users: %9, %8
%8 = load [trivial] %7 : $*Int // user: %15
end_access %7 : $*Int // id: %9
%10 = integer_literal $Builtin.IntLiteral, 1 // user: %13
%11 = metatype $@thin Int.Type // user: %13
// function_ref Int.init(_builtinIntegerLiteral:)
%12 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %13
%13 = apply %12(%10, %11) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %15
// function_ref static Int.+ infix(_:_:)
%14 = function_ref @$sSi1poiyS2i_SitFZ : $@convention(method) (Int, Int, @thin Int.Type) -> Int // user: %15
%15 = apply %14(%8, %13, %2) : $@convention(method) (Int, Int, @thin Int.Type) -> Int // user: %16
return %15 : $Int // id: %16
} // end sil function '$sSP17manglednamefinderE1aSiyFSiSPySiGXEfU_'
// UnsafePointer.pointee.unsafeAddressor
sil [transparent] [serialized] @$sSP7pointeexvlu : $@convention(method) <τ_0_0> (UnsafePointer<τ_0_0>) -> UnsafePointer<τ_0_0>
// static Int.+ infix(_:_:)
sil [transparent] [serialized] @$sSi1poiyS2i_SitFZ : $@convention(method) (Int, Int, @thin Int.Type) -> Int
// thunk for @callee_guaranteed (@unowned UnsafePointer<Int>) -> (@unowned Int, @error @owned Error)
sil shared [transparent] [serializable] [reabstraction_thunk] [ossa] @$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafePointer<Int>, @noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) {
// %0 // user: %5
// %1 // user: %3
// %2 // user: %3
bb0(%0 : $*Int, %1 : $UnsafePointer<Int>, %2 : $@noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error)):
try_apply %2(%1) : $@noescape @callee_guaranteed (UnsafePointer<Int>) -> (Int, @error Error), normal bb1, error bb2 // id: %3
// %4 // user: %5
bb1(%4 : $Int): // Preds: bb0
store %4 to [trivial] %0 : $*Int // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
// %8 // user: %9
bb2(%8 : @owned $Error): // Preds: bb0
throw %8 : $Error // id: %9
} // end sil function '$sSPySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR'
// UnsafePointer.withMemoryRebound<A, B>(to:capacity:_:)
sil [serialized] @$sSP17withMemoryRebound2to8capacity_qd_0_qd__m_Siqd_0_SPyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafePointer<τ_0_0>) -> (@out τ_1_1, @error Error)
// UnsafeMutablePointer.b()
sil hidden [ossa] @$sSp17manglednamefinderE1bSuyF : $@convention(method) <Pointee> (UnsafeMutablePointer<Pointee>) -> UInt {
// %0 "self" // users: %19, %1
bb0(%0 : $UnsafeMutablePointer<Pointee>):
debug_value %0 : $UnsafeMutablePointer<Pointee>, let, name "self", argno 1 // id: %1
%2 = alloc_stack $UInt // users: %22, %21, %19
%3 = metatype $@thin UInt.Type
%4 = metatype $@thick UInt.Type // user: %19
%5 = integer_literal $Builtin.IntLiteral, 1 // user: %8
%6 = metatype $@thin Int.Type // user: %8
// function_ref Int.init(_builtinIntegerLiteral:)
%7 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %8
%8 = apply %7(%5, %6) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %19
// function_ref closure #1 in UnsafeMutablePointer.b()
%9 = function_ref @$sSp17manglednamefinderE1bSuyFSuSpySuGXEfU_ : $@convention(thin) (UnsafeMutablePointer<UInt>) -> UInt // user: %10
%10 = convert_function %9 : $@convention(thin) (UnsafeMutablePointer<UInt>) -> UInt to $@convention(thin) @noescape (UnsafeMutablePointer<UInt>) -> UInt // user: %11
%11 = thin_to_thick_function %10 : $@convention(thin) @noescape (UnsafeMutablePointer<UInt>) -> UInt to $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> UInt // user: %12
%12 = convert_function %11 : $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> UInt to $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error) // user: %14
// function_ref thunk for @callee_guaranteed (@unowned UnsafeMutablePointer<UInt>) -> (@unowned UInt, @error @owned Error)
%13 = function_ref @$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TR : $@convention(thin) (UnsafeMutablePointer<UInt>, @noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error)) -> (@out UInt, @error Error) // user: %14
%14 = partial_apply [callee_guaranteed] %13(%12) : $@convention(thin) (UnsafeMutablePointer<UInt>, @noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error)) -> (@out UInt, @error Error) // user: %15
%15 = convert_function %14 : $@callee_guaranteed (UnsafeMutablePointer<UInt>) -> (@out UInt, @error Error) to $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutablePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <UInt, UInt> // users: %17, %16
%16 = convert_escape_to_noescape [not_guaranteed] %15 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutablePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <UInt, UInt> to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutablePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <UInt, UInt> // user: %19
destroy_value %15 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutablePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <UInt, UInt> // id: %17
// function_ref UnsafeMutablePointer.withMemoryRebound<A, B>(to:capacity:_:)
%18 = function_ref @$sSp17withMemoryRebound2to8capacity_qd_0_qd__m_Siqd_0_Spyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutablePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutablePointer<τ_0_0>) -> (@out τ_1_1, @error Error) // user: %19
try_apply %18<Pointee, UInt, UInt>(%2, %4, %8, %16, %0) : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutablePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutablePointer<τ_0_0>) -> (@out τ_1_1, @error Error), normal bb1, error bb2 // id: %19
bb1(%20 : $()): // Preds: bb0
%21 = load [trivial] %2 : $*UInt // user: %23
dealloc_stack %2 : $*UInt // id: %22
return %21 : $UInt // id: %23
bb2(%24 : @owned $Error): // Preds: bb0
unreachable // id: %25
} // end sil function '$sSp17manglednamefinderE1bSuyF'
// closure #1 in UnsafeMutablePointer.b()
sil private [ossa] @$sSp17manglednamefinderE1bSuyFSuSpySuGXEfU_ : $@convention(thin) (UnsafeMutablePointer<UInt>) -> UInt {
// %0 "$0" // users: %4, %1
bb0(%0 : $UnsafeMutablePointer<UInt>):
debug_value %0 : $UnsafeMutablePointer<UInt>, let, name "$0", argno 1 // id: %1
%2 = metatype $@thin UInt.Type // user: %15
// function_ref UnsafeMutablePointer.pointee.unsafeAddressor
%3 = function_ref @$sSp7pointeexvlu : $@convention(method) <τ_0_0> (UnsafeMutablePointer<τ_0_0>) -> UnsafePointer<τ_0_0> // user: %4
%4 = apply %3<UInt>(%0) : $@convention(method) <τ_0_0> (UnsafeMutablePointer<τ_0_0>) -> UnsafePointer<τ_0_0> // user: %5
%5 = struct_extract %4 : $UnsafePointer<UInt>, #UnsafePointer._rawValue // user: %6
%6 = pointer_to_address %5 : $Builtin.RawPointer to [strict] $*UInt // user: %7
%7 = begin_access [read] [unsafe] %6 : $*UInt // users: %9, %8
%8 = load [trivial] %7 : $*UInt // user: %15
end_access %7 : $*UInt // id: %9
%10 = integer_literal $Builtin.IntLiteral, 1 // user: %13
%11 = metatype $@thin UInt.Type // user: %13
// function_ref UInt.init(_builtinIntegerLiteral:)
%12 = function_ref @$sSu22_builtinIntegerLiteralSuBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin UInt.Type) -> UInt // user: %13
%13 = apply %12(%10, %11) : $@convention(method) (Builtin.IntLiteral, @thin UInt.Type) -> UInt // user: %15
// function_ref static UInt.+ infix(_:_:)
%14 = function_ref @$sSu1poiyS2u_SutFZ : $@convention(method) (UInt, UInt, @thin UInt.Type) -> UInt // user: %15
%15 = apply %14(%8, %13, %2) : $@convention(method) (UInt, UInt, @thin UInt.Type) -> UInt // user: %16
return %15 : $UInt // id: %16
} // end sil function '$sSp17manglednamefinderE1bSuyFSuSpySuGXEfU_'
// UnsafeMutablePointer.pointee.unsafeAddressor
sil [transparent] [serialized] @$sSp7pointeexvlu : $@convention(method) <τ_0_0> (UnsafeMutablePointer<τ_0_0>) -> UnsafePointer<τ_0_0>
// UInt.init(_builtinIntegerLiteral:)
sil [transparent] [serialized] @$sSu22_builtinIntegerLiteralSuBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin UInt.Type) -> UInt
// static UInt.+ infix(_:_:)
sil [transparent] [serialized] @$sSu1poiyS2u_SutFZ : $@convention(method) (UInt, UInt, @thin UInt.Type) -> UInt
// thunk for @callee_guaranteed (@unowned UnsafeMutablePointer<UInt>) -> (@unowned UInt, @error @owned Error)
sil shared [transparent] [serializable] [reabstraction_thunk] [ossa] @$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TR : $@convention(thin) (UnsafeMutablePointer<UInt>, @noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error)) -> (@out UInt, @error Error) {
// %0 // user: %5
// %1 // user: %3
// %2 // user: %3
bb0(%0 : $*UInt, %1 : $UnsafeMutablePointer<UInt>, %2 : $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error)):
try_apply %2(%1) : $@noescape @callee_guaranteed (UnsafeMutablePointer<UInt>) -> (UInt, @error Error), normal bb1, error bb2 // id: %3
// %4 // user: %5
bb1(%4 : $UInt): // Preds: bb0
store %4 to [trivial] %0 : $*UInt // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
// %8 // user: %9
bb2(%8 : @owned $Error): // Preds: bb0
throw %8 : $Error // id: %9
} // end sil function '$sSpySuGSus5Error_pIgydzo_AASusAB_pIegyrzo_TR'
// UnsafeMutablePointer.withMemoryRebound<A, B>(to:capacity:_:)
sil [serialized] @$sSp17withMemoryRebound2to8capacity_qd_0_qd__m_Siqd_0_Spyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, Int, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutablePointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutablePointer<τ_0_0>) -> (@out τ_1_1, @error Error)
// UnsafeBufferPointer.c()
sil hidden [ossa] @$sSR17manglednamefinderE1cSiyF : $@convention(method) <Element> (UnsafeBufferPointer<Element>) -> Int {
// %0 "self" // users: %15, %1
bb0(%0 : $UnsafeBufferPointer<Element>):
debug_value %0 : $UnsafeBufferPointer<Element>, let, name "self", argno 1 // id: %1
%2 = alloc_stack $Int // users: %18, %17, %15
%3 = metatype $@thin Int.Type
%4 = metatype $@thick Int.Type // user: %15
// function_ref closure #1 in UnsafeBufferPointer.c()
%5 = function_ref @$sSR17manglednamefinderE1cSiyFSiSRySiGXEfU_ : $@convention(thin) (UnsafeBufferPointer<Int>) -> Int // user: %6
%6 = convert_function %5 : $@convention(thin) (UnsafeBufferPointer<Int>) -> Int to $@convention(thin) @noescape (UnsafeBufferPointer<Int>) -> Int // user: %7
%7 = thin_to_thick_function %6 : $@convention(thin) @noescape (UnsafeBufferPointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> Int // user: %8
%8 = convert_function %7 : $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error) // user: %10
// function_ref thunk for @callee_guaranteed (@unowned UnsafeBufferPointer<Int>) -> (@unowned Int, @error @owned Error)
%9 = function_ref @$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafeBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // user: %10
%10 = partial_apply [callee_guaranteed] %9(%8) : $@convention(thin) (UnsafeBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // user: %11
%11 = convert_function %10 : $@callee_guaranteed (UnsafeBufferPointer<Int>) -> (@out Int, @error Error) to $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // users: %13, %12
%12 = convert_escape_to_noescape [not_guaranteed] %11 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // user: %15
destroy_value %11 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // id: %13
// function_ref UnsafeBufferPointer.withMemoryRebound<A, B>(to:_:)
%14 = function_ref @$sSR17withMemoryRebound2to_qd_0_qd__m_qd_0_SRyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error) // user: %15
try_apply %14<Element, Int, Int>(%2, %4, %12, %0) : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error), normal bb1, error bb2 // id: %15
bb1(%16 : $()): // Preds: bb0
%17 = load [trivial] %2 : $*Int // user: %19
dealloc_stack %2 : $*Int // id: %18
return %17 : $Int // id: %19
bb2(%20 : @owned $Error): // Preds: bb0
unreachable // id: %21
} // end sil function '$sSR17manglednamefinderE1cSiyF'
// closure #1 in UnsafeBufferPointer.c()
sil private [ossa] @$sSR17manglednamefinderE1cSiyFSiSRySiGXEfU_ : $@convention(thin) (UnsafeBufferPointer<Int>) -> Int {
// %0 "$0" // users: %9, %1
bb0(%0 : $UnsafeBufferPointer<Int>):
debug_value %0 : $UnsafeBufferPointer<Int>, let, name "$0", argno 1 // id: %1
%2 = metatype $@thin Int.Type // user: %16
%3 = integer_literal $Builtin.IntLiteral, 0 // user: %6
%4 = metatype $@thin Int.Type // user: %6
// function_ref Int.init(_builtinIntegerLiteral:)
%5 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %6
%6 = apply %5(%3, %4) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %9
%7 = alloc_stack $Int // users: %17, %10, %9
// function_ref UnsafeBufferPointer.subscript.getter
%8 = function_ref @$sSRyxSicig : $@convention(method) <τ_0_0> (Int, UnsafeBufferPointer<τ_0_0>) -> @out τ_0_0 // user: %9
%9 = apply %8<Int>(%7, %6, %0) : $@convention(method) <τ_0_0> (Int, UnsafeBufferPointer<τ_0_0>) -> @out τ_0_0
%10 = load [trivial] %7 : $*Int // user: %16
%11 = integer_literal $Builtin.IntLiteral, 1 // user: %14
%12 = metatype $@thin Int.Type // user: %14
// function_ref Int.init(_builtinIntegerLiteral:)
%13 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %14
%14 = apply %13(%11, %12) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %16
// function_ref static Int.+ infix(_:_:)
%15 = function_ref @$sSi1poiyS2i_SitFZ : $@convention(method) (Int, Int, @thin Int.Type) -> Int // user: %16
%16 = apply %15(%10, %14, %2) : $@convention(method) (Int, Int, @thin Int.Type) -> Int // user: %18
dealloc_stack %7 : $*Int // id: %17
return %16 : $Int // id: %18
} // end sil function '$sSR17manglednamefinderE1cSiyFSiSRySiGXEfU_'
// UnsafeBufferPointer.subscript.getter
sil [serialized] @$sSRyxSicig : $@convention(method) <τ_0_0> (Int, UnsafeBufferPointer<τ_0_0>) -> @out τ_0_0
// thunk for @callee_guaranteed (@unowned UnsafeBufferPointer<Int>) -> (@unowned Int, @error @owned Error)
sil shared [transparent] [serializable] [reabstraction_thunk] [ossa] @$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafeBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) {
// %0 // user: %5
// %1 // user: %3
// %2 // user: %3
bb0(%0 : $*Int, %1 : $UnsafeBufferPointer<Int>, %2 : $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error)):
try_apply %2(%1) : $@noescape @callee_guaranteed (UnsafeBufferPointer<Int>) -> (Int, @error Error), normal bb1, error bb2 // id: %3
// %4 // user: %5
bb1(%4 : $Int): // Preds: bb0
store %4 to [trivial] %0 : $*Int // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
// %8 // user: %9
bb2(%8 : @owned $Error): // Preds: bb0
throw %8 : $Error // id: %9
} // end sil function '$sSRySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR'
// UnsafeBufferPointer.withMemoryRebound<A, B>(to:_:)
sil [serialized] @$sSR17withMemoryRebound2to_qd_0_qd__m_qd_0_SRyqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error)
// UnsafeMutableBufferPointer.d()
sil hidden [ossa] @$sSr17manglednamefinderE1dSiyF : $@convention(method) <Element> (UnsafeMutableBufferPointer<Element>) -> Int {
// %0 "self" // users: %15, %1
bb0(%0 : $UnsafeMutableBufferPointer<Element>):
debug_value %0 : $UnsafeMutableBufferPointer<Element>, let, name "self", argno 1 // id: %1
%2 = alloc_stack $Int // users: %18, %17, %15
%3 = metatype $@thin Int.Type
%4 = metatype $@thick Int.Type // user: %15
// function_ref closure #1 in UnsafeMutableBufferPointer.d()
%5 = function_ref @$sSr17manglednamefinderE1dSiyFSiSrySiGXEfU_ : $@convention(thin) (UnsafeMutableBufferPointer<Int>) -> Int // user: %6
%6 = convert_function %5 : $@convention(thin) (UnsafeMutableBufferPointer<Int>) -> Int to $@convention(thin) @noescape (UnsafeMutableBufferPointer<Int>) -> Int // user: %7
%7 = thin_to_thick_function %6 : $@convention(thin) @noescape (UnsafeMutableBufferPointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> Int // user: %8
%8 = convert_function %7 : $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> Int to $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error) // user: %10
// function_ref thunk for @callee_guaranteed (@unowned UnsafeMutableBufferPointer<Int>) -> (@unowned Int, @error @owned Error)
%9 = function_ref @$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafeMutableBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // user: %10
%10 = partial_apply [callee_guaranteed] %9(%8) : $@convention(thin) (UnsafeMutableBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) // user: %11
%11 = convert_function %10 : $@callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (@out Int, @error Error) to $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // users: %13, %12
%12 = convert_escape_to_noescape [not_guaranteed] %11 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // user: %15
destroy_value %11 : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <Int, Int> // id: %13
// function_ref UnsafeMutableBufferPointer.withMemoryRebound<A, B>(to:_:)
%14 = function_ref @$sSr17withMemoryRebound2to_qd_0_qd__m_qd_0_Sryqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error) // user: %15
try_apply %14<Element, Int, Int>(%2, %4, %12, %0) : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error), normal bb1, error bb2 // id: %15
bb1(%16 : $()): // Preds: bb0
%17 = load [trivial] %2 : $*Int // user: %19
dealloc_stack %2 : $*Int // id: %18
return %17 : $Int // id: %19
bb2(%20 : @owned $Error): // Preds: bb0
unreachable // id: %21
} // end sil function '$sSr17manglednamefinderE1dSiyF'
// closure #1 in UnsafeMutableBufferPointer.d()
sil private [ossa] @$sSr17manglednamefinderE1dSiyFSiSrySiGXEfU_ : $@convention(thin) (UnsafeMutableBufferPointer<Int>) -> Int {
// %0 "$0" // users: %9, %1
bb0(%0 : $UnsafeMutableBufferPointer<Int>):
debug_value %0 : $UnsafeMutableBufferPointer<Int>, let, name "$0", argno 1 // id: %1
%2 = metatype $@thin Int.Type // user: %16
%3 = integer_literal $Builtin.IntLiteral, 0 // user: %6
%4 = metatype $@thin Int.Type // user: %6
// function_ref Int.init(_builtinIntegerLiteral:)
%5 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %6
%6 = apply %5(%3, %4) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %9
%7 = alloc_stack $Int // users: %17, %10, %9
// function_ref UnsafeMutableBufferPointer.subscript.getter
%8 = function_ref @$sSryxSicig : $@convention(method) <τ_0_0> (Int, UnsafeMutableBufferPointer<τ_0_0>) -> @out τ_0_0 // user: %9
%9 = apply %8<Int>(%7, %6, %0) : $@convention(method) <τ_0_0> (Int, UnsafeMutableBufferPointer<τ_0_0>) -> @out τ_0_0
%10 = load [trivial] %7 : $*Int // user: %16
%11 = integer_literal $Builtin.IntLiteral, 1 // user: %14
%12 = metatype $@thin Int.Type // user: %14
// function_ref Int.init(_builtinIntegerLiteral:)
%13 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %14
%14 = apply %13(%11, %12) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %16
// function_ref static Int.+ infix(_:_:)
%15 = function_ref @$sSi1poiyS2i_SitFZ : $@convention(method) (Int, Int, @thin Int.Type) -> Int // user: %16
%16 = apply %15(%10, %14, %2) : $@convention(method) (Int, Int, @thin Int.Type) -> Int // user: %18
dealloc_stack %7 : $*Int // id: %17
return %16 : $Int // id: %18
} // end sil function '$sSr17manglednamefinderE1dSiyFSiSrySiGXEfU_'
// UnsafeMutableBufferPointer.subscript.getter
sil [serialized] @$sSryxSicig : $@convention(method) <τ_0_0> (Int, UnsafeMutableBufferPointer<τ_0_0>) -> @out τ_0_0
// thunk for @callee_guaranteed (@unowned UnsafeMutableBufferPointer<Int>) -> (@unowned Int, @error @owned Error)
sil shared [transparent] [serializable] [reabstraction_thunk] [ossa] @$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR : $@convention(thin) (UnsafeMutableBufferPointer<Int>, @noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error)) -> (@out Int, @error Error) {
// %0 // user: %5
// %1 // user: %3
// %2 // user: %3
bb0(%0 : $*Int, %1 : $UnsafeMutableBufferPointer<Int>, %2 : $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error)):
try_apply %2(%1) : $@noescape @callee_guaranteed (UnsafeMutableBufferPointer<Int>) -> (Int, @error Error), normal bb1, error bb2 // id: %3
// %4 // user: %5
bb1(%4 : $Int): // Preds: bb0
store %4 to [trivial] %0 : $*Int // id: %5
%6 = tuple () // user: %7
return %6 : $() // id: %7
// %8 // user: %9
bb2(%8 : @owned $Error): // Preds: bb0
throw %8 : $Error // id: %9
} // end sil function '$sSrySiGSis5Error_pIgydzo_AASisAB_pIegyrzo_TR'
// UnsafeMutableBufferPointer.withMemoryRebound<A, B>(to:_:)
sil [serialized] @$sSr17withMemoryRebound2to_qd_0_qd__m_qd_0_Sryqd__GKXEtKr0_lF : $@convention(method) <τ_0_0><τ_1_0, τ_1_1> (@thick τ_1_0.Type, @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> (UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_0_1, @error Error) for <τ_1_0, τ_1_1>, UnsafeMutableBufferPointer<τ_0_0>) -> (@out τ_1_1, @error Error)
// Mappings from '#fileID' to '#filePath':
// 'manglednamefinder/manglednamefinder.swift' => 'manglednamefinder.swift'
extension UnsafePointer {
func a() -> Int {
self.withMemoryRebound(to: Int.self, capacity: 1) {
return $0.pointee + 1
}
}
}
extension UnsafeMutablePointer {
func b() -> UInt {
self.withMemoryRebound(to: UInt.self, capacity: 1) {
return $0.pointee + 1
}
}
}
extension UnsafeBufferPointer {
func c() -> Int {
self.withMemoryRebound(to: Int.self) {
return $0[0] + 1
}
}
}
extension UnsafeMutableBufferPointer {
func d() -> Int {
self.withMemoryRebound(to: Int.self) {
return $0[0] + 1
}
}
}

Expand usability of withMemoryRebound

Introduction

The function withMemoryRebound(to:capacity:_ body:) executes a closure while temporarily binding a range of memory to a different type than the callee is bound to. We propose to lift some notable limitations of withMemoryRebound and enable rebinding to a larger set of types, as well as rebinding from raw memory pointers and buffers.

Swift-evolution thread: Pitch thread

Motivation

When using Swift in a systems programming context or using Swift with libraries written in C, we occasionally need to temporarily access a range of memory as instances of a different type than has been declared (the pointer's Pointee type parameter). In those cases, withMemoryRebound is the tool to reach for, allowing scoped access to the range of memory as another type.

As a reminder, the function is declared as follows on the type UnsafePointer<Pointee>:

func withMemoryRebound<T, Result>(
  to type: T.Type,
  capacity count: Int,
  _ body: (UnsafePointer<T>) throws -> Result
) rethrows -> Result

This function is currently more limited than necessary. It requires that the stride of Pointee and T be equal. This requirement makes many legitimate use cases technically illegal, even though they could be supported by the compiler.

We propose to allow temporarily binding to a type T whose stride is a whole fraction or whole multiple of Pointee's stride, when the starting address is properly aligned for type T. As before, T's memory layout must be compatible with that ofPointee.

For example, suppose that a buffer of Double consisting of a series of (x,y) pairs is returned from data analysis code written in C. The next step might be to display it in a preview graph, which needs to read CGPoint values. We need to copy the Double values as pairs to values of type CGPoint (when executing on a 64-bit platform):

var count = 0
let pointer: UnsafePointer<Double> = calculation(&count)

var points = Array<CGPoint>(unsafeUninitializedCapacity: count/2) {
  buffer, initializedCount in
  var p = pointer
  for i in buffer.indices where p+1 < pointer+count {
    buffer.baseAddress!.advanced(by: i).initialize(to: CGPoint(x: p[0], y: p[1]))
    p += 2
  }
  initializedCount = pointer.distance(to: p)/2
}

We could do better with an improved version of withMemoryRebound. Since CGPoint values consist of a pair of CGFloat values, and CGFloat values are themselves layout-compatible with Double (when executing on a 64-bit platform):

var points = Array<CGPoint>(unsafeUninitializedCapacity: data.count/2) {
  buffer, initializedCount in
  pointer.withMemoryRebound(to: CGPoint.self, capacity: buffer.count) {
    buffer.baseAddress!.initialize(from: $0, count: buffer.count)
  }
  initializedCount = buffer.count
}

Alternately, the data could have been received as bytes from a network request, wrapped in a Data instance. Previously we would have needed to do:

let data: Data = ...

var points = Array<CGPoint>(unsafeUninitializedCapacity: data.count/MemoryLayout<CGPoint>.stride) {
  buffer, initializedCount in
  data.withUnsafeBytes { data in
    var read = 0
    for i in buffer.indices where (read+2*MemoryLayout<CGFloat>.stride)<=data.count {
      let x = data.load(fromByteOffset: read, as: CGFloat.self)
      read += MemoryLayout<CGFloat>.stride
      let y = data.load(fromByteOffset: read, as: CGFloat.self)
      read += MemoryLayout<CGFloat>.stride
      buffer.baseAddress!.advanced(by: i).initialize(to: CGPoint(x: x, y: y))
    }
    initializedCount = read / MemoryLayout<CGPoint>.stride
  }
}

In this case having the ability to use withMemoryRebound with UnsafeRawBuffer improves readability in a similar manner as in the example above:

var points = Array<CGPoint>(unsafeUninitializedCapacity: data.count/MemoryLayout<CGPoint>.stride) {
  buffer, initializedCount in
  data.withUnsafeBytes {
    $0.withMemoryRebound(to: CGPoint.self) {
      (_, initializedCount) = buffer.initialize(from: $0)
    }
  }
}

Proposed solution

We propose to lift the restriction that the strides of T and Pointee must be equal. This means that it will now be considered correct to re-bind from a homogeneous aggregate type to the type of its constitutive elements, as they are layout compatible, even though their stride is different.

Instance methods of UnsafePointer<Pointee> and UnsafeMutablePointer<Pointee>

We propose to lift the restriction that the strides of T and Pointee must be equal, when calling withMemoryRebound. The function declarations remain the same on these two types, though given the relaxed restriction, we must clarify the meaning of the capacity argument. capacity shall mean the number of strides of elements of the temporary type (T) to be temporarily bound. The documentation will be updated to reflect the changed behaviour. We will also add parameter labels to the closure type declaration to benefit code completion (a source compatible change.)

extension UnsafePointer {
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    capacity count: Int,
    _ body: (_ pointer: UnsafePointer<T>) throws -> Result
  ) rethrows -> Result
}

extension UnsafeMutablePointer {
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    capacity count: Int,
    _ body: (_ pointer: UnsafeMutablePointer<T>) throws -> Result
  ) rethrows -> Result
}

Instance methods of UnsafeRawPointer and UnsafeMutableRawPointer

We propose adding a withMemoryRebound method, which currently does not exist on these types. Since it operates on raw memory, this version of withMemoryRebound places no restriction on the temporary type (T). It is therefore up to the program author to ensure type safety when using these methods. As in the UnsafePointer case, capacity means the number of strides of elements of the temporary type (T) to be temporarily bound.

extension UnsafeRawPointer {
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    capacity count: Int,
    _ body: (_ pointer: UnsafePointer<T>) throws -> Result
  ) rethrows -> Result
}

extension UnsafeMutableRawPointer {
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    capacity count: Int,
    _ body: (_ pointer: UnsafeMutablePointer<T>) throws -> Result
  ) rethrows -> Result
}

Instance methods of UnsafeBufferPointer and UnsafeMutableBufferPointer

We propose to lift the restriction that the strides of T and Pointee must be equal, when calling withMemoryRebound. The function declarations remain the same on these two types. The capacity of the buffer to the temporary type will be calculated using the length of the UnsafeBufferPointer<Element> and the stride of the temporary type. The documentation will be updated to reflect the changed behaviour. We will add parameter labels to the closure type declaration to benefit code completion (a source compatible change.)

extension UnsafeBufferPointer {
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    _ body: (_ buffer: UnsafeBufferPointer<T>) throws -> Result
  ) rethrows -> Result
}

extension UnsafeMutableBufferPointer {
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    _ body: (_ buffer: UnsafeMutableBufferPointer<T>) throws -> Result
  ) rethrows -> Result
}

Instance methods of UnsafeRawBufferPointer and UnsafeMutableRawBufferPointer

We propose adding a withMemoryRebound method, which currently does not exist on these types. Since it operates on raw memory, this version of withMemoryRebound places no restriction on the temporary type (T). It is therefore up to the program author to ensure type safety when using these methods. The capacity of the buffer to the temporary type will be calculated using the length of the UnsafeRawBufferPointer and the stride of the temporary type.

Finally the set, we propose to add an assumingMemoryBound function that calculates the capacity of the returned UnsafeBufferPointer.

extension UnsafeRawBufferPointer {
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    _ body: (_ buffer: UnsafeBufferPointer<T>) throws -> Result
  ) rethrows -> Result
  
  public func assumingMemoryBound<T>(to type: T.Type) -> UnsafeBufferPointer<T>
}

extension UnsafeMutableRawBufferPointer {
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    _ body: (_ buffer: UnsafeMutableBufferPointer<T>) throws -> Result
  ) rethrows -> Result

  public func assumingMemoryBound<T>(to type: T.Type) -> UnsafeMutableBufferPointer<T>
}

Detailed design

Note: please see the draft PR to visualize the proposed changes rather than the proposed final state.

extension UnsafePointer {
  /// Executes the given closure while temporarily binding memory to
  /// the specified number of instances of type `T`.
  ///
  /// Use this method when you have a pointer to memory bound to one type and
  /// you need to access that memory as instances of another type. Accessing
  /// memory as a type `T` requires that the memory be bound to that type. A
  /// memory location may only be bound to one type at a time, so accessing
  /// the same memory as an unrelated type without first rebinding the memory
  /// is undefined.
  ///
  /// The region of memory that starts at this pointer and covers `count`
  /// strides of `T` instances must be bound to `Pointee`.
  /// Any instance of `T` within the re-bound region may be initialized or
  /// uninitialized. Every instance of `Pointee` overlapping with a given
  /// instance of `T` should have the same initialization state (i.e.
  /// initialized or uninitialized.) Accessing a `T` whose underlying
  /// `Pointee` storage is in a mixed initialization state shall be
  /// undefined behaviour.
  ///
  /// The following example temporarily rebinds the memory of a `UInt64`
  /// pointer to `Int64`, then accesses a property on the signed integer.
  ///
  ///     let uint64Pointer: UnsafePointer<UInt64> = fetchValue()
  ///     let isNegative = uint64Pointer.withMemoryRebound(to: Int64.self,
  ///                                                      capacity: 1) {
  ///         return $0.pointee < 0
  ///     }
  ///
  /// Because this pointer's memory is no longer bound to its `Pointee` type
  /// while the `body` closure executes, do not access memory using the
  /// original pointer from within `body`. Instead, use the `body` closure's
  /// pointer argument to access the values in memory as instances of type
  /// `T`.
  ///
  /// After executing `body`, this method rebinds memory back to the original
  /// `Pointee` type.
  ///
  /// - Note: Only use this method to rebind the pointer's memory to a type
  ///   that is layout compatible with the `Pointee` type. The stride of the
  ///   temporary type (`T`) may be an integer multiple or a whole fraction
  ///   of `Pointee`'s stride, for example to point to one element of
  ///   an aggregate.
  ///   To bind a region of memory to a type that does not match these
  ///   requirements, convert the pointer to a raw pointer and use the
  ///   `bindMemory(to:)` method.
  ///   If `T` and `Pointee` have different alignments, this pointer
  ///   must be aligned with the larger of the two alignments.
  ///
  /// - Parameters:
  ///   - type: The type to temporarily bind the memory referenced by this
  ///     pointer. The type `T` must be layout compatible
  ///     with the pointer's `Pointee` type.
  ///   - count: The number of instances of `T` in the re-bound region.
  ///   - body: A closure that takes a typed pointer to the
  ///     same memory as this pointer, only bound to type `T`. The closure's
  ///     pointer argument is valid only for the duration of the closure's
  ///     execution. If `body` has a return value, that value is also used as
  ///     the return value for the `withMemoryRebound(to:capacity:_:)` method.
  ///   - pointer: The pointer temporarily bound to `T`.
  /// - Returns: The return value, if any, of the `body` closure parameter.
  @_alwaysEmitIntoClient
  public func withMemoryRebound<T, Result>(
    to type: T.Type, capacity count: Int,
    _ body: (_ pointer: UnsafePointer<T>) throws -> Result
  ) rethrows -> Result
}
extension UnsafeMutablePointer {
  /// Executes the given closure while temporarily binding memory to
  /// the specified number of instances of the given type.
  ///
  /// Use this method when you have a pointer to memory bound to one type and
  /// you need to access that memory as instances of another type. Accessing
  /// memory as a type `T` requires that the memory be bound to that type. A
  /// memory location may only be bound to one type at a time, so accessing
  /// the same memory as an unrelated type without first rebinding the memory
  /// is undefined.
  ///
  /// The region of memory that starts at this pointer and covers `count`
  /// strides of `T` instances must be bound to `Pointee`.
  /// Any instance of `T` within the re-bound region may be initialized or
  /// uninitialized. Every instance of `Pointee` overlapping with a given
  /// instance of `T` should have the same initialization state (i.e.
  /// initialized or uninitialized.) Accessing a `T` whose underlying
  /// `Pointee` storage is in a mixed initialization state shall be
  /// undefined behaviour.
  ///
  /// The following example temporarily rebinds the memory of a `UInt64`
  /// pointer to `Int64`, then modifies the signed integer.
  ///
  ///     let uint64Pointer: UnsafeMutablePointer<UInt64> = fetchValue()
  ///     uint64Pointer.withMemoryRebound(to: Int64.self, capacity: 1) { ptr in
  ///         ptr.pointee.negate()
  ///     }
  ///
  /// Because this pointer's memory is no longer bound to its `Pointee` type
  /// while the `body` closure executes, do not access memory using the
  /// original pointer from within `body`. Instead, use the `body` closure's
  /// pointer argument to access the values in memory as instances of type
  /// `T`.
  ///
  /// After executing `body`, this method rebinds memory back to the original
  /// `Pointee` type.
  ///
  /// - Note: Only use this method to rebind the pointer's memory to a type
  ///   that is layout compatible with the `Pointee` type. The stride of the
  ///   temporary type (`T`) may be an integer multiple or a whole fraction
  ///   of `Pointee`'s stride, for example to point to one element of
  ///   an aggregate.
  ///   To bind a region of memory to a type that does not match these
  ///   requirements, convert the pointer to a raw pointer and use the
  ///   `bindMemory(to:)` method.
  ///   If `T` and `Pointee` have different alignments, this pointer
  ///   must be aligned with the larger of the two alignments.
  ///
  /// - Parameters:
  ///   - type: The type to temporarily bind the memory referenced by this
  ///     pointer. The type `T` must be layout compatible
  ///     with the pointer's `Pointee` type.
  ///   - count: The number of instances of `T` in the re-bound region.
  ///   - body: A closure that takes a mutable typed pointer to the
  ///     same memory as this pointer, only bound to type `T`. The closure's
  ///     pointer argument is valid only for the duration of the closure's
  ///     execution. If `body` has a return value, that value is also used as
  ///     the return value for the `withMemoryRebound(to:capacity:_:)` method.
  ///   - pointer: The pointer temporarily bound to `T`.
  /// - Returns: The return value, if any, of the `body` closure parameter.
  @_alwaysEmitIntoClient
  public func withMemoryRebound<T, Result>(
    to type: T.Type, capacity count: Int,
    _ body: (_ pointer: UnsafeMutablePointer<T>) throws -> Result
  ) rethrows -> Result
}
extension UnsafeBufferPointer {
  /// Executes the given closure while temporarily binding the memory referenced 
  /// by this buffer to the given type.
  ///
  /// Use this method when you have a buffer of memory bound to one type and
  /// you need to access that memory as a buffer of another type. Accessing
  /// memory as type `T` requires that the memory be bound to that type. A
  /// memory location may only be bound to one type at a time, so accessing
  /// the same memory as an unrelated type without first rebinding the memory
  /// is undefined.
  ///
  /// The number of instances of `T` referenced by the rebound buffer may be
  /// different than the number of instances of `Element` referenced by the
  /// original buffer. The number of instances of `T` will be calculated
  /// at runtime.
  /// 
  /// Any instance of `T` within the re-bound region may be initialized or
  /// uninitialized. Every instance of `Pointee` overlapping with a given
  /// instance of `T` should have the same initialization state (i.e.
  /// initialized or uninitialized.) Accessing a `T` whose underlying
  /// `Pointee` storage is in a mixed initialization state shall be
  /// undefined behaviour.
  ///
  /// Because this buffer's memory is no longer bound to its `Element` type
  /// while the `body` closure executes, do not access memory using the
  /// original buffer from within `body`. Instead, use the `body` closure's
  /// buffer argument to access the values in memory as instances of type
  /// `T`.
  ///
  /// After executing `body`, this method rebinds memory back to the original
  /// `Element` type.
  ///
  /// - Note: Only use this method to rebind the buffer's memory to a type
  ///   that is layout compatible with the currently bound `Element` type.
  ///   The stride of the temporary type (`T`) may be an integer multiple
  ///   or a whole fraction of `Element`'s stride.
  ///   To bind a region of memory to a type that does not match these
  ///   requirements, convert the buffer to a raw buffer and use the
  ///   `bindMemory(to:)` method.
  ///   If `T` and `Element` have different alignments, this buffer's
  ///   `baseAddress` must be aligned with the larger of the two alignments.
  ///
  /// - Parameters:
  ///   - type: The type to temporarily bind the memory referenced by this
  ///     buffer. The type `T` must be layout compatible
  ///     with the pointer's `Element` type.
  ///   - body: A closure that takes a  typed buffer to the
  ///     same memory as this buffer, only bound to type `T`. The buffer
  ///     parameter contains a number of complete instances of `T` based
  ///     on the capacity of the original buffer and the stride of `Element`.
  ///     The closure's buffer argument is valid only for the duration of the
  ///     closure's execution. If `body` has a return value, that value
  ///     is also used as the return value for the `withMemoryRebound(to:_:)`
  ///     method.
  ///   - buffer: The buffer temporarily bound to `T`.
  /// - Returns: The return value, if any, of the `body` closure parameter.
  @_alwaysEmitIntoClient
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    _ body: (_ buffer: UnsafeBufferPointer<T>) throws -> Result
  ) rethrows -> Result
}
extension UnsafeMutableBufferPointer {
  /// Executes the given closure while temporarily binding the memory referenced 
  /// by this buffer to the given type.
  ///
  /// Use this method when you have a buffer of memory bound to one type and
  /// you need to access that memory as a buffer of another type. Accessing
  /// memory as type `T` requires that the memory be bound to that type. A
  /// memory location may only be bound to one type at a time, so accessing
  /// the same memory as an unrelated type without first rebinding the memory
  /// is undefined.
  ///
  /// The number of instances of `T` referenced by the rebound buffer may be
  /// different than the number of instances of `Element` referenced by the
  /// original buffer. The number of instances of `T` will be calculated
  /// at runtime.
  /// 
  /// Any instance of `T` within the re-bound region may be initialized or
  /// uninitialized. Every instance of `Pointee` overlapping with a given
  /// instance of `T` should have the same initialization state (i.e.
  /// initialized or uninitialized.) Accessing a `T` whose underlying
  /// `Pointee` storage is in a mixed initialization state shall be
  /// undefined behaviour.
  ///
  /// Because this buffer's memory is no longer bound to its `Element` type
  /// while the `body` closure executes, do not access memory using the
  /// original buffer from within `body`. Instead, use the `body` closure's
  /// buffer argument to access the values in memory as instances of type
  /// `T`.
  ///
  /// After executing `body`, this method rebinds memory back to the original
  /// `Element` type.
  ///
  /// - Note: Only use this method to rebind the buffer's memory to a type
  ///   that is layout compatible with the currently bound `Element` type.
  ///   The stride of the temporary type (`T`) may be an integer multiple
  ///   or a whole fraction of `Element`'s stride.
  ///   To bind a region of memory to a type that does not match these
  ///   requirements, convert the buffer to a raw buffer and use the
  ///   `bindMemory(to:)` method.
  ///   If `T` and `Element` have different alignments, this buffer's
  ///   `baseAddress` must be aligned with the larger of the two alignments.
  ///
  /// - Parameters:
  ///   - type: The type to temporarily bind the memory referenced by this
  ///     buffer. The type `T` must be layout compatible
  ///     with the pointer's `Element` type.
  ///   - body: A closure that takes a mutable typed buffer to the
  ///     same memory as this buffer, only bound to type `T`. The buffer
  ///     parameter contains a number of complete instances of `T` based
  ///     on the capacity of the original buffer and the stride of `Element`.
  ///     The closure's buffer argument is valid only for the duration of the
  ///     closure's execution. If `body` has a return value, that value
  ///     is also used as the return value for the `withMemoryRebound(to:_:)`
  ///     method.
  ///   - buffer: The buffer temporarily bound to `T`.
  /// - Returns: The return value, if any, of the `body` closure parameter.
  @_alwaysEmitIntoClient
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    _ body: (_ buffer: UnsafeMutableBufferPointer<T>) throws -> Result
  ) rethrows -> Result
}
extension UnsafeRawPointer {
  /// Executes the given closure while temporarily binding memory to
  /// the specified number of instances of type `T`.
  ///
  /// Use this method when you have a pointer to raw memory and you need
  /// to access that memory as instances of a given type `T`. Accessing
  /// memory as a type `T` requires that the memory be bound to that type. A
  /// memory location may only be bound to one type at a time, so accessing
  /// the same memory as an unrelated type without first rebinding the memory
  /// is undefined.
  ///
  /// Any instance of `T` within the re-bound region may be initialized or
  /// uninitialized. The memory underlying any individual instance of `T`
  /// must have the same initialization state (i.e.  initialized or
  /// uninitialized.) Accessing a `T` whose underlying memory
  /// is in a mixed initialization state shall be undefined behaviour.
  ///
  /// The following example temporarily rebinds a raw memory pointer
  /// to `Int64`, then accesses a property on the signed integer.
  ///
  ///     let pointer: UnsafeRawPointer = fetchValue()
  ///     let isNegative = pointer.withMemoryRebound(to: Int64.self,
  ///                                                capacity: 1) {
  ///         return $0.pointee < 0
  ///     }
  ///
  /// After executing `body`, this method rebinds memory back to its original
  /// binding state. This can be unbound memory, or bound to a different type.
  ///
  /// - Note: The region of memory starting at this pointer must match the
  ///   alignment of `T` (as reported by `MemoryLayout<T>.alignment`).
  ///   That is, `Int(bitPattern: self) % MemoryLayout<T>.alignment`
  ///   must equal zero.
  ///
  /// - Note: The region of memory starting at this pointer may have been
  ///   bound to a type. If that is the case, then `T` must be
  ///   layout compatible with the type to which the memory has been bound.
  ///   This requirement does not apply if the region of memory
  ///   has not been bound to any type.
  ///
  /// - Parameters:
  ///   - type: The type to temporarily bind the memory referenced by this
  ///     pointer. This pointer must be a multiple of this type's alignment.
  ///   - count: The number of instances of `T` in the re-bound region.
  ///   - body: A closure that takes a typed pointer to the
  ///     same memory as this pointer, only bound to type `T`. The closure's
  ///     pointer argument is valid only for the duration of the closure's
  ///     execution. If `body` has a return value, that value is also used as
  ///     the return value for the `withMemoryRebound(to:capacity:_:)` method.
  ///   - pointer: The pointer temporarily bound to `T`.
  /// - Returns: The return value, if any, of the `body` closure parameter.
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    capacity count: Int,
    _ body: (_ pointer: UnsafePointer<T>) throws -> Result
  ) rethrows -> Result
}
extension UnsafeMutableRawPointer {
  /// Executes the given closure while temporarily binding memory to
  /// the specified number of instances of type `T`.
  ///
  /// Use this method when you have a pointer to raw memory and you need
  /// to access that memory as instances of a given type `T`. Accessing
  /// memory as a type `T` requires that the memory be bound to that type. A
  /// memory location may only be bound to one type at a time, so accessing
  /// the same memory as an unrelated type without first rebinding the memory
  /// is undefined.
  ///
  /// Any instance of `T` within the re-bound region may be initialized or
  /// uninitialized. The memory underlying any individual instance of `T`
  /// must have the same initialization state (i.e.  initialized or
  /// uninitialized.) Accessing a `T` whose underlying memory
  /// is in a mixed initialization state shall be undefined behaviour.
  ///
  /// The following example temporarily rebinds a raw memory pointer
  /// to `Int64`, then modifies the signed integer.
  ///
  ///     let pointer: UnsafeMutableRawPointer = fetchValue()
  ///     pointer.withMemoryRebound(to: Int64.self, capacity: 1) {
  ///         ptr.pointee.negate()
  ///     }
  ///
  /// After executing `body`, this method rebinds memory back to its original
  /// binding state. This can be unbound memory, or bound to a different type.
  ///
  /// - Note: The region of memory starting at this pointer must match the
  ///   alignment of `T` (as reported by `MemoryLayout<T>.alignment`).
  ///   That is, `Int(bitPattern: self) % MemoryLayout<T>.alignment`
  ///   must equal zero.
  ///
  /// - Note: The region of memory starting at this pointer may have been
  ///   bound to a type. If that is the case, then `T` must be
  ///   layout compatible with the type to which the memory has been bound.
  ///   This requirement does not apply if the region of memory
  ///   has not been bound to any type.
  ///
  /// - Parameters:
  ///   - type: The type to temporarily bind the memory referenced by this
  ///     pointer. This pointer must be a multiple of this type's alignment.
  ///   - count: The number of instances of `T` in the re-bound region.
  ///   - body: A closure that takes a typed pointer to the
  ///     same memory as this pointer, only bound to type `T`. The closure's
  ///     pointer argument is valid only for the duration of the closure's
  ///     execution. If `body` has a return value, that value is also used as
  ///     the return value for the `withMemoryRebound(to:capacity:_:)` method.
  ///   - pointer: The pointer temporarily bound to `T`.
  /// - Returns: The return value, if any, of the `body` closure parameter.
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    capacity count: Int,
    _ body: (_ pointer: UnsafeMutablePointer<T>) throws -> Result
  ) rethrows -> Result
}
extension UnsafeRawBufferPointer {
  /// Executes the given closure while temporarily binding the buffer to
  /// instances of type `T`.
  ///
  /// Use this method when you have a buffer to raw memory and you need
  /// to access that memory as instances of a given type `T`. Accessing
  /// memory as a type `T` requires that the memory be bound to that type.
  /// A memory location may only be bound to one type at a time, so accessing
  /// the same memory as an unrelated type without first rebinding the memory
  /// is undefined.
  ///
  /// Any instance of `T` within the re-bound region may be initialized or
  /// uninitialized. The memory underlying any individual instance of `T`
  /// must have the same initialization state (i.e.  initialized or
  /// uninitialized.) Accessing a `T` whose underlying memory
  /// is in a mixed initialization state shall be undefined behaviour.
  ///
  /// If the byte count of the original buffer is not a multiple of
  /// the stride of `T`, then the re-bound buffer is shorter
  /// than the original buffer.
  ///
  /// After executing `body`, this method rebinds memory back to its original
  /// binding state. This can be unbound memory, or bound to a different type.
  ///
  /// - Note: The buffer's base address must match the
  ///   alignment of `T` (as reported by `MemoryLayout<T>.alignment`).
  ///   That is, `Int(bitPattern: self.baseAddress) % MemoryLayout<T>.alignment`
  ///   must equal zero.
  ///
  /// - Note: A raw buffer may represent memory that has been bound to a type.
  ///   If that is the case, then `T` must be layout compatible with the
  ///   type to which the memory has been bound. This requirement does not
  ///   apply if the raw buffer represents memory that has not been bound
  ///   to any type.
  ///
  /// - Parameters:
  ///   - type: The type to temporarily bind the memory referenced by this
  ///     pointer. This pointer must be a multiple of this type's alignment.
  ///   - body: A closure that takes a typed pointer to the
  ///     same memory as this pointer, only bound to type `T`. The closure's
  ///     pointer argument is valid only for the duration of the closure's
  ///     execution. If `body` has a return value, that value is also used as
  ///     the return value for the `withMemoryRebound(to:capacity:_:)` method.
  ///   - buffer: The buffer temporarily bound to instances of `T`.
  /// - Returns: The return value, if any, of the `body` closure parameter.
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    _ body: (_ buffer: UnsafeBufferPointer<T>) throws -> Result
  ) rethrows -> Result

  /// Returns a typed buffer to the memory referenced by this buffer,
  /// assuming that the memory is already bound to the specified type.
  ///
  /// Use this method when you have a raw buffer to memory that has already
  /// been bound to the specified type. The memory starting at this pointer
  /// must be bound to the type `T`. Accessing memory through the returned
  /// pointer is undefined if the memory has not been bound to `T`. To bind
  /// memory to `T`, use `bindMemory(to:capacity:)` instead of this method.
  ///
  /// - Note: The buffer's base address must match the
  ///   alignment of `T` (as reported by `MemoryLayout<T>.alignment`).
  ///   That is, `Int(bitPattern: self.baseAddress) % MemoryLayout<T>.alignment`
  ///   must equal zero.
  ///
  /// - Parameter to: The type `T` that the memory has already been bound to.
  /// - Returns: A typed pointer to the same memory as this raw pointer.
  public func assumingMemoryBound<T>(
    to: T.Type
  ) -> UnsafeBufferPointer<T>
}
extension UnsafeMutableRawBufferPointer {
  /// Executes the given closure while temporarily binding the buffer to
  /// instances of type `T`.
  ///
  /// Use this method when you have a buffer to raw memory and you need
  /// to access that memory as instances of a given type `T`. Accessing
  /// memory as a type `T` requires that the memory be bound to that type.
  /// A memory location may only be bound to one type at a time, so accessing
  /// the same memory as an unrelated type without first rebinding the memory
  /// is undefined.
  ///
  /// Any instance of `T` within the re-bound region may be initialized or
  /// uninitialized. The memory underlying any individual instance of `T`
  /// must have the same initialization state (i.e.  initialized or
  /// uninitialized.) Accessing a `T` whose underlying memory
  /// is in a mixed initialization state shall be undefined behaviour.
  ///
  /// If the byte count of the original buffer is not a multiple of
  /// the stride of `T`, then the re-bound buffer is shorter
  /// than the original buffer.
  ///
  /// After executing `body`, this method rebinds memory back to its original
  /// binding state. This can be unbound memory, or bound to a different type.
  ///
  /// - Note: The buffer's base address must match the
  ///   alignment of `T` (as reported by `MemoryLayout<T>.alignment`).
  ///   That is, `Int(bitPattern: self.baseAddress) % MemoryLayout<T>.alignment`
  ///   must equal zero.
  ///
  /// - Note: A raw buffer may represent memory that has been bound to a type.
  ///   If that is the case, then `T` must be layout compatible with the
  ///   type to which the memory has been bound. This requirement does not
  ///   apply if the raw buffer represents memory that has not been bound
  ///   to any type.
  ///
  /// - Parameters:
  ///   - type: The type to temporarily bind the memory referenced by this
  ///     pointer. This pointer must be a multiple of this type's alignment.
  ///   - body: A closure that takes a typed pointer to the
  ///     same memory as this pointer, only bound to type `T`. The closure's
  ///     pointer argument is valid only for the duration of the closure's
  ///     execution. If `body` has a return value, that value is also used as
  ///     the return value for the `withMemoryRebound(to:capacity:_:)` method.
  ///   - buffer: The buffer temporarily bound to instances of `T`.
  /// - Returns: The return value, if any, of the `body` closure parameter.
  public func withMemoryRebound<T, Result>(
    to type: T.Type,
    _ body: (_ buffer: UnsafeMutableBufferPointer<T>) throws -> Result
  ) rethrows -> Result

  /// Returns a typed buffer to the memory referenced by this buffer,
  /// assuming that the memory is already bound to the specified type.
  ///
  /// Use this method when you have a raw buffer to memory that has already
  /// been bound to the specified type. The memory starting at this pointer
  /// must be bound to the type `T`. Accessing memory through the returned
  /// pointer is undefined if the memory has not been bound to `T`. To bind
  /// memory to `T`, use `bindMemory(to:capacity:)` instead of this method.
  ///
  /// - Note: The buffer's base address must match the
  ///   alignment of `T` (as reported by `MemoryLayout<T>.alignment`).
  ///   That is, `Int(bitPattern: self.baseAddress) % MemoryLayout<T>.alignment`
  ///   must equal zero.
  ///
  /// - Parameter to: The type `T` that the memory has already been bound to.
  /// - Returns: A typed pointer to the same memory as this raw pointer.
  public func assumingMemoryBound<T>(
    to: T.Type
  ) -> UnsafeMutableBufferPointer<T>
}

Source compatibility

This proposal is source-compatible. Some changes are compatible with existing correct uses of the API, while others are additive.

Effect on ABI stability

This proposal consists of ABI-preserving changes and ABI-additive changes.

Effect on API resilience

The behaviour change for the withMemoryRebound is compatible with previous uses, since restrictions were lifted. Code that depends on the new semantics may not be compatible with old versions of these functions. Back-deployment of new binaries will be supported by making the updated versions @_alwaysEmitIntoClient. Compatibility of old binaries with a new standard library will be supported by ensuring that a compatible entry point remains.

Alternatives considered

One alternative is to implement none of this change, and leave withMemoryRebound as is. The usability problems of withMemoryRebound would remain.

Another alternative is to leave the type layout restrictions as they are for the typed Pointer and BufferPointer types, but add the withMemoryRebound functions to the RawPointer and RawBufferPointer variants. In that case, the stride restriction would be no more than a speedbump, because it would be straightforward to bypass it by transiting through the appropriate Raw variant.

@atrick
Copy link

atrick commented Oct 7, 2021

@glessard

If a given instance of T overlaps with memory previously
/// bound to an uninitialized Pointee, it shall be considered uninitialized
/// when executing body.

I'm not sure we want to say this because it implies the following code is valid:

  func foo(buffer: UnsafeMutableBufferPointer<AnyObject>, object: AnyObject) {
    buffer[0] = object
    buffer.withMemoryRebound(to: (AnyObject, AnyObject).self) {
      let tuple = (object, object)
      $0.initialize(repeating: tuple)
    }
  }

We could say something like

"If a given instance of T overlaps with memory previously bound to an uninitialized Pointee, accessing that memory while it is bound to T is undefined behavior" (or "illegal" if you prefer)

@glessard
Copy link
Author

glessard commented Oct 7, 2021

Agreed: my wording wasn't right.

@atrick
Copy link

atrick commented Oct 7, 2021

For URBP.withMemoryRebound we need to replace the API docs for

count: The number of instances of `T` to bind to `type`.

to discuss the behavior when the byte count is not a multiple of T's stride.

We either assert or return a smaller buffer. asserting would be the safe bet of course.

Along those lines, we need to discuss the case when the byte buffer is not unbound. This should have the same constraints on the previously bound type as the typed withMemoryRebound

@glessard
Copy link
Author

glessard commented Oct 7, 2021

Fixed.

@atrick
Copy link

atrick commented Oct 7, 2021

Works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment