Skip to content

Commit b64823c

Browse files
authored
Merge pull request #1829 from swiftwasm/main
[pull] swiftwasm from main
2 parents cdd8db1 + 360afd6 commit b64823c

File tree

83 files changed

+915
-573
lines changed

Some content is hidden

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

83 files changed

+915
-573
lines changed

include/swift/AST/ASTScope.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,6 @@ class ASTScopeImpl {
344344
virtual NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion();
345345
virtual SourceRange sourceRangeForDeferredExpansion() const;
346346

347-
public:
348-
bool isATypeDeclScope() const;
349-
350347
private:
351348
virtual ScopeCreator &getScopeCreator();
352349

@@ -435,6 +432,7 @@ class ASTScopeImpl {
435432
return p->getParent().isNonNull() ? p : nullptr;
436433
}
437434

435+
public:
438436
/// The tree is organized by source location and for most nodes this is also
439437
/// what obtaines for scoping. However, guards are different. The scope after
440438
/// the guard else must hop into the innermoset scope of the guard condition.
@@ -1079,6 +1077,7 @@ class PatternEntryDeclScope final : public AbstractPatternEntryScope {
10791077

10801078
protected:
10811079
bool lookupLocalsOrMembers(DeclConsumer) const override;
1080+
bool isLabeledStmtLookupTerminator() const override;
10821081
};
10831082

10841083
class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
@@ -1093,6 +1092,7 @@ class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
10931092

10941093
protected:
10951094
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;
1095+
NullablePtr<const ASTScopeImpl> getLookupParent() const override;
10961096

10971097
private:
10981098
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);

include/swift/AST/Decl.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class alignas(1 << DeclAlignInBits) Decl {
578578
HasAnyUnavailableValues : 1
579579
);
580580

581-
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1+1,
581+
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1+1+1,
582582
/// If the module was or is being compiled with `-enable-testing`.
583583
TestingEnabled : 1,
584584

@@ -607,7 +607,10 @@ class alignas(1 << DeclAlignInBits) Decl {
607607
IsNonSwiftModule : 1,
608608

609609
/// Whether this module is the main module.
610-
IsMainModule : 1
610+
IsMainModule : 1,
611+
612+
/// Whether this module has incremental dependency information available.
613+
HasIncrementalInfo : 1
611614
);
612615

613616
SWIFT_INLINE_BITFIELD(PrecedenceGroupDecl, Decl, 1+2,
@@ -4121,12 +4124,14 @@ struct SelfReferenceKind {
41214124
return SelfReferenceKind(false, false, false, false);
41224125
}
41234126

4124-
/// The type refers to 'Self', but only as the result type of a method.
4127+
/// The type refers to 'Self', but only as the type of a property or
4128+
/// the result type of a method/subscript.
41254129
static SelfReferenceKind Result() {
41264130
return SelfReferenceKind(true, false, false, false);
41274131
}
41284132

4129-
/// The type refers to 'Self', but only as the parameter type of a method.
4133+
/// The type refers to 'Self', but only as the parameter type
4134+
/// of a method/subscript.
41304135
static SelfReferenceKind Parameter() {
41314136
return SelfReferenceKind(false, true, false, false);
41324137
}
@@ -5948,6 +5953,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
59485953
/// Returns true if the function is an @asyncHandler.
59495954
bool isAsyncHandler() const;
59505955

5956+
/// Returns true if the function if the signature matches the form of an
5957+
/// @asyncHandler.
5958+
bool canBeAsyncHandler() const;
5959+
59515960
/// Returns true if the function body throws.
59525961
bool hasThrows() const { return Bits.AbstractFunctionDecl.Throws; }
59535962

include/swift/AST/DiagnosticsSema.def

+8-7
Original file line numberDiff line numberDiff line change
@@ -1992,14 +1992,15 @@ NOTE(witness_self_weaken_same_type,none,
19921992
"consider weakening the same-type requirement %0 == %1 to a superclass "
19931993
"requirement", (Type, Type))
19941994
ERROR(witness_requires_dynamic_self,none,
1995-
"method %0 in non-final class %1 must return 'Self' to conform to "
1996-
"protocol %2",
1997-
(DeclName, Type, Type))
1995+
"%select{%error|method|property|subscript}0 %1 in non-final class %2 "
1996+
"must %select{%error|return|specify type|return}0 'Self' "
1997+
"to conform to protocol %3",
1998+
(RequirementKind, DeclName, Type, Type))
19981999
ERROR(witness_requires_class_implementation,none,
1999-
"method %0 in non-final class %1 cannot be implemented in a "
2000-
"protocol extension because it returns 'Self' and has associated type "
2001-
"requirements",
2002-
(DeclName, Type))
2000+
"%select{%error|method|%error|subscript}0 %1 in non-final class %2 "
2001+
"cannot be implemented in a protocol extension because it returns 'Self' "
2002+
"and has associated type requirements",
2003+
(RequirementKind, DeclName, Type))
20032004
ERROR(witness_not_accessible_proto,none,
20042005
"%select{initializer %1|method %1|%select{|setter for }2property %1"
20052006
"|subscript%select{| setter}2}0 must be declared "

include/swift/AST/FineGrainedDependencies.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ namespace swift {
5959
class DependencyTracker;
6060
class DiagnosticEngine;
6161
class FrontendOptions;
62+
class ModuleDecl;
6263
class SourceFile;
6364

6465
/// Use a new namespace to help keep the experimental code from clashing.
6566
namespace fine_grained_dependencies {
6667

68+
class SourceFileDepGraph;
69+
6770
using StringVec = std::vector<std::string>;
6871

6972
template <typename Element> using ConstPtrVec = std::vector<const Element *>;
@@ -343,11 +346,11 @@ class BiIndexedTwoStageMap {
343346
// MARK: Start of fine-grained-dependency-specific code
344347
//==============================================================================
345348

346-
/// The entry point into this system from the frontend:
347-
/// Write out the .swiftdeps file for a frontend compilation of a primary file.
348-
bool emitReferenceDependencies(DiagnosticEngine &diags, SourceFile *SF,
349-
const DependencyTracker &depTracker,
350-
StringRef outputPath, bool alsoEmitDotFile);
349+
bool withReferenceDependencies(
350+
llvm::PointerUnion<ModuleDecl *, SourceFile *> MSF,
351+
const DependencyTracker &depTracker, StringRef outputPath,
352+
bool alsoEmitDotFile, llvm::function_ref<bool(SourceFileDepGraph &&)>);
353+
351354
//==============================================================================
352355
// MARK: Enums
353356
//==============================================================================

include/swift/AST/FineGrainedDependencyFormat.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ bool readFineGrainedDependencyGraph(llvm::StringRef path,
124124

125125
/// Tries to write the dependency graph to the given path name.
126126
/// Returns true if there was an error.
127-
bool writeFineGrainedDependencyGraph(DiagnosticEngine &diags, llvm::StringRef path,
127+
bool writeFineGrainedDependencyGraphToPath(DiagnosticEngine &diags,
128+
llvm::StringRef path,
129+
const SourceFileDepGraph &g);
130+
131+
void writeFineGrainedDependencyGraph(llvm::BitstreamWriter &Out,
128132
const SourceFileDepGraph &g);
129133

130134
} // namespace fine_grained_dependencies

include/swift/AST/Module.h

+6
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,12 @@ class ModuleDecl : public DeclContext, public TypeDecl {
517517
Bits.ModuleDecl.RawResilienceStrategy = unsigned(strategy);
518518
}
519519

520+
/// Returns true if this module was or is being compiled for testing.
521+
bool hasIncrementalInfo() const { return Bits.ModuleDecl.HasIncrementalInfo; }
522+
void setHasIncrementalInfo(bool enabled = true) {
523+
Bits.ModuleDecl.HasIncrementalInfo = enabled;
524+
}
525+
520526
/// \returns true if this module is a system module; note that the StdLib is
521527
/// considered a system module.
522528
bool isSystemModule() const {

include/swift/AST/TypeCheckRequests.h

+19
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,25 @@ class IsAsyncHandlerRequest :
797797
bool isCached() const { return true; }
798798
};
799799

800+
/// Determine whether the given function can be an @asyncHandler, without
801+
/// producing any diagnostics.
802+
class CanBeAsyncHandlerRequest :
803+
public SimpleRequest<CanBeAsyncHandlerRequest,
804+
bool(FuncDecl *),
805+
RequestFlags::Cached> {
806+
public:
807+
using SimpleRequest::SimpleRequest;
808+
809+
private:
810+
friend SimpleRequest;
811+
812+
bool evaluate(Evaluator &evaluator, FuncDecl *func) const;
813+
814+
public:
815+
// Caching
816+
bool isCached() const { return true; }
817+
};
818+
800819
/// Determine whether the given class is an actor.
801820
class IsActorRequest :
802821
public SimpleRequest<IsActorRequest,

include/swift/AST/TypeCheckerTypeIDZone.def

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ SWIFT_REQUEST(TypeChecker, FunctionBuilderTypeRequest, Type(ValueDecl *),
8383
Cached, NoLocationInfo)
8484
SWIFT_REQUEST(TypeChecker, IsAsyncHandlerRequest, bool(FuncDecl *),
8585
Cached, NoLocationInfo)
86+
SWIFT_REQUEST(TypeChecker, CanBeAsyncHandlerRequest, bool(FuncDecl *),
87+
Cached, NoLocationInfo)
8688
SWIFT_REQUEST(TypeChecker, IsActorRequest, bool(ClassDecl *),
8789
Cached, NoLocationInfo)
8890
SWIFT_REQUEST(TypeChecker, ActorIsolationRequest,

include/swift/Driver/Compilation.h

+9-11
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,6 @@ class Compilation {
206206
/// of date.
207207
bool EnableIncrementalBuild;
208208

209-
/// When true, emit duplicated compilation record file whose filename is
210-
/// suffixed with '~moduleonly'.
211-
///
212-
/// This compilation record is used by '-emit-module'-only incremental builds
213-
/// so that module-only builds do not affect compilation record file for
214-
/// normal builds, while module-only incremental builds are able to use
215-
/// artifacts of normal builds if they are already up to date.
216-
bool OutputCompilationRecordForModuleOnlyBuild = false;
217-
218209
/// Indicates whether groups of parallel frontend jobs should be merged
219210
/// together and run in composite "batch jobs" when possible, to reduce
220211
/// redundant work.
@@ -290,6 +281,9 @@ class Compilation {
290281
/// Experiment with source-range-based dependencies
291282
const bool EnableSourceRangeDependencies;
292283

284+
/// (experimental) Enable cross-module incremental build scheduling.
285+
const bool EnableCrossModuleIncrementalBuild;
286+
293287
public:
294288
/// Will contain a comparator if an argument demands it.
295289
Optional<IncrementalSchemeComparator> IncrementalComparator;
@@ -313,7 +307,6 @@ class Compilation {
313307
std::unique_ptr<llvm::opt::DerivedArgList> TranslatedArgs,
314308
InputFileList InputsWithTypes,
315309
std::string CompilationRecordPath,
316-
bool OutputCompilationRecordForModuleOnlyBuild,
317310
StringRef ArgsHash, llvm::sys::TimePoint<> StartTime,
318311
llvm::sys::TimePoint<> LastBuildTime,
319312
size_t FilelistThreshold,
@@ -333,7 +326,8 @@ class Compilation {
333326
bool FineGrainedDependenciesIncludeIntrafileOnes = false,
334327
bool EnableSourceRangeDependencies = false,
335328
bool CompareIncrementalSchemes = false,
336-
StringRef CompareIncrementalSchemesPath = "");
329+
StringRef CompareIncrementalSchemesPath = "",
330+
bool EnableCrossModuleIncrementalBuild = false);
337331
// clang-format on
338332
~Compilation();
339333

@@ -439,6 +433,10 @@ class Compilation {
439433
return ShowDriverTimeCompilation;
440434
}
441435

436+
bool getEnableCrossModuleIncrementalBuild() const {
437+
return EnableCrossModuleIncrementalBuild;
438+
}
439+
442440
size_t getFilelistThreshold() const {
443441
return FilelistThreshold;
444442
}

include/swift/Frontend/FrontendOptions.h

+8
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ class FrontendOptions {
276276
/// of the main Swift module's source files.
277277
bool ImportPrescan = false;
278278

279+
/// When performing an incremental build, ensure that cross-module incremental
280+
/// build metadata is available in any swift modules emitted by this frontend
281+
/// job.
282+
///
283+
/// This flag is currently only propagated from the driver to
284+
/// any merge-modules jobs.
285+
bool EnableExperimentalCrossModuleIncrementalBuild = false;
286+
279287
/// The different modes for validating TBD against the LLVM IR.
280288
enum class TBDValidationMode {
281289
Default, ///< Do the default validation for the current platform.

include/swift/Option/Options.td

+5
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,11 @@ def experimental_cxx_stdlib :
584584
Separate<["-"], "experimental-cxx-stdlib">,
585585
HelpText<"C++ standard library to use; forwarded to Clang's -stdlib flag">;
586586

587+
def enable_experimental_cross_module_incremental_build :
588+
Flag<["-"], "enable-experimental-cross-module-incremental-build">,
589+
HelpText<"(experimental) Enable cross-module incremental build metadata and "
590+
"driver scheduling">;
591+
587592

588593
// Diagnostic control options
589594
def suppress_warnings : Flag<["-"], "suppress-warnings">,

include/swift/SIL/SILCloner.h

+7
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,13 @@ template <typename ImplClass>
15421542
void SILCloner<ImplClass>::visitUncheckedValueCastInst(
15431543
UncheckedValueCastInst *Inst) {
15441544
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1545+
if (!getBuilder().hasOwnership()) {
1546+
recordClonedInstruction(Inst, getBuilder().createUncheckedBitwiseCast(
1547+
getOpLocation(Inst->getLoc()),
1548+
getOpValue(Inst->getOperand()),
1549+
getOpType(Inst->getType())));
1550+
return;
1551+
}
15451552
recordClonedInstruction(Inst, getBuilder().createUncheckedValueCast(
15461553
getOpLocation(Inst->getLoc()),
15471554
getOpValue(Inst->getOperand()),

include/swift/SIL/SILModule.h

+22
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ class SILModule {
263263
/// to ensure that the module is serialized only once.
264264
bool serialized;
265265

266+
/// Set if we have registered a deserialization notification handler for
267+
/// lowering ownership in non transparent functions.
268+
/// This gets set in NonTransparent OwnershipModelEliminator pass.
269+
bool regDeserializationNotificationHandlerForNonTransparentFuncOME;
270+
/// Set if we have registered a deserialization notification handler for
271+
/// lowering ownership in transparent functions.
272+
/// This gets set in OwnershipModelEliminator pass.
273+
bool regDeserializationNotificationHandlerForAllFuncOME;
274+
266275
/// Action to be executed for serializing the SILModule.
267276
ActionCallback SerializeSILAction;
268277

@@ -301,6 +310,19 @@ class SILModule {
301310
deserializationNotificationHandlers.erase(handler);
302311
}
303312

313+
bool hasRegisteredDeserializationNotificationHandlerForNonTransparentFuncOME() {
314+
return regDeserializationNotificationHandlerForNonTransparentFuncOME;
315+
}
316+
bool hasRegisteredDeserializationNotificationHandlerForAllFuncOME() {
317+
return regDeserializationNotificationHandlerForAllFuncOME;
318+
}
319+
void setRegisteredDeserializationNotificationHandlerForNonTransparentFuncOME() {
320+
regDeserializationNotificationHandlerForNonTransparentFuncOME = true;
321+
}
322+
void setRegisteredDeserializationNotificationHandlerForAllFuncOME() {
323+
regDeserializationNotificationHandlerForAllFuncOME = true;
324+
}
325+
304326
/// Add a delete notification handler \p Handler to the module context.
305327
void registerDeleteNotificationHandler(DeleteNotificationHandler* Handler);
306328

include/swift/SILOptimizer/PassManager/PassManager.h

+5
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ class SILPassManager {
281281
/// Run the passes in Transform from \p FromTransIdx to \p ToTransIdx.
282282
void runFunctionPasses(unsigned FromTransIdx, unsigned ToTransIdx);
283283

284+
/// Helper function to check if the function pass should be run mandatorily
285+
/// All passes in mandatory pass pipeline and ownership model elimination are
286+
/// mandatory function passes.
287+
bool isMandatoryFunctionPass(SILFunctionTransform *);
288+
284289
/// A helper function that returns (based on SIL stage and debug
285290
/// options) whether we should continue running passes.
286291
bool continueTransforming();

include/swift/Serialization/SerializationOptions.h

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ namespace swift {
131131
bool SerializeAllSIL = false;
132132
bool SerializeOptionsForDebugging = false;
133133
bool IsSIB = false;
134+
bool ExperimentalCrossModuleIncrementalInfo = false;
134135
};
135136

136137
} // end namespace swift

include/swift/Serialization/SerializedModuleLoader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class SerializedModuleLoaderBase : public ModuleLoader {
153153
///
154154
/// If the AST cannot be loaded and \p diagLoc is present, a diagnostic is
155155
/// printed. (Note that \p diagLoc is allowed to be invalid.)
156-
FileUnit *
156+
LoadedFile *
157157
loadAST(ModuleDecl &M, Optional<SourceLoc> diagLoc,
158158
StringRef moduleInterfacePath,
159159
std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer,

include/swift/Subsystems.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ namespace swift {
7575
class TypeConverter;
7676
}
7777

78+
namespace fine_grained_dependencies {
79+
class SourceFileDepGraph;
80+
}
81+
7882
/// @{
7983

8084
/// \returns true if the declaration should be verified. This can return
@@ -174,8 +178,10 @@ namespace swift {
174178
using ModuleOrSourceFile = PointerUnion<ModuleDecl *, SourceFile *>;
175179

176180
/// Serializes a module or single source file to the given output file.
177-
void serialize(ModuleOrSourceFile DC, const SerializationOptions &options,
178-
const SILModule *M = nullptr);
181+
void
182+
serialize(ModuleOrSourceFile DC, const SerializationOptions &options,
183+
const SILModule *M = nullptr,
184+
const fine_grained_dependencies::SourceFileDepGraph *DG = nullptr);
179185

180186
/// Serializes a module or single source file to the given output file and
181187
/// returns back the file's contents as a memory buffer.

0 commit comments

Comments
 (0)