Skip to content

Commit 60f827c

Browse files
slavapestovRobert Widmann
authored andcommitted
---
yaml --- r: 343407 b: refs/heads/master-rebranch c: 39c7640 h: refs/heads/master i: 343405: d60862b 343403: 0ca6b67 343399: e9c97a7 343391: 6c9f0c5
1 parent 81896e0 commit 60f827c

36 files changed

+323
-332
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: f055791b9a5e2c4e9bed09baa4d752f2bfcda1fe
1458+
refs/heads/master-rebranch: 39c7640f37c32b10842f7b0bd1f324fa298f764a
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/CHANGELOG.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,6 @@ CHANGELOG
2626
Swift Next
2727
----------
2828

29-
* [SE-0253][]:
30-
31-
Values of types that declare `func callAsFunction` methods can be called
32-
like functions. The call syntax is shorthand for applying
33-
`func callAsFunction` methods.
34-
35-
```swift
36-
struct Adder {
37-
var base: Int
38-
func callAsFunction(_ x: Int) -> Int {
39-
return x + base
40-
}
41-
}
42-
var adder = Adder(base: 3)
43-
adder(10) // returns 13, same as `adder.callAsFunction(10)`
44-
```
45-
46-
* `func callAsFunction` argument labels are required at call sites.
47-
* Multiple `func callAsFunction` methods on a single type are supported.
48-
* `mutating func callAsFunction` is supported.
49-
* `func callAsFunction` works with `throws` and `rethrows`.
50-
* `func callAsFunction` works with trailing closures.
51-
5229
* [SR-4206][]:
5330

5431
A method override is no longer allowed to have a generic signature with
@@ -7734,7 +7711,6 @@ Swift 1.0
77347711
[SE-0244]: <https://github.com/apple/swift-evolution/blob/master/proposals/0244-opaque-result-types.md>
77357712
[SE-0245]: <https://github.com/apple/swift-evolution/blob/master/proposals/0245-array-uninitialized-initializer.md>
77367713
[SE-0252]: <https://github.com/apple/swift-evolution/blob/master/proposals/0252-keypath-dynamic-member-lookup.md>
7737-
[SE-0253]: <https://github.com/apple/swift-evolution/blob/master/proposals/0253-callable.md>
77387714
[SE-0254]: <https://github.com/apple/swift-evolution/blob/master/proposals/0254-static-subscripts.md>
77397715

77407716
[SR-106]: <https://bugs.swift.org/browse/SR-106>

branches/master-rebranch/include/swift/AST/Decl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5594,8 +5594,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
55945594
SourceRange BodyRange;
55955595
};
55965596

5597-
friend class ParseAbstractFunctionBodyRequest;
5598-
55995597
CaptureInfo Captures;
56005598

56015599
/// Location of the 'throws' token.

branches/master-rebranch/include/swift/AST/ParseRequests.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,6 @@ class ParseMembersRequest :
4848
bool isCached() const { return true; }
4949
};
5050

51-
/// Parse the body of a function, initializer, or deinitializer.
52-
class ParseAbstractFunctionBodyRequest :
53-
public SimpleRequest<ParseAbstractFunctionBodyRequest,
54-
BraceStmt *(AbstractFunctionDecl *),
55-
CacheKind::SeparatelyCached>
56-
{
57-
public:
58-
using SimpleRequest::SimpleRequest;
59-
60-
private:
61-
friend SimpleRequest;
62-
63-
// Evaluation.
64-
BraceStmt *evaluate(Evaluator &evaluator, AbstractFunctionDecl *afd) const;
65-
66-
public:
67-
// Caching
68-
bool isCached() const { return true; }
69-
Optional<BraceStmt *> getCachedResult() const;
70-
void cacheResult(BraceStmt *value) const;
71-
};
72-
7351
/// The zone number for the parser.
7452
#define SWIFT_TYPEID_ZONE Parse
7553
#define SWIFT_TYPEID_HEADER "swift/AST/ParseTypeIDZone.def"

branches/master-rebranch/include/swift/AST/ParseTypeIDZone.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
SWIFT_REQUEST(Parse, ParseMembersRequest)
18-
SWIFT_REQUEST(Parse, ParseAbstractFunctionBodyRequest)

branches/master-rebranch/include/swift/Basic/SourceManager.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ class SourceManager {
103103
rangeContainsTokenLoc(Enclosing, Inner.End);
104104
}
105105

106-
/// Returns true if range \p R contains the code-completion location, if any.
107-
bool rangeContainsCodeCompletionLoc(SourceRange R) const {
108-
return CodeCompletionBufferID
109-
? rangeContainsTokenLoc(R, getCodeCompletionLoc())
110-
: false;
111-
}
112-
113106
/// Returns the buffer ID for the specified *valid* location.
114107
///
115108
/// Because a valid source location always corresponds to a source buffer,

branches/master-rebranch/include/swift/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ class Parser {
11241124
DeclAttributes &Attributes,
11251125
bool HasFuncKeyword = true);
11261126
void parseAbstractFunctionBody(AbstractFunctionDecl *AFD);
1127-
BraceStmt *parseAbstractFunctionBodyDelayed(AbstractFunctionDecl *AFD);
1127+
bool parseAbstractFunctionBodyDelayed(AbstractFunctionDecl *AFD);
11281128
ParserResult<ProtocolDecl> parseDeclProtocol(ParseDeclOptions Flags,
11291129
DeclAttributes &Attributes);
11301130

branches/master-rebranch/include/swift/Parse/PersistentParserState.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ class PersistentParserState {
109109
PersistentParserState(ASTContext &ctx) : PersistentParserState() { }
110110
~PersistentParserState();
111111

112+
void delayFunctionBodyParsing(AbstractFunctionDecl *AFD,
113+
SourceRange BodyRange,
114+
SourceLoc PreviousLoc);
115+
std::unique_ptr<FunctionBodyState>
116+
takeFunctionBodyState(AbstractFunctionDecl *AFD);
117+
118+
bool hasFunctionBodyState(AbstractFunctionDecl *AFD);
119+
112120
void delayDecl(DelayedDeclKind Kind, unsigned Flags,
113121
DeclContext *ParentContext,
114122
SourceRange BodyRange, SourceLoc PreviousLoc);

branches/master-rebranch/include/swift/Sema/SourceLoader.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@ class ModuleDecl;
2424
class SourceLoader : public ModuleLoader {
2525
private:
2626
ASTContext &Ctx;
27+
bool SkipBodies;
2728
bool EnableLibraryEvolution;
2829

2930
explicit SourceLoader(ASTContext &ctx,
31+
bool skipBodies,
3032
bool enableResilience,
3133
DependencyTracker *tracker)
3234
: ModuleLoader(tracker), Ctx(ctx),
33-
EnableLibraryEvolution(enableResilience) {}
35+
SkipBodies(skipBodies), EnableLibraryEvolution(enableResilience) {}
3436

3537
public:
3638
static std::unique_ptr<SourceLoader>
37-
create(ASTContext &ctx, bool enableResilience,
39+
create(ASTContext &ctx, bool skipBodies, bool enableResilience,
3840
DependencyTracker *tracker = nullptr) {
3941
return std::unique_ptr<SourceLoader>{
40-
new SourceLoader(ctx, enableResilience, tracker)
42+
new SourceLoader(ctx, skipBodies, enableResilience, tracker)
4143
};
4244
}
4345

branches/master-rebranch/lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,9 @@ PrintOptions PrintOptions::printParseableInterfaceFile(bool preferTypeRepr) {
118118

119119
result.FunctionBody = [](const ValueDecl *decl, ASTPrinter &printer) {
120120
auto AFD = dyn_cast<AbstractFunctionDecl>(decl);
121-
if (!AFD)
122-
return;
121+
if (!AFD || !AFD->hasInlinableBodyText()) return;
123122
if (AFD->getResilienceExpansion() != ResilienceExpansion::Minimal)
124123
return;
125-
if (!AFD->hasInlinableBodyText())
126-
return;
127-
128124
SmallString<128> scratch;
129125
printer << " " << AFD->getInlinableBodyText(scratch);
130126
};

branches/master-rebranch/lib/AST/ASTScopeCreation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ void AbstractFunctionDeclScope::expandAScopeThatDoesNotCreateANewInsertionPoint(
12721272
// Create scope for the body.
12731273
// We create body scopes when there is no body for source kit to complete
12741274
// erroneous code in bodies. But don't let compiler synthesize one.
1275-
if (decl->getBodySourceRange().isValid() && decl->getBody(false)) {
1275+
if (decl->getBody(false) && decl->getBodySourceRange().isValid()) {
12761276
if (AbstractFunctionBodyScope::isAMethod(decl))
12771277
scopeCreator.constructExpandAndInsertUncheckable<MethodBodyScope>(leaf,
12781278
decl);
@@ -1771,10 +1771,10 @@ bool IterableTypeScope::isBodyCurrent() const {
17711771
}
17721772

17731773
void AbstractFunctionBodyScope::beCurrent() {
1774-
bodyWhenLastExpanded = decl->getBody(false);
1774+
bodyWhenLastExpanded = decl->getBody();
17751775
}
17761776
bool AbstractFunctionBodyScope::isCurrent() const {
1777-
return bodyWhenLastExpanded == decl->getBody(false);
1777+
return bodyWhenLastExpanded == decl->getBody();
17781778
;
17791779
}
17801780

branches/master-rebranch/lib/AST/Decl.cpp

Lines changed: 28 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "swift/AST/NameLookup.h"
3434
#include "swift/AST/NameLookupRequests.h"
3535
#include "swift/AST/ParameterList.h"
36-
#include "swift/AST/ParseRequests.h"
3736
#include "swift/AST/Pattern.h"
3837
#include "swift/AST/PropertyWrappers.h"
3938
#include "swift/AST/ProtocolConformance.h"
@@ -6308,22 +6307,37 @@ bool AbstractFunctionDecl::argumentNameIsAPIByDefault() const {
63086307
}
63096308

63106309
BraceStmt *AbstractFunctionDecl::getBody(bool canSynthesize) const {
6311-
if ((getBodyKind() == BodyKind::Synthesize ||
6312-
getBodyKind() == BodyKind::Unparsed) &&
6313-
!canSynthesize)
6310+
switch (getBodyKind()) {
6311+
case BodyKind::Deserialized:
6312+
case BodyKind::MemberwiseInitializer:
6313+
case BodyKind::None:
6314+
case BodyKind::Skipped:
63146315
return nullptr;
63156316

6316-
ASTContext &ctx = getASTContext();
6317+
case BodyKind::Parsed:
6318+
case BodyKind::TypeChecked:
6319+
return Body;
63176320

6318-
// Don't allow getBody() to trigger parsing of an unparsed body containing the
6319-
// code completion location.
6320-
if (getBodyKind() == BodyKind::Unparsed &&
6321-
ctx.SourceMgr.rangeContainsCodeCompletionLoc(getBodySourceRange())) {
6321+
case BodyKind::Unparsed:
6322+
// FIXME: Go parse now!
63226323
return nullptr;
6323-
}
63246324

6325-
auto mutableThis = const_cast<AbstractFunctionDecl *>(this);
6326-
return evaluateOrDefault(ctx.evaluator, ParseAbstractFunctionBodyRequest{mutableThis}, nullptr);
6325+
case BodyKind::Synthesize: {
6326+
if (!canSynthesize)
6327+
return nullptr;
6328+
6329+
const_cast<AbstractFunctionDecl *>(this)->setBodyKind(BodyKind::None);
6330+
BraceStmt *body;
6331+
bool isTypeChecked;
6332+
6333+
auto mutableThis = const_cast<AbstractFunctionDecl *>(this);
6334+
std::tie(body, isTypeChecked) = (Synthesizer.Fn)(
6335+
mutableThis, Synthesizer.Context);
6336+
mutableThis->setBody(
6337+
body, isTypeChecked ? BodyKind::TypeChecked : BodyKind::Parsed);
6338+
return body;
6339+
}
6340+
}
63276341
}
63286342

63296343
SourceRange AbstractFunctionDecl::getBodySourceRange() const {
@@ -6790,15 +6804,11 @@ bool AbstractFunctionDecl::hasInlinableBodyText() const {
67906804
switch (getBodyKind()) {
67916805
case BodyKind::Deserialized:
67926806
return true;
6793-
6794-
case BodyKind::Unparsed:
67956807
case BodyKind::Parsed:
67966808
case BodyKind::TypeChecked:
6797-
if (auto body = getBody())
6798-
return !body->isImplicit();
6799-
return false;
6800-
6809+
return getBody() && !getBody()->isImplicit();
68016810
case BodyKind::None:
6811+
case BodyKind::Unparsed:
68026812
case BodyKind::Synthesize:
68036813
case BodyKind::Skipped:
68046814
case BodyKind::MemberwiseInitializer:
@@ -7666,49 +7676,3 @@ SourceLoc swift::extractNearestSourceLoc(const Decl *decl) {
76667676

76677677
return extractNearestSourceLoc(decl->getDeclContext());
76687678
}
7669-
7670-
Optional<BraceStmt *>
7671-
ParseAbstractFunctionBodyRequest::getCachedResult() const {
7672-
using BodyKind = AbstractFunctionDecl::BodyKind;
7673-
auto afd = std::get<0>(getStorage());
7674-
switch (afd->getBodyKind()) {
7675-
case BodyKind::Deserialized:
7676-
case BodyKind::MemberwiseInitializer:
7677-
case BodyKind::None:
7678-
case BodyKind::Skipped:
7679-
return nullptr;
7680-
7681-
case BodyKind::TypeChecked:
7682-
case BodyKind::Parsed:
7683-
return afd->Body;
7684-
7685-
case BodyKind::Synthesize:
7686-
case BodyKind::Unparsed:
7687-
return None;
7688-
}
7689-
}
7690-
7691-
void ParseAbstractFunctionBodyRequest::cacheResult(BraceStmt *value) const {
7692-
using BodyKind = AbstractFunctionDecl::BodyKind;
7693-
auto afd = std::get<0>(getStorage());
7694-
switch (afd->getBodyKind()) {
7695-
case BodyKind::Deserialized:
7696-
case BodyKind::MemberwiseInitializer:
7697-
case BodyKind::None:
7698-
case BodyKind::Skipped:
7699-
// The body is always empty, so don't cache anything.
7700-
assert(value == nullptr);
7701-
return;
7702-
7703-
case BodyKind::Parsed:
7704-
case BodyKind::TypeChecked:
7705-
afd->Body = value;
7706-
return;
7707-
7708-
case BodyKind::Synthesize:
7709-
case BodyKind::Unparsed:
7710-
llvm_unreachable("evaluate() did not set the body kind");
7711-
return;
7712-
}
7713-
7714-
}

branches/master-rebranch/lib/AST/UnqualifiedLookup.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ void UnqualifiedLookupFactory::lookupNamesIntroducedByFunctionDecl(
663663
const bool isCascadingUse =
664664
AFD->isCascadingContextForLookup(false) &&
665665
(isCascadingUseArg.getValueOr(
666-
Loc.isInvalid() || AFD->getBodySourceRange().isInvalid() ||
666+
Loc.isInvalid() || !AFD->getBody() ||
667667
!SM.rangeContainsTokenLoc(AFD->getBodySourceRange(), Loc)));
668668

669669
if (AFD->getDeclContext()->isTypeContext())
@@ -814,9 +814,7 @@ void UnqualifiedLookupFactory::lookForLocalVariablesIn(
814814
// FIXME: when we can parse and typecheck the function body partially
815815
// for code completion, AFD->getBody() check can be removed.
816816

817-
if (Loc.isInvalid() || AFD->getBodySourceRange().isInvalid() ||
818-
!SM.rangeContainsTokenLoc(AFD->getBodySourceRange(), Loc) ||
819-
!AFD->getBody()) {
817+
if (Loc.isInvalid() || !AFD->getBody()) {
820818
return;
821819
}
822820

branches/master-rebranch/lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,12 @@ void CompilerInstance::setUpDiagnosticOptions() {
315315

316316
bool CompilerInstance::setUpModuleLoaders() {
317317
if (hasSourceImport()) {
318+
bool immediate = FrontendOptions::isActionImmediate(
319+
Invocation.getFrontendOptions().RequestedAction);
318320
bool enableLibraryEvolution =
319321
Invocation.getFrontendOptions().EnableLibraryEvolution;
320322
Context->addModuleLoader(SourceLoader::create(*Context,
323+
!immediate,
321324
enableLibraryEvolution,
322325
getDependencyTracker()));
323326
}

branches/master-rebranch/lib/FrontendTool/FrontendTool.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,12 @@ template <> struct ObjectTraits<LoadedModuleTraceFormat> {
241241
static bool emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
242242
DependencyTracker *depTracker,
243243
StringRef loadedModuleTracePath) {
244-
ASTContext &ctxt = mainModule->getASTContext();
245-
assert(!ctxt.hadError()
246-
&& "We may not be able to emit a proper trace if there was an error.");
247-
248244
if (loadedModuleTracePath.empty())
249245
return false;
250246
std::error_code EC;
251247
llvm::raw_fd_ostream out(loadedModuleTracePath, EC, llvm::sys::fs::F_Append);
252248

249+
ASTContext &ctxt = mainModule->getASTContext();
253250
if (out.has_error() || EC) {
254251
ctxt.Diags.diagnose(SourceLoc(), diag::error_opening_output,
255252
loadedModuleTracePath, EC.message());
@@ -274,9 +271,7 @@ static bool emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
274271
if (loadedDecl == mainModule)
275272
continue;
276273
assert(!loadedDecl->getModuleFilename().empty()
277-
&& ("Don't know how to handle modules with empty names."
278-
" One potential reason for getting an empty module name might"
279-
" be that the module could not be deserialized correctly."));
274+
&& "Don't know how to handle modules with empty names.");
280275
pathToModuleDecl.insert(
281276
std::make_pair(loadedDecl->getModuleFilename(), loadedDecl));
282277
}
@@ -1094,15 +1089,15 @@ static bool performCompile(CompilerInstance &Instance,
10941089

10951090
emitReferenceDependenciesForAllPrimaryInputsIfNeeded(Invocation, Instance);
10961091

1092+
(void)emitLoadedModuleTraceForAllPrimariesIfNeeded(
1093+
Instance.getMainModule(), Instance.getDependencyTracker(), opts);
1094+
10971095
if (Context.hadError()) {
10981096
// Emit the index store data even if there were compiler errors.
10991097
(void)emitIndexData(Invocation, Instance);
11001098
return true;
11011099
}
11021100

1103-
(void)emitLoadedModuleTraceForAllPrimariesIfNeeded(
1104-
Instance.getMainModule(), Instance.getDependencyTracker(), opts);
1105-
11061101
// FIXME: This is still a lousy approximation of whether the module file will
11071102
// be externally consumed.
11081103
bool moduleIsPublic =

0 commit comments

Comments
 (0)