Skip to content

Commit

Permalink
Merge pull request #746 from swiftwasm/master
Browse files Browse the repository at this point in the history
[pull] swiftwasm from master
  • Loading branch information
pull[bot] authored Apr 22, 2020
2 parents 0b07d4b + d49c83c commit ee5e906
Show file tree
Hide file tree
Showing 44 changed files with 1,538 additions and 242 deletions.
13 changes: 6 additions & 7 deletions include/swift/AST/SourceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ class SourceFile final : public FileUnit {
/// May be -1, to indicate no association with a buffer.
int BufferID;

/// Does this source file have any implementation-only imports?
/// If not, we can fast-path module checks.
bool HasImplementationOnlyImports = false;

/// The parsing options for the file.
ParsingOptions ParsingOpts;

Expand Down Expand Up @@ -333,6 +329,9 @@ class SourceFile final : public FileUnit {

~SourceFile();

/// Retrieve an immutable view of the source file's imports.
ArrayRef<ImportedModuleDesc> getImports() const { return *Imports; }

/// Set the imports for this source file. This gets called by import
/// resolution.
void setImports(ArrayRef<ImportedModuleDesc> imports);
Expand All @@ -350,9 +349,9 @@ class SourceFile final : public FileUnit {
hasTestableOrPrivateImport(AccessLevel accessLevel, const ValueDecl *ofDecl,
ImportQueryKind kind = TestableAndPrivate) const;

bool hasImplementationOnlyImports() const {
return HasImplementationOnlyImports;
}
/// Does this source file have any implementation-only imports?
/// If not, we can fast-path module checks.
bool hasImplementationOnlyImports() const;

bool isImportedImplementationOnly(const ModuleDecl *module) const;

Expand Down
17 changes: 17 additions & 0 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,23 @@ class ModuleImplicitImportsRequest
bool isCached() const { return true; }
};

/// Checks whether a file performs an implementation-only import.
class HasImplementationOnlyImportsRequest
: public SimpleRequest<HasImplementationOnlyImportsRequest,
bool(SourceFile *), RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

bool evaluate(Evaluator &evaluator, SourceFile *SF) const;

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

// Allow AnyValue to compare two Type values, even though Type doesn't
// support ==.
template<>
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 @@ -89,6 +89,8 @@ SWIFT_REQUEST(TypeChecker, HasDynamicMemberLookupAttributeRequest,
bool(CanType), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, HasDynamicCallableAttributeRequest,
bool(CanType), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, HasImplementationOnlyImportsRequest,
bool(SourceFile *), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, InferredGenericSignatureRequest,
GenericSignature (ModuleDecl *, GenericSignatureImpl *,
GenericParamSource,
Expand Down
10 changes: 1 addition & 9 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,6 @@ class CompilerInstance {
/// If \p BufID is already in the set, do nothing.
void recordPrimaryInputBuffer(unsigned BufID);

/// Record in PrimarySourceFiles the fact that \p SF is a primary, and
/// call recordPrimaryInputBuffer on \p SF's buffer (if it exists).
void recordPrimarySourceFile(SourceFile *SF);

bool isWholeModuleCompilation() { return PrimaryBufferIDs.empty(); }

public:
Expand Down Expand Up @@ -674,15 +670,11 @@ class CompilerInstance {
void performSemaUpTo(SourceFile::ASTStage_t LimitStage);
void parseAndCheckTypesUpTo(SourceFile::ASTStage_t LimitStage);

void parseLibraryFile(unsigned BufferID);

/// Return true if had load error
bool parsePartialModulesAndLibraryFiles();
bool parsePartialModulesAndInputFiles();

void forEachFileToTypeCheck(llvm::function_ref<void(SourceFile &)> fn);

void parseAndTypeCheckMainFileUpTo(SourceFile::ASTStage_t LimitStage);

void finishTypeChecking();

public:
Expand Down
1 change: 1 addition & 0 deletions include/swift/SIL/SILModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ class SILModule {
swift::SILRemarkStreamer *getSILRemarkStreamer() {
return silRemarkStreamer.get();
}

void installSILRemarkStreamer();

// This is currently limited to VarDecl because the visibility of global
Expand Down
22 changes: 20 additions & 2 deletions include/swift/SIL/SILRemarkStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,20 @@ namespace swift {

class SILRemarkStreamer {
private:
/// The \c LLVMContext the underlying streamer uses for scratch space.
std::unique_ptr<llvm::LLVMContext> streamerContext;
enum class Owner {
SILModule,
LLVM,
} owner;

/// The underlying LLVM streamer.
///
/// If owned by a SILModule, this will be non-null.
std::unique_ptr<llvm::remarks::RemarkStreamer> streamer;
/// The owning LLVM context.
///
/// If owned by LLVM, this will be non-null.
llvm::LLVMContext *context;

/// The remark output stream used to record SIL remarks to a file.
std::unique_ptr<llvm::raw_fd_ostream> remarkStream;

Expand All @@ -53,6 +65,12 @@ class SILRemarkStreamer {

const ASTContext &getASTContext() const { return ctx; }

public:
/// Perform a one-time ownership transfer to associate the underlying
/// \c llvm::remarks::RemarkStreamer with the given \c LLVMContext.
void intoLLVMContext(llvm::LLVMContext &Ctx) &;

public:
/// Emit a remark through the streamer.
template <typename RemarkT>
void emit(const OptRemark::Remark<RemarkT> &remark);
Expand Down
23 changes: 15 additions & 8 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2042,15 +2042,22 @@ void SourceFile::print(ASTPrinter &Printer, const PrintOptions &PO) {
void SourceFile::setImports(ArrayRef<ImportedModuleDesc> imports) {
assert(!Imports && "Already computed imports");
Imports = getASTContext().AllocateCopy(imports);
}

// Update the HasImplementationOnlyImports flag.
// TODO: Requestify this.
if (!HasImplementationOnlyImports) {
for (auto &desc : imports) {
if (desc.importOptions.contains(ImportFlags::ImplementationOnly))
HasImplementationOnlyImports = true;
}
}
bool HasImplementationOnlyImportsRequest::evaluate(Evaluator &evaluator,
SourceFile *SF) const {
using ModuleDesc = SourceFile::ImportedModuleDesc;
return llvm::any_of(SF->getImports(), [](ModuleDesc desc) {
return desc.importOptions.contains(
SourceFile::ImportFlags::ImplementationOnly);
});
}

bool SourceFile::hasImplementationOnlyImports() const {
auto &ctx = getASTContext();
auto *mutableThis = const_cast<SourceFile *>(this);
return evaluateOrDefault(
ctx.evaluator, HasImplementationOnlyImportsRequest{mutableThis}, false);
}

bool SourceFile::hasTestableOrPrivateImport(
Expand Down
Loading

0 comments on commit ee5e906

Please sign in to comment.