Skip to content

Commit 6049ce6

Browse files
committed
[fso] Do not try to specialize pseudo-generic functions today.
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>
1 parent 417e173 commit 6049ce6

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
@@ -642,7 +642,6 @@ bool FunctionSignatureTransform::run(bool hasCaller) {
642642
TransformDescriptor.hasOnlyDirectInModuleCallers;
643643
SILFunction *F = TransformDescriptor.OriginalFunction;
644644

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

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

654+
// Bail if we have a pseudo-generic function. We do not handle these today. If
655+
// we let it through here we crash when attempting to compute the optimized
656+
// function type.
657+
//
658+
// TODO: Add support for this.
659+
if (F->getLoweredFunctionType()->isPseudogeneric()) {
660+
LLVM_DEBUG(llvm::dbgs() << " function is pseudo-generic -> abort\n");
661+
return false;
662+
}
663+
655664
// Run OwnedToGuaranteed optimization.
656665
if (OwnedToGuaranteedAnalyze()) {
657666
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
@@ -962,6 +962,11 @@ if run_vendor == 'apple':
962962
config.target_sil_opt = (
963963
"%s %s %s %s" %
964964
(xcrun_prefix, config.sil_opt, target_options, config.sil_test_options))
965+
subst_target_sil_opt_mock_sdk = (
966+
"%s %s" %
967+
(config.sil_opt, target_options_for_mock_sdk))
968+
subst_target_sil_opt_mock_sdk_after = \
969+
target_options_for_mock_sdk_after
965970
config.target_swift_symbolgraph_extract = (
966971
"%s %s %s" %
967972
(xcrun_prefix, config.swift_symbolgraph_extract, target_options))
@@ -1042,6 +1047,8 @@ elif run_os in ['windows-msvc']:
10421047
('%r -target %s %s %s %s' % (config.sil_opt, config.variant_triple, \
10431048
resource_dir_opt, mcp_opt, \
10441049
config.sil_test_options))
1050+
subst_target_sil_opt_mock_sdk = config.target_sil_opt
1051+
subst_target_sil_opt_mock_sdk_after = ''
10451052
config.target_swift_symbolgraph_extract = \
10461053
('%r -target %s %s' % (config.swift_symbolgraph_extract, \
10471054
config.variant_triple, \
@@ -1151,6 +1158,8 @@ elif (run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'openbsd', 'windows-
11511158
config.target_sil_opt = (
11521159
'%s -target %s %s %s %s' %
11531160
(config.sil_opt, config.variant_triple, resource_dir_opt, mcp_opt, config.sil_test_options))
1161+
subst_target_sil_opt_mock_sdk = config.target_sil_opt
1162+
subst_target_sil_opt_mock_sdk_after = ""
11541163
config.target_swift_symbolgraph_extract = (
11551164
'%s -target %s %s' %
11561165
(config.swift_symbolgraph_extract, config.variant_triple, mcp_opt))
@@ -1272,6 +1281,8 @@ elif run_os == 'linux-androideabi' or run_os == 'linux-android':
12721281
'-target', config.variant_triple,
12731282
android_include_paths_opt,
12741283
resource_dir_opt, mcp_opt, config.sil_test_options])
1284+
subst_target_sil_opt_mock_sdk = config.target_sil_opt
1285+
subst_target_sil_opt_mock_sdk_after = ""
12751286
config.target_swift_symbolgraph_extract = ' '.join([
12761287
config.swift_symbolgraph_extract,
12771288
'-target', config.variant_triple,
@@ -1794,7 +1805,13 @@ config.substitutions.append(('%scale-test',
17941805
config.substitutions.append(('%empty-directory\(([^)]+)\)',
17951806
SubstituteCaptures(r'rm -rf "\1" && mkdir -p "\1"')))
17961807

1808+
config.substitutions.append(('%target-sil-opt\(mock-sdk:([^)]+)\)',
1809+
SubstituteCaptures(r'%s \1 %s' % (subst_target_sil_opt_mock_sdk,
1810+
subst_target_sil_opt_mock_sdk_after))))
1811+
# NOTE: This needs to be appended after the mock-sdk expansion to ensure that we
1812+
# first expand the mock-sdk when lit is processing.
17971813
config.substitutions.append(('%target-sil-opt', config.target_sil_opt))
1814+
17981815
config.substitutions.append(('%target-sil-func-extractor', config.target_sil_func_extractor))
17991816
config.substitutions.append(('%target-sil-llvm-gen', config.target_sil_llvm_gen))
18001817
config.substitutions.append(('%target-sil-nm', config.target_sil_nm))

0 commit comments

Comments
 (0)