Skip to content

Commit 86bb989

Browse files
committed
---
yaml --- r: 318973 b: refs/heads/master-rebranch c: a9cae77 h: refs/heads/master i: 318971: 9a6c1a4
1 parent 4fa9d4d commit 86bb989

27 files changed

+408
-1257
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,4 +1457,4 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14571457
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14581458
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14591459
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1460-
refs/heads/master-rebranch: ec83122128560f5628d70cf5b183fb1638fe4724
1460+
refs/heads/master-rebranch: a9cae779f444a8ea3156b6562a309af954ed01f4

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,15 +1055,26 @@ class CaseStmt final
10551055
return UnknownAttrLoc.isValid();
10561056
}
10571057

1058-
Optional<ArrayRef<VarDecl *>> getCaseBodyVariables() const {
1059-
if (!CaseBodyVariables)
1060-
return None;
1058+
/// Return an ArrayRef containing the case body variables of this CaseStmt.
1059+
///
1060+
/// Asserts if case body variables was not explicitly initialized. In contexts
1061+
/// where one wants a non-asserting version, \see
1062+
/// getCaseBodyVariablesOrEmptyArray.
1063+
ArrayRef<VarDecl *> getCaseBodyVariables() const {
10611064
ArrayRef<VarDecl *> a = *CaseBodyVariables;
10621065
return a;
10631066
}
10641067

1065-
Optional<MutableArrayRef<VarDecl *>> getCaseBodyVariables() {
1066-
return CaseBodyVariables;
1068+
bool hasCaseBodyVariables() const { return CaseBodyVariables.hasValue(); }
1069+
1070+
/// Return an MutableArrayRef containing the case body variables of this
1071+
/// CaseStmt.
1072+
///
1073+
/// Asserts if case body variables was not explicitly initialized. In contexts
1074+
/// where one wants a non-asserting version, \see
1075+
/// getCaseBodyVariablesOrEmptyArray.
1076+
MutableArrayRef<VarDecl *> getCaseBodyVariables() {
1077+
return *CaseBodyVariables;
10671078
}
10681079

10691080
ArrayRef<VarDecl *> getCaseBodyVariablesOrEmptyArray() const {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,13 +1622,13 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
16221622
if (S->hasUnknownAttr())
16231623
OS << " @unknown";
16241624

1625-
if (auto caseBodyVars = S->getCaseBodyVariables()) {
1625+
if (S->hasCaseBodyVariables()) {
16261626
OS << '\n';
16271627
OS.indent(Indent + 2);
16281628
PrintWithColorRAII(OS, ParenthesisColor) << '(';
16291629
PrintWithColorRAII(OS, StmtColor) << "case_body_variables";
16301630
OS << '\n';
1631-
for (auto *vd : *caseBodyVars) {
1631+
for (auto *vd : S->getCaseBodyVariables()) {
16321632
OS.indent(2);
16331633
// TODO: Printing a var decl does an Indent ... dump(vd) ... '\n'. We
16341634
// should see if we can factor this dumping so that the caller of

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5094,7 +5094,7 @@ NullablePtr<VarDecl> VarDecl::getCorrespondingCaseBodyVariable() const {
50945094

50955095
// A var decl associated with a case stmt implies that the case stmt has body
50965096
// var decls. So we can access the optional value here without worry.
5097-
auto caseBodyVars = *caseStmt->getCaseBodyVariables();
5097+
auto caseBodyVars = caseStmt->getCaseBodyVariables();
50985098
auto result = llvm::find_if(caseBodyVars, [&](VarDecl *caseBodyVar) {
50995099
return caseBodyVar->getName() == name;
51005100
});

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,10 +2349,8 @@ void FindLocalVal::visitCaseStmt(CaseStmt *S) {
23492349
}
23502350

23512351
if (!inPatterns && !items.empty()) {
2352-
if (auto caseBodyVars = S->getCaseBodyVariables()) {
2353-
for (auto *vd : *caseBodyVars) {
2354-
checkValueDecl(vd, DeclVisibilityKind::LocalVariable);
2355-
}
2352+
for (auto *vd : S->getCaseBodyVariablesOrEmptyArray()) {
2353+
checkValueDecl(vd, DeclVisibilityKind::LocalVariable);
23562354
}
23572355
}
23582356
visit(S->getBody());

branches/master-rebranch/lib/SILGen/SILGenPattern.cpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,12 +2332,8 @@ void PatternMatchEmission::initSharedCaseBlockDest(CaseStmt *caseBlock,
23322332
auto *block = SGF.createBasicBlock();
23332333
result.first->second.first = block;
23342334

2335-
// Add args for any pattern variables
2336-
auto caseBodyVars = caseBlock->getCaseBodyVariables();
2337-
if (!caseBodyVars)
2338-
return;
2339-
2340-
for (auto *vd : *caseBodyVars) {
2335+
// Add args for any pattern variables if we have any.
2336+
for (auto *vd : caseBlock->getCaseBodyVariablesOrEmptyArray()) {
23412337
if (!vd->hasName())
23422338
continue;
23432339

@@ -2365,14 +2361,10 @@ void PatternMatchEmission::emitAddressOnlyAllocations() {
23652361
for (auto &entry : SharedCases) {
23662362
CaseStmt *caseBlock = entry.first;
23672363

2368-
auto caseBodyVars = caseBlock->getCaseBodyVariables();
2369-
if (!caseBodyVars)
2370-
continue;
2371-
23722364
// If we have a shared case with bound decls, setup the arguments for the
23732365
// shared block by emitting the temporary allocation used for the arguments
23742366
// of the shared block.
2375-
for (auto *vd : *caseBodyVars) {
2367+
for (auto *vd : caseBlock->getCaseBodyVariablesOrEmptyArray()) {
23762368
if (!vd->hasName())
23772369
continue;
23782370

@@ -2436,8 +2428,7 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
24362428
assert(SGF.getCleanupsDepth() == PatternMatchStmtDepth);
24372429
SWIFT_DEFER { assert(SGF.getCleanupsDepth() == PatternMatchStmtDepth); };
24382430

2439-
auto caseBodyVars = caseBlock->getCaseBodyVariables();
2440-
if (!caseBodyVars) {
2431+
if (!caseBlock->hasCaseBodyVariables()) {
24412432
emitCaseBody(caseBlock);
24422433
continue;
24432434
}
@@ -2448,7 +2439,7 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
24482439
// args needing Cleanup will get that as well.
24492440
Scope scope(SGF.Cleanups, CleanupLocation(caseBlock));
24502441
unsigned argIndex = 0;
2451-
for (auto *vd : *caseBodyVars) {
2442+
for (auto *vd : caseBlock->getCaseBodyVariables()) {
24522443
if (!vd->hasName())
24532444
continue;
24542445

@@ -2606,14 +2597,14 @@ static void switchCaseStmtSuccessCallback(SILGenFunction &SGF,
26062597
if (!row.hasFallthroughTo() && caseBlock->getCaseLabelItems().size() == 1) {
26072598
// If we have case body vars, set them up to point at the matching var
26082599
// decls.
2609-
if (auto caseBodyVars = caseBlock->getCaseBodyVariables()) {
2600+
if (caseBlock->hasCaseBodyVariables()) {
26102601
// Since we know that we only have one case label item, grab its pattern
26112602
// vars and use that to update expected with the right SILValue.
26122603
//
26132604
// TODO: Do we need a copy here?
26142605
SmallVector<VarDecl *, 4> patternVars;
26152606
row.getCasePattern()->collectVariables(patternVars);
2616-
for (auto *expected : *caseBodyVars) {
2607+
for (auto *expected : caseBlock->getCaseBodyVariables()) {
26172608
if (!expected->hasName())
26182609
continue;
26192610
for (auto *vd : patternVars) {
@@ -2622,7 +2613,8 @@ static void switchCaseStmtSuccessCallback(SILGenFunction &SGF,
26222613
}
26232614

26242615
// Ok, we found a match. Update the VarLocs for the case block.
2625-
SGF.VarLocs[expected] = SGF.VarLocs[vd];
2616+
auto v = SGF.VarLocs[vd];
2617+
SGF.VarLocs[expected] = v;
26262618
}
26272619
}
26282620
}
@@ -2639,8 +2631,7 @@ static void switchCaseStmtSuccessCallback(SILGenFunction &SGF,
26392631

26402632
// If we do not have any bound decls, we do not need to setup any
26412633
// variables. Just jump to the shared destination.
2642-
auto caseBodyVars = caseBlock->getCaseBodyVariables();
2643-
if (!caseBodyVars) {
2634+
if (!caseBlock->hasCaseBodyVariables()) {
26442635
// Don't emit anything yet, we emit it at the cleanup level of the switch
26452636
// statement.
26462637
JumpDest sharedDest = emission.getSharedCaseBlockDest(caseBlock);
@@ -2657,7 +2648,7 @@ static void switchCaseStmtSuccessCallback(SILGenFunction &SGF,
26572648
SILModule &M = SGF.F.getModule();
26582649
SmallVector<VarDecl *, 4> patternVars;
26592650
row.getCasePattern()->collectVariables(patternVars);
2660-
for (auto *expected : *caseBodyVars) {
2651+
for (auto *expected : caseBlock->getCaseBodyVariables()) {
26612652
if (!expected->hasName())
26622653
continue;
26632654
for (auto *var : patternVars) {
@@ -2844,8 +2835,7 @@ void SILGenFunction::emitSwitchFallthrough(FallthroughStmt *S) {
28442835

28452836
// If our destination case doesn't have any bound decls, there is no rebinding
28462837
// to do. Just jump to the shared dest.
2847-
auto destCaseBodyVars = destCaseStmt->getCaseBodyVariables();
2848-
if (!destCaseBodyVars) {
2838+
if (!destCaseStmt->hasCaseBodyVariables()) {
28492839
Cleanups.emitBranchAndCleanups(sharedDest, S);
28502840
return;
28512841
}
@@ -2855,13 +2845,13 @@ void SILGenFunction::emitSwitchFallthrough(FallthroughStmt *S) {
28552845
SmallVector<SILValue, 4> args;
28562846
CaseStmt *fallthroughSourceStmt = S->getFallthroughSource();
28572847

2858-
for (auto *expected : *destCaseBodyVars) {
2848+
for (auto *expected : destCaseStmt->getCaseBodyVariables()) {
28592849
if (!expected->hasName())
28602850
continue;
28612851

28622852
// The type checker enforces that if our destination case has variables then
28632853
// our fallthrough source must as well.
2864-
for (auto *var : *fallthroughSourceStmt->getCaseBodyVariables()) {
2854+
for (auto *var : fallthroughSourceStmt->getCaseBodyVariables()) {
28652855
if (!var->hasName() || var->getName() != expected->getName()) {
28662856
continue;
28672857
}

branches/master-rebranch/lib/Sema/MiscDiagnostics.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,10 +2414,8 @@ class VarDeclUsageChecker : public ASTWalker {
24142414

24152415
// Make sure that we setup our case body variables.
24162416
if (auto *caseStmt = dyn_cast<CaseStmt>(S)) {
2417-
if (auto caseBoundDecls = caseStmt->getCaseBodyVariables()) {
2418-
for (auto *vd : *caseBoundDecls) {
2419-
VarDecls[vd] |= 0;
2420-
}
2417+
for (auto *vd : caseStmt->getCaseBodyVariablesOrEmptyArray()) {
2418+
VarDecls[vd] |= 0;
24212419
}
24222420
}
24232421

branches/master-rebranch/stdlib/public/Darwin/CoreGraphics/CGFloat.swift.gyb

Lines changed: 11 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -513,111 +513,18 @@ public func %=(lhs: inout CGFloat, rhs: CGFloat) {
513513
// tgmath
514514
//===----------------------------------------------------------------------===//
515515

516-
%from SwiftMathFunctions import *
517-
extension CGFloat: Real {
518-
% for func in ElementaryFunctions + RealFunctions:
519-
520-
@_alwaysEmitIntoClient
521-
public static func ${func.decl("CGFloat")} {
522-
return CGFloat(NativeType.${func.swiftName}(${func.params("", ".native")}))
523-
}
524-
% end
525-
526-
@_alwaysEmitIntoClient
527-
public static func pow(_ x: CGFloat, _ y: CGFloat) -> CGFloat {
528-
return CGFloat(NativeType.pow(x.native, y.native))
529-
}
530-
531-
@_alwaysEmitIntoClient
532-
public static func pow(_ x: CGFloat, _ n: Int) -> CGFloat {
533-
return CGFloat(NativeType.pow(x.native, n))
534-
}
535-
536-
@_alwaysEmitIntoClient
537-
public static func root(_ x: CGFloat, _ n: Int) -> CGFloat {
538-
return CGFloat(NativeType.root(x.native, n))
539-
}
540-
541-
@_alwaysEmitIntoClient
542-
public static func atan2(y: CGFloat, x: CGFloat) -> CGFloat {
543-
return CGFloat(NativeType.atan2(y: y.native, x: x.native))
544-
}
545-
546-
#if !os(Windows)
547-
@_alwaysEmitIntoClient
548-
public static func logGamma(_ x: CGFloat) -> CGFloat {
549-
return CGFloat(NativeType.logGamma(x.native))
550-
}
551-
#endif
552-
}
553-
554-
@available(swift, deprecated: 5.1, message: "Use `root(x, 3)`.")
555-
@_transparent
556-
public func cbrt(_ x: CGFloat) -> CGFloat {
557-
return CGFloat.root(x, 3)
558-
}
559-
560-
@available(swift, deprecated: 5.1, message: "Use CGFloat.minimum( ) or Swift.min( )")
561-
@_transparent
562-
public func fmin(_ x: CGFloat, _ y: CGFloat) -> CGFloat {
563-
return .minimum(x, y)
564-
}
565-
566-
@available(swift, deprecated: 5.1, message: "Use CGFloat.maximum( ) or Swift.max( )")
567-
@_transparent
568-
public func fmax(_ x: CGFloat, _ y: CGFloat) -> CGFloat {
569-
return .maximum(x, y)
570-
}
571-
572-
#if !os(Windows)
573-
@available(swift, deprecated: 5.1, message: "Use (logGamma(x), signGamma(x)).")
574-
@_transparent
575-
public func lgamma(_ x: CGFloat) -> (CGFloat, Int) {
576-
return (CGFloat.logGamma(x), CGFloat.signGamma(x) == .plus ? 1 : -1)
577-
}
578-
#endif
579-
580-
@available(swift, deprecated: 5.1, message: "Use `x.exponent` or `floor(log2(x))`.")
581-
@_transparent
582-
public func logb(_ x: CGFloat) -> CGFloat {
583-
return CGFloat.log2(x).rounded(.down)
584-
}
585-
586-
@available(swift, deprecated: 5.1, message: "Swift does not model dynamic rounding modes, use x.rounded(.toNearestOrEven).")
587-
@_transparent
588-
public func nearbyint(_ x: CGFloat) -> CGFloat {
589-
return x.rounded(.toNearestOrEven)
590-
}
591-
592-
@available(swift, deprecated: 5.1, message: "Use the .nextUp or .nextDown property.")
593-
@_transparent
594-
public func nextafter(_ x: CGFloat, _ y: CGFloat) -> CGFloat {
595-
return y > x ? x.nextUp : (y < x ? x.nextDown : y)
596-
}
597-
598-
@available(swift, deprecated: 5.1, message: "Swift does not model dynamic rounding modes, use x.rounded(.toNearestOrEven).")
599-
@_transparent
600-
public func rint(_ x: CGFloat) -> CGFloat {
601-
return x.rounded(.toNearestOrEven)
602-
}
603-
604-
@available(swift, deprecated: 5.1, message: "Use `gamma(x)`.")
605-
@_transparent
606-
public func tgamma(_ x: CGFloat) -> CGFloat {
607-
return CGFloat.gamma(x)
608-
}
609-
610516
%{
611517
UnaryFunctions = [
612518
'acos', 'asin', 'atan', 'cos', 'sin', 'tan',
613519
'acosh', 'asinh', 'atanh', 'cosh', 'sinh', 'tanh',
614520
'exp', 'exp2', 'expm1',
615-
'log', 'log10', 'log1p', 'log2',
616-
'erf', 'erfc',
521+
'log', 'log10', 'log1p', 'log2', 'logb',
522+
'cbrt', 'erf', 'erfc', 'tgamma',
523+
'nearbyint', 'rint'
617524
]
618525

619526
BinaryFunctions = [
620-
'atan2', 'hypot', 'pow', 'copysign', 'fdim'
527+
'atan2', 'hypot', 'pow', 'copysign', 'nextafter', 'fdim', 'fmax', 'fmin'
621528
]
622529
}%
623530

@@ -664,12 +571,18 @@ public func ldexp(_ x: CGFloat, _ n: Int) -> CGFloat {
664571
return CGFloat(ldexp(x.native, n))
665572
}
666573

667-
@available(swift, deprecated: 4.2, obsoleted: 5.1, message: "use the exponent property.")
574+
@available(swift, deprecated: 4.2, message: "use the exponent property.")
668575
@_transparent
669576
public func ilogb(_ x: CGFloat) -> Int {
670577
return Int(x.exponent)
671578
}
672579

580+
@_transparent
581+
public func lgamma(_ x: CGFloat) -> (CGFloat, Int) {
582+
let (value, sign) = lgamma(x.native)
583+
return (CGFloat(value), sign)
584+
}
585+
673586
@_transparent
674587
public func remquo(_ x: CGFloat, _ y: CGFloat) -> (CGFloat, Int) {
675588
let (rem, quo) = remquo(x.native, y.native)

0 commit comments

Comments
 (0)