Skip to content

Commit b9fd62a

Browse files
committed
Merge branch 'master' of github.com:swiftwasm/swift into maxd/master-merge
# Conflicts: # test/stdlib/simd.swift.gyb # test/stdlib/simd_diagnostics.swift
2 parents 9c80702 + cdc38da commit b9fd62a

File tree

662 files changed

+5841
-3609
lines changed

Some content is hidden

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

662 files changed

+5841
-3609
lines changed

include/swift/AST/Attr.h

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "swift/AST/PlatformKind.h"
3737
#include "swift/AST/Requirement.h"
3838
#include "swift/AST/TrailingCallArguments.h"
39-
#include "swift/AST/TypeLoc.h"
4039
#include "llvm/ADT/SmallVector.h"
4140
#include "llvm/ADT/StringRef.h"
4241
#include "llvm/Support/ErrorHandling.h"
@@ -56,6 +55,7 @@ class LazyConformanceLoader;
5655
class LazyMemberLoader;
5756
class PatternBindingInitializer;
5857
class TrailingWhereClause;
58+
class TypeExpr;
5959

6060
/// TypeAttributes - These are attributes that may be applied to types.
6161
class TypeAttributes {
@@ -1110,47 +1110,41 @@ class DynamicReplacementAttr final
11101110

11111111
/// The \c @_typeEraser(TypeEraserType) attribute.
11121112
class TypeEraserAttr final : public DeclAttribute {
1113-
TypeLoc TypeEraserLoc;
1113+
TypeExpr *TypeEraserExpr;
11141114
LazyMemberLoader *Resolver;
11151115
uint64_t ResolverContextData;
11161116

11171117
friend class ResolveTypeEraserTypeRequest;
11181118

1119-
TypeEraserAttr(SourceLoc atLoc, SourceRange range, TypeLoc typeEraserLoc,
1119+
TypeEraserAttr(SourceLoc atLoc, SourceRange range, TypeExpr *typeEraserExpr,
11201120
LazyMemberLoader *Resolver, uint64_t Data)
11211121
: DeclAttribute(DAK_TypeEraser, atLoc, range, /*Implicit=*/false),
1122-
TypeEraserLoc(typeEraserLoc),
1122+
TypeEraserExpr(typeEraserExpr),
11231123
Resolver(Resolver), ResolverContextData(Data) {}
11241124

11251125
public:
11261126
static TypeEraserAttr *create(ASTContext &ctx,
11271127
SourceLoc atLoc, SourceRange range,
1128-
TypeLoc typeEraserLoc);
1128+
TypeExpr *typeEraserRepr);
11291129

11301130
static TypeEraserAttr *create(ASTContext &ctx,
11311131
LazyMemberLoader *Resolver,
11321132
uint64_t Data);
11331133

11341134
/// Retrieve the parsed type repr for this attribute, if it
11351135
/// was parsed. Else returns \c nullptr.
1136-
TypeRepr *getParsedTypeEraserTypeRepr() const {
1137-
return TypeEraserLoc.getTypeRepr();
1138-
}
1136+
TypeRepr *getParsedTypeEraserTypeRepr() const;
11391137

11401138
/// Retrieve the parsed location for this attribute, if it was parsed.
1141-
SourceLoc getLoc() const {
1142-
return TypeEraserLoc.getLoc();
1143-
}
1139+
SourceLoc getLoc() const;
11441140

11451141
/// Retrieve the resolved type of this attribute if it has been resolved by a
11461142
/// successful call to \c getResolvedType(). Otherwise,
11471143
/// returns \c Type()
11481144
///
11491145
/// This entrypoint is only suitable for syntactic clients like the
11501146
/// AST printer. Semantic clients should use \c getResolvedType() instead.
1151-
Type getTypeWithoutResolving() const {
1152-
return TypeEraserLoc.getType();
1153-
}
1147+
Type getTypeWithoutResolving() const;
11541148

11551149
/// Returns \c true if the type eraser type has a valid implementation of the
11561150
/// erasing initializer for the given protocol.
@@ -1464,25 +1458,26 @@ class SpecializeAttr : public DeclAttribute {
14641458
/// The @_implements attribute, which treats a decl as the implementation for
14651459
/// some named protocol requirement (but otherwise not-visible by that name).
14661460
class ImplementsAttr : public DeclAttribute {
1467-
1468-
TypeLoc ProtocolType;
1461+
TypeExpr *ProtocolType;
14691462
DeclName MemberName;
14701463
DeclNameLoc MemberNameLoc;
14711464

14721465
public:
14731466
ImplementsAttr(SourceLoc atLoc, SourceRange Range,
1474-
TypeLoc ProtocolType,
1467+
TypeExpr *ProtocolType,
14751468
DeclName MemberName,
14761469
DeclNameLoc MemberNameLoc);
14771470

14781471
static ImplementsAttr *create(ASTContext &Ctx, SourceLoc atLoc,
14791472
SourceRange Range,
1480-
TypeLoc ProtocolType,
1473+
TypeExpr *ProtocolType,
14811474
DeclName MemberName,
14821475
DeclNameLoc MemberNameLoc);
14831476

1484-
TypeLoc getProtocolType() const;
1485-
TypeLoc &getProtocolType();
1477+
void setProtocolType(Type ty);
1478+
Type getProtocolType() const;
1479+
TypeRepr *getProtocolTypeRepr() const;
1480+
14861481
DeclName getMemberName() const { return MemberName; }
14871482
DeclNameLoc getMemberNameLoc() const { return MemberNameLoc; }
14881483

@@ -1595,27 +1590,27 @@ class ClangImporterSynthesizedTypeAttr : public DeclAttribute {
15951590
/// Defines a custom attribute.
15961591
class CustomAttr final : public DeclAttribute,
15971592
public TrailingCallArguments<CustomAttr> {
1598-
TypeLoc type;
1593+
TypeExpr *typeExpr;
15991594
Expr *arg;
16001595
PatternBindingInitializer *initContext;
16011596
Expr *semanticInit = nullptr;
16021597

16031598
unsigned hasArgLabelLocs : 1;
16041599
unsigned numArgLabels : 16;
16051600

1606-
CustomAttr(SourceLoc atLoc, SourceRange range, TypeLoc type,
1601+
CustomAttr(SourceLoc atLoc, SourceRange range, TypeExpr *type,
16071602
PatternBindingInitializer *initContext, Expr *arg,
16081603
ArrayRef<Identifier> argLabels, ArrayRef<SourceLoc> argLabelLocs,
16091604
bool implicit);
16101605

16111606
public:
1612-
static CustomAttr *create(ASTContext &ctx, SourceLoc atLoc, TypeLoc type,
1607+
static CustomAttr *create(ASTContext &ctx, SourceLoc atLoc, TypeExpr *type,
16131608
bool implicit = false) {
16141609
return create(ctx, atLoc, type, false, nullptr, SourceLoc(), { }, { }, { },
16151610
SourceLoc(), implicit);
16161611
}
16171612

1618-
static CustomAttr *create(ASTContext &ctx, SourceLoc atLoc, TypeLoc type,
1613+
static CustomAttr *create(ASTContext &ctx, SourceLoc atLoc, TypeExpr *type,
16191614
bool hasInitializer,
16201615
PatternBindingInitializer *initContext,
16211616
SourceLoc lParenLoc,
@@ -1628,8 +1623,8 @@ class CustomAttr final : public DeclAttribute,
16281623
unsigned getNumArguments() const { return numArgLabels; }
16291624
bool hasArgumentLabelLocs() const { return hasArgLabelLocs; }
16301625

1631-
TypeLoc &getTypeLoc() { return type; }
1632-
const TypeLoc &getTypeLoc() const { return type; }
1626+
TypeRepr *getTypeRepr() const;
1627+
Type getType() const;
16331628

16341629
Expr *getArg() const { return arg; }
16351630
void setArg(Expr *newArg) { arg = newArg; }
@@ -1642,6 +1637,14 @@ class CustomAttr final : public DeclAttribute,
16421637
static bool classof(const DeclAttribute *DA) {
16431638
return DA->getKind() == DAK_Custom;
16441639
}
1640+
1641+
private:
1642+
friend class CustomAttrNominalRequest;
1643+
void resetTypeInformation(TypeExpr *repr);
1644+
1645+
private:
1646+
friend class CustomAttrTypeRequest;
1647+
void setType(Type ty);
16451648
};
16461649

16471650
/// Relates a property to its projection value property, as described by a property wrapper. For

include/swift/AST/EvaluatorDependencies.h

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ using DependencySource = llvm::PointerIntPair<SourceFile *, 1, DependencyScope>;
109109

110110
struct DependencyRecorder;
111111

112+
/// A \c DependencyCollector defines an abstract write-only buffer of
113+
/// \c Reference objects. References are added to a collector during the write
114+
/// phase of request evaluation (in \c writeDependencySink) with the various
115+
/// \c add* functions below..
116+
///
117+
/// A \c DependencyCollector cannot be created directly. You must invoke
118+
/// \c DependencyRecorder::record, which will wire a dependency collector into
119+
/// the provided continuation block.
112120
struct DependencyCollector {
113121
friend DependencyRecorder;
114122

@@ -227,11 +235,15 @@ struct DependencyCollector {
227235
void addDynamicLookupName(DeclBaseName name);
228236

229237
public:
238+
/// Retrieves the dependency recorder that created this dependency collector.
230239
const DependencyRecorder &getRecorder() const { return parent; }
240+
241+
/// Returns \c true if this collector has not accumulated
242+
/// any \c Reference objects.
231243
bool empty() const { return scratch.empty(); }
232244
};
233245

234-
/// A \c DependencyCollector is an aggregator of named references discovered in a
246+
/// A \c DependencyRecorder is an aggregator of named references discovered in a
235247
/// particular \c DependencyScope during the course of request evaluation.
236248
struct DependencyRecorder {
237249
friend DependencyCollector;
@@ -266,22 +278,62 @@ struct DependencyRecorder {
266278
explicit DependencyRecorder(Mode mode) : mode{mode}, isRecording{false} {};
267279

268280
private:
281+
/// Records the given \c Reference as a dependency of the current dependency
282+
/// source.
283+
///
284+
/// This is as opposed to merely collecting a \c Reference, which may just buffer
285+
/// it for realization or replay later.
269286
void realize(const DependencyCollector::Reference &ref);
270287

271288
public:
272-
void replay(const llvm::SetVector<swift::ActiveRequest> &stack,
273-
const swift::ActiveRequest &req);
289+
/// Begins the recording of references by invoking the given continuation
290+
/// with a fresh \c DependencyCollector object. This object should be used
291+
/// to buffer dependency-relevant references to names looked up by a
292+
/// given request.
293+
///
294+
/// Recording only occurs for requests that are dependency sinks.
274295
void record(const llvm::SetVector<swift::ActiveRequest> &stack,
275296
llvm::function_ref<void(DependencyCollector &)> rec);
276297

298+
/// Replays the \c Reference objects collected by a given cached request and
299+
/// its sub-requests into the current dependency scope.
300+
///
301+
/// Dependency replay ensures that cached requests do not "hide" names from
302+
/// the active dependency scope. This would otherwise occur frequently in
303+
/// batch mode, where cached requests effectively block the re-evaluation of
304+
/// a large quantity of computations that perform name lookups by design.
305+
///
306+
/// Replay need only occur for requests that are (separately) cached.
307+
void replay(const llvm::SetVector<swift::ActiveRequest> &stack,
308+
const swift::ActiveRequest &req);
277309
private:
310+
/// Given the current stack of requests and a buffer of \c Reference objects
311+
/// walk the active stack looking for the next-innermost cached request. If
312+
/// found, insert the buffer of references into that request's known reference
313+
/// set.
314+
///
315+
/// This algorithm ensures that references propagate lazily up the request
316+
/// graph from cached sub-requests to their cached parents. Once this process
317+
/// completes, all cached requests in the request graph will see the
318+
/// union of all references recorded while evaluating their sub-requests.
319+
///
320+
/// This algorithm *must* be tail-called during
321+
/// \c DependencyRecorder::record or \c DependencyRecorder::replay
322+
/// or the corresponding set of references for the active dependency scope
323+
/// will become incoherent.
278324
void
279325
unionNearestCachedRequest(ArrayRef<swift::ActiveRequest> stack,
280326
const DependencyCollector::ReferenceSet &scratch);
281327

282328
public:
283329
using ReferenceEnumerator =
284330
llvm::function_ref<void(const DependencyCollector::Reference &)>;
331+
332+
/// Enumerates the set of references associated with a given source file,
333+
/// passing them to the given enumeration callback.
334+
///
335+
/// The order of enumeration is completely undefined. It is the responsibility
336+
/// of callers to ensure they are order-invariant or are sorting the result.
285337
void enumerateReferencesInFile(const SourceFile *SF,
286338
ReferenceEnumerator f) const ;
287339

include/swift/AST/Expr.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,13 +597,23 @@ class ErrorExpr : public Expr {
597597
/// CodeCompletionExpr - Represents the code completion token in the AST, this
598598
/// can help us preserve the context of the code completion position.
599599
class CodeCompletionExpr : public Expr {
600-
SourceRange Range;
600+
Expr *Base;
601+
SourceLoc Loc;
601602

602603
public:
603-
CodeCompletionExpr(SourceRange Range, Type Ty = Type())
604-
: Expr(ExprKind::CodeCompletion, /*Implicit=*/true, Ty), Range(Range) {}
604+
CodeCompletionExpr(Expr *Base, SourceLoc Loc)
605+
: Expr(ExprKind::CodeCompletion, /*Implicit=*/true, Type()),
606+
Base(Base), Loc(Loc) {}
605607

606-
SourceRange getSourceRange() const { return Range; }
608+
CodeCompletionExpr(SourceLoc Loc)
609+
: CodeCompletionExpr(/*Base=*/nullptr, Loc) {}
610+
611+
Expr *getBase() const { return Base; }
612+
void setBase(Expr *E) { Base = E; }
613+
614+
SourceLoc getLoc() const { return Loc; }
615+
SourceLoc getStartLoc() const { return Base ? Base->getStartLoc() : Loc; }
616+
SourceLoc getEndLoc() const { return Loc; }
607617

608618
static bool classof(const Expr *E) {
609619
return E->getKind() == ExprKind::CodeCompletion;

include/swift/AST/FileSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/Basic/FileSystem.h"
1717
#include "swift/AST/DiagnosticEngine.h"
18+
#include "swift/AST/DiagnosticsCommon.h"
1819

1920
namespace swift {
2021

include/swift/AST/FineGrainedDependencies.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===----- FineGrainedependencies.h -----------------------------*- C++ -*-===//
1+
//===----- FineGrainedDependencies.h ----------------------------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -632,6 +632,11 @@ class DepGraphNode {
632632

633633
const DependencyKey &getKey() const { return key; }
634634

635+
/// Only used when the driver is reading a SourceFileDepGraphNode.
636+
void setKey(const DependencyKey &key) {
637+
this->key = key;
638+
}
639+
635640
const Optional<StringRef> getFingerprint() const {
636641
if (fingerprint) {
637642
return StringRef(fingerprint.getValue());
@@ -684,15 +689,15 @@ class SourceFileDepGraphNode : public DepGraphNode {
684689
/// True iff a Decl exists for this node.
685690
/// If a provides and a depends in the existing system both have the same key,
686691
/// only one SourceFileDepGraphNode is emitted.
687-
bool isProvides;
692+
bool isProvides = false;
688693

689694
friend ::llvm::yaml::MappingContextTraits<SourceFileDepGraphNode,
690695
SourceFileDepGraph>;
691696

692697
public:
693698
/// When the driver imports a node create an uninitialized instance for
694699
/// deserializing.
695-
SourceFileDepGraphNode() : DepGraphNode(), sequenceNumber(~0) {}
700+
SourceFileDepGraphNode() : DepGraphNode() {}
696701

697702
/// Used by the frontend to build nodes.
698703
SourceFileDepGraphNode(DependencyKey key, Optional<StringRef> fingerprint,
@@ -736,6 +741,9 @@ class SourceFileDepGraphNode : public DepGraphNode {
736741
: "somewhere else");
737742
}
738743

744+
SWIFT_DEBUG_DUMP;
745+
void dump(llvm::raw_ostream &os) const;
746+
739747
bool verify() const {
740748
DepGraphNode::verify();
741749
assert(getIsProvides() || isDepends());
@@ -872,7 +880,6 @@ class SourceFileDepGraph {
872880

873881
void emitDotFile(StringRef outputPath, DiagnosticEngine &diags);
874882

875-
private:
876883
void addNode(SourceFileDepGraphNode *n) {
877884
n->setSequenceNumber(allNodes.size());
878885
allNodes.push_back(n);

0 commit comments

Comments
 (0)