Skip to content

Commit 0240f08

Browse files
authored
Merge pull request #1841 from swiftwasm/main
[pull] swiftwasm from main
2 parents b04be70 + f158e6a commit 0240f08

Some content is hidden

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

43 files changed

+631
-266
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
SWIFT_TYPEID(ActorIsolation)
1919
SWIFT_TYPEID(AncestryFlags)
20+
SWIFT_TYPEID(BodyInitKind)
21+
SWIFT_TYPEID(BodyInitKindAndExpr)
2022
SWIFT_TYPEID(CtorInitializerKind)
2123
SWIFT_TYPEID(FunctionBuilderBodyPreCheck)
2224
SWIFT_TYPEID(GenericSignature)
@@ -35,6 +37,7 @@ SWIFT_TYPEID(TypePair)
3537
SWIFT_TYPEID(TypeWitnessAndDecl)
3638
SWIFT_TYPEID(Witness)
3739
SWIFT_TYPEID_NAMED(AbstractFunctionDecl *, AbstractFunctionDecl)
40+
SWIFT_TYPEID_NAMED(ApplyExpr *, ApplyExpr)
3841
SWIFT_TYPEID_NAMED(ClosureExpr *, ClosureExpr)
3942
SWIFT_TYPEID_NAMED(CodeCompletionCallbacksFactory *,
4043
CodeCompletionCallbacksFactory)

include/swift/AST/ASTTypeIDs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ namespace swift {
2424

2525
class AbstractFunctionDecl;
2626
class ActorIsolation;
27+
class ApplyExpr;
28+
enum class BodyInitKind;
29+
struct BodyInitKindAndExpr;
2730
class BraceStmt;
2831
class ClosureExpr;
2932
class CodeCompletionCallbacksFactory;

include/swift/AST/Decl.h

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,7 @@ class alignas(1 << DeclAlignInBits) Decl {
451451
/// Whether we have computed the above.
452452
IsTransparentComputed : 1);
453453

454-
SWIFT_INLINE_BITFIELD(ConstructorDecl, AbstractFunctionDecl, 3+1+1,
455-
/// The body initialization kind (+1), or zero if not yet computed.
456-
///
457-
/// This value is cached but is not serialized, because it is a property
458-
/// of the definition of the constructor that is useful only to semantic
459-
/// analysis and SIL generation.
460-
ComputedBodyInitKind : 3,
461-
454+
SWIFT_INLINE_BITFIELD(ConstructorDecl, AbstractFunctionDecl, 1+1,
462455
/// Whether this constructor can fail, by building an Optional type.
463456
Failable : 1,
464457

@@ -6770,6 +6763,37 @@ enum class CtorInitializerKind {
67706763
Factory
67716764
};
67726765

6766+
/// Specifies the kind of initialization call performed within the body
6767+
/// of the constructor, e.g., self.init or super.init.
6768+
enum class BodyInitKind {
6769+
/// There are no calls to self.init or super.init.
6770+
None,
6771+
/// There is a call to self.init, which delegates to another (peer)
6772+
/// initializer.
6773+
Delegating,
6774+
/// There is a call to super.init, which chains to a superclass initializer.
6775+
Chained,
6776+
/// There are no calls to self.init or super.init explicitly in the body of
6777+
/// the constructor, but a 'super.init' call will be implicitly added
6778+
/// by semantic analysis.
6779+
ImplicitChained
6780+
};
6781+
6782+
struct BodyInitKindAndExpr {
6783+
BodyInitKind initKind;
6784+
ApplyExpr *initExpr;
6785+
6786+
BodyInitKindAndExpr() : initKind(BodyInitKind::None), initExpr(nullptr) {}
6787+
6788+
BodyInitKindAndExpr(BodyInitKind initKind, ApplyExpr *initExpr)
6789+
: initKind(initKind), initExpr(initExpr) {}
6790+
6791+
friend bool operator==(BodyInitKindAndExpr lhs, BodyInitKindAndExpr rhs) {
6792+
return (lhs.initKind == rhs.initKind &&
6793+
lhs.initExpr == rhs.initExpr);
6794+
}
6795+
};
6796+
67736797
/// ConstructorDecl - Declares a constructor for a type. For example:
67746798
///
67756799
/// \code
@@ -6818,38 +6842,11 @@ class ConstructorDecl : public AbstractFunctionDecl {
68186842

68196843
ParamDecl **getImplicitSelfDeclStorage() { return &SelfDecl; }
68206844

6821-
/// Specifies the kind of initialization call performed within the body
6822-
/// of the constructor, e.g., self.init or super.init.
6823-
enum class BodyInitKind {
6824-
/// There are no calls to self.init or super.init.
6825-
None,
6826-
/// There is a call to self.init, which delegates to another (peer)
6827-
/// initializer.
6828-
Delegating,
6829-
/// There is a call to super.init, which chains to a superclass initializer.
6830-
Chained,
6831-
/// There are no calls to self.init or super.init explicitly in the body of
6832-
/// the constructor, but a 'super.init' call will be implicitly added
6833-
/// by semantic analysis.
6834-
ImplicitChained
6835-
};
6836-
68376845
/// Determine whether the body of this constructor contains any delegating
68386846
/// or superclass initializations (\c self.init or \c super.init,
68396847
/// respectively) within its body.
6840-
///
6841-
/// \param diags If non-null, this check will ensure that the constructor
6842-
/// body is consistent in its use of delegation vs. chaining and emit any
6843-
/// diagnostics through the given diagnostic engine.
6844-
///
6845-
/// \param init If non-null and there is an explicit \c self.init or
6846-
/// \c super.init within the body, will be set to point at that
6847-
/// initializer.
6848-
BodyInitKind getDelegatingOrChainedInitKind(DiagnosticEngine *diags,
6849-
ApplyExpr **init = nullptr) const;
6850-
void clearCachedDelegatingOrChainedInitKind() {
6851-
Bits.ConstructorDecl.ComputedBodyInitKind = 0;
6852-
}
6848+
BodyInitKindAndExpr getDelegatingOrChainedInitKind() const;
6849+
void clearCachedDelegatingOrChainedInitKind();
68536850

68546851
/// Whether this constructor is required.
68556852
bool isRequired() const {

include/swift/AST/Evaluator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ class Evaluator {
322322
cache.insert({AnyRequest(request), std::move(output)});
323323
}
324324

325+
/// Do not introduce new callers of this function.
326+
template<typename Request,
327+
typename std::enable_if<!Request::hasExternalCache>::type* = nullptr>
328+
void clearCachedOutput(const Request &request) {
329+
cache.erase(AnyRequest(request));
330+
}
331+
325332
/// Clear the cache stored within this evaluator.
326333
///
327334
/// Note that this does not clear the caches of requests that use external

include/swift/AST/Expr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5793,6 +5793,7 @@ Expr *packSingleArgument(
57935793

57945794
void simple_display(llvm::raw_ostream &out, const ClosureExpr *CE);
57955795
void simple_display(llvm::raw_ostream &out, const DefaultArgumentExpr *expr);
5796+
void simple_display(llvm::raw_ostream &out, const Expr *expr);
57965797

57975798
SourceLoc extractNearestSourceLoc(const DefaultArgumentExpr *expr);
57985799

include/swift/AST/FineGrainedDependencies.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,8 @@ class SourceFileDepGraph {
851851
/// Read a swiftdeps file from \p buffer and return a SourceFileDepGraph if
852852
/// successful.
853853
Optional<SourceFileDepGraph> static loadFromBuffer(llvm::MemoryBuffer &);
854+
Optional<SourceFileDepGraph> static loadFromSwiftModuleBuffer(
855+
llvm::MemoryBuffer &);
854856

855857
void verifySame(const SourceFileDepGraph &other) const;
856858

include/swift/AST/FineGrainedDependencyFormat.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ using NodeKindField = BCFixed<3>;
4848
using DeclAspectField = BCFixed<1>;
4949

5050
const unsigned RECORD_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID;
51+
const unsigned INCREMENTAL_INFORMATION_BLOCK_ID = 196;
5152

5253
/// The swiftdeps file format consists of a METADATA record, followed by zero or more
5354
/// IDENTIFIER_NODE records.
@@ -113,10 +114,16 @@ namespace record_block {
113114
}
114115

115116
/// Tries to read the dependency graph from the given buffer.
116-
/// Returns true if there was an error.
117+
/// Returns \c true if there was an error.
117118
bool readFineGrainedDependencyGraph(llvm::MemoryBuffer &buffer,
118119
SourceFileDepGraph &g);
119120

121+
/// Tries to read the dependency graph from the given buffer, assuming that it
122+
/// is in the format of a swiftmodule file.
123+
/// Returns \c true if there was an error.
124+
bool readFineGrainedDependencyGraphFromSwiftModule(llvm::MemoryBuffer &buffer,
125+
SourceFileDepGraph &g);
126+
120127
/// Tries to read the dependency graph from the given path name.
121128
/// Returns true if there was an error.
122129
bool readFineGrainedDependencyGraph(llvm::StringRef path,

include/swift/AST/NameLookup.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,14 @@ class ASTScope {
684684
static void unqualifiedLookup(SourceFile *, SourceLoc,
685685
namelookup::AbstractASTScopeDeclConsumer &);
686686

687+
/// Lookup that only finds local declarations and does not trigger
688+
/// interface type computation.
689+
static void lookupLocalDecls(SourceFile *, DeclName, SourceLoc,
690+
SmallVectorImpl<ValueDecl *> &);
691+
692+
/// Returns the result if there is exactly one, nullptr otherwise.
693+
static ValueDecl *lookupSingleLocalDecl(SourceFile *, DeclName, SourceLoc);
694+
687695
/// Entry point to record the visible statement labels from the given
688696
/// point.
689697
///

include/swift/AST/TypeCheckRequests.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,29 @@ class InitKindRequest :
211211
CtorInitializerKind
212212
evaluate(Evaluator &evaluator, ConstructorDecl *decl) const;
213213

214+
public:
215+
// Caching.
216+
bool isCached() const { return true; }
217+
};
218+
219+
void simple_display(llvm::raw_ostream &out, BodyInitKind initKind);
220+
void simple_display(llvm::raw_ostream &out, BodyInitKindAndExpr initKindAndExpr);
221+
222+
/// Computes the kind of initializer call (self.init or super.init) performed
223+
/// in the body of a \c ConstructorDecl
224+
class BodyInitKindRequest :
225+
public SimpleRequest<BodyInitKindRequest,
226+
BodyInitKindAndExpr(ConstructorDecl *),
227+
RequestFlags::Cached> {
228+
public:
229+
using SimpleRequest::SimpleRequest;
230+
231+
private:
232+
friend SimpleRequest;
233+
234+
// Evaluation.
235+
BodyInitKindAndExpr evaluate(Evaluator &evaluator, ConstructorDecl *decl) const;
236+
214237
public:
215238
// Caching.
216239
bool isCached() const { return true; }

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ SWIFT_REQUEST(TypeChecker, InheritsSuperclassInitializersRequest,
121121
bool(ClassDecl *), SeparatelyCached, NoLocationInfo)
122122
SWIFT_REQUEST(TypeChecker, InitKindRequest,
123123
CtorInitializerKind(ConstructorDecl *), Cached, NoLocationInfo)
124+
SWIFT_REQUEST(TypeChecker, BodyInitKindRequest,
125+
BodyInitKindAndExpr(ConstructorDecl *), Cached,
126+
NoLocationInfo)
124127
SWIFT_REQUEST(TypeChecker, InterfaceTypeRequest,
125128
Type(ValueDecl *), SeparatelyCached, NoLocationInfo)
126129
SWIFT_REQUEST(TypeChecker, IsAccessorTransparentRequest, bool(AccessorDecl *),

0 commit comments

Comments
 (0)