Skip to content

Commit a3862fd

Browse files
authored
---
yaml --- r: 349040 b: refs/heads/master c: 4a9cda9 h: refs/heads/master
1 parent 2b2218b commit a3862fd

Some content is hidden

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

50 files changed

+1078
-366
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 05e24c0aaf6467e42815d6bf422cd28e2d761843
2+
refs/heads/master: 4a9cda999e0b79cfb66c26c85dc9ded9f57e9814
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/ASTContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ namespace swift {
109109
class TypeAliasDecl;
110110
class VarDecl;
111111
class UnifiedStatsReporter;
112+
class IndexSubset;
112113

113114
enum class KnownProtocolKind : uint8_t;
114115

trunk/include/swift/AST/Decl.h

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -369,21 +369,14 @@ class alignas(1 << DeclAlignInBits) Decl {
369369
IsPropertyWrapperBackingProperty : 1
370370
);
371371

372-
SWIFT_INLINE_BITFIELD(ParamDecl, VarDecl, 1+2+1+NumDefaultArgumentKindBits,
372+
SWIFT_INLINE_BITFIELD(ParamDecl, VarDecl, 1+2+NumDefaultArgumentKindBits,
373373
/// Whether we've computed the specifier yet.
374374
SpecifierComputed : 1,
375375

376376
/// The specifier associated with this parameter. This determines
377377
/// the storage semantics of the value e.g. mutability.
378378
Specifier : 2,
379379

380-
/// True if the type is implicitly specified in the source, but this has an
381-
/// apparently valid typeRepr. This is used in accessors, which look like:
382-
/// set (value) {
383-
/// but need to get the typeRepr from the property as a whole so Sema can
384-
/// resolve the type.
385-
IsTypeLocImplicit : 1,
386-
387380
/// Information about a symbolic default argument, like #file.
388381
defaultArgumentKind : NumDefaultArgumentKindBits
389382
);
@@ -4804,8 +4797,7 @@ class VarDecl : public AbstractStorageDecl {
48044797
bool issCaptureList, SourceLoc nameLoc, Identifier name,
48054798
DeclContext *dc, StorageIsMutable_t supportsMutation);
48064799

4807-
/// This is the type specified, including location information.
4808-
TypeLoc typeLoc;
4800+
TypeRepr *ParentRepr = nullptr;
48094801

48104802
Type typeInContext;
48114803

@@ -4825,8 +4817,10 @@ class VarDecl : public AbstractStorageDecl {
48254817
return hasName() ? getBaseName().getIdentifier().str() : "_";
48264818
}
48274819

4828-
TypeLoc &getTypeLoc() { return typeLoc; }
4829-
TypeLoc getTypeLoc() const { return typeLoc; }
4820+
/// Retrieve the TypeRepr corresponding to the parsed type of the parent
4821+
/// pattern, if it exists.
4822+
TypeRepr *getTypeRepr() const { return ParentRepr; }
4823+
void setTypeRepr(TypeRepr *repr) { ParentRepr = repr; }
48304824

48314825
bool hasType() const {
48324826
// We have a type if either the type has been computed already or if
@@ -5201,10 +5195,8 @@ class ParamDecl : public VarDecl {
52015195
Identifier argumentName, SourceLoc parameterNameLoc,
52025196
Identifier parameterName, DeclContext *dc);
52035197

5204-
/// Clone constructor, allocates a new ParamDecl identical to the first.
5205-
/// Intentionally not defined as a typical copy constructor to avoid
5206-
/// accidental copies.
5207-
ParamDecl(ParamDecl *PD, bool withTypes);
5198+
/// Create a new ParamDecl identical to the first except without the interface type.
5199+
static ParamDecl *cloneWithoutType(const ASTContext &Ctx, ParamDecl *PD);
52085200

52095201
/// Retrieve the argument (API) name for this function parameter.
52105202
Identifier getArgumentName() const { return ArgumentName; }
@@ -5221,10 +5213,7 @@ class ParamDecl : public VarDecl {
52215213
SourceLoc getParameterNameLoc() const { return ParameterNameLoc; }
52225214

52235215
SourceLoc getSpecifierLoc() const { return SpecifierLoc; }
5224-
5225-
bool isTypeLocImplicit() const { return Bits.ParamDecl.IsTypeLocImplicit; }
5226-
void setIsTypeLocImplicit(bool val) { Bits.ParamDecl.IsTypeLocImplicit = val; }
5227-
5216+
52285217
DefaultArgumentKind getDefaultArgumentKind() const {
52295218
return static_cast<DefaultArgumentKind>(Bits.ParamDecl.defaultArgumentKind);
52305219
}

trunk/include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ ERROR(cannot_convert_argument_value,none,
381381
(Type,Type))
382382

383383
NOTE(candidate_has_invalid_argument_at_position,none,
384-
"candidate expects value of type %0 for parameter #%1",
385-
(Type, unsigned))
384+
"candidate expects %select{|in-out }2value of type %0 for parameter #%1",
385+
(Type, unsigned, bool))
386386

387387
ERROR(cannot_convert_array_to_variadic,none,
388388
"cannot pass array of type %0 as variadic arguments of type %1",

trunk/include/swift/AST/IndexSubset.h

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
//===---------- IndexSubset.h - Fixed-size subset of indices --------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines the `IndexSubset` class and support logic.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_AST_INDEXSUBSET_H
18+
#define SWIFT_AST_INDEXSUBSET_H
19+
20+
#include "swift/Basic/LLVM.h"
21+
#include "swift/Basic/Range.h"
22+
#include "swift/Basic/STLExtras.h"
23+
#include "llvm/ADT/ArrayRef.h"
24+
#include "llvm/ADT/FoldingSet.h"
25+
#include "llvm/ADT/SmallBitVector.h"
26+
#include "llvm/Support/raw_ostream.h"
27+
28+
namespace swift {
29+
30+
class ASTContext;
31+
32+
/// An efficient index subset data structure, uniqued in `ASTContext`.
33+
/// Stores a bit vector representing set indices and a total capacity.
34+
class IndexSubset : public llvm::FoldingSetNode {
35+
public:
36+
typedef uint64_t BitWord;
37+
38+
static constexpr unsigned bitWordSize = sizeof(BitWord);
39+
static constexpr unsigned numBitsPerBitWord = bitWordSize * 8;
40+
41+
static std::pair<unsigned, unsigned>
42+
getBitWordIndexAndOffset(unsigned index) {
43+
auto bitWordIndex = index / numBitsPerBitWord;
44+
auto bitWordOffset = index % numBitsPerBitWord;
45+
return {bitWordIndex, bitWordOffset};
46+
}
47+
48+
static unsigned getNumBitWordsNeededForCapacity(unsigned capacity) {
49+
if (capacity == 0) return 0;
50+
return capacity / numBitsPerBitWord + 1;
51+
}
52+
53+
private:
54+
/// The total capacity of the index subset, which is `1` less than the largest
55+
/// index.
56+
unsigned capacity;
57+
/// The number of bit words in the index subset.
58+
unsigned numBitWords;
59+
60+
BitWord *getBitWordsData() {
61+
return reinterpret_cast<BitWord *>(this + 1);
62+
}
63+
64+
const BitWord *getBitWordsData() const {
65+
return reinterpret_cast<const BitWord *>(this + 1);
66+
}
67+
68+
ArrayRef<BitWord> getBitWords() const {
69+
return {getBitWordsData(), getNumBitWords()};
70+
}
71+
72+
BitWord getBitWord(unsigned i) const {
73+
return getBitWordsData()[i];
74+
}
75+
76+
BitWord &getBitWord(unsigned i) {
77+
return getBitWordsData()[i];
78+
}
79+
80+
MutableArrayRef<BitWord> getMutableBitWords() {
81+
return {const_cast<BitWord *>(getBitWordsData()), getNumBitWords()};
82+
}
83+
84+
explicit IndexSubset(const SmallBitVector &indices)
85+
: capacity((unsigned)indices.size()),
86+
numBitWords(getNumBitWordsNeededForCapacity(capacity)) {
87+
std::uninitialized_fill_n(getBitWordsData(), numBitWords, 0);
88+
for (auto i : indices.set_bits()) {
89+
unsigned bitWordIndex, offset;
90+
std::tie(bitWordIndex, offset) = getBitWordIndexAndOffset(i);
91+
getBitWord(bitWordIndex) |= (1 << offset);
92+
}
93+
}
94+
95+
public:
96+
IndexSubset() = delete;
97+
IndexSubset(const IndexSubset &) = delete;
98+
IndexSubset &operator=(const IndexSubset &) = delete;
99+
100+
// Defined in ASTContext.cpp.
101+
static IndexSubset *get(ASTContext &ctx, const SmallBitVector &indices);
102+
103+
static IndexSubset *get(ASTContext &ctx, unsigned capacity,
104+
ArrayRef<unsigned> indices) {
105+
SmallBitVector indicesBitVec(capacity, false);
106+
for (auto index : indices)
107+
indicesBitVec.set(index);
108+
return IndexSubset::get(ctx, indicesBitVec);
109+
}
110+
111+
static IndexSubset *getDefault(ASTContext &ctx, unsigned capacity,
112+
bool includeAll = false) {
113+
return get(ctx, SmallBitVector(capacity, includeAll));
114+
}
115+
116+
static IndexSubset *getFromRange(ASTContext &ctx, unsigned capacity,
117+
unsigned start, unsigned end) {
118+
assert(start < capacity);
119+
assert(end <= capacity);
120+
SmallBitVector bitVec(capacity);
121+
bitVec.set(start, end);
122+
return get(ctx, bitVec);
123+
}
124+
125+
/// Creates an index subset corresponding to the given string generated by
126+
/// `getString()`. If the string is invalid, returns nullptr.
127+
static IndexSubset *getFromString(ASTContext &ctx, StringRef string);
128+
129+
/// Returns the number of bit words used to store the index subset.
130+
// Note: Use `getCapacity()` to get the total index subset capacity.
131+
// This is public only for unit testing
132+
// (in unittests/AST/SILAutoDiffIndices.cpp).
133+
unsigned getNumBitWords() const {
134+
return numBitWords;
135+
}
136+
137+
/// Returns the capacity of the index subset.
138+
unsigned getCapacity() const {
139+
return capacity;
140+
}
141+
142+
/// Returns a textual string description of these indices.
143+
///
144+
/// It has the format `[SU]+`, where the total number of characters is equal
145+
/// to the capacity, and where "S" means that the corresponding index is
146+
/// contained and "U" means that the corresponding index is not.
147+
std::string getString() const;
148+
149+
class iterator;
150+
151+
iterator begin() const {
152+
return iterator(this);
153+
}
154+
155+
iterator end() const {
156+
return iterator(this, (int)capacity);
157+
}
158+
159+
/// Returns an iterator range of indices in the index subset.
160+
iterator_range<iterator> getIndices() const {
161+
return make_range(begin(), end());
162+
}
163+
164+
/// Returns the number of indices in the index subset.
165+
unsigned getNumIndices() const {
166+
return (unsigned)std::distance(begin(), end());
167+
}
168+
169+
SmallBitVector getBitVector() const {
170+
SmallBitVector indicesBitVec(capacity, false);
171+
for (auto index : getIndices())
172+
indicesBitVec.set(index);
173+
return indicesBitVec;
174+
}
175+
176+
bool contains(unsigned index) const {
177+
unsigned bitWordIndex, offset;
178+
std::tie(bitWordIndex, offset) = getBitWordIndexAndOffset(index);
179+
return getBitWord(bitWordIndex) & (1 << offset);
180+
}
181+
182+
bool isEmpty() const {
183+
return llvm::all_of(getBitWords(), [](BitWord bw) { return !(bool)bw; });
184+
}
185+
186+
bool equals(IndexSubset *other) const {
187+
return capacity == other->getCapacity() &&
188+
getBitWords().equals(other->getBitWords());
189+
}
190+
191+
bool isSubsetOf(IndexSubset *other) const;
192+
bool isSupersetOf(IndexSubset *other) const;
193+
194+
IndexSubset *adding(unsigned index, ASTContext &ctx) const;
195+
IndexSubset *extendingCapacity(ASTContext &ctx,
196+
unsigned newCapacity) const;
197+
198+
void Profile(llvm::FoldingSetNodeID &id) const {
199+
id.AddInteger(capacity);
200+
for (auto index : getIndices())
201+
id.AddInteger(index);
202+
}
203+
204+
void print(llvm::raw_ostream &s = llvm::outs()) const {
205+
s << '{';
206+
interleave(range(capacity), [this, &s](unsigned i) { s << contains(i); },
207+
[&s] { s << ", "; });
208+
s << '}';
209+
}
210+
211+
void dump(llvm::raw_ostream &s = llvm::errs()) const {
212+
s << "(index_subset capacity=" << capacity << " indices=(";
213+
interleave(getIndices(), [&s](unsigned i) { s << i; },
214+
[&s] { s << ", "; });
215+
s << "))";
216+
}
217+
218+
int findNext(int startIndex) const;
219+
int findFirst() const { return findNext(-1); }
220+
int findPrevious(int endIndex) const;
221+
int findLast() const { return findPrevious(capacity); }
222+
223+
class iterator {
224+
public:
225+
typedef unsigned value_type;
226+
typedef unsigned difference_type;
227+
typedef unsigned * pointer;
228+
typedef unsigned & reference;
229+
typedef std::forward_iterator_tag iterator_category;
230+
231+
private:
232+
const IndexSubset *parent;
233+
int current = 0;
234+
235+
void advance() {
236+
assert(current != -1 && "Trying to advance past end.");
237+
current = parent->findNext(current);
238+
}
239+
240+
public:
241+
iterator(const IndexSubset *parent, int current)
242+
: parent(parent), current(current) {}
243+
explicit iterator(const IndexSubset *parent)
244+
: iterator(parent, parent->findFirst()) {}
245+
iterator(const iterator &) = default;
246+
247+
iterator operator++(int) {
248+
auto prev = *this;
249+
advance();
250+
return prev;
251+
}
252+
253+
iterator &operator++() {
254+
advance();
255+
return *this;
256+
}
257+
258+
unsigned operator*() const { return current; }
259+
260+
bool operator==(const iterator &other) const {
261+
assert(parent == other.parent &&
262+
"Comparing iterators from different IndexSubsets");
263+
return current == other.current;
264+
}
265+
266+
bool operator!=(const iterator &other) const {
267+
assert(parent == other.parent &&
268+
"Comparing iterators from different IndexSubsets");
269+
return current != other.current;
270+
}
271+
};
272+
};
273+
274+
}
275+
276+
#endif // SWIFT_AST_INDEXSUBSET_H

trunk/include/swift/AST/ParameterList.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ class alignas(ParamDecl *) ParameterList final :
111111
/// The cloned pattern is for an inherited constructor; mark default
112112
/// arguments as inherited, and mark unnamed arguments as named.
113113
Inherited = 0x02,
114-
/// The cloned pattern will strip type information.
115-
WithoutTypes = 0x04,
116114
};
117115

118116
friend OptionSet<CloneFlags> operator|(CloneFlags flag1, CloneFlags flag2) {

trunk/include/swift/Parse/ASTGen.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class ASTGen {
108108
const SourceLoc Loc);
109109
Expr *generate(const syntax::PoundDsohandleExprSyntax &Expr,
110110
const SourceLoc Loc);
111+
Expr *generate(const syntax::ObjcKeyPathExprSyntax &Expr,
112+
const SourceLoc Loc);
111113
Expr *generate(const syntax::ObjectLiteralExprSyntax &Expr,
112114
const SourceLoc Loc);
113115
Expr *generate(const syntax::CodeCompletionExprSyntax &Expr,

trunk/include/swift/Parse/Parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,7 @@ class Parser {
14521452
ParserResult<Expr> parseExprPrimary(Diag<> ID, bool isExprBasic);
14531453
ParserResult<Expr> parseExprUnary(Diag<> ID, bool isExprBasic);
14541454
ParserResult<Expr> parseExprKeyPathObjC();
1455+
ParsedSyntaxResult<ParsedExprSyntax> parseExprObjcKeyPathSyntax();
14551456
ParserResult<Expr> parseExprKeyPath();
14561457
ParserResult<Expr> parseExprSelector();
14571458
ParserResult<Expr> parseExprSuper();

0 commit comments

Comments
 (0)