Skip to content

Commit 34835d6

Browse files
committed
---
yaml --- r: 276479 b: refs/heads/master c: 85ee550 h: refs/heads/master i: 276477: 076875b 276475: 3c2ce24 276471: a994877 276463: d775d62 276447: c7d6790 276415: 4ca5358 276351: c54072c 276223: b0fefd7 275967: 5ec1aca 275455: 00caeb6 274431: dece103
1 parent e03421f commit 34835d6

File tree

16 files changed

+66
-146
lines changed

16 files changed

+66
-146
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: d7b919ce8b9540fd1251303972da62469fd46323
2+
refs/heads/master: 85ee5506693be3e4f82b3bc613694e9a1b17abea
33
refs/heads/master-next: e1ea272cf30ad8dda92fed0a4f7a6eb23cc519ba
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ NOTE(inout_change_var_type_if_possible,none,
238238
ERROR(cannot_pass_rvalue_inout,none,
239239
"cannot pass immutable value of type %0 as inout argument",
240240
(Type))
241-
ERROR(cannot_provide_default_value_inout,none,
242-
"cannot provide default value to inout parameter %0", (Identifier))
243241

244242
ERROR(cannot_assign_to_literal,none,
245243
"cannot assign to a literal value", ())

trunk/include/swift/SIL/SILInstruction.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5959,7 +5959,7 @@ class InitExistentialValueInst final
59595959
class InitExistentialRefInst final
59605960
: public UnaryInstructionWithTypeDependentOperandsBase<
59615961
SILInstructionKind::InitExistentialRefInst, InitExistentialRefInst,
5962-
SingleValueInstruction> {
5962+
OwnershipForwardingSingleValueInst> {
59635963
friend SILBuilder;
59645964

59655965
CanType ConcreteType;
@@ -5970,7 +5970,8 @@ class InitExistentialRefInst final
59705970
ArrayRef<SILValue> TypeDependentOperands,
59715971
ArrayRef<ProtocolConformanceRef> Conformances)
59725972
: UnaryInstructionWithTypeDependentOperandsBase(
5973-
DebugLoc, Instance, TypeDependentOperands, ExistentialType),
5973+
DebugLoc, Instance, TypeDependentOperands, ExistentialType,
5974+
Instance.getOwnershipKind()),
59745975
ConcreteType(FormalConcreteType), Conformances(Conformances) {}
59755976

59765977
static InitExistentialRefInst *

trunk/lib/SIL/OperandOwnership.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ CONSTANT_OWNERSHIP_INST(Owned, MustBeInvalidated, DestroyValue)
161161
CONSTANT_OWNERSHIP_INST(Owned, MustBeInvalidated, ReleaseValue)
162162
CONSTANT_OWNERSHIP_INST(Owned, MustBeInvalidated, ReleaseValueAddr)
163163
CONSTANT_OWNERSHIP_INST(Owned, MustBeInvalidated, StrongRelease)
164-
CONSTANT_OWNERSHIP_INST(Owned, MustBeInvalidated, EndLifetime)
165164
CONSTANT_OWNERSHIP_INST(Owned, MustBeInvalidated, InitExistentialRef)
165+
CONSTANT_OWNERSHIP_INST(Owned, MustBeInvalidated, EndLifetime)
166166
CONSTANT_OWNERSHIP_INST(Any, MustBeLive, AbortApply)
167167
CONSTANT_OWNERSHIP_INST(Any, MustBeLive, AddressToPointer)
168168
CONSTANT_OWNERSHIP_INST(Any, MustBeLive, BeginAccess)

trunk/lib/SIL/ValueOwnership.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ CONSTANT_OWNERSHIP_INST(Owned, KeyPath)
7777
CONSTANT_OWNERSHIP_INST(Owned, InitExistentialValue)
7878
CONSTANT_OWNERSHIP_INST(Owned, GlobalValue) // TODO: is this correct?
7979

80-
// NOTE: Even though init_existential_ref from a reference counting perspective
81-
// is not considered to be "owned" since it doesn't affect reference counts,
82-
// conceptually we want to treat it as an owned value that produces owned
83-
// things, rather than a forwarding thing since initialization is generally a
84-
// consuming operation.
85-
CONSTANT_OWNERSHIP_INST(Owned, InitExistentialRef)
86-
8780
// One would think that these /should/ be unowned. In truth they are owned since
8881
// objc metatypes do not go through the retain/release fast path. In their
8982
// implementations of retain/release nothing happens, so this is safe.
@@ -239,6 +232,7 @@ ValueOwnershipKindClassifier::visitForwardingInst(SILInstruction *i,
239232
}
240233
FORWARDING_OWNERSHIP_INST(BridgeObjectToRef)
241234
FORWARDING_OWNERSHIP_INST(ConvertFunction)
235+
FORWARDING_OWNERSHIP_INST(InitExistentialRef)
242236
FORWARDING_OWNERSHIP_INST(OpenExistentialRef)
243237
FORWARDING_OWNERSHIP_INST(RefToBridgeObject)
244238
FORWARDING_OWNERSHIP_INST(SelectValue)

trunk/lib/SILGen/SILGenPattern.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,37 +1868,44 @@ void PatternMatchEmission::emitEnumElementObjectDispatch(
18681868
// instruction to receive the enum case data if it has any.
18691869

18701870
SILType eltTy;
1871-
bool hasElt = false;
1872-
if (elt->hasAssociatedValues()) {
1871+
bool hasNonVoidAssocValue = false;
1872+
bool hasAssocValue = elt->hasAssociatedValues();
1873+
if (hasAssocValue) {
18731874
eltTy = src.getType().getEnumElementType(elt, SGF.SGM.M);
1874-
hasElt = !eltTy.getASTType()->isVoid();
1875+
hasNonVoidAssocValue = !eltTy.getASTType()->isVoid();
18751876
}
18761877

18771878
ConsumableManagedValue eltCMV, origCMV;
18781879

1879-
// Empty cases. Try to avoid making an empty tuple value if it's
1880-
// obviously going to be ignored. This assumes that we won't even
1881-
// try to touch the value in such cases, although we may touch the
1882-
// cleanup (enough to see that it's not present).
1883-
if (!hasElt) {
1884-
bool hasNonAny = false;
1885-
for (auto &specRow : specializedRows) {
1886-
auto pattern = specRow.Patterns[0];
1887-
if (pattern &&
1888-
!isa<AnyPattern>(pattern->getSemanticsProvidingPattern())) {
1889-
hasNonAny = true;
1890-
break;
1880+
// Void (i.e. empty) cases.
1881+
//
1882+
if (!hasNonVoidAssocValue) {
1883+
// Inline constructor.
1884+
eltCMV = [&]() -> ConsumableManagedValue {
1885+
// If we have an associated value, rather than no payload at all, we
1886+
// still need to create the argument. So do that instead of creating the
1887+
// empty-tuple. Otherwise, we need to create undef or the empty-tuple.
1888+
if (hasAssocValue) {
1889+
return {SGF.B.createOwnedPhiArgument(eltTy),
1890+
CastConsumptionKind::TakeAlways};
18911891
}
1892-
}
18931892

1894-
SILValue result;
1895-
if (hasNonAny) {
1896-
result = SGF.emitEmptyTuple(loc);
1897-
} else {
1898-
result = SILUndef::get(SGF.SGM.Types.getEmptyTupleType(), SGF.F);
1899-
}
1900-
origCMV = ConsumableManagedValue::forUnmanaged(result);
1901-
eltCMV = origCMV;
1893+
// Otherwise, try to avoid making an empty tuple value if it's obviously
1894+
// going to be ignored. This assumes that we won't even try to touch the
1895+
// value in such cases, although we may touch the cleanup (enough to see
1896+
// that it's not present).
1897+
bool hasNonAny =
1898+
llvm::any_of(specializedRows, [&](const SpecializedRow &row) {
1899+
auto *p = row.Patterns[0];
1900+
return p && !isa<AnyPattern>(p->getSemanticsProvidingPattern());
1901+
});
1902+
if (hasNonAny) {
1903+
return ConsumableManagedValue::forUnmanaged(SGF.emitEmptyTuple(loc));
1904+
}
1905+
1906+
return ConsumableManagedValue::forUnmanaged(
1907+
SILUndef::get(SGF.SGM.Types.getEmptyTupleType(), SGF.F));
1908+
}();
19021909

19031910
// Okay, specialize on the argument.
19041911
} else {

trunk/lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -639,24 +639,25 @@ SILPassPipelinePlan
639639
SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
640640
SILPassPipelinePlan P(Options);
641641

642-
// First serialize the SIL if we are asked to.
643-
P.startPipeline("Serialization");
644-
P.addSerializeSILPass();
645-
646-
// And then strip ownership...
647-
if (!Options.StripOwnershipDuringDiagnosticsPipeline)
648-
P.addOwnershipModelEliminator();
642+
// First specialize user-code.
643+
P.startPipeline("Prespecialization");
644+
P.addUsePrespecialized();
649645

650-
// Finally perform some small transforms.
651646
P.startPipeline("Rest of Onone");
652-
P.addUsePrespecialized();
653647

654648
// Has only an effect if the -assume-single-thread option is specified.
655649
P.addAssumeSingleThreaded();
656650

657651
// Has only an effect if the -gsil option is specified.
658652
P.addSILDebugInfoGenerator();
659653

654+
// Finally serialize the SIL if we are asked to.
655+
P.addSerializeSILPass();
656+
657+
// And then strip ownership before we IRGen.
658+
if (!Options.StripOwnershipDuringDiagnosticsPipeline)
659+
P.addOwnershipModelEliminator();
660+
660661
return P;
661662
}
662663

trunk/lib/Sema/TypeCheckExpr.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ TypeChecker::lookupPrecedenceGroupForInfixOperator(DeclContext *DC, Expr *E) {
217217
/// 'findLHS(DC, expr, '==')' returns nullptr.
218218
Expr *TypeChecker::findLHS(DeclContext *DC, Expr *E, Identifier name) {
219219
auto right = lookupPrecedenceGroupForOperator(*this, DC, name, E->getEndLoc());
220-
if (!right)
221-
return nullptr;
222-
223220
while (true) {
224221

225222
// Look through implicit conversions.

trunk/lib/Sema/TypeCheckPattern.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -863,14 +863,6 @@ bool TypeChecker::typeCheckParameterList(ParameterList *PL,
863863
param->setSpecifier(VarDecl::Specifier::Owned);
864864
}
865865
}
866-
867-
if (param->isInOut() && param->isDefaultArgument()) {
868-
diagnose(param->getDefaultValue()->getLoc(),
869-
swift::diag::cannot_provide_default_value_inout,
870-
param->getName());
871-
param->markInvalid();
872-
hadError = true;
873-
}
874866
}
875867

876868
return hadError;

trunk/test/SIL/ownership-verifier/over_consume.sil

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ class SuperKlass {
2929
class Klass : SuperKlass {
3030
}
3131

32-
typealias AnyObject = Builtin.AnyObject
33-
34-
class ClassProtConformingRef {}
35-
protocol ClassProt : AnyObject {}
36-
extension ClassProtConformingRef : ClassProt {}
37-
3832
///////////
3933
// Tests //
4034
///////////
@@ -458,30 +452,4 @@ bb0(%0 : @owned $Klass):
458452
dealloc_stack %1 : $*SuperKlass
459453
%9999 = tuple()
460454
return %9999 : $()
461-
}
462-
463-
// CHECK-LABEL: Function: 'init_existential_ref_not_forwarding'
464-
// CHECK: Have operand with incompatible ownership?!
465-
// CHECK: Value: %0 = argument of bb0 : $ClassProtConformingRef
466-
// CHECK: User: %2 = init_existential_ref %0 : $ClassProtConformingRef : $ClassProtConformingRef, $ClassProt
467-
// CHECK: Operand Number: 0
468-
// CHECK: Conv: guaranteed
469-
// CHECK: OwnershipMap:
470-
// CHECK: -- OperandOwnershipKindMap --
471-
// CHECK: unowned: No.
472-
// CHECK: owned: Yes. Liveness: MustBeInvalidated
473-
// CHECK: guaranteed: No.
474-
// CHECK: any: Yes. Liveness: MustBeLive
475-
// CHECK-NOT: init_existential_ref %1
476-
// CHECK: Function: 'init_existential_ref_not_forwarding'
477-
// CHECK: Error! Found a leaked owned value that was never consumed.
478-
// CHECK: Value: %2 = init_existential_ref %0 : $ClassProtConformingRef : $ClassProtConformingRef, $ClassProt
479-
// CHECK-NOT: init_existential_ref %1
480-
sil [ossa] @init_existential_ref_not_forwarding : $@convention(thin) (@guaranteed ClassProtConformingRef, @owned ClassProtConformingRef) -> @owned (ClassProt, ClassProt) {
481-
bb0(%0 : @guaranteed $ClassProtConformingRef, %1 : @owned $ClassProtConformingRef):
482-
%2 = init_existential_ref %0 : $ClassProtConformingRef : $ClassProtConformingRef, $ClassProt
483-
%3 = copy_value %2 : $ClassProt
484-
%4 = init_existential_ref %1 : $ClassProtConformingRef : $ClassProtConformingRef, $ClassProt
485-
%5 = tuple(%3 : $ClassProt, %4 : $ClassProt)
486-
return %5 : $(ClassProt, ClassProt)
487-
}
455+
}

trunk/test/SILGen/switch.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,3 +1291,15 @@ indirect enum SR6664_Base<Element> {
12911291
}
12921292
}
12931293
}
1294+
1295+
// Make sure that we properly create switch_enum success arguments if we have an
1296+
// associated type that is a void type.
1297+
func testVoidType() {
1298+
let x: Optional<()> = ()
1299+
switch x {
1300+
case .some(let x):
1301+
break
1302+
case .none:
1303+
break
1304+
}
1305+
}

trunk/test/decl/func/default-values.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,3 @@ struct X<T> {
122122

123123
let testXa: X<Int> = .foo(i: 0)
124124
let testXb: X<Int> = .bar
125-
126-
// SR-10062
127-
128-
var aLiteral = 1
129-
let bLiteral = 2
130-
131-
func inoutFuncWithDefaultArg1(x: inout Int = 1) {} // expected-error {{cannot provide default value to inout parameter 'x'}}
132-
func inoutFuncWithDefaultArg2(x: inout Int = bLiteral) {} // expected-error {{cannot provide default value to inout parameter 'x'}}
133-
func inoutFuncWithDefaultArg3(x: inout Int = aLiteral) {} // expected-error {{cannot provide default value to inout parameter 'x'}}
134-
func inoutFuncWithDefaultArg4(x: inout Int = &aLiteral) {} // expected-error {{cannot provide default value to inout parameter 'x'}}
135-
func inoutFuncWithDefaultArg5(x: inout Int = &bLiteral) {} // expected-error {{cannot provide default value to inout parameter 'x'}}
136-
func inoutFuncWithDefaultArg6(x: inout Int = #file) {} // expected-error {{cannot provide default value to inout parameter 'x'}}
137-
func inoutFuncWithDefaultArg7(_: inout Int = 1) {} // expected-error {{cannot provide default value to inout parameter '_'}}

trunk/test/expr/expressions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ func inoutTests(_ arr: inout Int) {
844844

845845
// <rdar://problem/20802757> Compiler crash in default argument & inout expr
846846
var g20802757 = 2
847-
func r20802757(_ z: inout Int = &g20802757) { // expected-error {{cannot provide default value to inout parameter 'z'}}
847+
func r20802757(_ z: inout Int = &g20802757) { // expected-error {{use of extraneous '&'}}
848848
print(z)
849849
}
850850

trunk/test/sil-passpipeline-dump/basic.test-sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33

44
// CHECK: [
55
// CHECK: [
6-
// CHECK: "Serialization",
7-
// CHECK: ["SerializeSILPass","serialize-sil"]
6+
// CHECK: "Prespecialization",
7+
// CHECK-NEXT: ["UsePrespecialized","use-prespecialized"]
88
// CHECK: ],
99
// CHECK: [
1010
// CHECK: "Rest of Onone",
11-
// CHECK: ["UsePrespecialized","use-prespecialized"],
12-
// CHECK: ["AssumeSingleThreaded","sil-assume-single-threaded"],
13-
// CHECK: ["SILDebugInfoGenerator","sil-debuginfo-gen"]
11+
// CHECK-NEXT: ["AssumeSingleThreaded","sil-assume-single-threaded"],
12+
// CHECK-NEXT: ["SILDebugInfoGenerator","sil-debuginfo-gen"]
1413
// CHECK: ]
15-
// CHECK: ]
14+
// CHECK: ]

trunk/validation-test/IDE/crashers_2_fixed/rdar48648877.swift

Lines changed: 0 additions & 30 deletions
This file was deleted.

trunk/validation-test/compiler_crashers_2_fixed/sr10062.swift

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)