mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Closure literals are sometimes type-checked as one type then immediately converted to another type in the AST. One particular case of this is when a closure body never throws, but the closure is used as an argument to a function that takes a parameter that `throws`. Emitting this naively, by emitting the closure as its original type, then converting to throws, can be expensive for async closures, since that takes a reabstraction thunk. Even for non-async functions, we still want to get the benefit of reabstraction optimization for the closure literal through the conversion too. So if the function conversion just add `throws`, emit the closure as throwing, and pass down the context abstraction pattern when emitting the closure as well.
55 lines
1.5 KiB
Swift
55 lines
1.5 KiB
Swift
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
|
|
|
|
@frozen
|
|
public struct UnicodeScalar {
|
|
var _value: UInt32
|
|
public var value: UInt32 { return _value }
|
|
}
|
|
|
|
public func mangle(s: [UnicodeScalar]) -> [UnicodeScalar] {
|
|
let replacementUnichar = UnicodeScalar(_value: 0)
|
|
var mangledUnichars: [UnicodeScalar] = s.map {
|
|
switch $0.value {
|
|
case
|
|
// A-Z
|
|
0x0041...0x005A,
|
|
// a-z
|
|
0x0061...0x007A,
|
|
// 0-9
|
|
0x0030...0x0039,
|
|
// _
|
|
0x005F,
|
|
// Latin (1)
|
|
0x00AA...0x00AA:
|
|
return $0
|
|
default:
|
|
return replacementUnichar
|
|
}
|
|
}
|
|
return mangledUnichars
|
|
}
|
|
|
|
// The patterns in the first case statement each define an anonymous variable,
|
|
// which shares the storage with the expression in the switch statement.
|
|
|
|
// Do we care to expose these via lldb?
|
|
|
|
// CHECK: define {{.*}}@"$s11patternvars6mangle1sSayAA13UnicodeScalarVGAF_tFA2EXEfU_"
|
|
// CHECK: %[[VAL:[0-9]+]] = call swiftcc i32 @"$s11patternvars13UnicodeScalarV5values6UInt32Vvg"(
|
|
// CHECK: {{[0-9]+}}:
|
|
// CHECK-NOT: call void @llvm.dbg.value
|
|
// CHECK-NOT: call void asm sideeffect "", "r"
|
|
|
|
// CHECK: {{[0-9]+}}:
|
|
// CHECK-NOT: call void @llvm.dbg.value
|
|
// CHECK-NOT: call void asm sideeffect "", "r"
|
|
|
|
// CHECK: {{[0-9]+}}:
|
|
// CHECK-NOT: call void @llvm.dbg.value
|
|
// CHECK-NOT: call void asm sideeffect "", "r"
|
|
|
|
// CHECK: {{[0-9]+}}:
|
|
// CHECK-NOT: call void @llvm.dbg.value
|
|
// CHECK-NOT: call void asm sideeffect "", "r"
|
|
|