Skip to content

Commit 9f37da8

Browse files
author
Dave Abrahams
authored
Merge branch 'master' into string-init-from-character-speedup
2 parents 4db3509 + 49a8cf0 commit 9f37da8

File tree

85 files changed

+1659
-2675
lines changed

Some content is hidden

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

85 files changed

+1659
-2675
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,9 +1435,6 @@ ERROR(unsupported_platform_runtime_condition_argument,none,
14351435
ERROR(unsupported_platform_condition_argument,none,
14361436
"unexpected platform condition argument: expected %0",
14371437
(StringRef))
1438-
ERROR(unexpected_version_comparison_operator,none,
1439-
"expected '>=' prefix operator on a version requirement",
1440-
())
14411438
ERROR(unsupported_conditional_compilation_expression_type,none,
14421439
"invalid conditional compilation expression", ())
14431440
WARNING(swift3_unsupported_conditional_compilation_expression_type,none,

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ FUNCTION(GetInitializedObjCClass, swift_getInitializedObjCClass, RegisterPreserv
12421242
FUNCTION(Swift3ImplicitObjCEntrypoint, swift_objc_swift3ImplicitObjCEntrypoint,
12431243
DefaultCC,
12441244
RETURNS(VoidTy),
1245-
ARGS(ObjCPtrTy, ObjCSELTy),
1245+
ARGS(ObjCPtrTy, ObjCSELTy, Int8PtrTy, SizeTy, SizeTy, SizeTy),
12461246
ATTRS(NoUnwind))
12471247

12481248
#endif

include/swift/Serialization/ModuleFormat.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -855,12 +855,13 @@ namespace decls_block {
855855
CtorInitializerKindField, // initializer kind
856856
GenericEnvironmentIDField, // generic environment
857857
TypeIDField, // interface type
858-
TypeIDField, // canonical interface type
859858
DeclIDField, // overridden decl
860859
AccessibilityKindField, // accessibility
861860
BCFixed<1>, // requires a new vtable slot
862861
BCFixed<1>, // 'required' but overridden is not (used for recovery)
863-
BCArray<IdentifierIDField> // argument names
862+
BCVBR<5>, // number of parameter name components
863+
BCArray<IdentifierIDField> // name components,
864+
// followed by TypeID dependencies
864865
// Trailed by its generic parameters, if any, followed by the parameter
865866
// patterns.
866867
>;
@@ -876,7 +877,6 @@ namespace decls_block {
876877
BCFixed<1>, // HasNonPatternBindingInit?
877878
StorageKindField, // StorageKind
878879
TypeIDField, // interface type
879-
TypeIDField, // canonical interface type
880880
DeclIDField, // getter
881881
DeclIDField, // setter
882882
DeclIDField, // materializeForSet
@@ -886,7 +886,8 @@ namespace decls_block {
886886
DeclIDField, // didset
887887
DeclIDField, // overridden decl
888888
AccessibilityKindField, // accessibility
889-
AccessibilityKindField // setter accessibility, if applicable
889+
AccessibilityKindField, // setter accessibility, if applicable
890+
BCArray<TypeIDField> // dependencies
890891
>;
891892

892893
using ParamLayout = BCRecordLayout<
@@ -911,15 +912,16 @@ namespace decls_block {
911912
BCVBR<5>, // number of parameter patterns
912913
GenericEnvironmentIDField, // generic environment
913914
TypeIDField, // interface type
914-
TypeIDField, // canonical interface type
915915
DeclIDField, // operator decl
916916
DeclIDField, // overridden function
917917
DeclIDField, // AccessorStorageDecl
918-
BCFixed<1>, // name is compound?
918+
BCVBR<5>, // 0 for a simple name, otherwise the number of parameter name
919+
// components plus one
919920
AddressorKindField, // addressor kind
920921
AccessibilityKindField, // accessibility
921922
BCFixed<1>, // requires a new vtable slot
922-
BCArray<IdentifierIDField> // name components
923+
BCArray<IdentifierIDField> // name components,
924+
// followed by TypeID dependencies
923925
// The record is trailed by:
924926
// - its _silgen_name, if any
925927
// - its generic parameters, if any
@@ -984,7 +986,6 @@ namespace decls_block {
984986
StorageKindField, // StorageKind
985987
GenericEnvironmentIDField, // generic environment
986988
TypeIDField, // interface type
987-
TypeIDField, // canonical interface type
988989
DeclIDField, // getter
989990
DeclIDField, // setter
990991
DeclIDField, // materializeForSet
@@ -995,7 +996,9 @@ namespace decls_block {
995996
DeclIDField, // overridden decl
996997
AccessibilityKindField, // accessibility
997998
AccessibilityKindField, // setter accessibility, if applicable
998-
BCArray<IdentifierIDField> // name components
999+
BCVBR<5>, // number of parameter name components
1000+
BCArray<IdentifierIDField> // name components,
1001+
// followed by TypeID dependencies
9991002
// Trailed by:
10001003
// - generic parameters, if any
10011004
// - the indices pattern

lib/AST/Builtins.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,9 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
17831783
return getTSanInoutAccess(Context, Id);
17841784

17851785
case BuiltinValueKind::Swift3ImplicitObjCEntrypoint:
1786-
return getBuiltinFunction(Id, {}, TupleType::getEmpty(Context));
1786+
return getBuiltinFunction(Id,
1787+
{},
1788+
TupleType::getEmpty(Context));
17871789
}
17881790

17891791
llvm_unreachable("bad builtin value!");

lib/IRGen/GenBuiltin.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -860,20 +860,30 @@ if (Builtin.ID == BuiltinValueKind::id) { \
860860
}
861861

862862
if (Builtin.ID == BuiltinValueKind::Swift3ImplicitObjCEntrypoint) {
863-
llvm::Value *args[2];
863+
llvm::Value *entrypointArgs[6];
864864
auto argIter = IGF.CurFn->arg_begin();
865865

866866
// self
867-
args[0] = &*argIter++;
868-
if (args[0]->getType() != IGF.IGM.ObjCPtrTy)
869-
args[0] = IGF.Builder.CreateBitCast(args[0], IGF.IGM.ObjCPtrTy);
867+
entrypointArgs[0] = &*argIter++;
868+
if (entrypointArgs[0]->getType() != IGF.IGM.ObjCPtrTy)
869+
entrypointArgs[0] = IGF.Builder.CreateBitCast(entrypointArgs[0], IGF.IGM.ObjCPtrTy);
870870

871871
// _cmd
872-
args[1] = &*argIter;
873-
if (args[1]->getType() != IGF.IGM.ObjCSELTy)
874-
args[1] = IGF.Builder.CreateBitCast(args[1], IGF.IGM.ObjCSELTy);
875-
876-
IGF.Builder.CreateCall(IGF.IGM.getSwift3ImplicitObjCEntrypointFn(), args);
872+
entrypointArgs[1] = &*argIter;
873+
if (entrypointArgs[1]->getType() != IGF.IGM.ObjCSELTy)
874+
entrypointArgs[1] = IGF.Builder.CreateBitCast(entrypointArgs[1], IGF.IGM.ObjCSELTy);
875+
876+
// Filename pointer
877+
entrypointArgs[2] = args.claimNext();
878+
// Filename length
879+
entrypointArgs[3] = args.claimNext();
880+
// Line
881+
entrypointArgs[4] = args.claimNext();
882+
// Column
883+
entrypointArgs[5] = args.claimNext();
884+
885+
IGF.Builder.CreateCall(IGF.IGM.getSwift3ImplicitObjCEntrypointFn(),
886+
entrypointArgs);
877887
return;
878888
}
879889

lib/Migrator/TypeOfMigratorPass.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ using namespace swift::migrator;
2424

2525
namespace {
2626

27-
struct TypeOfMigratorPass: public ASTMigratorPass,
27+
class TypeOfMigratorPass: public ASTMigratorPass,
2828
public SourceEntityWalker {
2929

30+
std::vector<DeclContext *> ContextStack;
31+
3032
void handleTypeOf(const DynamicTypeExpr *DTE) {
3133
if (!SF->getASTContext().LangOpts.isSwiftVersion3()) {
3234
return;
@@ -39,12 +41,22 @@ struct TypeOfMigratorPass: public ASTMigratorPass,
3941

4042
UnqualifiedLookup Lookup {
4143
{ SF->getASTContext().getIdentifier("type") },
42-
SF->getModuleScopeContext(),
43-
/*TypeResolver=*/nullptr,
44+
ContextStack.empty() ? SF->getModuleScopeContext() : ContextStack.back(),
45+
/*TypeResolver=*/SF->getASTContext().getLazyResolver(),
4446
/*IsKnownPrivate=*/false,
4547
DTE->getLoc()
4648
};
47-
if (Lookup.Results.empty()) {
49+
auto isShadowing = [&]() -> bool {
50+
if (Lookup.Results.empty())
51+
return false;
52+
if (Lookup.Results.size() != 1)
53+
return true;
54+
if (auto VD = Lookup.Results.front().getValueDecl()) {
55+
return !VD->getModuleContext()->isStdlibModule();
56+
}
57+
return false;
58+
};
59+
if (!isShadowing()) {
4860
// There won't be a name shadowing here in Swift 4, so we don't need to
4961
// do anything.
5062
return;
@@ -58,6 +70,19 @@ struct TypeOfMigratorPass: public ASTMigratorPass,
5870
}
5971
return true;
6072
}
73+
74+
bool walkToDeclPre(Decl *D, CharSourceRange Range) override {
75+
if (auto DC = dyn_cast<DeclContext>(D))
76+
ContextStack.push_back(DC);
77+
return true;
78+
}
79+
80+
bool walkToDeclPost(Decl *D) override {
81+
if (isa<DeclContext>(D))
82+
ContextStack.pop_back();
83+
return true;
84+
}
85+
6186
public:
6287
TypeOfMigratorPass(EditorAdapter &Editor,
6388
SourceFile *SF,

lib/Parse/ParseIfConfig.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class ValidateIfConfigCondition :
265265

266266
auto Val = version::Version::parseCompilerVersionString(
267267
SLE->getValue(), SLE->getLoc(), &D);
268-
if(!Val.hasValue())
268+
if (!Val.hasValue())
269269
return nullptr;
270270
return E;
271271
}
@@ -284,7 +284,7 @@ class ValidateIfConfigCondition :
284284
auto versionString = extractExprSource(Ctx.SourceMgr, PUE->getArg());
285285
auto Val = version::Version::parseVersionString(
286286
versionString, PUE->getArg()->getStartLoc(), &D);
287-
if(!Val.hasValue())
287+
if (!Val.hasValue())
288288
return nullptr;
289289
return E;
290290
}

lib/SILGen/SILGenBridging.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,23 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
10501050
if (attr->isSwift3Inferred() &&
10511051
!decl->getAttrs().hasAttribute<DynamicAttr>() &&
10521052
!getASTContext().LangOpts.isSwiftVersion3()) {
1053-
B.createBuiltin(loc, getASTContext().getIdentifier("swift3ImplicitObjCEntrypoint"),
1054-
getModule().Types.getEmptyTupleType(), { }, { });
1053+
1054+
// Get the starting source location of the declaration so we can say
1055+
// exactly where to stick '@objc'.
1056+
SourceLoc objcInsertionLoc =
1057+
decl->getAttributeInsertionLoc(/*modifier*/ false);
1058+
1059+
auto objcInsertionLocArgs
1060+
= emitSourceLocationArgs(objcInsertionLoc, loc);
1061+
1062+
B.createBuiltin(loc,
1063+
getASTContext().getIdentifier("swift3ImplicitObjCEntrypoint"),
1064+
getModule().Types.getEmptyTupleType(), { }, {
1065+
objcInsertionLocArgs.filenameStartPointer.forward(*this),
1066+
objcInsertionLocArgs.filenameLength.forward(*this),
1067+
objcInsertionLocArgs.line.forward(*this),
1068+
objcInsertionLocArgs.column.forward(*this)
1069+
});
10551070
}
10561071
}
10571072
}

lib/SILGen/SILGenConvert.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,18 @@ getOptionalSomeValue(SILLocation loc, ManagedValue value,
135135
return emitManagedRValueWithCleanup(result, optTL);
136136
}
137137

138-
static void emitSourceLocationArgs(SILGenFunction &gen,
139-
SILLocation loc,
140-
ManagedValue (&args)[4]) {
141-
auto &ctx = gen.getASTContext();
142-
auto sourceLoc = loc.getSourceLoc();
138+
auto SILGenFunction::emitSourceLocationArgs(SourceLoc sourceLoc,
139+
SILLocation emitLoc)
140+
-> SourceLocArgs {
141+
auto &ctx = getASTContext();
143142

144143
StringRef filename = "";
145144
unsigned line = 0;
145+
unsigned column = 0;
146146
if (sourceLoc.isValid()) {
147147
unsigned bufferID = ctx.SourceMgr.findBufferContainingLoc(sourceLoc);
148148
filename = ctx.SourceMgr.getIdentifierForBuffer(bufferID);
149-
line = ctx.SourceMgr.getLineAndColumn(sourceLoc).first;
149+
std::tie(line, column) = ctx.SourceMgr.getLineAndColumn(sourceLoc);
150150
}
151151

152152
bool isASCII = true;
@@ -160,19 +160,24 @@ static void emitSourceLocationArgs(SILGenFunction &gen,
160160
auto wordTy = SILType::getBuiltinWordType(ctx);
161161
auto i1Ty = SILType::getBuiltinIntegerType(1, ctx);
162162

163-
// File
164-
SILValue literal = gen.B.createStringLiteral(loc, filename,
165-
StringLiteralInst::Encoding::UTF8);
166-
args[0] = ManagedValue::forUnmanaged(literal);
163+
SourceLocArgs result;
164+
SILValue literal = B.createStringLiteral(emitLoc, filename,
165+
StringLiteralInst::Encoding::UTF8);
166+
result.filenameStartPointer = ManagedValue::forUnmanaged(literal);
167167
// File length
168-
literal = gen.B.createIntegerLiteral(loc, wordTy, filename.size());
169-
args[1] = ManagedValue::forUnmanaged(literal);
168+
literal = B.createIntegerLiteral(emitLoc, wordTy, filename.size());
169+
result.filenameLength = ManagedValue::forUnmanaged(literal);
170170
// File is ascii
171-
literal = gen.B.createIntegerLiteral(loc, i1Ty, isASCII);
172-
args[2] = ManagedValue::forUnmanaged(literal);
171+
literal = B.createIntegerLiteral(emitLoc, i1Ty, isASCII);
172+
result.filenameIsAscii = ManagedValue::forUnmanaged(literal);
173173
// Line
174-
literal = gen.B.createIntegerLiteral(loc, wordTy, line);
175-
args[3] = ManagedValue::forUnmanaged(literal);
174+
literal = B.createIntegerLiteral(emitLoc, wordTy, line);
175+
result.line = ManagedValue::forUnmanaged(literal);
176+
// Column
177+
literal = B.createIntegerLiteral(emitLoc, wordTy, column);
178+
result.column = ManagedValue::forUnmanaged(literal);
179+
180+
return result;
176181
}
177182

178183
ManagedValue
@@ -204,10 +209,15 @@ SILGenFunction::emitPreconditionOptionalHasValue(SILLocation loc,
204209
// Call the standard library implementation of _diagnoseUnexpectedNilOptional.
205210
if (auto diagnoseFailure =
206211
getASTContext().getDiagnoseUnexpectedNilOptional(nullptr)) {
207-
ManagedValue args[4];
208-
emitSourceLocationArgs(*this, loc, args);
212+
auto args = emitSourceLocationArgs(loc.getSourceLoc(), loc);
209213

210-
emitApplyOfLibraryIntrinsic(loc, diagnoseFailure, SubstitutionMap(), args,
214+
emitApplyOfLibraryIntrinsic(loc, diagnoseFailure, SubstitutionMap(),
215+
{
216+
args.filenameStartPointer,
217+
args.filenameLength,
218+
args.filenameIsAscii,
219+
args.line
220+
},
211221
SGFContext());
212222
}
213223

lib/SILGen/SILGenFunction.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,23 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
869869
ManagedValue getOptionalSomeValue(SILLocation loc, ManagedValue value,
870870
const TypeLowering &optTL);
871871

872+
struct SourceLocArgs {
873+
ManagedValue filenameStartPointer,
874+
filenameLength,
875+
filenameIsAscii,
876+
line,
877+
column;
878+
};
879+
880+
/// Emit raw lowered arguments for a runtime diagnostic to report the given
881+
/// source location:
882+
/// - The first three arguments are the components necessary to construct
883+
/// a StaticString for the filename: start pointer, length, and
884+
/// "is ascii" bit.
885+
/// - The fourth argument is the line number.
886+
SourceLocArgs
887+
emitSourceLocationArgs(SourceLoc loc, SILLocation emitLoc);
888+
872889
/// \brief Emit a call to the library intrinsic _doesOptionalHaveValue.
873890
///
874891
/// The result is a Builtin.Int1.

lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@ bool swift::isPureCall(FullApplySite AI, SideEffectAnalysis *SEA) {
727727
return false;
728728
// Check if all parameters are constant.
729729
auto Args = AI.getArgumentsWithoutIndirectResults();
730-
bool allArgsConstant = true;
731730
for (auto Arg : Args) {
732731
if (!isConstantValue(Arg)) {
733732
return false;

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,11 @@ static SmallVector<TupleTypeElt, 4> decomposeIntoTupleElements(Type type) {
526526
return result;
527527
}
528528

529+
if (auto parenTy = dyn_cast<ParenType>(type.getPointer())) {
530+
result.push_back(parenTy->getUnderlyingType());
531+
return result;
532+
}
533+
529534
result.push_back(type);
530535
return result;
531536
}
@@ -4579,7 +4584,15 @@ void ConformanceChecker::resolveTypeWitnesses() {
45794584
auto &typeWitnesses = solutions.front().TypeWitnesses;
45804585
for (auto assocType : unresolvedAssocTypes) {
45814586
assert(typeWitnesses.count(assocType) == 1 && "missing witness");
4582-
recordTypeWitness(assocType, typeWitnesses[assocType].first, nullptr, true);
4587+
auto replacement = typeWitnesses[assocType].first;
4588+
// FIXME: We can end up here with dependent types that were not folded
4589+
// away for some reason.
4590+
if (replacement.findIf([](Type t) -> bool {
4591+
return isa<DependentMemberType>(t.getPointer());
4592+
})) {
4593+
replacement = ErrorType::get(TC.Context);
4594+
}
4595+
recordTypeWitness(assocType, replacement, nullptr, true);
45834596
}
45844597

45854598
return;

0 commit comments

Comments
 (0)