Skip to content

Commit 9548ba6

Browse files
authored
Merge pull request #4385 from swiftwasm/release/5.6
[pull] swiftwasm-release/5.6 from release/5.6
2 parents 8a512b3 + 4bbe435 commit 9548ba6

File tree

5 files changed

+68
-10
lines changed

5 files changed

+68
-10
lines changed

lib/SILOptimizer/Utils/ConstantFolding.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,11 @@ static bool isApplyOfBuiltin(SILInstruction &I, BuiltinValueKind kind) {
14081408
}
14091409

14101410
static bool isApplyOfKnownAvailability(SILInstruction &I) {
1411+
// Inlinable functions can be deserialized in other modules which can be
1412+
// compiled with a different deployment target.
1413+
if (I.getFunction()->getResilienceExpansion() != ResilienceExpansion::Maximal)
1414+
return false;
1415+
14111416
auto apply = FullApplySite::isa(&I);
14121417
if (!apply)
14131418
return false;

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,20 @@ usePrespecialized(SILOptFunctionBuilder &funcBuilder, ApplySite apply,
24962496
auto specializationAvail = SA->getAvailability();
24972497
auto &ctxt = funcBuilder.getModule().getSwiftModule()->getASTContext();
24982498
auto deploymentAvail = AvailabilityContext::forDeploymentTarget(ctxt);
2499-
auto currentFnAvailability = apply.getFunction()->getAvailabilityForLinkage();
2499+
auto currentFn = apply.getFunction();
2500+
auto isInlinableCtxt = (currentFn->getResilienceExpansion()
2501+
== ResilienceExpansion::Minimal);
2502+
auto currentFnAvailability = currentFn->getAvailabilityForLinkage();
2503+
2504+
// If we are in an inlineable function we can't use the specialization except
2505+
// the inlinable function itself has availability we can use.
2506+
if (currentFnAvailability.isAlwaysAvailable() && isInlinableCtxt) {
2507+
continue;
2508+
}
2509+
else if (isInlinableCtxt) {
2510+
deploymentAvail = currentFnAvailability;
2511+
}
2512+
25002513
if (!currentFnAvailability.isAlwaysAvailable() &&
25012514
!deploymentAvail.isContainedIn(currentFnAvailability))
25022515
deploymentAvail = currentFnAvailability;

lib/Sema/MiscDiagnostics.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4723,19 +4723,20 @@ static void diagUnqualifiedAccessToMethodNamedSelf(const Expr *E,
47234723
if (auto typeContext = DC->getInnermostTypeContext()) {
47244724
// self() is not easily confusable
47254725
if (!isa<CallExpr>(Parent.getAsExpr())) {
4726-
47274726
auto baseType = typeContext->getDeclaredInterfaceType();
4728-
auto baseTypeString = baseType.getString();
4727+
if (!baseType->getEnumOrBoundGenericEnum()) {
4728+
auto baseTypeString = baseType.getString();
47294729

4730-
Ctx.Diags.diagnose(E->getLoc(), diag::self_refers_to_method,
4731-
baseTypeString);
4730+
Ctx.Diags.diagnose(E->getLoc(), diag::self_refers_to_method,
4731+
baseTypeString);
47324732

4733-
Ctx.Diags
4733+
Ctx.Diags
47344734
.diagnose(E->getLoc(),
4735-
diag::fix_unqualified_access_member_named_self,
4736-
baseTypeString)
4735+
diag::fix_unqualified_access_member_named_self,
4736+
baseTypeString)
47374737
.fixItInsert(E->getLoc(), diag::insert_type_qualification,
4738-
baseType);
4738+
baseType);
4739+
}
47394740
}
47404741
}
47414742
}

test/Parse/self_rebinding.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,13 @@ struct TypeWithSelfProperty {
116116

117117
let `self`: () = ()
118118
}
119+
120+
enum EnumCaseNamedSelf {
121+
case `self`
122+
123+
init() {
124+
self = .self // OK
125+
self = .`self` // OK
126+
self = EnumCaseNamedSelf.`self` // OK
127+
}
128+
}

test/SILOptimizer/constant_propagation_availability.swift

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// RUN: %target-swift-frontend -target %target-cpu-apple-macos10.15 -emit-sil %s | %FileCheck --check-prefix=CHECK-macosx10_15 %s
22
// RUN: %target-swift-frontend -target %target-cpu-apple-macos10.14 -emit-sil %s | %FileCheck --check-prefix=CHECK-macosx10_14 %s
3-
// RUN: %target-swift-frontend -O -target %target-cpu-apple-macos10.15 -emit-sil %s | %FileCheck --check-prefix=CHECK-macosx10_15 %s
3+
// RUN: %target-swift-frontend -O -target %target-cpu-apple-macos10.15 -emit-sil %s | %FileCheck --check-prefix=CHECK-macosx10_15 --check-prefix=CHECK-macosx10_15_opt %s
44
// RUN: %target-swift-frontend -O -target %target-cpu-apple-macos10.14 -emit-sil %s | %FileCheck --check-prefix=CHECK-macosx10_14 %s
55

6+
// RUN: %empty-directory(%t)
7+
// RUN: %target-swift-frontend -O -target %target-cpu-apple-macos10.15 -module-name=Test -emit-module -emit-module-path %t/Test.swiftmodule %s
8+
// RUN: %sil-opt -target %target-cpu-apple-macos10.15 %t/Test.swiftmodule | %FileCheck --check-prefix=CHECK-inlinable %s
9+
610
// REQUIRES: OS=macosx
711

812
@available(macOS 10.15, *)
@@ -24,13 +28,31 @@ public func testAvailabilityPropagation() -> Int {
2428
}
2529
}
2630

31+
@inlinable
32+
public func testInlinable() -> Int {
33+
if #available(macOS 10.15, *) {
34+
return newFunction()
35+
} else {
36+
return 0
37+
}
38+
}
39+
2740
// CHECK-macosx10_15-LABEL: sil @$s33constant_propagation_availability27testAvailabilityPropagationSiyF : $@convention(thin) () -> Int {
2841
// CHECK-macosx10_15-NOT: apply
2942
// CHECK-macosx10_15: [[F:%.*]] = function_ref @$s33constant_propagation_availability11newFunctionSiyF
3043
// CHECK-macosx10_15: apply [[F]]() : $@convention(thin) () -> Int
3144
// CHECK-macosx10_15-NOT: apply
3245
// CHECK-macosx10_15: } // end sil function '$s33constant_propagation_availability27testAvailabilityPropagationSiyF'
3346

47+
// After serialization, availability checks can be constant folded.
48+
49+
// CHECK-macosx10_15_opt-LABEL: sil @$s33constant_propagation_availability13testInlinableSiyF : $@convention(thin) () -> Int {
50+
// CHECK-macosx10_15_opt-NOT: apply
51+
// CHECK-macosx10_15_opt: [[F:%.*]] = function_ref @$s33constant_propagation_availability11newFunctionSiyF
52+
// CHECK-macosx10_15_opt: apply [[F]]() : $@convention(thin) () -> Int
53+
// CHECK-macosx10_15_opt-NOT: apply
54+
// CHECK-macosx10_15_opt: } // end sil function '$s33constant_propagation_availability13testInlinableSiyF'
55+
3456
// CHECK-macosx10_14-LABEL: sil @$s33constant_propagation_availability27testAvailabilityPropagationSiyF : $@convention(thin) () -> Int {
3557
// CHECK-macosx10_14: [[F:%.*]] = function_ref @$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF
3658
// CHECK-macosx10_14: apply [[F]]
@@ -41,3 +63,10 @@ public func testAvailabilityPropagation() -> Int {
4163
// CHECK-macosx10_14: } // end sil function '$s33constant_propagation_availability27testAvailabilityPropagationSiyF'
4264

4365
// CHECK-macosx10_14: sil [readnone] [_semantics "availability.osversion"] @$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF
66+
67+
// CHECK-inlinable-LABEL: sil {{.*}} @$s4Test13testInlinableSiyF : $@convention(thin) () -> Int {
68+
// CHECK-inlinable: [[F:%.*]] = function_ref @$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF
69+
// CHECK-inlinable: apply [[F]]
70+
// CHECK-inlinable: [[F:%.*]] = function_ref @$s4Test11newFunctionSiyF
71+
// CHECK-inlinable: apply [[F]]() : $@convention(thin) () -> Int
72+
// CHECK-inlinable: } // end sil function '$s4Test13testInlinableSiyF'

0 commit comments

Comments
 (0)