Skip to content

Commit 5c334c5

Browse files
committed
Requestify the loading of access notes
Replace `loadAccessNotesIfNeeded` with a request that loads the access notes on-demand.
1 parent 033638e commit 5c334c5

File tree

11 files changed

+85
-43
lines changed

11 files changed

+85
-43
lines changed

include/swift/AST/ASTContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,10 @@ class ASTContext final {
16261626
AvailabilityDomain getTargetAvailabilityDomain() const;
16271627
};
16281628

1629+
inline SourceLoc extractNearestSourceLoc(const ASTContext *ctx) {
1630+
return SourceLoc();
1631+
}
1632+
16291633
} // end namespace swift
16301634

16311635
#endif

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,6 @@ WARNING(module_incompatible_with_skip_function_bodies,none,
565565
"-experimental-skip-*-function-bodies* flags; they have "
566566
"been automatically disabled", (StringRef))
567567

568-
WARNING(access_notes_file_io_error,none,
569-
"ignored access notes file at '%0' because it cannot be read: %1",
570-
(StringRef, StringRef))
571568
WARNING(error_in_access_notes_file,none,
572569
"ignored access notes file because it cannot be parsed: %0",
573570
(StringRef))

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7853,6 +7853,10 @@ ERROR(atomics_ordering_must_be_constant, none,
78537853

78547854
#define WHICH_ACCESS_NOTE(reason) "specified by access note for %" #reason
78557855

7856+
WARNING(access_notes_file_io_error,none,
7857+
"ignored access notes file at '%0' because it cannot be read: %1",
7858+
(StringRef, StringRef))
7859+
78567860
REMARK(attr_added_by_access_note, none,
78577861
"implicitly added '%1' to this %kindonly2, as " WHICH_ACCESS_NOTE(0),
78587862
(StringRef, StringRef, const ValueDecl *))

include/swift/AST/Module.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,6 @@ class ModuleDecl
345345
/// \see EntryPointInfoTy
346346
EntryPointInfoTy EntryPointInfo;
347347

348-
AccessNotesFile accessNotes;
349-
350348
/// Used by the debugger to bypass resilient access to fields.
351349
bool BypassResilience = false;
352350

@@ -415,8 +413,9 @@ class ModuleDecl
415413
/// imports.
416414
ImplicitImportList getImplicitImports() const;
417415

418-
AccessNotesFile &getAccessNotes() { return accessNotes; }
419-
const AccessNotesFile &getAccessNotes() const { return accessNotes; }
416+
/// Retrieve the access notes to apply for the module, or \c nullptr if there
417+
/// are no access notes.
418+
const AccessNotesFile *getAccessNotes() const;
420419

421420
/// Return whether the module was imported with resilience disabled. The
422421
/// debugger does this to access private fields.

include/swift/AST/TypeCheckRequests.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4089,6 +4089,31 @@ class PrimarySourceFilesRequest
40894089
bool isCached() const { return true; }
40904090
};
40914091

4092+
/// Load the access notes to apply for the main module.
4093+
///
4094+
/// Note this is keyed on the ASTContext instead of the ModuleDecl to avoid
4095+
/// needing to re-load the access notes in cases where we have multiple main
4096+
/// modules, e.g when doing cached top-level code completion.
4097+
///
4098+
/// FIXME: This isn't really a type-checking request, if we ever split off a
4099+
/// zone for more general requests, this should be moved there.
4100+
class LoadAccessNotesRequest
4101+
: public SimpleRequest<LoadAccessNotesRequest,
4102+
const AccessNotesFile *(ASTContext *),
4103+
RequestFlags::Cached> {
4104+
public:
4105+
using SimpleRequest::SimpleRequest;
4106+
4107+
private:
4108+
friend SimpleRequest;
4109+
4110+
const AccessNotesFile *evaluate(Evaluator &evaluator, ASTContext *ctx) const;
4111+
4112+
public:
4113+
// Cached.
4114+
bool isCached() const { return true; }
4115+
};
4116+
40924117
/// Kinds of types for CustomAttr.
40934118
enum class CustomAttrTypeKind {
40944119
/// The type is required to not be expressed in terms of

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ SWIFT_REQUEST(TypeChecker, PatternBindingCheckedAndContextualizedInitRequest,
275275
SeparatelyCached, NoLocationInfo)
276276
SWIFT_REQUEST(TypeChecker, PrimarySourceFilesRequest,
277277
ArrayRef<SourceFile *>(ModuleDecl *), Cached, NoLocationInfo)
278+
SWIFT_REQUEST(TypeChecker, LoadAccessNotesRequest,
279+
const AccessNotesFile *(ASTContext *), Cached, NoLocationInfo)
278280
SWIFT_REQUEST(TypeChecker, PropertyWrapperAuxiliaryVariablesRequest,
279281
PropertyWrapperAuxiliaryVariables(VarDecl *),
280282
SeparatelyCached | SplitCached,

include/swift/Frontend/Frontend.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,6 @@ class CompilerInstance {
790790
/// Parses and type-checks all input files.
791791
void performSema();
792792

793-
/// Loads any access notes for the main module.
794-
///
795-
/// FIXME: This should be requestified.
796-
void loadAccessNotesIfNeeded();
797-
798793
/// Parses and performs import resolution on all input files.
799794
///
800795
/// This is similar to a parse-only invocation, but module imports will also

lib/AST/Module.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,16 @@ ImplicitImportList ModuleDecl::getImplicitImports() const {
823823
{});
824824
}
825825

826+
const AccessNotesFile *ModuleDecl::getAccessNotes() const {
827+
// Only the main module has access notes.
828+
if (!isMainModule())
829+
return nullptr;
830+
831+
auto &ctx = getASTContext();
832+
return evaluateOrDefault(ctx.evaluator, LoadAccessNotesRequest{&ctx},
833+
nullptr);
834+
}
835+
826836
SourceFile *ModuleDecl::getSourceFileContainingLocation(SourceLoc loc) {
827837
if (loc.isInvalid())
828838
return nullptr;

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,38 +1553,13 @@ void CompilerInstance::setMainModule(ModuleDecl *newMod) {
15531553
Context->MainModule = newMod;
15541554
}
15551555

1556-
void CompilerInstance::loadAccessNotesIfNeeded() {
1557-
if (Invocation.getLangOptions().AccessNotesPath.empty())
1558-
return;
1559-
1560-
auto *mainModule = getMainModule();
1561-
1562-
auto accessNotesPath = Invocation.getLangOptions().AccessNotesPath;
1563-
1564-
auto bufferOrError =
1565-
swift::vfs::getFileOrSTDIN(getFileSystem(), accessNotesPath);
1566-
if (bufferOrError) {
1567-
int sourceID = SourceMgr.addNewSourceBuffer(std::move(bufferOrError.get()));
1568-
auto buffer = SourceMgr.getLLVMSourceMgr().getMemoryBuffer(sourceID);
1569-
1570-
if (auto accessNotesFile = AccessNotesFile::load(*Context, buffer))
1571-
mainModule->getAccessNotes() = *accessNotesFile;
1572-
} else {
1573-
Diagnostics.diagnose(SourceLoc(), diag::access_notes_file_io_error,
1574-
accessNotesPath, bufferOrError.getError().message());
1575-
}
1576-
}
1577-
15781556
bool CompilerInstance::performParseAndResolveImportsOnly() {
15791557
FrontendStatsTracer tracer(getStatsReporter(), "parse-and-resolve-imports");
15801558

15811559
// NOTE: Do not add new logic to this function, use the request evaluator to
15821560
// lazily evaluate instead. Once the below computations are requestified we
15831561
// ought to be able to remove this function.
15841562

1585-
// Load access notes.
1586-
loadAccessNotesIfNeeded();
1587-
15881563
// Resolve imports for all the source files in the module.
15891564
auto *mainModule = getMainModule();
15901565
performImportResolution(mainModule);

lib/IDETool/IDEInspectionInstance.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ void IDEInspectionInstance::performNewOperation(
517517
CI->getASTContext().CancellationFlag = CancellationFlag;
518518
registerIDERequestFunctions(CI->getASTContext().evaluator);
519519

520-
CI->loadAccessNotesIfNeeded();
521520
performImportResolution(CI->getMainModule());
522521

523522
bool DidFindIDEInspectionTarget = CI->getIDEInspectionFile()

0 commit comments

Comments
 (0)