Skip to content

Commit 834bb63

Browse files
committed
Sema: Refactor source of truth for exceptions to exportability check
1 parent 627b8f9 commit 834bb63

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
294294
}
295295
});
296296

297+
if (where.canReferenceOrigin(originKind))
298+
return false;
299+
297300
auto fragileKind = where.getFragileFunctionKind();
298301
switch (originKind) {
299302
case DisallowedOriginKind::None:
@@ -326,14 +329,10 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
326329
if (reason && reason == ExportabilityReason::AvailableAttribute &&
327330
ctx.LangOpts.LibraryLevel == LibraryLevel::API)
328331
return false;
329-
LLVM_FALLTHROUGH;
332+
break;
330333

331334
case DisallowedOriginKind::SPIImported:
332335
case DisallowedOriginKind::SPILocal:
333-
if (fragileKind.kind == FragileFunctionKind::EmbeddedAlwaysEmitIntoClient)
334-
return false;
335-
break;
336-
337336
case DisallowedOriginKind::ImplementationOnly:
338337
case DisallowedOriginKind::FragileCxxAPI:
339338
case DisallowedOriginKind::ImplementationOnlyMemoryLayout:

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,27 @@ bool ExportContext::canReferenceOrigin(DisallowedOriginKind originKind) const {
239239
if (originKind == DisallowedOriginKind::None)
240240
return true;
241241

242-
// Non public imports aren't hidden dependencies in embedded mode,
243-
// don't enforce them on implicitly always emit into client code.
244-
if (originKind == DisallowedOriginKind::NonPublicImport &&
245-
getFragileFunctionKind().kind ==
246-
FragileFunctionKind::EmbeddedAlwaysEmitIntoClient)
247-
return true;
242+
// Implicitly always emit into client code in embedded mode can still
243+
// access many restricted origins as more dependencies are loaded
244+
// in non-library-evolution mode and there isn't an enforced separation of
245+
// public vs SPI.
246+
if (getFragileFunctionKind().kind ==
247+
FragileFunctionKind::EmbeddedAlwaysEmitIntoClient) {
248+
switch (originKind) {
249+
case DisallowedOriginKind::None:
250+
case DisallowedOriginKind::NonPublicImport:
251+
case DisallowedOriginKind::SPIOnly:
252+
case DisallowedOriginKind::SPIImported:
253+
case DisallowedOriginKind::SPILocal:
254+
return true;
255+
case DisallowedOriginKind::MissingImport:
256+
case DisallowedOriginKind::InternalBridgingHeaderImport:
257+
case DisallowedOriginKind::ImplementationOnly:
258+
case DisallowedOriginKind::FragileCxxAPI:
259+
case DisallowedOriginKind::ImplementationOnlyMemoryLayout:
260+
break;
261+
}
262+
}
248263

249264
return false;
250265
}

0 commit comments

Comments
 (0)