Skip to content

Commit 49e8527

Browse files
committed
---
yaml --- r: 268767 b: refs/heads/marcrasi-const-evaluator-part-2 c: 0f319dd h: refs/heads/master i: 268765: d1131e9 268763: b30b825 268759: 0239b72 268751: cb3e0f3 268735: e7f256a
1 parent 060e2da commit 49e8527

File tree

263 files changed

+1856
-2150
lines changed

Some content is hidden

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

263 files changed

+1856
-2150
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-09-28-a: c30bf9b3ca148b1b90ebcd80141d9
10811081
refs/heads/bananaphone: 2af9a1dc7f40dcb4b2949876f7e237763d1a7972
10821082
refs/heads/marcrasi-const-evaluator-part-3: 867d96d6aa4cfb5079b7478be617387a1f621c88
10831083
refs/heads/marcrasi-const-evaluator-part-1: 390daeaeea2181a1fc24910e09b5861053cd3558
1084-
refs/heads/marcrasi-const-evaluator-part-2: 8112f68b96b48300b07f6155c49c236f078720e6
1084+
refs/heads/marcrasi-const-evaluator-part-2: 0f319dda67b003c38d56c13b8624bc7e8feef03a
10851085
refs/heads/revert-19689-keep-sourcekitd-response-alive-while-variant-lives: b5b1d9ab2340a64a3c7332529cdca1cb2318d93c
10861086
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-10-01-a: 63059bdab8bbcdd68591738fa28c68c8c19bde75
10871087
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-10-02-a: 12514879eff2c34a64ac6e65b323447f6525cfd0

branches/marcrasi-const-evaluator-part-2/include/swift/AST/Decl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,9 +3985,6 @@ class ProtocolDecl final : public NominalTypeDecl {
39853985
->existentialConformsToSelfSlow();
39863986
}
39873987

3988-
/// Does this protocol require a self-conformance witness table?
3989-
bool requiresSelfConformanceWitnessTable() const;
3990-
39913988
/// Find direct Self references within the given requirement.
39923989
///
39933990
/// \param allowCovariantParameters If true, 'Self' is assumed to be

branches/marcrasi-const-evaluator-part-2/include/swift/SIL/SILBuilder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,8 +2095,7 @@ class SILBuilder {
20952095
/// lowering for the non-address value.
20962096
void emitDestroyValueOperation(SILLocation Loc, SILValue v) {
20972097
assert(!v->getType().isAddress());
2098-
if (F->hasQualifiedOwnership() &&
2099-
v.getOwnershipKind() == ValueOwnershipKind::Any)
2098+
if (v.getOwnershipKind() == ValueOwnershipKind::Trivial)
21002099
return;
21012100
auto &lowering = getTypeLowering(v->getType());
21022101
lowering.emitDestroyValue(*this, Loc, v);

branches/marcrasi-const-evaluator-part-2/include/swift/SIL/SILCloner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,8 +2130,8 @@ void SILCloner<ImplClass>::visitUncheckedOwnershipConversionInst(
21302130
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
21312131
ValueOwnershipKind Kind = SILValue(Inst).getOwnershipKind();
21322132
if (getOpValue(Inst->getOperand()).getOwnershipKind() ==
2133-
ValueOwnershipKind::Any) {
2134-
Kind = ValueOwnershipKind::Any;
2133+
ValueOwnershipKind::Trivial) {
2134+
Kind = ValueOwnershipKind::Trivial;
21352135
}
21362136
recordClonedInstruction(Inst, getBuilder().createUncheckedOwnershipConversion(
21372137
getOpLocation(Inst->getLoc()),

branches/marcrasi-const-evaluator-part-2/include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5023,7 +5023,7 @@ class EnumInst : public InstructionBase<SILInstructionKind::EnumInst,
50235023
: InstructionBase(DebugLoc, ResultTy,
50245024
Operand
50255025
? Operand.getOwnershipKind()
5026-
: ValueOwnershipKind(ValueOwnershipKind::Any)),
5026+
: ValueOwnershipKind(ValueOwnershipKind::Trivial)),
50275027
Element(Element) {
50285028
if (Operand) {
50295029
OptionalOperand.emplace(this, Operand);

branches/marcrasi-const-evaluator-part-2/include/swift/SIL/SILValue.h

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "swift/Basic/Range.h"
2121
#include "swift/Basic/ArrayRefView.h"
22-
#include "swift/Basic/STLExtras.h"
2322
#include "swift/SIL/SILNode.h"
2423
#include "swift/SIL/SILType.h"
2524
#include "llvm/ADT/ArrayRef.h"
@@ -87,6 +86,17 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
8786
/// have.
8887
struct ValueOwnershipKind {
8988
enum innerty : uint8_t {
89+
/// A SILValue with Trivial ownership kind is an independent value that can
90+
/// not be owned. Ownership does not place any constraints on how a SILValue
91+
/// with Trivial ownership kind can be used. Other side effects (e.g. Memory
92+
/// dependencies) must still be respected. A SILValue with Trivial ownership
93+
/// kind must be of Trivial SILType (i.e. SILType::isTrivial(SILModule &)
94+
/// must return true).
95+
///
96+
/// Some examples of SIL types with Trivial ownership are: Builtin.Int32,
97+
/// Builtin.RawPointer, aggregates containing all trivial types.
98+
Trivial,
99+
90100
/// A SILValue with `Unowned` ownership kind is an independent value that
91101
/// has a lifetime that is only guaranteed to last until the next program
92102
/// visible side-effect. To maintain the lifetime of an unowned value, it
@@ -117,11 +127,10 @@ struct ValueOwnershipKind {
117127
/// instruction exactly once along any path through the program.
118128
Guaranteed,
119129

120-
/// A SILValue with Any ownership kind is an independent value outside of
121-
/// the ownership system. It is used to model trivially typed values as well
122-
/// as trivial cases of non-trivial enums. Naturally Any can be merged with
123-
/// any ValueOwnershipKind allowing us to naturally model merge and branch
124-
/// points in the SSA graph.
130+
/// A SILValue with undefined ownership. It can pair with /Any/ ownership
131+
/// kinds. This means that it could take on /any/ ownership semantics. This
132+
/// is meant only to model SILUndef and to express certain situations where
133+
/// we use unqualified ownership. Expected to tighten over time.
125134
Any,
126135

127136
LastValueOwnershipKind = Any,
@@ -153,6 +162,10 @@ struct ValueOwnershipKind {
153162

154163
Optional<ValueOwnershipKind> merge(ValueOwnershipKind RHS) const;
155164

165+
bool isTrivialOr(ValueOwnershipKind Kind) const {
166+
return Value == Trivial || Value == Kind;
167+
}
168+
156169
/// Given that there is an aggregate value (like a struct or enum) with this
157170
/// ownership kind, and a subobject of type Proj is being projected from the
158171
/// aggregate, return Trivial if Proj has trivial type and the aggregate's
@@ -167,6 +180,7 @@ struct ValueOwnershipKind {
167180
/// kinds.
168181
UseLifetimeConstraint getForwardingLifetimeConstraint() const {
169182
switch (Value) {
183+
case ValueOwnershipKind::Trivial:
170184
case ValueOwnershipKind::Any:
171185
case ValueOwnershipKind::Guaranteed:
172186
case ValueOwnershipKind::Unowned:
@@ -185,16 +199,12 @@ struct ValueOwnershipKind {
185199
return merge(other).hasValue();
186200
}
187201

188-
template <typename RangeTy>
189-
static Optional<ValueOwnershipKind> merge(RangeTy &&r) {
190-
auto initial = Optional<ValueOwnershipKind>(ValueOwnershipKind::Any);
191-
return accumulate(
192-
std::forward<RangeTy>(r), initial,
193-
[](Optional<ValueOwnershipKind> acc, ValueOwnershipKind x) {
194-
if (!acc)
195-
return acc;
196-
return acc.getValue().merge(x);
197-
});
202+
/// Returns true if \p Other is compatible with ValueOwnershipKind::Trivial or
203+
/// this. See isCompatibleWith for more information on what "compatibility"
204+
/// means.
205+
bool isTrivialOrCompatibleWith(ValueOwnershipKind other) const {
206+
return isCompatibleWith(ValueOwnershipKind::Trivial) ||
207+
isCompatibleWith(other);
198208
}
199209
};
200210

branches/marcrasi-const-evaluator-part-2/include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5252
/// describe what change you made. The content of this comment isn't important;
5353
/// it just ensures a conflict if two people change the module format.
5454
/// Don't worry about adhering to the 80-column limit for this line.
55-
const uint16_t SWIFTMODULE_VERSION_MINOR = 470; // Last change: Remove @trivial
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 469; // @_hasStorage
5656

5757
using DeclIDField = BCFixed<31>;
5858

branches/marcrasi-const-evaluator-part-2/lib/AST/Decl.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,22 +3910,15 @@ bool ProtocolDecl::requiresClassSlow() {
39103910
return Bits.ProtocolDecl.RequiresClass;
39113911
}
39123912

3913-
bool ProtocolDecl::requiresSelfConformanceWitnessTable() const {
3914-
return isSpecificProtocol(KnownProtocolKind::Error);
3915-
}
3916-
39173913
bool ProtocolDecl::existentialConformsToSelfSlow() {
39183914
// Assume for now that the existential conforms to itself; this
39193915
// prevents circularity issues.
39203916
Bits.ProtocolDecl.ExistentialConformsToSelfValid = true;
39213917
Bits.ProtocolDecl.ExistentialConformsToSelf = true;
39223918

3923-
// If it's not @objc, it conforms to itself only if it has a
3924-
// self-conformance witness table.
39253919
if (!isObjC()) {
3926-
bool hasSelfConformance = requiresSelfConformanceWitnessTable();
3927-
Bits.ProtocolDecl.ExistentialConformsToSelf = hasSelfConformance;
3928-
return hasSelfConformance;
3920+
Bits.ProtocolDecl.ExistentialConformsToSelf = false;
3921+
return false;
39293922
}
39303923

39313924
// Check whether this protocol conforms to itself.

branches/marcrasi-const-evaluator-part-2/lib/AST/Module.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -585,15 +585,6 @@ ModuleDecl::lookupExistentialConformance(Type type, ProtocolDecl *protocol) {
585585
// existential to an archetype parameter, so for now we restrict this to
586586
// @objc protocols.
587587
if (!layout.isObjC()) {
588-
// There's a specific exception for protocols with self-conforming
589-
// witness tables, but the existential has to be *exactly* that type.
590-
// TODO: synthesize witness tables on-demand for protocol compositions
591-
// that can satisfy the requirement.
592-
if (protocol->requiresSelfConformanceWitnessTable() &&
593-
type->is<ProtocolType>() &&
594-
type->castTo<ProtocolType>()->getDecl() == protocol)
595-
return ProtocolConformanceRef(protocol);
596-
597588
return None;
598589
}
599590

@@ -685,7 +676,7 @@ ModuleDecl::lookupConformance(Type type, ProtocolDecl *protocol) {
685676
auto nominal = type->getAnyNominal();
686677

687678
// If we don't have a nominal type, there are no conformances.
688-
if (!nominal || isa<ProtocolDecl>(nominal)) return None;
679+
if (!nominal) return None;
689680

690681
// Find the (unspecialized) conformance.
691682
SmallVector<ProtocolConformance *, 2> conformances;

branches/marcrasi-const-evaluator-part-2/lib/AST/ProtocolConformance.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,12 +1432,9 @@ DeclContext::getLocalConformances(
14321432
if (!nominal)
14331433
return result;
14341434

1435-
// Protocols only have self-conformances.
1436-
if (auto protocol = dyn_cast<ProtocolDecl>(nominal)) {
1437-
if (protocol->requiresSelfConformanceWitnessTable())
1438-
return { protocol->getASTContext().getSelfConformance(protocol) };
1435+
// Protocols don't have conformances.
1436+
if (isa<ProtocolDecl>(nominal))
14391437
return { };
1440-
}
14411438

14421439
// Update to record all potential conformances.
14431440
nominal->prepareConformanceTable();

branches/marcrasi-const-evaluator-part-2/lib/IRGen/GenProto.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,23 +2876,16 @@ llvm::Value *irgen::emitWitnessTableRef(IRGenFunction &IGF,
28762876
// If we don't have concrete conformance information, the type must be
28772877
// an archetype and the conformance must be via one of the protocol
28782878
// requirements of the archetype. Look at what's locally bound.
2879-
ProtocolConformance *concreteConformance;
28802879
if (conformance.isAbstract()) {
2881-
if (auto archetype = dyn_cast<ArchetypeType>(srcType))
2882-
return emitArchetypeWitnessTableRef(IGF, archetype, proto);
2883-
2884-
// Otherwise, this must be a self-conformance.
2885-
assert(proto->requiresSelfConformanceWitnessTable());
2886-
assert(cast<ProtocolType>(srcType)->getDecl() == proto);
2887-
concreteConformance = IGF.IGM.Context.getSelfConformance(proto);
2880+
auto archetype = cast<ArchetypeType>(srcType);
2881+
return emitArchetypeWitnessTableRef(IGF, archetype, proto);
2882+
}
28882883

28892884
// All other source types should be concrete enough that we have
28902885
// conformance info for them. However, that conformance info might be
28912886
// more concrete than we're expecting.
28922887
// TODO: make a best effort to devirtualize, maybe?
2893-
} else {
2894-
concreteConformance = conformance.getConcrete();
2895-
}
2888+
auto concreteConformance = conformance.getConcrete();
28962889
assert(concreteConformance->getProtocol() == proto);
28972890

28982891
auto cacheKind =

branches/marcrasi-const-evaluator-part-2/lib/IRGen/LoadableByAddress.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ SILArgument *LoadableStorageAllocation::replaceArgType(SILBuilder &argBuilder,
13261326
arg) == pass.largeLoadableArgs.end());
13271327

13281328
arg = arg->getParent()->replaceFunctionArgument(
1329-
arg->getIndex(), newSILType, ValueOwnershipKind::Any, arg->getDecl());
1329+
arg->getIndex(), newSILType, ValueOwnershipKind::Trivial, arg->getDecl());
13301330

13311331
copyArg->replaceAllUsesWith(arg);
13321332
copyArg->eraseFromParent();
@@ -1352,7 +1352,7 @@ void LoadableStorageAllocation::insertIndirectReturnArgs() {
13521352
ctx.getIdentifier("$return_value"),
13531353
pass.F->getDeclContext());
13541354
pass.F->begin()->insertFunctionArgument(0, resultStorageType.getAddressType(),
1355-
ValueOwnershipKind::Any, var);
1355+
ValueOwnershipKind::Trivial, var);
13561356
}
13571357

13581358
void LoadableStorageAllocation::convertIndirectFunctionArgs() {

branches/marcrasi-const-evaluator-part-2/lib/ParseSIL/ParseSIL.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,11 @@ namespace {
329329
bool parseSILOwnership(ValueOwnershipKind &OwnershipKind) {
330330
// We parse here @ <identifier>.
331331
if (!P.consumeIf(tok::at_sign)) {
332-
// If we fail, we must have @any ownership.
333-
OwnershipKind = ValueOwnershipKind::Any;
334-
return false;
332+
// Add error here.
333+
return true;
335334
}
336335

337-
StringRef AllOwnershipKinds[3] = {"unowned", "owned",
336+
StringRef AllOwnershipKinds[4] = {"trivial", "unowned", "owned",
338337
"guaranteed"};
339338
return parseSILIdentifierSwitch(OwnershipKind, AllOwnershipKinds,
340339
diag::expected_sil_value_ownership_kind);

0 commit comments

Comments
 (0)