Skip to content

Commit d736586

Browse files
authored
[fso] Do not try to specialize pseudo-generic functions today. (swiftlang#33056)
This is just fixing an assert violation. I also needed to add support for target-sil-opt(mock-sdk: ...) so I added support to lit for that here. <rdar://problem/62262811> (cherry picked from commit 6049ce6)
1 parent 9b7c609 commit d736586

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

lib/SILOptimizer/FunctionSignatureTransforms/FunctionSignatureOpts.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ bool FunctionSignatureTransform::run(bool hasCaller) {
641641
TransformDescriptor.hasOnlyDirectInModuleCallers;
642642
SILFunction *F = TransformDescriptor.OriginalFunction;
643643

644-
645644
// If we are asked to assume a caller for testing purposes, set the flag.
646645
hasCaller |= FSOOptimizeIfNotCalled;
647646

@@ -651,6 +650,16 @@ bool FunctionSignatureTransform::run(bool hasCaller) {
651650
return false;
652651
}
653652

653+
// Bail if we have a pseudo-generic function. We do not handle these today. If
654+
// we let it through here we crash when attempting to compute the optimized
655+
// function type.
656+
//
657+
// TODO: Add support for this.
658+
if (F->getLoweredFunctionType()->isPseudogeneric()) {
659+
LLVM_DEBUG(llvm::dbgs() << " function is pseudo-generic -> abort\n");
660+
return false;
661+
}
662+
654663
// Run OwnedToGuaranteed optimization.
655664
if (OwnedToGuaranteedAnalyze()) {
656665
Changed = true;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %build-clang-importer-objc-overlays
3+
// RUN: %target-sil-opt(mock-sdk: %clang-importer-sdk-nosource -I %t) -function-signature-opts -sil-fso-optimize-if-not-called %s | %FileCheck %s
4+
5+
// Make sure that we do not try to specialize pseudo-generics with FSO.
6+
7+
// REQUIRES: objc_interop
8+
9+
sil_stage canonical
10+
11+
import Swift
12+
import Foundation
13+
import objc_generics
14+
15+
// CHECK: sil [signature_optimized_thunk] [always_inline] @non_pseudo_method :
16+
sil @non_pseudo_method : $@convention(thin) <T: AnyObject> (Int64) -> () {
17+
entry(%0 : $Int64):
18+
return undef : $()
19+
}
20+
21+
// CHECK: sil @method :
22+
sil @method : $@convention(method) @pseudogeneric <T: AnyObject> (Int64, @guaranteed GenericClass<T>) -> () {
23+
entry(%0 : $Int64, %1 : $GenericClass<T>):
24+
return undef : $()
25+
}
26+
27+
// CHECK: sil @objcMethod :
28+
sil @objcMethod : $@convention(objc_method) @pseudogeneric <T: AnyObject> (Int64, @guaranteed GenericClass<T>) -> () {
29+
entry(%0 : $Int64, %1 : $GenericClass<T>):
30+
return undef : $()
31+
}

test/lit.cfg

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,11 @@ if run_vendor == 'apple':
10011001
config.target_sil_opt = (
10021002
"%s %s %s %s" %
10031003
(xcrun_prefix, config.sil_opt, target_options, config.sil_test_options))
1004+
subst_target_sil_opt_mock_sdk = (
1005+
"%s %s" %
1006+
(config.sil_opt, target_options_for_mock_sdk))
1007+
subst_target_sil_opt_mock_sdk_after = \
1008+
target_options_for_mock_sdk_after
10041009
config.target_swift_symbolgraph_extract = (
10051010
"%s %s %s" %
10061011
(xcrun_prefix, config.swift_symbolgraph_extract, target_options))
@@ -1080,6 +1085,8 @@ elif run_os in ['windows-msvc']:
10801085
('%r -target %s %s %s %s' % (config.sil_opt, config.variant_triple, \
10811086
resource_dir_opt, mcp_opt, \
10821087
config.sil_test_options))
1088+
subst_target_sil_opt_mock_sdk = config.target_sil_opt
1089+
subst_target_sil_opt_mock_sdk_after = ''
10831090
config.target_swift_symbolgraph_extract = \
10841091
('%r -target %s %s' % (config.swift_symbolgraph_extract, \
10851092
config.variant_triple, \
@@ -1183,6 +1190,8 @@ elif (run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'openbsd', 'windows-
11831190
config.target_sil_opt = (
11841191
'%s -target %s %s %s %s' %
11851192
(config.sil_opt, config.variant_triple, resource_dir_opt, mcp_opt, config.sil_test_options))
1193+
subst_target_sil_opt_mock_sdk = config.target_sil_opt
1194+
subst_target_sil_opt_mock_sdk_after = ""
11861195
config.target_swift_symbolgraph_extract = (
11871196
'%s -target %s %s' %
11881197
(config.swift_symbolgraph_extract, config.variant_triple, mcp_opt))
@@ -1303,6 +1312,8 @@ elif run_os == 'linux-androideabi' or run_os == 'linux-android':
13031312
'-target', config.variant_triple,
13041313
android_include_paths_opt,
13051314
resource_dir_opt, mcp_opt, config.sil_test_options])
1315+
subst_target_sil_opt_mock_sdk = config.target_sil_opt
1316+
subst_target_sil_opt_mock_sdk_after = ""
13061317
config.target_swift_symbolgraph_extract = ' '.join([
13071318
config.swift_symbolgraph_extract,
13081319
'-target', config.variant_triple,
@@ -1754,7 +1765,13 @@ config.substitutions.append(('%scale-test',
17541765
config.substitutions.append(('%empty-directory\(([^)]+)\)',
17551766
SubstituteCaptures(r'rm -rf "\1" && mkdir -p "\1"')))
17561767

1768+
config.substitutions.append(('%target-sil-opt\(mock-sdk:([^)]+)\)',
1769+
SubstituteCaptures(r'%s \1 %s' % (subst_target_sil_opt_mock_sdk,
1770+
subst_target_sil_opt_mock_sdk_after))))
1771+
# NOTE: This needs to be appended after the mock-sdk expansion to ensure that we
1772+
# first expand the mock-sdk when lit is processing.
17571773
config.substitutions.append(('%target-sil-opt', config.target_sil_opt))
1774+
17581775
config.substitutions.append(('%target-sil-func-extractor', config.target_sil_func_extractor))
17591776
config.substitutions.append(('%target-sil-llvm-gen', config.target_sil_llvm_gen))
17601777
config.substitutions.append(('%target-sil-nm', config.target_sil_nm))

0 commit comments

Comments
 (0)