← Back to Pull requests

Sema: respect @usableFromInline / AEIC on property setters in inlinable-access check. #90315

Open
nkcsgexi opened this pull request with 60 lines diff across 3 files
View on GitHub
nkcsgexi nkcsgexi commented on Jul 01, 2026 00:29 UTC
Author
Diff: 60 lines (+59 / -1) across 3 files Reviewer: tshortli Review duration: 225606m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.38) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.38 · 60 lines diff across 3 files
0.38
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 5 substantive comment(s)
0.91
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
85%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.246
Real PR Conversation Timeline
8 items
nkcsgexi nkcsgexi commented on Jul 01, 2026 00:30 UTC
Author

@swift-ci please smoke test

tshortli tshortli commented on code on Jul 01, 2026 02:37 UTC
Code Review
lib/Sema/ResilienceDiagnostics.cpp:1
@@ -50,6 +50,18 @@ static bool addMissingImport(SourceLoc loc, const Decl *D,
   return true;
 }
 
+/// Whether a setter is referenceable from inlinable code, even if its formal
+/// access is narrower than its storage's.
+static bool isSetterUsableFromInline(const AccessorDecl *accessor) {
+  assert(accessor->isSetter() && "expected a setter accessor");
+  auto *storage = accessor->getStorage();
+  return accessor->getAttrs().hasAttribute<UsableFromInlineAttr>() ||

Isn't this duplicating logic that should be part of ValueDecl::isUsableFromInline()?

sepy97 sepy97 commented on code on Jul 01, 2026 17:17 UTC
Code Review
lib/Sema/ResilienceDiagnostics.cpp:1
@@ -88,7 +100,8 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
     if (auto *accessor = dyn_cast<AccessorDecl>(D)) {
       if (accessor->getAccessorKind() == AccessorKind::Set) {
         auto storage = accessor->getStorage();
-        if (accessor->getFormalAccess() < storage->getFormalAccess()) {
+        if (!isSetterUsableFromInline(accessor) &&

It's not a big deal, but is it not faster to first check getFormalAccess() levels and then call isSetterUsableFromInline(...)?

sepy97 sepy97 commented on Jul 01, 2026 17:18 UTC
Reviewer

Besides my comment, looks good, thanks!

tshortli tshortli commented on Jul 01, 2026 18:12 UTC
Contributor

This fix ensures that Sema accepts these patterns, but are we sure they function correctly? Are these cases already tested in the ModuleInterface suite and in SILGen to ensure that the compiler emits the setters with the correct linkage visibility?

nkcsgexi nkcsgexi commented on Jul 01, 2026 21:30 UTC
Author

@tshortli You're right to push on this! I checked end-to-end and the module interface printing story doesn't line up well with the drop of the warning. For @usableFromInline set the printer drops internal(set) and emits @usableFromInline on a now-public setter (illegal); for @_alwaysEmitIntoClient the setter isn't surfaced in the interface at all, so inlinable code that assigns it can't round-trip. These warnings are desirable to make sure the module interface is healthy.

nkcsgexi nkcsgexi commented on Jul 01, 2026 21:32 UTC
Author

I plan to redirect these added tests to test that we do emit warnings here. Any objections?

Reviewers
Assignees
nkcsgexi nkcsgexi
Labels
risk: low confidence: 85.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 37.5% (MEDIUM) · Higher = larger blast radius
37.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 85.7% · Lower = rushed or shallow review
85.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 5.3% · Safe to merge
5.3%