Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,10 @@ class ASTContext final {
AvailabilityDomain getTargetAvailabilityDomain() const;
};

inline SourceLoc extractNearestSourceLoc(const ASTContext *ctx) {
return SourceLoc();
}

} // end namespace swift

#endif
3 changes: 0 additions & 3 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,6 @@ WARNING(module_incompatible_with_skip_function_bodies,none,
"-experimental-skip-*-function-bodies* flags; they have "
"been automatically disabled", (StringRef))

WARNING(access_notes_file_io_error,none,
"ignored access notes file at '%0' because it cannot be read: %1",
(StringRef, StringRef))
WARNING(error_in_access_notes_file,none,
"ignored access notes file because it cannot be parsed: %0",
(StringRef))
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -7853,6 +7853,10 @@ ERROR(atomics_ordering_must_be_constant, none,

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

WARNING(access_notes_file_io_error,none,
"ignored access notes file at '%0' because it cannot be read: %1",
(StringRef, StringRef))

REMARK(attr_added_by_access_note, none,
"implicitly added '%1' to this %kindonly2, as " WHICH_ACCESS_NOTE(0),
(StringRef, StringRef, const ValueDecl *))
Expand Down
7 changes: 3 additions & 4 deletions include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@ class ModuleDecl
/// \see EntryPointInfoTy
EntryPointInfoTy EntryPointInfo;

AccessNotesFile accessNotes;

/// Used by the debugger to bypass resilient access to fields.
bool BypassResilience = false;

Expand Down Expand Up @@ -415,8 +413,9 @@ class ModuleDecl
/// imports.
ImplicitImportList getImplicitImports() const;

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

/// Return whether the module was imported with resilience disabled. The
/// debugger does this to access private fields.
Expand Down
25 changes: 25 additions & 0 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -4089,6 +4089,31 @@ class PrimarySourceFilesRequest
bool isCached() const { return true; }
};

/// Load the access notes to apply for the main module.
///
/// Note this is keyed on the ASTContext instead of the ModuleDecl to avoid
/// needing to re-load the access notes in cases where we have multiple main
/// modules, e.g when doing cached top-level code completion.
///
/// FIXME: This isn't really a type-checking request, if we ever split off a
/// zone for more general requests, this should be moved there.
class LoadAccessNotesRequest
: public SimpleRequest<LoadAccessNotesRequest,
const AccessNotesFile *(ASTContext *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

const AccessNotesFile *evaluate(Evaluator &evaluator, ASTContext *ctx) const;

public:
// Cached.
bool isCached() const { return true; }
};

/// Kinds of types for CustomAttr.
enum class CustomAttrTypeKind {
/// The type is required to not be expressed in terms of
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ SWIFT_REQUEST(TypeChecker, PatternBindingCheckedAndContextualizedInitRequest,
SeparatelyCached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, PrimarySourceFilesRequest,
ArrayRef<SourceFile *>(ModuleDecl *), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, LoadAccessNotesRequest,
const AccessNotesFile *(ASTContext *), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, PropertyWrapperAuxiliaryVariablesRequest,
PropertyWrapperAuxiliaryVariables(VarDecl *),
SeparatelyCached | SplitCached,
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ namespace swift {
std::shared_ptr<llvm::Regex> OptimizationRemarkPassedPattern;
std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;

/// The path to load access notes from.
std::string AccessNotesPath;

/// How should we emit diagnostics about access notes?
AccessNoteDiagnosticBehavior AccessNoteBehavior =
AccessNoteDiagnosticBehavior::RemarkOnFailureOrSuccess;
Expand Down
5 changes: 0 additions & 5 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,6 @@ class CompilerInstance {
/// Parses and type-checks all input files.
void performSema();

/// Loads any access notes for the main module.
///
/// FIXME: This should be requestified.
void loadAccessNotesIfNeeded();

/// Parses and performs import resolution on all input files.
///
/// This is similar to a parse-only invocation, but module imports will also
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ class FrontendOptions {
/// The path to which we should store indexing data, if any.
std::string IndexStorePath;

/// The path to load access notes from.
std::string AccessNotesPath;

/// The path to look in when loading a module interface file, to see if a
/// binary module has already been built for use by the compiler.
std::string PrebuiltModuleCachePath;
Expand Down
10 changes: 10 additions & 0 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,16 @@ ImplicitImportList ModuleDecl::getImplicitImports() const {
{});
}

const AccessNotesFile *ModuleDecl::getAccessNotes() const {
// Only the main module has access notes.
if (!isMainModule())
return nullptr;

auto &ctx = getASTContext();
return evaluateOrDefault(ctx.evaluator, LoadAccessNotesRequest{&ctx},
nullptr);
}

SourceFile *ModuleDecl::getSourceFileContainingLocation(SourceLoc loc) {
if (loc.isInvalid())
return nullptr;
Expand Down
3 changes: 0 additions & 3 deletions lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,6 @@ bool ArgsToFrontendOptionsConverter::convert(
if (!computeModuleAliases())
return true;

if (const Arg *A = Args.getLastArg(OPT_access_notes_path))
Opts.AccessNotesPath = A->getValue();

if (const Arg *A = Args.getLastArg(OPT_serialize_debugging_options,
OPT_no_serialize_debugging_options)) {
Opts.SerializeOptionsForDebugging =
Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.OptimizationRemarkMissedPattern =
generateOptimizationRemarkRegex(Diags, Args, A);

if (const Arg *A = Args.getLastArg(OPT_access_notes_path))
Opts.AccessNotesPath = A->getValue();

if (Arg *A = Args.getLastArg(OPT_Raccess_note)) {
auto value =
llvm::StringSwitch<std::optional<AccessNoteDiagnosticBehavior>>(
Expand Down
25 changes: 0 additions & 25 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,38 +1553,13 @@ void CompilerInstance::setMainModule(ModuleDecl *newMod) {
Context->MainModule = newMod;
}

void CompilerInstance::loadAccessNotesIfNeeded() {
if (Invocation.getFrontendOptions().AccessNotesPath.empty())
return;

auto *mainModule = getMainModule();

auto accessNotesPath = Invocation.getFrontendOptions().AccessNotesPath;

auto bufferOrError =
swift::vfs::getFileOrSTDIN(getFileSystem(), accessNotesPath);
if (bufferOrError) {
int sourceID = SourceMgr.addNewSourceBuffer(std::move(bufferOrError.get()));
auto buffer = SourceMgr.getLLVMSourceMgr().getMemoryBuffer(sourceID);

if (auto accessNotesFile = AccessNotesFile::load(*Context, buffer))
mainModule->getAccessNotes() = *accessNotesFile;
} else {
Diagnostics.diagnose(SourceLoc(), diag::access_notes_file_io_error,
accessNotesPath, bufferOrError.getError().message());
}
}

bool CompilerInstance::performParseAndResolveImportsOnly() {
FrontendStatsTracer tracer(getStatsReporter(), "parse-and-resolve-imports");

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

// Load access notes.
loadAccessNotesIfNeeded();

// Resolve imports for all the source files in the module.
auto *mainModule = getMainModule();
performImportResolution(mainModule);
Expand Down
1 change: 0 additions & 1 deletion lib/IDETool/IDEInspectionInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ void IDEInspectionInstance::performNewOperation(
CI->getASTContext().CancellationFlag = CancellationFlag;
registerIDERequestFunctions(CI->getASTContext().evaluator);

CI->loadAccessNotesIfNeeded();
performImportResolution(CI->getMainModule());

bool DidFindIDEInspectionTarget = CI->getIDEInspectionFile()
Expand Down
1 change: 1 addition & 0 deletions lib/Sema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ add_swift_host_library(swiftSema STATIC
SyntacticElementTarget.cpp
TypeOfReference.cpp
TypeCheckAccess.cpp
TypeCheckAccessNotes.cpp
TypeCheckAttr.cpp
TypeCheckAttrABI.cpp
TypeCheckAvailability.cpp
Expand Down
Loading