Skip to content

Commit 9187230

Browse files
committed
---
yaml --- r: 341415 b: refs/heads/rxwei-patch-1 c: 5430aa0 h: refs/heads/master i: 341413: 7d70261 341411: 718f538 341407: 860a5b7
1 parent fc06715 commit 9187230

File tree

15 files changed

+109
-53
lines changed

15 files changed

+109
-53
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: 6bf46b9350edf9022cf12f1dfe46609fd813ce00
1018+
refs/heads/rxwei-patch-1: 5430aa0b178bcff77e4fa3f619e030784b780a2f
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/include/swift/AST/Builtins.def

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,20 @@ BUILTIN_MISC_OPERATION(WillThrow, "willThrow", "", Special)
551551
/// poundAssert has type (Builtin.Int1, Builtin.RawPointer) -> ().
552552
BUILTIN_MISC_OPERATION(PoundAssert, "poundAssert", "", Special)
553553

554+
// BUILTIN_MISC_OPERATION_WITH_SILGEN - Miscellaneous operations that are
555+
// specially emitted during SIL generation.
556+
#ifndef BUILTIN_MISC_OPERATION_WITH_SILGEN
557+
#define BUILTIN_MISC_OPERATION_WITH_SILGEN(Id, Name, Attrs, Overload) \
558+
BUILTIN_MISC_OPERATION(Id, Name, Attrs, Overload)
559+
#endif
560+
561+
/// globalStringTablePointer has type String -> Builtin.RawPointer.
562+
/// It returns an immortal, global string table pointer for strings constructed
563+
/// from string literals.
564+
BUILTIN_MISC_OPERATION_WITH_SILGEN(GlobalStringTablePointer, "globalStringTablePointer", "", Special)
565+
566+
#undef BUILTIN_MISC_OPERATION_WITH_SILGEN
567+
554568
#undef BUILTIN_MISC_OPERATION
555569

556570
/// Builtins for instrumentation added by sanitizers during SILGen.

branches/rxwei-patch-1/include/swift/AST/Identifier.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,6 @@ class DeclBaseName {
264264

265265
bool isSpecial() const { return getKind() != Kind::Normal; }
266266

267-
bool isSubscript() const { return getKind() == Kind::Subscript; }
268-
269267
/// Return the identifier backing the name. Assumes that the name is not
270268
/// special.
271269
Identifier getIdentifier() const {

branches/rxwei-patch-1/lib/AST/Builtins.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,13 @@ static ValueDecl *getGetObjCTypeEncodingOperation(ASTContext &Context,
951951
return builder.build(Id);
952952
}
953953

954+
static ValueDecl *getGlobalStringTablePointer(ASTContext &Context,
955+
Identifier Id) {
956+
// String -> Builtin.RawPointer
957+
auto stringType = NominalType::get(Context.getStringDecl(), Type(), Context);
958+
return getBuiltinFunction(Id, {stringType}, Context.TheRawPointerType);
959+
}
960+
954961
static ValueDecl *getPoundAssert(ASTContext &Context, Identifier Id) {
955962
auto int1Type = BuiltinIntegerType::get(1, Context);
956963
auto optionalRawPointerType = BoundGenericEnumType::get(
@@ -1960,6 +1967,9 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
19601967
case BuiltinValueKind::GetObjCTypeEncoding:
19611968
return getGetObjCTypeEncodingOperation(Context, Id);
19621969

1970+
case BuiltinValueKind::GlobalStringTablePointer:
1971+
return getGlobalStringTablePointer(Context, Id);
1972+
19631973
case BuiltinValueKind::PoundAssert:
19641974
return getPoundAssert(Context, Id);
19651975

branches/rxwei-patch-1/lib/IRGen/GenBuiltin.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,18 @@ if (Builtin.ID == BuiltinValueKind::id) { \
354354
#define BUILTIN(ID, Name, Attrs) // Ignore the rest.
355355
#include "swift/AST/Builtins.def"
356356

357+
if (Builtin.ID == BuiltinValueKind::GlobalStringTablePointer) {
358+
// This builtin should be used only on strings constructed from a
359+
// string literal. If we ever get to the point of executing this builtin
360+
// at run time, it implies an incorrect use of the builtin and must result
361+
// in a trap.
362+
IGF.emitTrap(/*Unreachable=*/false);
363+
auto returnValue = llvm::UndefValue::get(IGF.IGM.Int8PtrTy);
364+
// Consume the arguments of the builtin.
365+
(void)args.claimAll();
366+
return out.add(returnValue);
367+
}
368+
357369
if (Builtin.ID == BuiltinValueKind::WillThrow) {
358370
// willThrow is emitted like a Swift function call with the error in
359371
// the error return register. We also have to pass a fake context

branches/rxwei-patch-1/lib/SIL/OperandOwnership.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,16 @@ CONSTANT_OWNERSHIP_BUILTIN(Any, MustBeLive, Swift3ImplicitObjCEntrypoint)
10571057
CONSTANT_OWNERSHIP_BUILTIN(Any, MustBeLive, PoundAssert)
10581058
#undef CONSTANT_OWNERSHIP_BUILTIN
10591059

1060+
// CONSTANT_OWNERSHIP_BUILTIN(Owned, MustBeLive, GlobalStringTablePointer)
1061+
1062+
OperandOwnershipKindMap
1063+
OperandOwnershipKindBuiltinClassifier::visitGlobalStringTablePointer(
1064+
BuiltinInst *bi, StringRef attr) {
1065+
return Map::compatibilityMap(
1066+
{{ValueOwnershipKind::Guaranteed, UseLifetimeConstraint::MustBeLive},
1067+
{ValueOwnershipKind::Owned, UseLifetimeConstraint::MustBeLive}});
1068+
}
1069+
10601070
// Builtins that should be lowered to SIL instructions so we should never see
10611071
// them.
10621072
#define BUILTIN_SIL_OPERATION(ID, NAME, CATEGORY) \

branches/rxwei-patch-1/lib/SIL/ValueOwnership.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ CONSTANT_OWNERSHIP_BUILTIN(Any, OnceWithContext)
491491
CONSTANT_OWNERSHIP_BUILTIN(Any, TSanInoutAccess)
492492
CONSTANT_OWNERSHIP_BUILTIN(Any, Swift3ImplicitObjCEntrypoint)
493493
CONSTANT_OWNERSHIP_BUILTIN(Any, PoundAssert)
494+
CONSTANT_OWNERSHIP_BUILTIN(Any, GlobalStringTablePointer)
494495

495496
#undef CONSTANT_OWNERSHIP_BUILTIN
496497

branches/rxwei-patch-1/lib/SILGen/SILGenApply.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4057,12 +4057,14 @@ CallEmission::applySpecializedEmitter(SpecializedEmitter &specializedEmitter,
40574057
return firstLevelResult;
40584058
}
40594059

4060-
// Builtins.
4060+
// Named Builtins.
40614061
assert(specializedEmitter.isNamedBuiltin());
40624062
auto builtinName = specializedEmitter.getBuiltinName();
40634063
SmallVector<SILValue, 4> consumedArgs;
40644064
for (auto arg : uncurriedArgs) {
4065-
// Builtins have a special convention that takes everything at +1.
4065+
// Named builtins are by default assumed to take all arguments at +1 i.e.,
4066+
// as Owned or Trivial. Named builtins that don't follow this convention
4067+
// must use a specialized emitter.
40664068
auto maybePlusOne = arg.ensurePlusOne(SGF, uncurriedLoc.getValue());
40674069
consumedArgs.push_back(maybePlusOne.forward(SGF));
40684070
}

branches/rxwei-patch-1/lib/SILGen/SILGenBuiltin.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,28 @@ static ManagedValue emitBuiltinTypeTrait(SILGenFunction &SGF,
10281028
return ManagedValue::forUnmanaged(val);
10291029
}
10301030

1031+
/// Emit SIL for the named builtin: globalStringTablePointer. Unlike the default
1032+
/// ownership convention for named builtins, which is to take (non-trivial)
1033+
/// arguments as Owned, this builtin accepts owned as well as guaranteed
1034+
/// arguments, and hence doesn't require the arguments to be at +1. Therefore,
1035+
/// this builtin is emitted specially.
1036+
static ManagedValue
1037+
emitBuiltinGlobalStringTablePointer(SILGenFunction &SGF, SILLocation loc,
1038+
SubstitutionMap subs,
1039+
ArrayRef<ManagedValue> args, SGFContext C) {
1040+
assert(args.size() == 1);
1041+
1042+
SILValue argValue = args[0].getValue();
1043+
auto &astContext = SGF.getASTContext();
1044+
Identifier builtinId = astContext.getIdentifier(
1045+
getBuiltinName(BuiltinValueKind::GlobalStringTablePointer));
1046+
1047+
auto resultVal = SGF.B.createBuiltin(loc, builtinId,
1048+
SILType::getRawPointerType(astContext),
1049+
subs, ArrayRef<SILValue>(argValue));
1050+
return SGF.emitManagedRValueWithCleanup(resultVal);
1051+
}
1052+
10311053
Optional<SpecializedEmitter>
10321054
SpecializedEmitter::forDecl(SILGenModule &SGM, SILDeclRef function) {
10331055
// Only consider standalone declarations in the Builtin module.
@@ -1052,6 +1074,7 @@ SpecializedEmitter::forDecl(SILGenModule &SGM, SILDeclRef function) {
10521074
#define BUILTIN(Id, Name, Attrs) \
10531075
case BuiltinValueKind::Id:
10541076
#define BUILTIN_SIL_OPERATION(Id, Name, Overload)
1077+
#define BUILTIN_MISC_OPERATION_WITH_SILGEN(Id, Name, Attrs, Overload)
10551078
#define BUILTIN_SANITIZER_OPERATION(Id, Name, Attrs)
10561079
#define BUILTIN_TYPE_CHECKER_OPERATION(Id, Name)
10571080
#define BUILTIN_TYPE_TRAIT_OPERATION(Id, Name)
@@ -1068,8 +1091,12 @@ SpecializedEmitter::forDecl(SILGenModule &SGM, SILDeclRef function) {
10681091
case BuiltinValueKind::Id: \
10691092
return SpecializedEmitter(&emitBuiltin##Id);
10701093

1071-
// Sanitizer builtins should never directly be called; they should only
1072-
// be inserted as instrumentation by SILGen.
1094+
#define BUILTIN_MISC_OPERATION_WITH_SILGEN(Id, Name, Attrs, Overload) \
1095+
case BuiltinValueKind::Id: \
1096+
return SpecializedEmitter(&emitBuiltin##Id);
1097+
1098+
// Sanitizer builtins should never directly be called; they should only
1099+
// be inserted as instrumentation by SILGen.
10731100
#define BUILTIN_SANITIZER_OPERATION(Id, Name, Attrs) \
10741101
case BuiltinValueKind::Id: \
10751102
llvm_unreachable("Sanitizer builtin called directly?");

branches/rxwei-patch-1/lib/SILOptimizer/Transforms/AccessEnforcementReleaseSinking.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ static bool isBarrier(SILInstruction *inst) {
130130
case BuiltinValueKind::Swift3ImplicitObjCEntrypoint:
131131
case BuiltinValueKind::WillThrow:
132132
case BuiltinValueKind::PoundAssert:
133+
case BuiltinValueKind::GlobalStringTablePointer:
133134
return false;
134135

135136
// Handle some rare builtins that may be sensitive to object lifetime

branches/rxwei-patch-1/lib/Sema/CSSimplify.cpp

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3973,19 +3973,6 @@ bool swift::hasDynamicMemberLookupAttribute(Type type) {
39733973
return ::hasDynamicMemberLookupAttribute(type, DynamicMemberLookupCache);
39743974
}
39753975

3976-
static bool isForKeyPathSubscript(ConstraintSystem &cs,
3977-
ConstraintLocator *locator) {
3978-
if (!locator || !locator->getAnchor())
3979-
return false;
3980-
3981-
if (auto *SE = dyn_cast<SubscriptExpr>(locator->getAnchor())) {
3982-
auto *indexExpr = dyn_cast<TupleExpr>(SE->getIndex());
3983-
return indexExpr && indexExpr->getNumElements() == 1 &&
3984-
indexExpr->getElementName(0) == cs.getASTContext().Id_keyPath;
3985-
}
3986-
return false;
3987-
}
3988-
39893976
/// Given a ValueMember, UnresolvedValueMember, or TypeMember constraint,
39903977
/// perform a lookup into the specified base type to find a candidate list.
39913978
/// The list returned includes the viable candidates as well as the unviable
@@ -4017,7 +4004,14 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
40174004
MemberLookupResult result;
40184005
result.OverallResult = MemberLookupResult::HasResults;
40194006

4020-
if (isForKeyPathSubscript(*this, memberLocator)) {
4007+
// If we're looking for a subscript, consider key path operations.
4008+
//
4009+
// TODO: This logic needs to be refactored to make sure that implicit
4010+
// keypath result is only introduced when it makes sense e.g. if there
4011+
// is a single argument with `keypath:` label or `\.` syntax is used.
4012+
if (memberName.isSimpleName() &&
4013+
memberName.getBaseName().getKind() == DeclBaseName::Kind::Subscript &&
4014+
!(memberLocator && memberLocator->isForKeyPathDynamicMemberLookup())) {
40214015
if (baseTy->isAnyObject()) {
40224016
result.addUnviable(
40234017
OverloadChoice(baseTy, OverloadChoiceKind::KeyPathApplication),
@@ -4762,21 +4756,17 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
47624756
performMemberLookup(kind, member, baseTy, functionRefKind, locator,
47634757
/*includeInaccessibleMembers*/ shouldAttemptFixes());
47644758

4765-
auto formUnsolved = [&] {
4759+
switch (result.OverallResult) {
4760+
case MemberLookupResult::Unsolved:
47664761
// If requested, generate a constraint.
47674762
if (flags.contains(TMF_GenerateConstraints)) {
4768-
addUnsolvedConstraint(Constraint::createMemberOrOuterDisjunction(
4769-
*this, kind, baseTy, memberTy, member, useDC, functionRefKind,
4770-
outerAlternatives, locator));
4763+
addUnsolvedConstraint(
4764+
Constraint::createMemberOrOuterDisjunction(*this, kind, baseTy, memberTy, member, useDC,
4765+
functionRefKind, outerAlternatives, locator));
47714766
return SolutionKind::Solved;
47724767
}
47734768

47744769
return SolutionKind::Unsolved;
4775-
};
4776-
4777-
switch (result.OverallResult) {
4778-
case MemberLookupResult::Unsolved:
4779-
return formUnsolved();
47804770

47814771
case MemberLookupResult::ErrorAlreadyDiagnosed:
47824772
return SolutionKind::Error;
@@ -4789,18 +4779,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
47894779
SmallVector<Constraint *, 4> candidates;
47904780
// If we found viable candidates, then we're done!
47914781
if (!result.ViableCandidates.empty()) {
4792-
// If only possible choice to refer to member is via keypath
4793-
// dynamic member dispatch, let's delay solving this constraint
4794-
// until constraint generation phase is complete, because
4795-
// subscript dispatch relies on presence of function application.
4796-
if (result.ViableCandidates.size() == 1) {
4797-
auto &choice = result.ViableCandidates.front();
4798-
if (!solverState && choice.isKeyPathDynamicMemberLookup() &&
4799-
member.getBaseName().isSubscript()) {
4800-
return formUnsolved();
4801-
}
4802-
}
4803-
48044782
generateConstraints(
48054783
candidates, memberTy, result.ViableCandidates, useDC, locator,
48064784
result.getFavoredIndex(), /*requiresFix=*/false,
@@ -5877,11 +5855,7 @@ Type ConstraintSystem::simplifyAppliedOverloads(
58775855
}
58785856

58795857
// FIXME: Could also rewrite fnType to include this result type.
5880-
// Introduction of `Bind` constraint here could result in the disconnect
5881-
// in the constraint system with unintended consequences because e.g.
5882-
// in case of key path application it could disconnect one of the
5883-
// components like subscript from the rest of the context.
5884-
addConstraint(ConstraintKind::Equal, argFnType->getResult(),
5858+
addConstraint(ConstraintKind::Bind, argFnType->getResult(),
58855859
commonResultType, locator);
58865860
}
58875861

branches/rxwei-patch-1/lib/Sema/OverloadChoice.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ class OverloadChoice {
256256
/// unwrapped.
257257
bool isImplicitlyUnwrappedValueOrReturnValue() const;
258258

259-
bool isKeyPathDynamicMemberLookup() const {
260-
return getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup;
261-
}
262-
263259
/// Get the name of the overload choice.
264260
DeclName getName() const;
265261

branches/rxwei-patch-1/test/Constraints/overload_filtering.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ struct X {
2626
}
2727

2828
func testSubscript(x: X, i: Int) {
29-
// CHECK: disabled disjunction term {{.*}}X.subscript(_:)
29+
// CHECK: disabled disjunction term {{.*}} bound to key path application
30+
// CHECK-NEXT: disabled disjunction term {{.*}}X.subscript(_:)
3031
// CHECK-NEXT: disabled disjunction term {{.*}}X.subscript(_:_:_:)
3132
// CHECK-NEXT: introducing single enabled disjunction term {{.*}} bound to decl overload_filtering.(file).X.subscript(_:_:)
3233
_ = x[i, i]

branches/rxwei-patch-1/test/IRGen/builtins.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,15 @@ enum MyError : Error {
804804

805805
throw MyError.A
806806

807+
/// Builtin.globalStringTablePointer must be reduced to a string_literal instruction before IRGen. IRGen
808+
/// should make this a trap.
809+
// CHECK-LABEL: define {{.*}}globalStringTablePointer
810+
// CHECK: call void @llvm.trap()
811+
// CHECK: ret i8* undef
812+
func globalStringTablePointerUse(_ str: String) -> Builtin.RawPointer {
813+
return Builtin.globalStringTablePointer(str);
814+
}
807815

808816

809-
// CHECK: ![[R]] = !{i64 0, i64 9223372036854775807}
810817

818+
// CHECK: ![[R]] = !{i64 0, i64 9223372036854775807}

branches/rxwei-patch-1/test/expr/unary/keypath/keypath.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ func testKeyPath(sub: Sub, optSub: OptSub,
128128
let _: ReferenceWritableKeyPath<A, Prop> = \.property
129129
//expected-error@-1 {{cannot convert value of type 'WritableKeyPath<A, Prop>' to specified type 'ReferenceWritableKeyPath<A, Prop>'}}
130130

131+
// FIXME: shouldn't be ambiguous
132+
// expected-error@+1{{ambiguous}}
131133
let _: PartialKeyPath<A> = \.[sub]
132134
let _: KeyPath<A, A> = \.[sub]
133135
let _: WritableKeyPath<A, A> = \.[sub]

0 commit comments

Comments
 (0)