Skip to content

Commit ecd0d8e

Browse files
authored
Merge pull request #1884 from swiftwasm/main
[pull] swiftwasm from main
2 parents c536b0b + a71e4fb commit ecd0d8e

Some content is hidden

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

45 files changed

+2451
-2076
lines changed

docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ documentation, please create a thread on the Swift forums under the
113113
Describes how the "Omit Needless Words" algorithm works,
114114
making imported names more idiomatic.
115115
- Type-checking and inference:
116-
- [TypeChecker.rst](/docs/TypeChecker.rst):
116+
- [TypeChecker.md](/docs/TypeChecker.md):
117117
Provides an overview of how type-checking and inference work.
118118
- [RequestEvaluator.md](/docs/RequestEvaluator.md):
119119
Describes the request evaluator architecture, which is used for

docs/contents.rst

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Contents
1212
Generics
1313
StoredAndComputedVariables
1414
SIL
15-
TypeChecker
1615
OptimizationTips
1716
ABI: TypeMetadata <ABI/TypeMetadata>
1817
ABI: TypeLayout <ABI/TypeLayout>

include/swift/AST/ASTContext.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,12 @@ class ASTContext final {
762762
bool isClang = false, bool isDWARF = false,
763763
bool IsInterface = false);
764764

765+
/// Add a module interface checker to use for this AST context.
766+
void addModuleInterfaceChecker(std::unique_ptr<ModuleInterfaceChecker> checker);
767+
768+
/// Retrieve the module interface checker associated with this AST context.
769+
ModuleInterfaceChecker *getModuleInterfaceChecker() const;
770+
765771
/// Retrieve the module dependencies for the module with the given name.
766772
///
767773
/// \param isUnderlyingClangModule When true, only look for a Clang module
@@ -839,9 +845,6 @@ class ASTContext final {
839845
/// If there is no Clang module loader, returns a null pointer.
840846
/// The loader is owned by the AST context.
841847
ClangModuleLoader *getDWARFModuleLoader() const;
842-
843-
/// Retrieve the module interface loader for this ASTContext.
844-
ModuleLoader *getModuleInterfaceLoader() const;
845848
public:
846849
namelookup::ImportCache &getImportCache() const;
847850

include/swift/AST/Decl.h

+8
Original file line numberDiff line numberDiff line change
@@ -4842,6 +4842,14 @@ class VarDecl : public AbstractStorageDecl {
48424842
/// property wrapper with a \c projectedValue .
48434843
VarDecl *getPropertyWrapperProjectionVar() const;
48444844

4845+
/// Visit all auxiliary declarations to this VarDecl.
4846+
///
4847+
/// An auxiliary declaration is a declaration synthesized by the compiler to support
4848+
/// this VarDecl, such as synthesized property wrapper variables.
4849+
///
4850+
/// \note this function only visits auxiliary decls that are not part of the AST.
4851+
void visitAuxiliaryDecls(llvm::function_ref<void(VarDecl *)>) const;
4852+
48454853
/// Retrieve the backing storage property for a lazy property.
48464854
VarDecl *getLazyStorageProperty() const;
48474855

include/swift/AST/DiagnosticsSema.def

-2
Original file line numberDiff line numberDiff line change
@@ -5216,8 +5216,6 @@ ERROR(property_wrapper_mutating_get_composed_to_get_only,none,
52165216
"property wrapper %0 with a mutating getter cannot be composed inside "
52175217
"get-only property wrapper %1", (TypeLoc, TypeLoc))
52185218

5219-
ERROR(property_wrapper_local,none,
5220-
"property wrappers are not yet supported on local properties", ())
52215219
ERROR(property_wrapper_top_level,none,
52225220
"property wrappers are not yet supported in top-level code", ())
52235221
ERROR(property_wrapper_let, none,

include/swift/AST/ModuleLoader.h

+17
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,23 @@ struct SubCompilerInstanceInfo {
116116
ArrayRef<StringRef> ExtraPCMArgs;
117117
};
118118

119+
/// Abstract interface for a checker of module interfaces and prebuilt modules.
120+
class ModuleInterfaceChecker {
121+
public:
122+
virtual std::vector<std::string>
123+
getCompiledModuleCandidatesForInterface(StringRef moduleName,
124+
StringRef interfacePath) = 0;
125+
126+
/// Given a list of potential ready-to-use compiled modules for \p interfacePath,
127+
/// check if any one of them is up-to-date. If so, emit a forwarding module
128+
/// to the candidate binary module to \p outPath.
129+
virtual bool tryEmitForwardingModule(StringRef moduleName,
130+
StringRef interfacePath,
131+
ArrayRef<std::string> candidates,
132+
StringRef outPath) = 0;
133+
virtual ~ModuleInterfaceChecker() = default;
134+
};
135+
119136
/// Abstract interface to run an action in a sub ASTContext.
120137
struct InterfaceSubContextDelegate {
121138
virtual std::error_code runInSubContext(StringRef moduleName,

include/swift/Basic/STLExtras.h

+41
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,47 @@ inline Iterator prev_or_begin(Iterator it, Iterator begin) {
217217

218218
/// @}
219219

220+
/// An iterator that walks a linked list of objects until it reaches
221+
/// a null pointer.
222+
template <class T, T* (&getNext)(T*)>
223+
class LinkedListIterator {
224+
T *Pointer;
225+
public:
226+
using iterator_category = std::forward_iterator_tag;
227+
using value_type = T *;
228+
using reference = T *;
229+
using pointer = void;
230+
231+
/// Returns an iterator range starting from the given pointer and
232+
/// running until it reaches a null pointer.
233+
static llvm::iterator_range<LinkedListIterator> rangeBeginning(T *pointer) {
234+
return {pointer, nullptr};
235+
}
236+
237+
constexpr LinkedListIterator(T *pointer) : Pointer(pointer) {}
238+
239+
T *operator*() const {
240+
assert(Pointer && "dereferencing a null iterator");
241+
return Pointer;
242+
}
243+
244+
LinkedListIterator &operator++() {
245+
Pointer = getNext(Pointer);
246+
return *this;
247+
}
248+
LinkedListIterator operator++(int) {
249+
auto copy = *this;
250+
Pointer = getNext(Pointer);
251+
return copy;
252+
}
253+
254+
friend bool operator==(LinkedListIterator lhs, LinkedListIterator rhs) {
255+
return lhs.Pointer == rhs.Pointer;
256+
}
257+
friend bool operator!=(LinkedListIterator lhs, LinkedListIterator rhs) {
258+
return lhs.Pointer != rhs.Pointer;
259+
}
260+
};
220261

221262
/// An iterator that transforms the result of an underlying bidirectional
222263
/// iterator with a given operation.

include/swift/Frontend/ModuleInterfaceLoader.h

+39-29
Original file line numberDiff line numberDiff line change
@@ -309,27 +309,52 @@ struct ModuleInterfaceLoaderOptions {
309309
ModuleInterfaceLoaderOptions() = default;
310310
};
311311

312+
class ModuleInterfaceCheckerImpl: public ModuleInterfaceChecker {
313+
friend class ModuleInterfaceLoader;
314+
ASTContext &Ctx;
315+
std::string CacheDir;
316+
std::string PrebuiltCacheDir;
317+
ModuleInterfaceLoaderOptions Opts;
318+
319+
public:
320+
explicit ModuleInterfaceCheckerImpl(ASTContext &Ctx,
321+
StringRef cacheDir,
322+
StringRef prebuiltCacheDir,
323+
ModuleInterfaceLoaderOptions Opts)
324+
: Ctx(Ctx), CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir),
325+
Opts(Opts) {}
326+
327+
std::vector<std::string>
328+
getCompiledModuleCandidatesForInterface(StringRef moduleName,
329+
StringRef interfacePath) override;
330+
331+
/// Given a list of potential ready-to-use compiled modules for \p interfacePath,
332+
/// check if any one of them is up-to-date. If so, emit a forwarding module
333+
/// to the candidate binary module to \p outPath.
334+
bool tryEmitForwardingModule(StringRef moduleName,
335+
StringRef interfacePath,
336+
ArrayRef<std::string> candidates,
337+
StringRef outPath) override;
338+
bool isCached(StringRef DepPath);
339+
};
340+
312341
/// A ModuleLoader that runs a subordinate \c CompilerInvocation and
313342
/// \c CompilerInstance to convert .swiftinterface files to .swiftmodule
314343
/// files on the fly, caching the resulting .swiftmodules in the module cache
315344
/// directory, and loading the serialized .swiftmodules from there.
316345
class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
317346
friend class unittest::ModuleInterfaceLoaderTest;
318347
explicit ModuleInterfaceLoader(
319-
ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
348+
ASTContext &ctx, ModuleInterfaceCheckerImpl &InterfaceChecker,
320349
DependencyTracker *tracker, ModuleLoadingMode loadMode,
321350
ArrayRef<std::string> PreferInterfaceForModules,
322-
bool IgnoreSwiftSourceInfoFile, ModuleInterfaceLoaderOptions Opts)
323-
: SerializedModuleLoaderBase(ctx, tracker, loadMode,
324-
IgnoreSwiftSourceInfoFile),
325-
CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir),
326-
PreferInterfaceForModules(PreferInterfaceForModules),
327-
Opts(Opts) {}
351+
bool IgnoreSwiftSourceInfoFile)
352+
: SerializedModuleLoaderBase(ctx, tracker, loadMode, IgnoreSwiftSourceInfoFile),
353+
InterfaceChecker(InterfaceChecker),
354+
PreferInterfaceForModules(PreferInterfaceForModules){}
328355

329-
std::string CacheDir;
330-
std::string PrebuiltCacheDir;
356+
ModuleInterfaceCheckerImpl &InterfaceChecker;
331357
ArrayRef<std::string> PreferInterfaceForModules;
332-
ModuleInterfaceLoaderOptions Opts;
333358

334359
std::error_code findModuleFilesInDirectory(
335360
ImportPath::Element ModuleID,
@@ -343,17 +368,14 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
343368
bool isCached(StringRef DepPath) override;
344369
public:
345370
static std::unique_ptr<ModuleInterfaceLoader>
346-
create(ASTContext &ctx, StringRef cacheDir, StringRef prebuiltCacheDir,
371+
create(ASTContext &ctx, ModuleInterfaceCheckerImpl &InterfaceChecker,
347372
DependencyTracker *tracker, ModuleLoadingMode loadMode,
348373
ArrayRef<std::string> PreferInterfaceForModules = {},
349-
ModuleInterfaceLoaderOptions Opts = ModuleInterfaceLoaderOptions(),
350374
bool IgnoreSwiftSourceInfoFile = false) {
351375
return std::unique_ptr<ModuleInterfaceLoader>(
352-
new ModuleInterfaceLoader(ctx, cacheDir, prebuiltCacheDir,
353-
tracker, loadMode,
354-
PreferInterfaceForModules,
355-
IgnoreSwiftSourceInfoFile,
356-
Opts));
376+
new ModuleInterfaceLoader(ctx, InterfaceChecker, tracker, loadMode,
377+
PreferInterfaceForModules,
378+
IgnoreSwiftSourceInfoFile));
357379
}
358380

359381
/// Append visible module names to \p names. Note that names are possibly
@@ -373,18 +395,6 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
373395
StringRef ModuleName, StringRef InPath, StringRef OutPath,
374396
bool SerializeDependencyHashes, bool TrackSystemDependencies,
375397
ModuleInterfaceLoaderOptions Opts);
376-
377-
std::vector<std::string>
378-
getCompiledModuleCandidatesForInterface(StringRef moduleName,
379-
StringRef interfacePath) override;
380-
381-
/// Given a list of potential ready-to-use compiled modules for \p interfacePath,
382-
/// check if any one of them is up-to-date. If so, emit a forwarding module
383-
/// to the candidate binary module to \p outPath.
384-
bool tryEmitForwardingModule(StringRef moduleName,
385-
StringRef interfacePath,
386-
ArrayRef<std::string> candidates,
387-
StringRef outPath) override;
388398
};
389399

390400
struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {

include/swift/SILOptimizer/Utils/InstOptUtils.h

+6
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ void getConsumedPartialApplyArgs(PartialApplyInst *pai,
357357
SmallVectorImpl<Operand *> &argOperands,
358358
bool includeTrivialAddrArgs);
359359

360+
/// Emit destroy operation for \p operand, and call appropriate functions from
361+
/// \p callbacks for newly created instructions and deleted instructions.
362+
void emitDestroyOperation(SILBuilder &builder, SILLocation loc,
363+
SILValue operand, InstModCallbacks callbacks);
364+
360365
/// Collect all (transitive) users of \p inst which just copy or destroy \p
361366
/// inst.
362367
///
@@ -366,6 +371,7 @@ void getConsumedPartialApplyArgs(PartialApplyInst *pai,
366371
/// destroys, i.e. if \p inst can be considered as "dead".
367372
bool collectDestroys(SingleValueInstruction *inst,
368373
SmallVectorImpl<SILInstruction *> &destroys);
374+
369375
/// If Closure is a partial_apply or thin_to_thick_function with only local
370376
/// ref count users and a set of post-dominating releases:
371377
///

include/swift/Serialization/SerializedModuleLoader.h

-12
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,6 @@ class SerializedModuleLoaderBase : public ModuleLoader {
201201
virtual Optional<ModuleDependencies> getModuleDependencies(
202202
StringRef moduleName, ModuleDependenciesCache &cache,
203203
InterfaceSubContextDelegate &delegate) override;
204-
205-
virtual std::vector<std::string>
206-
getCompiledModuleCandidatesForInterface(StringRef moduleName,
207-
StringRef interfacePath) {
208-
return std::vector<std::string>();
209-
}
210-
virtual bool tryEmitForwardingModule(StringRef moduleName,
211-
StringRef interfacePath,
212-
ArrayRef<std::string> candidates,
213-
StringRef outPath) {
214-
return false;
215-
}
216204
};
217205

218206
/// Imports serialized Swift modules into an ASTContext.

include/swift/Strings.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_UNSAFEVALUEBUFFER =
113113
{"Builtin.UnsafeValueBuffer"};
114114
/// The name of the Builtin type for UnknownObject
115115
///
116-
/// This no longer exists as an AST-accessible type, but it's still used for
116+
/// This no longer exists as an AST-accessible type, but it's still used for
117117
/// fields shaped like AnyObject when ObjC interop is enabled.
118118
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_UNKNOWNOBJECT = {
119119
"Builtin.UnknownObject"};

lib/AST/ASTContext.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ struct ASTContext::Implementation {
255255
/// The set of known protocols, lazily populated as needed.
256256
ProtocolDecl *KnownProtocols[NumKnownProtocols] = { };
257257

258+
/// The module interface checker owned by the ASTContext.
259+
std::unique_ptr<ModuleInterfaceChecker> InterfaceChecker;
260+
258261
/// The various module loaders that import external modules into this
259262
/// ASTContext.
260263
SmallVector<std::unique_ptr<swift::ModuleLoader>, 4> ModuleLoaders;
@@ -268,9 +271,6 @@ struct ASTContext::Implementation {
268271
/// The module loader used to load Clang modules from DWARF.
269272
ClangModuleLoader *TheDWARFModuleLoader = nullptr;
270273

271-
/// The module loader used to load Swift textual interface.
272-
ModuleLoader *TheModuleInterfaceLoader = nullptr;
273-
274274
/// Map from Swift declarations to raw comments.
275275
llvm::DenseMap<const Decl *, RawComment> RawComments;
276276

@@ -1522,11 +1522,15 @@ void ASTContext::addModuleLoader(std::unique_ptr<ModuleLoader> loader,
15221522
if (IsClang && IsDwarf && !getImpl().TheDWARFModuleLoader)
15231523
getImpl().TheDWARFModuleLoader =
15241524
static_cast<ClangModuleLoader *>(loader.get());
1525-
if (IsInterface && !getImpl().TheModuleInterfaceLoader)
1526-
getImpl().TheModuleInterfaceLoader = loader.get();
15271525
getImpl().ModuleLoaders.push_back(std::move(loader));
15281526
}
15291527

1528+
void ASTContext::addModuleInterfaceChecker(
1529+
std::unique_ptr<ModuleInterfaceChecker> checker) {
1530+
assert(!getImpl().InterfaceChecker && "Checker has been set already");
1531+
getImpl().InterfaceChecker = std::move(checker);
1532+
}
1533+
15301534
Optional<ModuleDependencies> ASTContext::getModuleDependencies(
15311535
StringRef moduleName, bool isUnderlyingClangModule,
15321536
ModuleDependenciesCache &cache, InterfaceSubContextDelegate &delegate) {
@@ -1613,8 +1617,10 @@ ClangModuleLoader *ASTContext::getDWARFModuleLoader() const {
16131617
return getImpl().TheDWARFModuleLoader;
16141618
}
16151619

1616-
ModuleLoader *ASTContext::getModuleInterfaceLoader() const {
1617-
return getImpl().TheModuleInterfaceLoader;
1620+
ModuleInterfaceChecker *ASTContext::getModuleInterfaceChecker() const {
1621+
auto *result = getImpl().InterfaceChecker.get();
1622+
assert(result);
1623+
return result;
16181624
}
16191625

16201626
ModuleDecl *ASTContext::getLoadedModule(

lib/AST/Decl.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -5835,6 +5835,17 @@ VarDecl *VarDecl::getPropertyWrapperProjectionVar() const {
58355835
return getPropertyWrapperBackingPropertyInfo().projectionVar;
58365836
}
58375837

5838+
void VarDecl::visitAuxiliaryDecls(llvm::function_ref<void(VarDecl *)> visit) const {
5839+
if (getDeclContext()->isTypeContext())
5840+
return;
5841+
5842+
if (auto *backingVar = getPropertyWrapperBackingProperty())
5843+
visit(backingVar);
5844+
5845+
if (auto *projectionVar = getPropertyWrapperProjectionVar())
5846+
visit(projectionVar);
5847+
}
5848+
58385849
VarDecl *VarDecl::getLazyStorageProperty() const {
58395850
auto &ctx = getASTContext();
58405851
auto mutableThis = const_cast<VarDecl *>(this);

lib/AST/UnqualifiedLookup.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/ModuleNameLookup.h"
2323
#include "swift/AST/NameLookup.h"
2424
#include "swift/AST/NameLookupRequests.h"
25+
#include "swift/AST/PropertyWrappers.h"
2526
#include "swift/Basic/Debug.h"
2627
#include "swift/Basic/STLExtras.h"
2728
#include "swift/Basic/SourceManager.h"
@@ -564,8 +565,22 @@ bool ASTScopeDeclConsumerForUnqualifiedLookup::consume(
564565
}
565566
}
566567

567-
if (!value->getName().matchesRef(factory.Name.getFullName()))
568-
continue;
568+
auto fullName = factory.Name.getFullName();
569+
if (!value->getName().matchesRef(fullName)) {
570+
bool foundMatch = false;
571+
if (auto *varDecl = dyn_cast<VarDecl>(value)) {
572+
// Check if the name matches any auxiliary decls not in the AST
573+
varDecl->visitAuxiliaryDecls([&](VarDecl *auxiliaryVar) {
574+
if (auxiliaryVar->ValueDecl::getName().matchesRef(fullName)) {
575+
value = auxiliaryVar;
576+
foundMatch = true;
577+
}
578+
});
579+
}
580+
581+
if (!foundMatch)
582+
continue;
583+
}
569584

570585
// In order to preserve the behavior of the existing context-based lookup,
571586
// which finds all results for non-local variables at the top level instead

0 commit comments

Comments
 (0)