Skip to content

Commit 8e460d1

Browse files
authored
Merge pull request #84225 from hamishknight/access-noted
Requestify the loading of access notes
2 parents 73255ab + 5c334c5 commit 8e460d1

18 files changed

+311
-236
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
@@ -7856,6 +7856,10 @@ ERROR(atomics_ordering_must_be_constant, none,
78567856

78577857
#define WHICH_ACCESS_NOTE(reason) "specified by access note for %" #reason
78587858

7859+
WARNING(access_notes_file_io_error,none,
7860+
"ignored access notes file at '%0' because it cannot be read: %1",
7861+
(StringRef, StringRef))
7862+
78597863
REMARK(attr_added_by_access_note, none,
78607864
"implicitly added '%1' to this %kindonly2, as " WHICH_ACCESS_NOTE(0),
78617865
(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/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ namespace swift {
493493
std::shared_ptr<llvm::Regex> OptimizationRemarkPassedPattern;
494494
std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
495495

496+
/// The path to load access notes from.
497+
std::string AccessNotesPath;
498+
496499
/// How should we emit diagnostics about access notes?
497500
AccessNoteDiagnosticBehavior AccessNoteBehavior =
498501
AccessNoteDiagnosticBehavior::RemarkOnFailureOrSuccess;

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

include/swift/Frontend/FrontendOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ class FrontendOptions {
107107
/// The path to which we should store indexing data, if any.
108108
std::string IndexStorePath;
109109

110-
/// The path to load access notes from.
111-
std::string AccessNotesPath;
112-
113110
/// The path to look in when loading a module interface file, to see if a
114111
/// binary module has already been built for use by the compiler.
115112
std::string PrebuiltModuleCachePath;

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;

0 commit comments

Comments
 (0)