mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[embedded] Support _findStringSwitchCaseWithCache in Embedded Swift
This commit is contained in:
@@ -80,6 +80,16 @@ fileprivate struct PathFunctionTuple: Hashable {
|
||||
|
||||
private func optimize(function: Function, _ context: FunctionPassContext, _ moduleContext: ModulePassContext, _ worklist: inout FunctionWorklist) {
|
||||
var alreadyInlinedFunctions: Set<PathFunctionTuple> = Set()
|
||||
|
||||
// ObjectOutliner replaces calls to findStringSwitchCase with _findStringSwitchCaseWithCache, but this happens as a late SIL optimization,
|
||||
// which is a problem for Embedded Swift, because _findStringSwitchCaseWithCache will then reference non-specialized code. Solve this by
|
||||
// eagerly linking and specializing _findStringSwitchCaseWithCache whenever findStringSwitchCase is found in the module.
|
||||
if context.options.enableEmbeddedSwift {
|
||||
if function.hasSemanticsAttribute("findStringSwitchCase"),
|
||||
let f = context.lookupStdlibFunction(name: "_findStringSwitchCaseWithCache") {
|
||||
worklist.pushIfNotVisited(f)
|
||||
}
|
||||
}
|
||||
|
||||
var changed = true
|
||||
while changed {
|
||||
|
||||
@@ -1929,7 +1929,11 @@ OptionalBridgedFunction BridgedPassContext::lookupStdlibFunction(BridgedStringRe
|
||||
|
||||
SILDeclRef declRef(decl, SILDeclRef::Kind::Func);
|
||||
SILOptFunctionBuilder funcBuilder(*invocation->getTransform());
|
||||
return {funcBuilder.getOrCreateFunction(SILLocation(decl), declRef, NotForDefinition)};
|
||||
SILFunction *function = funcBuilder.getOrCreateFunction(SILLocation(decl), declRef, NotForDefinition);
|
||||
if (mod->getOptions().EmbeddedSwift) {
|
||||
mod->linkFunction(function, SILModule::LinkingMode::LinkAll);
|
||||
}
|
||||
return {function};
|
||||
}
|
||||
|
||||
OptionalBridgedFunction BridgedPassContext::lookUpNominalDeinitFunction(BridgedDeclObj nominal) const {
|
||||
|
||||
37
test/embedded/string-switch2.swift
Normal file
37
test/embedded/string-switch2.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -wmo -O -Xlinker %swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos/libswiftUnicodeDataTables.a) | %FileCheck %s
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: optimized_stdlib
|
||||
// REQUIRES: swift_stdlib_no_asserts
|
||||
// REQUIRES: OS=macosx
|
||||
// REQUIRES: swift_feature_Embedded
|
||||
|
||||
enum MyEnum: String {
|
||||
case case1
|
||||
case case2
|
||||
case case3
|
||||
case case4
|
||||
case case5
|
||||
case case6
|
||||
case case7
|
||||
case case8
|
||||
case case9
|
||||
case case10
|
||||
case case11
|
||||
case case12
|
||||
case case13
|
||||
case case14
|
||||
case case15
|
||||
case case16
|
||||
case case17
|
||||
case case18
|
||||
case case19
|
||||
}
|
||||
|
||||
var e = MyEnum.case1
|
||||
print(e.rawValue)
|
||||
e = MyEnum.case2
|
||||
print(e.rawValue)
|
||||
// CHECK: case1
|
||||
// CHECK: case2
|
||||
Reference in New Issue
Block a user