Skip to content

Commit b81b73a

Browse files
committed
---
yaml --- r: 345079 b: refs/heads/master c: 7ba6065 h: refs/heads/master i: 345077: 373a789 345075: 5dfd920 345071: 276a87a
1 parent 3335fa4 commit b81b73a

File tree

9 files changed

+247
-104
lines changed

9 files changed

+247
-104
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: f49b28c977213ad5f79f13499e372f9a776cee07
2+
refs/heads/master: 7ba60653c9b74119265866ad14266e2cff7304a6
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/Basic/Statistics.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ FRONTEND_STATISTIC(Frontend, NumProcessFailures)
8383
/// Total instructions-executed count in each frontend process.
8484
FRONTEND_STATISTIC(Frontend, NumInstructionsExecuted)
8585

86+
/// Maximum number of bytes allocated via malloc.
87+
FRONTEND_STATISTIC(Frontend, MaxMallocUsage)
88+
8689
/// Number of source buffers visible in the source manager.
8790
FRONTEND_STATISTIC(AST, NumSourceBuffers)
8891

trunk/include/swift/IDE/CodeCompletion.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ enum class CompletionKind {
487487
PostfixExprParen,
488488
SuperExpr,
489489
SuperExprDot,
490-
KeyPathExpr,
491-
KeyPathExprDot,
490+
KeyPathExprObjC,
491+
KeyPathExprSwift,
492492
TypeSimpleBeginning,
493493
TypeIdentifierWithDot,
494494
TypeIdentifierWithoutDot,
@@ -506,7 +506,6 @@ enum class CompletionKind {
506506
AfterPound,
507507
AfterIfStmtElse,
508508
GenericParams,
509-
SwiftKeyPath,
510509
};
511510

512511
/// \brief A single code completion result.

trunk/include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class CodeCompletionCallbacks {
153153
/// \param KPE A partial #keyPath expression that can be used to
154154
/// provide context. This will be \c NULL if no components of the
155155
/// #keyPath argument have been parsed yet.
156-
virtual void completeExprKeyPath(KeyPathExpr *KPE, bool HasDot) = 0;
156+
virtual void completeExprKeyPath(KeyPathExpr *KPE, SourceLoc DotLoc) = 0;
157157

158158
/// \brief Complete the beginning of type-simple -- no tokens provided
159159
/// by user.

trunk/include/swift/Parse/Parser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ class Parser {
160160
bool InPoundLineEnvironment = false;
161161
bool InPoundIfEnvironment = false;
162162
bool InSwiftKeyPath = false;
163-
Expr* SwiftKeyPathRoot = nullptr;
164-
SourceLoc SwiftKeyPathSlashLoc = SourceLoc();
165163

166164
LocalContext *CurLocalContext = nullptr;
167165

trunk/lib/Basic/Statistic.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
#ifdef HAVE_PROC_PID_RUSAGE
4343
#include <libproc.h>
4444
#endif
45+
#ifdef HAVE_MALLOC_MALLOC_H
46+
#include <malloc/malloc.h>
47+
#endif
4548

4649
namespace swift {
4750
using namespace llvm;
@@ -500,6 +503,21 @@ void updateProcessWideFrontendCounters(
500503
C.NumInstructionsExecuted = ru.ri_instructions;
501504
}
502505
#endif
506+
507+
#if defined(HAVE_MALLOC_ZONE_STATISTICS) && defined(HAVE_MALLOC_MALLOC_H)
508+
// On Darwin we have a lifetime max that's maintained by malloc we can
509+
// just directly query, even if we only make one query on shutdown.
510+
malloc_statistics_t Stats;
511+
malloc_zone_statistics(malloc_default_zone(), &Stats);
512+
C.MaxMallocUsage = (int64_t)Stats.max_size_in_use;
513+
#else
514+
// If we don't have a malloc-tracked max-usage counter, we have to rely
515+
// on taking the max over current-usage samples while running and hoping
516+
// we get called often enough. This will happen when profiling/tracing,
517+
// but not while doing single-query-on-shutdown collection.
518+
C.MaxMallocUsage = std::max(C.MaxMallocUsage,
519+
(int64_t)llvm::sys::Process::GetMallocUsage());
520+
#endif
503521
}
504522

505523
static inline void
@@ -614,7 +632,8 @@ UnifiedStatsReporter::~UnifiedStatsReporter()
614632
}
615633
}
616634

617-
updateProcessWideFrontendCounters(getFrontendCounters());
635+
if (FrontendCounters)
636+
updateProcessWideFrontendCounters(getFrontendCounters());
618637

619638
// NB: Timer needs to be Optional<> because it needs to be destructed early;
620639
// LLVM will complain about double-stopping a timer if you tear down a

trunk/lib/IDE/CodeCompletion.cpp

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,8 +1390,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13901390

13911391
// Figure out the kind of type-check we'll be performing.
13921392
auto CheckKind = CompletionTypeCheckKind::Normal;
1393-
if (Kind == CompletionKind::KeyPathExpr ||
1394-
Kind == CompletionKind::KeyPathExprDot)
1393+
if (Kind == CompletionKind::KeyPathExprObjC)
13951394
CheckKind = CompletionTypeCheckKind::KeyPath;
13961395

13971396
// If we've already successfully type-checked the expression for some
@@ -1444,7 +1443,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
14441443
void completePostfixExprParen(Expr *E, Expr *CodeCompletionE) override;
14451444
void completeExprSuper(SuperRefExpr *SRE) override;
14461445
void completeExprSuperDot(SuperRefExpr *SRE) override;
1447-
void completeExprKeyPath(KeyPathExpr *KPE, bool HasDot) override;
1446+
void completeExprKeyPath(KeyPathExpr *KPE, SourceLoc DotLoc) override;
14481447

14491448
void completeTypeSimpleBeginning() override;
14501449
void completeTypeIdentifierWithDot(IdentTypeRepr *ITR) override;
@@ -1619,6 +1618,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
16191618
bool IsSelfRefExpr = false;
16201619
bool IsKeyPathExpr = false;
16211620
bool IsSwiftKeyPathExpr = false;
1621+
bool IsAfterSwiftKeyPathRoot = false;
16221622
bool IsDynamicLookup = false;
16231623
bool PreferFunctionReferencesToCalls = false;
16241624
bool HaveLeadingSpace = false;
@@ -1777,8 +1777,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
17771777
IsKeyPathExpr = true;
17781778
}
17791779

1780-
void setIsSwiftKeyPathExpr() {
1780+
void setIsSwiftKeyPathExpr(bool onRoot) {
17811781
IsSwiftKeyPathExpr = true;
1782+
IsAfterSwiftKeyPathRoot = onRoot;
17821783
}
17831784

17841785
void setIsDynamicLookup() {
@@ -2625,21 +2626,33 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
26252626
}
26262627
}
26272628

2628-
bool shouldAddSubscriptCall() {
2629-
if (IsSwiftKeyPathExpr)
2630-
return true;
2631-
return !HaveDot;
2632-
}
2633-
26342629
void addSubscriptCall(const SubscriptDecl *SD, DeclVisibilityKind Reason) {
2635-
assert(shouldAddSubscriptCall() && "cannot add a subscript after a dot");
2630+
// Don't add subscript call to meta types.
2631+
if (!ExprType || ExprType->is<AnyMetatypeType>())
2632+
return;
2633+
2634+
// Subscript after '.' is valid only after type part of Swift keypath
2635+
// expression. (e.g. '\TyName.SubTy.[0])
2636+
if (HaveDot && !IsAfterSwiftKeyPathRoot)
2637+
return;
2638+
26362639
CommandWordsPairs Pairs;
26372640
CodeCompletionResultBuilder Builder(
26382641
Sink,
26392642
CodeCompletionResult::ResultKind::Declaration,
26402643
getSemanticContext(SD, Reason), ExpectedTypes);
26412644
Builder.setAssociatedDecl(SD);
26422645
setClangDeclKeywords(SD, Pairs, Builder);
2646+
2647+
// '\TyName#^TOKEN^#' requires leading dot.
2648+
if (!HaveDot && IsAfterSwiftKeyPathRoot)
2649+
Builder.addLeadingDot();
2650+
2651+
if (NeedOptionalUnwrap) {
2652+
Builder.setNumBytesToErase(NumBytesToEraseForOptionalUnwrap);
2653+
Builder.addQuestionMark();
2654+
}
2655+
26432656
Builder.addLeftBracket();
26442657
addParameters(Builder, SD->getIndices());
26452658
Builder.addRightBracket();
@@ -2973,12 +2986,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
29732986
}
29742987

29752988
// Swift key path allows .[0]
2976-
if (shouldAddSubscriptCall()) {
2977-
if (auto *SD = dyn_cast<SubscriptDecl>(D)) {
2978-
if (ExprType && !ExprType->is<AnyMetatypeType>())
2979-
addSubscriptCall(SD, Reason);
2980-
return;
2981-
}
2989+
if (auto *SD = dyn_cast<SubscriptDecl>(D)) {
2990+
addSubscriptCall(SD, Reason);
2991+
return;
29822992
}
29832993
return;
29842994

@@ -4352,8 +4362,6 @@ void CodeCompletionCallbacksImpl::completeDotExpr(Expr *E, SourceLoc DotLoc) {
43524362
return;
43534363

43544364
Kind = CompletionKind::DotExpr;
4355-
if (E->getKind() == ExprKind::KeyPath)
4356-
Kind = CompletionKind::SwiftKeyPath;
43574365
if (ParseExprSelectorContext != ObjCSelectorContext::None) {
43584366
PreferFunctionReferencesToCalls = true;
43594367
CompleteExprSelectorContext = ParseExprSelectorContext;
@@ -4474,9 +4482,11 @@ void CodeCompletionCallbacksImpl::completeExprSuperDot(SuperRefExpr *SRE) {
44744482
}
44754483

44764484
void CodeCompletionCallbacksImpl::completeExprKeyPath(KeyPathExpr *KPE,
4477-
bool HasDot) {
4478-
Kind = HasDot ? CompletionKind::KeyPathExprDot : CompletionKind::KeyPathExpr;
4485+
SourceLoc DotLoc) {
4486+
Kind = (!KPE || KPE->isObjC()) ? CompletionKind::KeyPathExprObjC
4487+
: CompletionKind::KeyPathExprSwift;
44794488
ParsedExpr = KPE;
4489+
this->DotLoc = DotLoc;
44804490
CurDeclContext = P.CurDeclContext;
44814491
}
44824492

@@ -4737,9 +4747,8 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
47374747
case CompletionKind::CallArg:
47384748
case CompletionKind::AfterPound:
47394749
case CompletionKind::GenericParams:
4740-
case CompletionKind::KeyPathExpr:
4741-
case CompletionKind::KeyPathExprDot:
4742-
case CompletionKind::SwiftKeyPath:
4750+
case CompletionKind::KeyPathExprObjC:
4751+
case CompletionKind::KeyPathExprSwift:
47434752
break;
47444753

47454754
case CompletionKind::StmtOrExpr:
@@ -5135,8 +5144,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
51355144

51365145
if (!ExprType && Kind != CompletionKind::PostfixExprParen &&
51375146
Kind != CompletionKind::CallArg &&
5138-
Kind != CompletionKind::KeyPathExpr &&
5139-
Kind != CompletionKind::KeyPathExprDot)
5147+
Kind != CompletionKind::KeyPathExprObjC)
51405148
return;
51415149
}
51425150

@@ -5190,17 +5198,32 @@ void CodeCompletionCallbacksImpl::doneParsing() {
51905198
break;
51915199
}
51925200

5193-
case CompletionKind::SwiftKeyPath: {
5194-
Lookup.setHaveDot(DotLoc);
5195-
Lookup.setIsSwiftKeyPathExpr();
5196-
if (auto BGT = (*ExprType)->getAs<BoundGenericType>()) {
5197-
auto AllArgs = BGT->getGenericArgs();
5198-
if (AllArgs.size() == 2) {
5199-
// The second generic type argument of KeyPath<Root, Value> should be
5200-
// the value we pull code completion results from.
5201-
Lookup.getValueExprCompletions(AllArgs[1]);
5202-
}
5201+
case CompletionKind::KeyPathExprSwift: {
5202+
auto KPE = dyn_cast<KeyPathExpr>(ParsedExpr);
5203+
auto BGT = (*ExprType)->getAs<BoundGenericType>();
5204+
if (!KPE || !BGT || BGT->getGenericArgs().size() != 2)
5205+
break;
5206+
assert(!KPE->isObjC());
5207+
5208+
if (DotLoc.isValid())
5209+
Lookup.setHaveDot(DotLoc);
5210+
5211+
bool OnRoot = !KPE->getComponents().front().isValid();
5212+
Lookup.setIsSwiftKeyPathExpr(OnRoot);
5213+
5214+
auto ParsedType = BGT->getGenericArgs()[1];
5215+
auto Components = KPE->getComponents();
5216+
if (Components.back().getKind() ==
5217+
KeyPathExpr::Component::Kind::OptionalWrap) {
5218+
// KeyPath expr with '?' (e.g. '\Ty.[0].prop?.another').
5219+
// Althogh expected type is optional, we should unwrap it because it's
5220+
// unwrapped.
5221+
ParsedType = ParsedType->getOptionalObjectType();
52035222
}
5223+
5224+
// The second generic type argument of KeyPath<Root, Value> should be
5225+
// the value we pull code completion results from.
5226+
Lookup.getValueExprCompletions(ParsedType);
52045227
break;
52055228
}
52065229

@@ -5276,11 +5299,9 @@ void CodeCompletionCallbacksImpl::doneParsing() {
52765299
break;
52775300
}
52785301

5279-
case CompletionKind::KeyPathExprDot:
5280-
Lookup.setHaveDot(SourceLoc());
5281-
LLVM_FALLTHROUGH;
5282-
5283-
case CompletionKind::KeyPathExpr: {
5302+
case CompletionKind::KeyPathExprObjC: {
5303+
if (DotLoc.isValid())
5304+
Lookup.setHaveDot(DotLoc);
52845305
Lookup.setIsKeyPathExpr();
52855306
Lookup.includeInstanceMembers();
52865307

0 commit comments

Comments
 (0)