Skip to content

Commit

Permalink
Merge pull request swiftlang#1635 from swiftwasm/maxd/5.3-merge
Browse files Browse the repository at this point in the history
Fix build issues in the 5.3 branch
  • Loading branch information
MaxDesiatov authored Aug 28, 2020
2 parents 027036c + 8751dd6 commit 4fe9b11
Show file tree
Hide file tree
Showing 47 changed files with 610 additions and 129 deletions.
6 changes: 6 additions & 0 deletions include/swift/AST/DiagnosticEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,12 @@ namespace swift {
}
}

bool hasDiagnostics() const {
return std::distance(Engine.TentativeDiagnostics.begin() +
PrevDiagnostics,
Engine.TentativeDiagnostics.end()) > 0;
}

/// Abort and close this transaction and erase all diagnostics
/// record while it was open.
void abort() {
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/FileUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class FileUnit : public DeclContext {
/// Find all SPI names imported from \p importedModule by this module,
/// collecting the identifiers in \p spiGroups.
virtual void lookupImportedSPIGroups(
const ModuleDecl *importedModule,
SmallVectorImpl<Identifier> &spiGroups) const {};
const ModuleDecl *importedModule,
SmallSetVector<Identifier, 4> &spiGroups) const {};

protected:
/// Look up an operator declaration. Do not call directly, use
Expand Down
11 changes: 9 additions & 2 deletions include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,9 @@ class ModuleDecl : public DeclContext, public TypeDecl {

/// Find all SPI names imported from \p importedModule by this module,
/// collecting the identifiers in \p spiGroups.
void lookupImportedSPIGroups(const ModuleDecl *importedModule,
SmallVectorImpl<Identifier> &spiGroups) const;
void lookupImportedSPIGroups(
const ModuleDecl *importedModule,
llvm::SmallSetVector<Identifier, 4> &spiGroups) const;

/// \sa getImportedModules
enum class ImportFilterKind {
Expand Down Expand Up @@ -611,6 +612,12 @@ class ModuleDecl : public DeclContext, public TypeDecl {
void
getImportedModulesForLookup(SmallVectorImpl<ImportedModule> &imports) const;

/// Has \p module been imported via an '@_implementationOnly' import
/// instead of another kind of import?
///
/// This assumes that \p module was imported.
bool isImportedImplementationOnly(const ModuleDecl *module) const;

/// Uniques the items in \p imports, ignoring the source locations of the
/// access paths.
///
Expand Down
5 changes: 3 additions & 2 deletions include/swift/AST/SourceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,9 @@ class SourceFile final : public FileUnit {
/// Find all SPI names imported from \p importedModule by this file,
/// collecting the identifiers in \p spiGroups.
virtual void
lookupImportedSPIGroups(const ModuleDecl *importedModule,
SmallVectorImpl<Identifier> &spiGroups) const override;
lookupImportedSPIGroups(
const ModuleDecl *importedModule,
llvm::SmallSetVector<Identifier, 4> &spiGroups) const override;

// Is \p targetDecl accessible as an explictly imported SPI from this file?
bool isImportedAsSPI(const ValueDecl *targetDecl) const;
Expand Down
6 changes: 4 additions & 2 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,8 @@ enum class FunctionBuilderBodyPreCheck : uint8_t {
class PreCheckFunctionBuilderRequest
: public SimpleRequest<PreCheckFunctionBuilderRequest,
FunctionBuilderBodyPreCheck(AnyFunctionRef,
BraceStmt *),
BraceStmt *,
bool),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;
Expand All @@ -1832,7 +1833,8 @@ class PreCheckFunctionBuilderRequest

// Evaluation.
FunctionBuilderBodyPreCheck evaluate(Evaluator &evaluator, AnyFunctionRef fn,
BraceStmt *body) const;
BraceStmt *body,
bool suppressDiagnostics) const;

public:
// Separate caching.
Expand Down
5 changes: 3 additions & 2 deletions include/swift/Serialization/SerializedModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,9 @@ class SerializedASTFile final : public LoadedFile {
SmallVectorImpl<AbstractFunctionDecl *> &results) const override;

virtual void
lookupImportedSPIGroups(const ModuleDecl *importedModule,
SmallVectorImpl<Identifier> &spiGroups) const override;
lookupImportedSPIGroups(
const ModuleDecl *importedModule,
llvm::SmallSetVector<Identifier, 4> &spiGroups) const override;

Optional<CommentInfo> getCommentForDecl(const Decl *D) const override;

Expand Down
18 changes: 18 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(bool preferTypeRepr,
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
if (!shouldPrint(ED->getExtendedNominal(), options))
return false;

// Skip extensions to implementation-only imported types that have
// no public members.
auto localModule = ED->getParentModule();
auto nominalModule = ED->getExtendedNominal()->getParentModule();
if (localModule != nominalModule &&
localModule->isImportedImplementationOnly(nominalModule)) {

bool shouldPrintMembers = llvm::any_of(
ED->getMembers(),
[&](const Decl *member) -> bool {
return shouldPrint(member, options);
});

if (!shouldPrintMembers)
return false;
}

for (const Requirement &req : ED->getGenericRequirements()) {
if (!isPublicOrUsableFromInline(req.getFirstType()))
return false;
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ASTScopeLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ bool BraceStmtScope::lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
bool PatternEntryInitializerScope::lookupLocalsOrMembers(
ArrayRef<const ASTScopeImpl *>, DeclConsumer consumer) const {
// 'self' is available within the pattern initializer of a 'lazy' variable.
auto *initContext = cast_or_null<PatternBindingInitializer>(
auto *initContext = dyn_cast_or_null<PatternBindingInitializer>(
decl->getInitContext(0));
if (initContext) {
if (auto *selfParam = initContext->getImplicitSelfDecl()) {
Expand Down Expand Up @@ -782,7 +782,7 @@ Optional<bool> ClosureBodyScope::resolveIsCascadingUseForThisScope(
Optional<bool> PatternEntryInitializerScope::resolveIsCascadingUseForThisScope(
Optional<bool> isCascadingUse) const {
auto *const initContext = getPatternEntry().getInitContext();
auto *PBI = cast_or_null<PatternBindingInitializer>(initContext);
auto *PBI = dyn_cast_or_null<PatternBindingInitializer>(initContext);
auto *isd = PBI ? PBI->getImplicitSelfDecl() : nullptr;

// 'self' is available within the pattern initializer of a 'lazy' variable.
Expand Down
13 changes: 4 additions & 9 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7434,13 +7434,11 @@ AbstractGenericSignatureRequest::evaluate(
if (baseSignature)
canBaseSignature = baseSignature->getCanonicalSignature();

llvm::SmallDenseMap<GenericTypeParamType *, Type> mappedTypeParameters;
SmallVector<GenericTypeParamType *, 2> canAddedParameters;
canAddedParameters.reserve(addedParameters.size());
for (auto gp : addedParameters) {
auto canGP = gp->getCanonicalType()->castTo<GenericTypeParamType>();
canAddedParameters.push_back(canGP);
mappedTypeParameters[canGP] = Type(gp);
}

SmallVector<Requirement, 2> canAddedRequirements;
Expand All @@ -7457,10 +7455,8 @@ AbstractGenericSignatureRequest::evaluate(
if (!canSignatureResult || !*canSignatureResult)
return GenericSignature();

// Substitute in the original generic parameters to form a more-sugared
// result closer to what the original request wanted. Note that this
// loses sugar on concrete types, but for abstract signatures that
// shouldn't matter.
// Substitute in the original generic parameters to form the sugared
// result the original request wanted.
auto canSignature = *canSignatureResult;
SmallVector<GenericTypeParamType *, 2> resugaredParameters;
resugaredParameters.reserve(canSignature->getGenericParams().size());
Expand All @@ -7478,9 +7474,8 @@ AbstractGenericSignatureRequest::evaluate(
auto resugaredReq = req.subst(
[&](SubstitutableType *type) {
if (auto gp = dyn_cast<GenericTypeParamType>(type)) {
auto knownGP = mappedTypeParameters.find(gp);
if (knownGP != mappedTypeParameters.end())
return knownGP->second;
unsigned ordinal = canSignature->getGenericParamOrdinal(gp);
return Type(resugaredParameters[ordinal]);
}
return Type(type);
},
Expand Down
44 changes: 32 additions & 12 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,9 @@ void ModuleDecl::lookupObjCMethods(
FORWARD(lookupObjCMethods, (selector, results));
}

void ModuleDecl::lookupImportedSPIGroups(const ModuleDecl *importedModule,
SmallVectorImpl<Identifier> &spiGroups) const {
void ModuleDecl::lookupImportedSPIGroups(
const ModuleDecl *importedModule,
llvm::SmallSetVector<Identifier, 4> &spiGroups) const {
FORWARD(lookupImportedSPIGroups, (importedModule, spiGroups));
}

Expand Down Expand Up @@ -2190,31 +2191,50 @@ bool SourceFile::isImportedImplementationOnly(const ModuleDecl *module) const {
return !imports.isImportedBy(module, getParentModule());
}

void SourceFile::lookupImportedSPIGroups(const ModuleDecl *importedModule,
SmallVectorImpl<Identifier> &spiGroups) const {
bool ModuleDecl::isImportedImplementationOnly(const ModuleDecl *module) const {
auto &imports = getASTContext().getImportCache();

// Look through non-implementation-only imports to see if module is imported
// in some other way. Otherwise we assume it's implementation-only imported.
ModuleDecl::ImportFilter filter;
filter |= ModuleDecl::ImportFilterKind::Public;
filter |= ModuleDecl::ImportFilterKind::Private;
filter |= ModuleDecl::ImportFilterKind::SPIAccessControl;
filter |= ModuleDecl::ImportFilterKind::ShadowedBySeparateOverlay;
SmallVector<ModuleDecl::ImportedModule, 4> results;
getImportedModules(results, filter);

for (auto &desc : results) {
if (imports.isImportedBy(module, desc.second))
return false;
}

return true;
}

void SourceFile::lookupImportedSPIGroups(
const ModuleDecl *importedModule,
llvm::SmallSetVector<Identifier, 4> &spiGroups) const {
for (auto &import : Imports) {
if (import.importOptions.contains(ImportFlags::SPIAccessControl) &&
importedModule == std::get<ModuleDecl*>(import.module)) {
auto importedSpis = import.spiGroups;
spiGroups.append(importedSpis.begin(), importedSpis.end());
spiGroups.insert(importedSpis.begin(), importedSpis.end());
}
}
}

bool SourceFile::isImportedAsSPI(const ValueDecl *targetDecl) const {
auto targetModule = targetDecl->getModuleContext();
SmallVector<Identifier, 4> importedSPIGroups;
llvm::SmallSetVector<Identifier, 4> importedSPIGroups;
lookupImportedSPIGroups(targetModule, importedSPIGroups);
if (importedSPIGroups.empty()) return false;

auto declSPIGroups = targetDecl->getSPIGroups();

// Note: If we reach a point where there are many SPI imports or SPI groups
// on decls we could optimize this further by using a set.
for (auto importedSPI : importedSPIGroups)
for (auto declSPI : declSPIGroups)
if (importedSPI == declSPI)
return true;
for (auto declSPI : declSPIGroups)
if (importedSPIGroups.count(declSPI))
return true;

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/ModuleInterfaceSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static void printImports(raw_ostream &out,
continue;
}

llvm::SmallVector<Identifier, 4> spis;
llvm::SmallSetVector<Identifier, 4> spis;
M->lookupImportedSPIGroups(importedModule, spis);

// Only print implementation-only imports which have an SPI import.
Expand Down
2 changes: 0 additions & 2 deletions lib/IDE/CompletionInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,6 @@ bool CompletionInstance::performCachedOperationIfPossible(
}

CachedReuseCount += 1;
cacheDependencyHashIfNeeded(CI, CurrentModule, SM.getCodeCompletionBufferID(),
InMemoryDependencyHash);

return true;
}
Expand Down
28 changes: 25 additions & 3 deletions lib/IRGen/ScalarTypeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,33 @@ class SingleScalarTypeInfo : public ScalarTypeInfo<Derived, Base> {
schema.add(ExplosionSchema::Element::forScalar(ty));
}

void storeAsBytes(IRGenFunction &IGF, Explosion &src, Address addr) const {
auto &IGM = IGF.IGM;

// Store in multiples of bytes to avoid undefined bits.
auto storageTy = addr.getAddress()->getType()->getPointerElementType();
if (storageTy->isIntegerTy() && (storageTy->getIntegerBitWidth() % 8)) {
auto &Builder = IGF.Builder;
auto nextByteSize = (storageTy->getIntegerBitWidth() + 7) & ~7UL;
auto nextByteSizedIntTy =
llvm::IntegerType::get(IGM.getLLVMContext(), nextByteSize);
auto newAddr =
Address(Builder.CreatePointerCast(addr.getAddress(),
nextByteSizedIntTy->getPointerTo()),
addr.getAlignment());
auto newValue = Builder.CreateZExt(src.claimNext(), nextByteSizedIntTy);
Builder.CreateStore(newValue, newAddr);
return;
}

IGF.Builder.CreateStore(src.claimNext(), addr);
}

void initialize(IRGenFunction &IGF, Explosion &src, Address addr,
bool isOutlined) const override {
addr = asDerived().projectScalar(IGF, addr);
IGF.Builder.CreateStore(src.claimNext(), addr);

storeAsBytes(IGF, src, addr);
}

void loadAsCopy(IRGenFunction &IGF, Address addr,
Expand Down Expand Up @@ -149,8 +172,7 @@ class SingleScalarTypeInfo : public ScalarTypeInfo<Derived, Base> {
}

// Store.
llvm::Value *newValue = src.claimNext();
IGF.Builder.CreateStore(newValue, dest);
storeAsBytes(IGF, src, dest);

// Release the old value if we need to.
if (!Derived::IsScalarPOD) {
Expand Down
Loading

0 comments on commit 4fe9b11

Please sign in to comment.