Skip to content

Conversation

@eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Jan 26, 2022

The specified deployment target only applies to the currently compiled module, but not to any client modules, which use inlinable functions from the current module.
Therefore, optimizations which depend on the deployment target must not optimize inlinable functions, except they run after the module has been serialized.

  • constant folding of availability checks
  • simplification of ARC operations on immortal objects (which depends on the 5.1 runtime)

rdar://88117184

The same thing needs to be done in Sema. There is already a PR for this: #33855, but unfortunately currently reverted.

@eeckstein
Copy link
Contributor Author

@swift-ci test

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci test

@aschwaighofer
Copy link
Contributor

We also need to fix availability guarded prespecialization uses. Something like:

--- a/lib/SILOptimizer/Utils/Generics.cpp
+++ b/lib/SILOptimizer/Utils/Generics.cpp
@@ -2512,7 +2512,21 @@ usePrespecialized(SILOptFunctionBuilder &funcBuilder, ApplySite apply,
     auto specializationAvail = SA->getAvailability();
     auto &ctxt = funcBuilder.getModule().getSwiftModule()->getASTContext();
     auto deploymentAvail = AvailabilityContext::forDeploymentTarget(ctxt);
-    auto currentFnAvailability = apply.getFunction()->getAvailabilityForLinkage();
+    auto currentFn = apply.getFunction();
+    auto isInlinableCtxt = currentFn->getResilienceExpansion()
+      == ResilienceExpansion::Minimal;
+    auto currentFnAvailability = currentFn->getAvailabilityForLinkage();
+
+    // If we are in an inlineable function we can't use the specialization except
+    // it the inlinable function itself has availability we can used.
+    if (currentFnAvailability.isAlwaysAvailable() &&
+        isInlinableCtxt) {
+      continue;
+    }
+    else if (isInlinableCtxt) {
+      deploymentAvail = currentFnAvailability;
+    }
+
     if (!currentFnAvailability.isAlwaysAvailable() &&
         !deploymentAvail.isContainedIn(currentFnAvailability))
       deploymentAvail = currentFnAvailability;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Knitpick. Should we move this earlier in this function before the other checks.

Copy link
Contributor

@aschwaighofer aschwaighofer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - d38bb040474b6b2929cffd3f9b069c50c1607889

@eeckstein eeckstein force-pushed the fix-availability-checks branch from d38bb04 to 2f5aa9e Compare January 27, 2022 08:00
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein eeckstein force-pushed the fix-availability-checks branch from 2f5aa9e to 9016c2c Compare January 27, 2022 12:24
because they need a minimum deployment target, which might not be available in client modules, which de-serialize such functions.
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@eeckstein eeckstein merged commit e5433cd into swiftlang:main Jan 27, 2022
@eeckstein eeckstein deleted the fix-availability-checks branch January 27, 2022 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants