Skip to content

Commit 4fe9b11

Browse files
authored
Merge pull request #1635 from swiftwasm/maxd/5.3-merge
Fix build issues in the 5.3 branch
2 parents 027036c + 8751dd6 commit 4fe9b11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+610
-129
lines changed

include/swift/AST/DiagnosticEngine.h

+6
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,12 @@ namespace swift {
10251025
}
10261026
}
10271027

1028+
bool hasDiagnostics() const {
1029+
return std::distance(Engine.TentativeDiagnostics.begin() +
1030+
PrevDiagnostics,
1031+
Engine.TentativeDiagnostics.end()) > 0;
1032+
}
1033+
10281034
/// Abort and close this transaction and erase all diagnostics
10291035
/// record while it was open.
10301036
void abort() {

include/swift/AST/FileUnit.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ class FileUnit : public DeclContext {
107107
/// Find all SPI names imported from \p importedModule by this module,
108108
/// collecting the identifiers in \p spiGroups.
109109
virtual void lookupImportedSPIGroups(
110-
const ModuleDecl *importedModule,
111-
SmallVectorImpl<Identifier> &spiGroups) const {};
110+
const ModuleDecl *importedModule,
111+
SmallSetVector<Identifier, 4> &spiGroups) const {};
112112

113113
protected:
114114
/// Look up an operator declaration. Do not call directly, use

include/swift/AST/Module.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,9 @@ class ModuleDecl : public DeclContext, public TypeDecl {
575575

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

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

615+
/// Has \p module been imported via an '@_implementationOnly' import
616+
/// instead of another kind of import?
617+
///
618+
/// This assumes that \p module was imported.
619+
bool isImportedImplementationOnly(const ModuleDecl *module) const;
620+
614621
/// Uniques the items in \p imports, ignoring the source locations of the
615622
/// access paths.
616623
///

include/swift/AST/SourceFile.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,9 @@ class SourceFile final : public FileUnit {
365365
/// Find all SPI names imported from \p importedModule by this file,
366366
/// collecting the identifiers in \p spiGroups.
367367
virtual void
368-
lookupImportedSPIGroups(const ModuleDecl *importedModule,
369-
SmallVectorImpl<Identifier> &spiGroups) const override;
368+
lookupImportedSPIGroups(
369+
const ModuleDecl *importedModule,
370+
llvm::SmallSetVector<Identifier, 4> &spiGroups) const override;
370371

371372
// Is \p targetDecl accessible as an explictly imported SPI from this file?
372373
bool isImportedAsSPI(const ValueDecl *targetDecl) const;

include/swift/AST/TypeCheckRequests.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,8 @@ enum class FunctionBuilderBodyPreCheck : uint8_t {
18221822
class PreCheckFunctionBuilderRequest
18231823
: public SimpleRequest<PreCheckFunctionBuilderRequest,
18241824
FunctionBuilderBodyPreCheck(AnyFunctionRef,
1825-
BraceStmt *),
1825+
BraceStmt *,
1826+
bool),
18261827
RequestFlags::Cached> {
18271828
public:
18281829
using SimpleRequest::SimpleRequest;
@@ -1832,7 +1833,8 @@ class PreCheckFunctionBuilderRequest
18321833

18331834
// Evaluation.
18341835
FunctionBuilderBodyPreCheck evaluate(Evaluator &evaluator, AnyFunctionRef fn,
1835-
BraceStmt *body) const;
1836+
BraceStmt *body,
1837+
bool suppressDiagnostics) const;
18361838

18371839
public:
18381840
// Separate caching.

include/swift/Serialization/SerializedModuleLoader.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,9 @@ class SerializedASTFile final : public LoadedFile {
359359
SmallVectorImpl<AbstractFunctionDecl *> &results) const override;
360360

361361
virtual void
362-
lookupImportedSPIGroups(const ModuleDecl *importedModule,
363-
SmallVectorImpl<Identifier> &spiGroups) const override;
362+
lookupImportedSPIGroups(
363+
const ModuleDecl *importedModule,
364+
llvm::SmallSetVector<Identifier, 4> &spiGroups) const override;
364365

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

lib/AST/ASTPrinter.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(bool preferTypeRepr,
168168
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
169169
if (!shouldPrint(ED->getExtendedNominal(), options))
170170
return false;
171+
172+
// Skip extensions to implementation-only imported types that have
173+
// no public members.
174+
auto localModule = ED->getParentModule();
175+
auto nominalModule = ED->getExtendedNominal()->getParentModule();
176+
if (localModule != nominalModule &&
177+
localModule->isImportedImplementationOnly(nominalModule)) {
178+
179+
bool shouldPrintMembers = llvm::any_of(
180+
ED->getMembers(),
181+
[&](const Decl *member) -> bool {
182+
return shouldPrint(member, options);
183+
});
184+
185+
if (!shouldPrintMembers)
186+
return false;
187+
}
188+
171189
for (const Requirement &req : ED->getGenericRequirements()) {
172190
if (!isPublicOrUsableFromInline(req.getFirstType()))
173191
return false;

lib/AST/ASTScopeLookup.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ bool BraceStmtScope::lookupLocalsOrMembers(ArrayRef<const ASTScopeImpl *>,
485485
bool PatternEntryInitializerScope::lookupLocalsOrMembers(
486486
ArrayRef<const ASTScopeImpl *>, DeclConsumer consumer) const {
487487
// 'self' is available within the pattern initializer of a 'lazy' variable.
488-
auto *initContext = cast_or_null<PatternBindingInitializer>(
488+
auto *initContext = dyn_cast_or_null<PatternBindingInitializer>(
489489
decl->getInitContext(0));
490490
if (initContext) {
491491
if (auto *selfParam = initContext->getImplicitSelfDecl()) {
@@ -782,7 +782,7 @@ Optional<bool> ClosureBodyScope::resolveIsCascadingUseForThisScope(
782782
Optional<bool> PatternEntryInitializerScope::resolveIsCascadingUseForThisScope(
783783
Optional<bool> isCascadingUse) const {
784784
auto *const initContext = getPatternEntry().getInitContext();
785-
auto *PBI = cast_or_null<PatternBindingInitializer>(initContext);
785+
auto *PBI = dyn_cast_or_null<PatternBindingInitializer>(initContext);
786786
auto *isd = PBI ? PBI->getImplicitSelfDecl() : nullptr;
787787

788788
// 'self' is available within the pattern initializer of a 'lazy' variable.

lib/AST/GenericSignatureBuilder.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -7434,13 +7434,11 @@ AbstractGenericSignatureRequest::evaluate(
74347434
if (baseSignature)
74357435
canBaseSignature = baseSignature->getCanonicalSignature();
74367436

7437-
llvm::SmallDenseMap<GenericTypeParamType *, Type> mappedTypeParameters;
74387437
SmallVector<GenericTypeParamType *, 2> canAddedParameters;
74397438
canAddedParameters.reserve(addedParameters.size());
74407439
for (auto gp : addedParameters) {
74417440
auto canGP = gp->getCanonicalType()->castTo<GenericTypeParamType>();
74427441
canAddedParameters.push_back(canGP);
7443-
mappedTypeParameters[canGP] = Type(gp);
74447442
}
74457443

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

7460-
// Substitute in the original generic parameters to form a more-sugared
7461-
// result closer to what the original request wanted. Note that this
7462-
// loses sugar on concrete types, but for abstract signatures that
7463-
// shouldn't matter.
7458+
// Substitute in the original generic parameters to form the sugared
7459+
// result the original request wanted.
74647460
auto canSignature = *canSignatureResult;
74657461
SmallVector<GenericTypeParamType *, 2> resugaredParameters;
74667462
resugaredParameters.reserve(canSignature->getGenericParams().size());
@@ -7478,9 +7474,8 @@ AbstractGenericSignatureRequest::evaluate(
74787474
auto resugaredReq = req.subst(
74797475
[&](SubstitutableType *type) {
74807476
if (auto gp = dyn_cast<GenericTypeParamType>(type)) {
7481-
auto knownGP = mappedTypeParameters.find(gp);
7482-
if (knownGP != mappedTypeParameters.end())
7483-
return knownGP->second;
7477+
unsigned ordinal = canSignature->getGenericParamOrdinal(gp);
7478+
return Type(resugaredParameters[ordinal]);
74847479
}
74857480
return Type(type);
74867481
},

lib/AST/Module.cpp

+32-12
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,9 @@ void ModuleDecl::lookupObjCMethods(
639639
FORWARD(lookupObjCMethods, (selector, results));
640640
}
641641

642-
void ModuleDecl::lookupImportedSPIGroups(const ModuleDecl *importedModule,
643-
SmallVectorImpl<Identifier> &spiGroups) const {
642+
void ModuleDecl::lookupImportedSPIGroups(
643+
const ModuleDecl *importedModule,
644+
llvm::SmallSetVector<Identifier, 4> &spiGroups) const {
644645
FORWARD(lookupImportedSPIGroups, (importedModule, spiGroups));
645646
}
646647

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

2193-
void SourceFile::lookupImportedSPIGroups(const ModuleDecl *importedModule,
2194-
SmallVectorImpl<Identifier> &spiGroups) const {
2194+
bool ModuleDecl::isImportedImplementationOnly(const ModuleDecl *module) const {
2195+
auto &imports = getASTContext().getImportCache();
2196+
2197+
// Look through non-implementation-only imports to see if module is imported
2198+
// in some other way. Otherwise we assume it's implementation-only imported.
2199+
ModuleDecl::ImportFilter filter;
2200+
filter |= ModuleDecl::ImportFilterKind::Public;
2201+
filter |= ModuleDecl::ImportFilterKind::Private;
2202+
filter |= ModuleDecl::ImportFilterKind::SPIAccessControl;
2203+
filter |= ModuleDecl::ImportFilterKind::ShadowedBySeparateOverlay;
2204+
SmallVector<ModuleDecl::ImportedModule, 4> results;
2205+
getImportedModules(results, filter);
2206+
2207+
for (auto &desc : results) {
2208+
if (imports.isImportedBy(module, desc.second))
2209+
return false;
2210+
}
2211+
2212+
return true;
2213+
}
2214+
2215+
void SourceFile::lookupImportedSPIGroups(
2216+
const ModuleDecl *importedModule,
2217+
llvm::SmallSetVector<Identifier, 4> &spiGroups) const {
21952218
for (auto &import : Imports) {
21962219
if (import.importOptions.contains(ImportFlags::SPIAccessControl) &&
21972220
importedModule == std::get<ModuleDecl*>(import.module)) {
21982221
auto importedSpis = import.spiGroups;
2199-
spiGroups.append(importedSpis.begin(), importedSpis.end());
2222+
spiGroups.insert(importedSpis.begin(), importedSpis.end());
22002223
}
22012224
}
22022225
}
22032226

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

22102233
auto declSPIGroups = targetDecl->getSPIGroups();
22112234

2212-
// Note: If we reach a point where there are many SPI imports or SPI groups
2213-
// on decls we could optimize this further by using a set.
2214-
for (auto importedSPI : importedSPIGroups)
2215-
for (auto declSPI : declSPIGroups)
2216-
if (importedSPI == declSPI)
2217-
return true;
2235+
for (auto declSPI : declSPIGroups)
2236+
if (importedSPIGroups.count(declSPI))
2237+
return true;
22182238

22192239
return false;
22202240
}

lib/Frontend/ModuleInterfaceSupport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static void printImports(raw_ostream &out,
139139
continue;
140140
}
141141

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

145145
// Only print implementation-only imports which have an SPI import.

lib/IDE/CompletionInstance.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,6 @@ bool CompletionInstance::performCachedOperationIfPossible(
491491
}
492492

493493
CachedReuseCount += 1;
494-
cacheDependencyHashIfNeeded(CI, CurrentModule, SM.getCodeCompletionBufferID(),
495-
InMemoryDependencyHash);
496494

497495
return true;
498496
}

lib/IRGen/ScalarTypeInfo.h

+25-3
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,33 @@ class SingleScalarTypeInfo : public ScalarTypeInfo<Derived, Base> {
117117
schema.add(ExplosionSchema::Element::forScalar(ty));
118118
}
119119

120+
void storeAsBytes(IRGenFunction &IGF, Explosion &src, Address addr) const {
121+
auto &IGM = IGF.IGM;
122+
123+
// Store in multiples of bytes to avoid undefined bits.
124+
auto storageTy = addr.getAddress()->getType()->getPointerElementType();
125+
if (storageTy->isIntegerTy() && (storageTy->getIntegerBitWidth() % 8)) {
126+
auto &Builder = IGF.Builder;
127+
auto nextByteSize = (storageTy->getIntegerBitWidth() + 7) & ~7UL;
128+
auto nextByteSizedIntTy =
129+
llvm::IntegerType::get(IGM.getLLVMContext(), nextByteSize);
130+
auto newAddr =
131+
Address(Builder.CreatePointerCast(addr.getAddress(),
132+
nextByteSizedIntTy->getPointerTo()),
133+
addr.getAlignment());
134+
auto newValue = Builder.CreateZExt(src.claimNext(), nextByteSizedIntTy);
135+
Builder.CreateStore(newValue, newAddr);
136+
return;
137+
}
138+
139+
IGF.Builder.CreateStore(src.claimNext(), addr);
140+
}
141+
120142
void initialize(IRGenFunction &IGF, Explosion &src, Address addr,
121143
bool isOutlined) const override {
122144
addr = asDerived().projectScalar(IGF, addr);
123-
IGF.Builder.CreateStore(src.claimNext(), addr);
145+
146+
storeAsBytes(IGF, src, addr);
124147
}
125148

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

151174
// Store.
152-
llvm::Value *newValue = src.claimNext();
153-
IGF.Builder.CreateStore(newValue, dest);
175+
storeAsBytes(IGF, src, dest);
154176

155177
// Release the old value if we need to.
156178
if (!Derived::IsScalarPOD) {

0 commit comments

Comments
 (0)