Skip to content

Commit 5d1eeac

Browse files
Resolving conflicts
2 parents 638d702 + eb0b307 commit 5d1eeac

File tree

127 files changed

+1513
-861
lines changed

Some content is hidden

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

127 files changed

+1513
-861
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ CHANGELOG
2626
Swift 5.2
2727
---------
2828

29+
* [SR-2189][]:
30+
31+
The compiler now supports local functions whose default arguments capture
32+
values from outer scopes.
33+
34+
```swift
35+
func outer(x: Int) -> (Int, Int) {
36+
func inner(y: Int = x) -> Int {
37+
return y
38+
}
39+
40+
return (inner(), inner(y: 0))
41+
}
42+
```
43+
2944
* [SR-11429][]:
3045

3146
The compiler will now correctly strip argument labels from function references
@@ -7803,6 +7818,7 @@ Swift 1.0
78037818
[SR-1529]: <https://bugs.swift.org/browse/SR-1529>
78047819
[SR-2131]: <https://bugs.swift.org/browse/SR-2131>
78057820
[SR-2176]: <https://bugs.swift.org/browse/SR-2176>
7821+
[SR-2189]: <https://bugs.swift.org/browse/SR-2189>
78067822
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
78077823
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
78087824
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>

cmake/modules/SwiftHandleGybSources.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
121121
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/DeclNodes.py"
122122
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/ExprNodes.py"
123123
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/GenericNodes.py"
124+
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/NodeSerializationCodes.py"
124125
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/PatternNodes.py"
125126
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/StmtNodes.py"
126127
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/TypeNodes.py"

include/swift/AST/Decl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5834,10 +5834,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
58345834
}
58355835

58365836
public:
5837-
/// Compute the interface type of this function declaration from the
5838-
/// parameter types.
5839-
void computeType(AnyFunctionType::ExtInfo Info = FunctionType::ExtInfo());
5840-
58415837
/// Retrieve the source range of the function body.
58425838
SourceRange getBodySourceRange() const;
58435839

include/swift/AST/DiagnosticsSIL.def

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,33 @@ ERROR(capture_before_declaration_defer,none,
130130
NOTE(captured_value_declared_here,none,
131131
"captured value declared here", ())
132132

133+
#define SELECT_ESCAPING_CLOSURE_KIND "escaping %select{local function|closure}0"
134+
133135
// Invalid escaping capture diagnostics.
134136
ERROR(escaping_inout_capture,none,
135-
"escaping closure captures 'inout' parameter %0", (Identifier))
137+
SELECT_ESCAPING_CLOSURE_KIND
138+
" captures 'inout' parameter %1",
139+
(unsigned, Identifier))
136140
NOTE(inout_param_defined_here,none,
137141
"parameter %0 is declared 'inout'", (Identifier))
138142
ERROR(escaping_mutable_self_capture,none,
139-
"escaping closure captures mutating 'self' parameter", ())
143+
SELECT_ESCAPING_CLOSURE_KIND
144+
" captures mutating 'self' parameter", (unsigned))
140145

141146
ERROR(escaping_noescape_param_capture,none,
142-
"escaping closure captures non-escaping parameter %0", (Identifier))
147+
SELECT_ESCAPING_CLOSURE_KIND
148+
" captures non-escaping parameter %1", (unsigned, Identifier))
143149
NOTE(noescape_param_defined_here,none,
144150
"parameter %0 is implicitly non-escaping", (Identifier))
145151

146152
ERROR(escaping_noescape_var_capture,none,
147-
"escaping closure captures non-escaping value", ())
153+
SELECT_ESCAPING_CLOSURE_KIND
154+
" captures non-escaping value", (unsigned))
148155

149156
NOTE(value_captured_here,none,"captured here", ())
150157

158+
#undef SELECT_ESCAPING_CLOSURE_KIND
159+
151160
NOTE(value_captured_transitively,none,
152161
"captured indirectly by this call", ())
153162

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3401,6 +3401,11 @@ ERROR(unresolved_label_corrected,none,
34013401
"use of unresolved label %0; did you mean %1?",
34023402
(Identifier, Identifier))
34033403

3404+
ERROR(foreach_sequence_does_not_conform_to_expected_protocol,none,
3405+
"for-in loop requires %0 to conform to %1"
3406+
"%select{|; did you mean to unwrap optional?}2",
3407+
(Type, Type, bool))
3408+
34043409
// Switch Stmt
34053410
ERROR(no_match_operator,none,
34063411
"no binary '~=' operator available for 'switch' statement", ())

include/swift/AST/IndexSubset.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class IndexSubset : public llvm::FoldingSetNode {
5757
/// The number of bit words in the index subset.
5858
unsigned numBitWords;
5959

60+
static unsigned getNumBytesNeededForCapacity(unsigned capacity) {
61+
return getNumBitWordsNeededForCapacity(capacity) * bitWordSize;
62+
}
63+
6064
BitWord *getBitWordsData() {
6165
return reinterpret_cast<BitWord *>(this + 1);
6266
}

include/swift/Frontend/Frontend.h

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ namespace Lowering {
6060
class TypeConverter;
6161
}
6262

63+
struct ModuleBuffers {
64+
std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer;
65+
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer;
66+
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer;
67+
ModuleBuffers(std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer,
68+
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer = nullptr,
69+
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer = nullptr):
70+
ModuleBuffer(std::move(ModuleBuffer)),
71+
ModuleDocBuffer(std::move(ModuleDocBuffer)),
72+
ModuleSourceInfoBuffer(std::move(ModuleSourceInfoBuffer)) {}
73+
};
74+
6375
/// The abstract configuration of the compiler, including:
6476
/// - options for all stages of translation,
6577
/// - information about the build environment,
@@ -392,15 +404,9 @@ class CompilerInstance {
392404
/// Contains buffer IDs for input source code files.
393405
std::vector<unsigned> InputSourceCodeBufferIDs;
394406

395-
struct PartialModuleInputs {
396-
std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer;
397-
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer;
398-
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer;
399-
};
400-
401407
/// Contains \c MemoryBuffers for partial serialized module files and
402408
/// corresponding partial serialized module documentation files.
403-
std::vector<PartialModuleInputs> PartialModules;
409+
std::vector<ModuleBuffers> PartialModules;
404410

405411
enum : unsigned { NO_SUCH_BUFFER = ~0U };
406412
unsigned MainBufferID = NO_SUCH_BUFFER;
@@ -556,18 +562,6 @@ class CompilerInstance {
556562

557563
Optional<unsigned> getRecordedBufferID(const InputFile &input, bool &failed);
558564

559-
struct ModuleBuffers {
560-
std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer;
561-
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer;
562-
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer;
563-
ModuleBuffers(std::unique_ptr<llvm::MemoryBuffer> ModuleBuffer,
564-
std::unique_ptr<llvm::MemoryBuffer> ModuleDocBuffer = nullptr,
565-
std::unique_ptr<llvm::MemoryBuffer> ModuleSourceInfoBuffer = nullptr):
566-
ModuleBuffer(std::move(ModuleBuffer)),
567-
ModuleDocBuffer(std::move(ModuleDocBuffer)),
568-
ModuleSourceInfoBuffer(std::move(ModuleSourceInfoBuffer)) {}
569-
};
570-
571565
/// Given an input file, return a buffer to use for its contents,
572566
/// and a buffer for the corresponding module doc file if one exists.
573567
/// On failure, return a null pointer for the first element of the returned

include/swift/Parse/ParsedRawSyntaxNode.h

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ParsedRawSyntaxNode {
5252
};
5353
struct DeferredLayoutNode {
5454
MutableArrayRef<ParsedRawSyntaxNode> Children;
55+
CharSourceRange Range;
5556
};
5657
struct DeferredTokenNode {
5758
const ParsedTriviaPiece *TriviaPieces;
@@ -72,9 +73,9 @@ class ParsedRawSyntaxNode {
7273
/// Primary used for capturing a deferred missing token.
7374
bool IsMissing = false;
7475

75-
ParsedRawSyntaxNode(syntax::SyntaxKind k,
76+
ParsedRawSyntaxNode(syntax::SyntaxKind k, CharSourceRange r,
7677
MutableArrayRef<ParsedRawSyntaxNode> deferredNodes)
77-
: DeferredLayout({deferredNodes}),
78+
: DeferredLayout({deferredNodes, r}),
7879
SynKind(uint16_t(k)), TokKind(uint16_t(tok::unknown)),
7980
DK(DataKind::DeferredLayout) {
8081
assert(getKind() == k && "Syntax kind with too large value!");
@@ -109,10 +110,12 @@ class ParsedRawSyntaxNode {
109110
}
110111

111112
ParsedRawSyntaxNode(syntax::SyntaxKind k, tok tokKind,
112-
CharSourceRange r, OpaqueSyntaxNode n)
113+
CharSourceRange r, OpaqueSyntaxNode n,
114+
bool IsMissing = false)
113115
: RecordedData{n, r},
114116
SynKind(uint16_t(k)), TokKind(uint16_t(tokKind)),
115-
DK(DataKind::Recorded) {
117+
DK(DataKind::Recorded),
118+
IsMissing(IsMissing) {
116119
assert(getKind() == k && "Syntax kind with too large value!");
117120
assert(getTokenKind() == tokKind && "Token kind with too large value!");
118121
}
@@ -209,9 +212,20 @@ class ParsedRawSyntaxNode {
209212
return copy;
210213
}
211214

215+
CharSourceRange getDeferredRange() const {
216+
switch (DK) {
217+
case DataKind::DeferredLayout:
218+
return getDeferredLayoutRange();
219+
case DataKind::DeferredToken:
220+
return getDeferredTokenRangeWithTrivia();
221+
default:
222+
llvm_unreachable("node not deferred");
223+
}
224+
}
225+
212226
// Recorded Data ===========================================================//
213227

214-
CharSourceRange getRange() const {
228+
CharSourceRange getRecordedRange() const {
215229
assert(isRecorded());
216230
return RecordedData.Range;
217231
}
@@ -228,6 +242,10 @@ class ParsedRawSyntaxNode {
228242

229243
// Deferred Layout Data ====================================================//
230244

245+
CharSourceRange getDeferredLayoutRange() const {
246+
assert(DK == DataKind::DeferredLayout);
247+
return DeferredLayout.Range;
248+
}
231249
ArrayRef<ParsedRawSyntaxNode> getDeferredChildren() const {
232250
assert(DK == DataKind::DeferredLayout);
233251
return DeferredLayout.Children;
@@ -259,6 +277,19 @@ class ParsedRawSyntaxNode {
259277

260278
// Deferred Token Data =====================================================//
261279

280+
CharSourceRange getDeferredTokenRangeWithTrivia() const {
281+
assert(DK == DataKind::DeferredToken);
282+
auto leadTriviaPieces = getDeferredLeadingTriviaPieces();
283+
auto trailTriviaPieces = getDeferredTrailingTriviaPieces();
284+
285+
auto leadTriviaLen = ParsedTriviaPiece::getTotalLength(leadTriviaPieces);
286+
auto trailTriviaLen = ParsedTriviaPiece::getTotalLength(trailTriviaPieces);
287+
288+
SourceLoc begin = DeferredToken.TokLoc.getAdvancedLoc(-leadTriviaLen);
289+
unsigned len = leadTriviaLen + DeferredToken.TokLength + trailTriviaLen;
290+
291+
return CharSourceRange{begin, len};
292+
}
262293
CharSourceRange getDeferredTokenRange() const {
263294
assert(DK == DataKind::DeferredToken);
264295
return CharSourceRange{DeferredToken.TokLoc, DeferredToken.TokLength};

include/swift/Parse/ParsedRawSyntaxRecorder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class ParsedRawSyntaxRecorder {
7373
/// Used for incremental re-parsing.
7474
ParsedRawSyntaxNode lookupNode(size_t lexerOffset, SourceLoc loc,
7575
syntax::SyntaxKind kind);
76+
77+
#ifndef NDEBUG
78+
static void verifyElementRanges(ArrayRef<ParsedRawSyntaxNode> elements);
79+
#endif
7680
};
7781

7882
} // end namespace swift

include/swift/Parse/ParsedSyntaxBuilders.h.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public:
6262
% end
6363

6464
Parsed${node.name} build();
65-
Parsed${node.name} makeDeferred();
6665

6766
private:
67+
Parsed${node.name} makeDeferred();
6868
Parsed${node.name} record();
6969
void finishLayout(bool deferred);
7070
};

0 commit comments

Comments
 (0)