Skip to content

Commit bf149d9

Browse files
authored
---
yaml --- r: 349128 b: refs/heads/master c: ff8c6e2 h: refs/heads/master
1 parent b5f8afa commit bf149d9

Some content is hidden

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

53 files changed

+318
-193
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: 2f95cf0236c48863094c37d3861b8a338bc704bc
2+
refs/heads/master: ff8c6e2571feb5e7923cab2e4e9da3c59d0da48a
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/benchmark/single-source/UTF8Decode.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ public let UTF8Decode = [
4242
name: "UTF8Decode_InitFromBytes_ascii",
4343
runFunction: run_UTF8Decode_InitFromBytes_ascii,
4444
tags: [.validation, .api, .String]),
45+
BenchmarkInfo(
46+
name: "UTF8Decode_InitFromData_ascii_as_ascii",
47+
runFunction: run_UTF8Decode_InitFromData_ascii_as_ascii,
48+
tags: [.validation, .api, .String]),
49+
BenchmarkInfo(
50+
name: "UTF8Decode_InitDecoding_ascii_as_ascii",
51+
runFunction: run_UTF8Decode_InitDecoding_ascii_as_ascii,
52+
tags: [.validation, .api, .String]),
53+
BenchmarkInfo(
54+
name: "UTF8Decode_InitFromBytes_ascii_as_ascii",
55+
runFunction: run_UTF8Decode_InitFromBytes_ascii_as_ascii,
56+
tags: [.validation, .api, .String]),
4557
]
4658

4759
// 1-byte sequences
@@ -129,4 +141,26 @@ public func run_UTF8Decode_InitFromBytes_ascii(_ N: Int) {
129141
}
130142
}
131143

144+
@inline(never)
145+
public func run_UTF8Decode_InitFromData_ascii_as_ascii(_ N: Int) {
146+
let input = asciiData
147+
for _ in 0..<1_000*N {
148+
blackHole(String(data: input, encoding: .ascii))
149+
}
150+
}
151+
@inline(never)
152+
public func run_UTF8Decode_InitDecoding_ascii_as_ascii(_ N: Int) {
153+
let input = asciiBytes
154+
for _ in 0..<1_000*N {
155+
blackHole(String(decoding: input, as: Unicode.ASCII.self))
156+
}
157+
}
158+
@inline(never)
159+
public func run_UTF8Decode_InitFromBytes_ascii_as_ascii(_ N: Int) {
160+
let input = asciiBytes
161+
for _ in 0..<1_000*N {
162+
blackHole(String(bytes: input, encoding: .ascii))
163+
}
164+
}
165+
132166

trunk/include/swift/AST/Decl.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace swift {
7171
class GenericTypeParamDecl;
7272
class GenericTypeParamType;
7373
class ModuleDecl;
74+
class NamedPattern;
7475
class EnumCaseDecl;
7576
class EnumElementDecl;
7677
class ParameterList;
@@ -4773,6 +4774,8 @@ enum class PropertyWrapperSynthesizedPropertyKind {
47734774

47744775
/// VarDecl - 'var' and 'let' declarations.
47754776
class VarDecl : public AbstractStorageDecl {
4777+
NamedPattern *NamingPattern = nullptr;
4778+
47764779
public:
47774780
enum class Introducer : uint8_t {
47784781
Let = 0,
@@ -4786,10 +4789,6 @@ class VarDecl : public AbstractStorageDecl {
47864789
bool issCaptureList, SourceLoc nameLoc, Identifier name,
47874790
DeclContext *dc, StorageIsMutable_t supportsMutation);
47884791

4789-
TypeRepr *ParentRepr = nullptr;
4790-
4791-
Type typeInContext;
4792-
47934792
public:
47944793
VarDecl(bool isStatic, Introducer introducer, bool isCaptureList,
47954794
SourceLoc nameLoc, Identifier name, DeclContext *dc)
@@ -4806,26 +4805,10 @@ class VarDecl : public AbstractStorageDecl {
48064805
return hasName() ? getBaseName().getIdentifier().str() : "_";
48074806
}
48084807

4809-
/// Retrieve the TypeRepr corresponding to the parsed type of the parent
4810-
/// pattern, if it exists.
4811-
TypeRepr *getTypeRepr() const { return ParentRepr; }
4812-
void setTypeRepr(TypeRepr *repr) { ParentRepr = repr; }
4813-
4814-
bool hasType() const {
4815-
// We have a type if either the type has been computed already or if
4816-
// this is a deserialized declaration with an interface type.
4817-
return !typeInContext.isNull();
4818-
}
4819-
48204808
/// Get the type of the variable within its context. If the context is generic,
48214809
/// this will use archetypes.
48224810
Type getType() const;
48234811

4824-
/// Set the type of the variable within its context.
4825-
void setType(Type t);
4826-
4827-
void markInvalid();
4828-
48294812
/// Retrieve the source range of the variable type, or an invalid range if the
48304813
/// variable's type is not explicitly written in the source.
48314814
///
@@ -4864,6 +4847,14 @@ class VarDecl : public AbstractStorageDecl {
48644847
///
48654848
Pattern *getParentPattern() const;
48664849

4850+
/// Returns the parsed type of this variable declaration. For parameters, this
4851+
/// is the parsed type the user explicitly wrote. For variables, this is the
4852+
/// type the user wrote in the typed pattern that binds this variable.
4853+
///
4854+
/// Note that there are many cases where the user may elide types. This will
4855+
/// return null in those cases.
4856+
TypeRepr *getTypeReprOrParentPatternTypeRepr() const;
4857+
48674858
/// Return the statement that owns the pattern associated with this VarDecl,
48684859
/// if one exists.
48694860
///
@@ -4904,6 +4895,9 @@ class VarDecl : public AbstractStorageDecl {
49044895
Parent = v;
49054896
}
49064897

4898+
NamedPattern *getNamingPattern() const { return NamingPattern; }
4899+
void setNamingPattern(NamedPattern *Pat) { NamingPattern = Pat; }
4900+
49074901
/// If this is a VarDecl that does not belong to a CaseLabelItem's pattern,
49084902
/// return this. Otherwise, this VarDecl must belong to a CaseStmt's
49094903
/// CaseLabelItem. In that case, return the first case label item of the first
@@ -5158,6 +5152,8 @@ class ParamDecl : public VarDecl {
51585152
SourceLoc ArgumentNameLoc;
51595153
SourceLoc SpecifierLoc;
51605154

5155+
TypeRepr *TyRepr = nullptr;
5156+
51615157
struct StoredDefaultArgument {
51625158
PointerUnion<Expr *, VarDecl *> DefaultArg;
51635159
Initializer *InitContext = nullptr;
@@ -5203,6 +5199,10 @@ class ParamDecl : public VarDecl {
52035199

52045200
SourceLoc getSpecifierLoc() const { return SpecifierLoc; }
52055201

5202+
/// Retrieve the TypeRepr corresponding to the parsed type of the parameter, if it exists.
5203+
TypeRepr *getTypeRepr() const { return TyRepr; }
5204+
void setTypeRepr(TypeRepr *repr) { TyRepr = repr; }
5205+
52065206
DefaultArgumentKind getDefaultArgumentKind() const {
52075207
return static_cast<DefaultArgumentKind>(Bits.ParamDecl.defaultArgumentKind);
52085208
}

trunk/include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,9 @@ ERROR(pattern_binds_no_variables,none,
15091509
"%select{property|global variable}0 declaration does not bind any "
15101510
"variables",
15111511
(unsigned))
1512+
ERROR(variable_bound_by_no_pattern,none,
1513+
"variable %0 is not bound by any pattern",
1514+
(DeclName))
15121515

15131516
WARNING(optional_ambiguous_case_ref,none,
15141517
"assuming you mean '%0.%2'; did you mean '%1.%2' instead?",

trunk/include/swift/SIL/SILDeclRef.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ struct SILDeclRef {
249249
bool isStoredPropertyInitializer() const {
250250
return kind == Kind::StoredPropertyInitializer;
251251
}
252+
/// True if the SILDeclRef references the initializer for the backing storage
253+
/// of a property wrapper.
254+
bool isPropertyWrapperBackingInitializer() const {
255+
return kind == Kind::PropertyWrapperBackingInitializer;
256+
}
252257

253258
/// True if the SILDeclRef references the ivar initializer or deinitializer of
254259
/// a class.

trunk/lib/AST/ASTDumper.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ namespace {
725725

726726
if (auto *var = dyn_cast<VarDecl>(VD)) {
727727
PrintWithColorRAII(OS, TypeColor) << " type='";
728-
if (var->hasType())
728+
if (auto varTy = var->hasInterfaceType())
729729
var->getType().print(PrintWithColorRAII(OS, TypeColor).getOS());
730730
else
731731
PrintWithColorRAII(OS, TypeColor) << "<null type>";
@@ -954,13 +954,11 @@ namespace {
954954
PrintWithColorRAII(OS, IdentifierColor)
955955
<< " apiName=" << P->getArgumentName();
956956

957-
if (P->hasType()) {
957+
if (P->hasInterfaceType()) {
958958
PrintWithColorRAII(OS, TypeColor) << " type='";
959959
P->getType().print(PrintWithColorRAII(OS, TypeColor).getOS());
960960
PrintWithColorRAII(OS, TypeColor) << "'";
961-
}
962961

963-
if (P->hasInterfaceType()) {
964962
PrintWithColorRAII(OS, InterfaceTypeColor) << " interface type='";
965963
P->getInterfaceType().print(
966964
PrintWithColorRAII(OS, InterfaceTypeColor).getOS());

trunk/lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,7 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
25242524
if (decl->hasInterfaceType()) {
25252525
Printer << ": ";
25262526
TypeLoc tyLoc;
2527-
if (auto *repr = decl->getTypeRepr())
2527+
if (auto *repr = decl->getTypeReprOrParentPatternTypeRepr())
25282528
tyLoc = TypeLoc(repr, decl->getInterfaceType());
25292529
else
25302530
tyLoc = TypeLoc::withoutLoc(decl->getInterfaceType());

trunk/lib/AST/Decl.cpp

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,7 +2595,7 @@ OpaqueReturnTypeRepr *ValueDecl::getOpaqueResultTypeRepr() const {
25952595
}
25962596
}
25972597
} else {
2598-
returnRepr = VD->getTypeRepr();
2598+
returnRepr = VD->getTypeReprOrParentPatternTypeRepr();
25992599
}
26002600
} else if (auto *FD = dyn_cast<FuncDecl>(this)) {
26012601
returnRepr = FD->getBodyResultTypeLoc().getTypeRepr();
@@ -5007,24 +5007,7 @@ VarDecl::VarDecl(DeclKind kind, bool isStatic, VarDecl::Introducer introducer,
50075007
}
50085008

50095009
Type VarDecl::getType() const {
5010-
if (!typeInContext) {
5011-
const_cast<VarDecl *>(this)->typeInContext =
5012-
getDeclContext()->mapTypeIntoContext(
5013-
getInterfaceType());
5014-
}
5015-
5016-
return typeInContext;
5017-
}
5018-
5019-
void VarDecl::setType(Type t) {
5020-
assert(t.isNull() || !t->is<InOutType>());
5021-
typeInContext = t;
5022-
}
5023-
5024-
void VarDecl::markInvalid() {
5025-
auto &Ctx = getASTContext();
5026-
setType(ErrorType::get(Ctx));
5027-
setInterfaceType(ErrorType::get(Ctx));
5010+
return getDeclContext()->mapTypeIntoContext(getInterfaceType());
50285011
}
50295012

50305013
/// Returns whether the var is settable in the specified context: this
@@ -5269,9 +5252,6 @@ Pattern *VarDecl::getParentPattern() const {
52695252
if (pat->containsVarDecl(this))
52705253
return pat;
52715254
}
5272-
5273-
//stmt->dump();
5274-
assert(0 && "Unknown parent pattern statement?");
52755255
}
52765256

52775257
// Otherwise, check if we have to walk our case stmt's var decl list to find
@@ -5285,6 +5265,16 @@ Pattern *VarDecl::getParentPattern() const {
52855265
return nullptr;
52865266
}
52875267

5268+
TypeRepr *VarDecl::getTypeReprOrParentPatternTypeRepr() const {
5269+
if (auto *param = dyn_cast<ParamDecl>(this))
5270+
return param->getTypeRepr();
5271+
5272+
if (auto *parentPattern = dyn_cast_or_null<TypedPattern>(getParentPattern()))
5273+
return parentPattern->getTypeRepr();
5274+
5275+
return nullptr;
5276+
}
5277+
52885278
NullablePtr<VarDecl>
52895279
VarDecl::getCorrespondingFirstCaseLabelItemVarDecl() const {
52905280
if (!hasName())

trunk/lib/ClangImporter/ImportDecl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,6 @@ applyPropertyOwnership(VarDecl *prop,
21102110
if (attrs & clang::ObjCPropertyDecl::OBJC_PR_weak) {
21112111
prop->getAttrs().add(new (ctx)
21122112
ReferenceOwnershipAttr(ReferenceOwnership::Weak));
2113-
prop->setType(WeakStorageType::get(prop->getType(), ctx));
21142113
prop->setInterfaceType(WeakStorageType::get(
21152114
prop->getInterfaceType(), ctx));
21162115
return;
@@ -2119,7 +2118,6 @@ applyPropertyOwnership(VarDecl *prop,
21192118
(attrs & clang::ObjCPropertyDecl::OBJC_PR_unsafe_unretained)) {
21202119
prop->getAttrs().add(
21212120
new (ctx) ReferenceOwnershipAttr(ReferenceOwnership::Unmanaged));
2122-
prop->setType(UnmanagedStorageType::get(prop->getType(), ctx));
21232121
prop->setInterfaceType(UnmanagedStorageType::get(
21242122
prop->getInterfaceType(), ctx));
21252123
return;

trunk/lib/Frontend/Frontend.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,23 @@ void CompilerInstance::setUpDiagnosticOptions() {
318318
}
319319
}
320320

321+
// The ordering of ModuleLoaders is important!
322+
//
323+
// 1. SourceLoader: This is a hack and only the compiler's tests are using it,
324+
// to avoid writing repetitive code involving generating modules/interfaces.
325+
// Ideally, we'd get rid of it.
326+
// 2. MemoryBufferSerializedModuleLoader: This is used by LLDB, because it might
327+
// already have the module available in memory.
328+
// 3. ModuleInterfaceLoader: Tries to find an up-to-date swiftmodule. If it
329+
// succeeds, it issues a particular "error" (see
330+
// [Note: ModuleInterfaceLoader-defer-to-SerializedModuleLoader]), which
331+
// is interpreted by the overarching loader as a command to use the
332+
// SerializedModuleLoader. If we failed to find a .swiftmodule, this falls
333+
// back to using an interface. Actual errors lead to diagnostics.
334+
// 4. SerializedModuleLoader: Loads a serialized module if it can.
335+
// 5. ClangImporter: This must come after all the Swift module loaders because
336+
// in the presence of overlays and mixed-source frameworks, we want to prefer
337+
// the overlay or framework module over the underlying Clang module.
321338
bool CompilerInstance::setUpModuleLoaders() {
322339
if (hasSourceImport()) {
323340
bool enableLibraryEvolution =
@@ -354,10 +371,6 @@ bool CompilerInstance::setUpModuleLoaders() {
354371
Context->addModuleLoader(std::move(MemoryBufferLoader));
355372
}
356373

357-
std::unique_ptr<SerializedModuleLoader> SML =
358-
SerializedModuleLoader::create(*Context, getDependencyTracker(), MLM);
359-
this->SML = SML.get();
360-
361374
// Wire up the Clang importer. If the user has specified an SDK, use it.
362375
// Otherwise, we just keep it around as our interface to Clang's ABI
363376
// knowledge.
@@ -380,7 +393,12 @@ bool CompilerInstance::setUpModuleLoaders() {
380393
FEOpts.RemarkOnRebuildFromModuleInterface);
381394
Context->addModuleLoader(std::move(PIML));
382395
}
396+
397+
std::unique_ptr<SerializedModuleLoader> SML =
398+
SerializedModuleLoader::create(*Context, getDependencyTracker(), MLM);
399+
this->SML = SML.get();
383400
Context->addModuleLoader(std::move(SML));
401+
384402
Context->addModuleLoader(std::move(clangImporter), /*isClang*/ true);
385403

386404
return false;

trunk/lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ class ModuleInterfaceLoaderImpl {
764764
}
765765
}
766766

767+
// [Note: ModuleInterfaceLoader-defer-to-SerializedModuleLoader]
767768
// Finally, if there's a module adjacent to the .swiftinterface that we can
768769
// _likely_ load (it validates OK and is up to date), bail early with
769770
// errc::not_supported, so the next (serialized) loader in the chain will

trunk/lib/IRGen/GenEnum.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,10 +1127,12 @@ namespace {
11271127
protected:
11281128
int64_t getDiscriminatorIndex(EnumElementDecl *target) const override {
11291129
// The elements are assigned discriminators ABI-compatible with their
1130-
// raw values from C.
1131-
assert(target->getRawValueExpr()
1132-
&& "c-compatible enum elt has no raw value?!");
1133-
auto intExpr = cast<IntegerLiteralExpr>(target->getRawValueExpr());
1130+
// raw values from C. An invalid raw value is assigned the error index -1.
1131+
auto intExpr =
1132+
dyn_cast_or_null<IntegerLiteralExpr>(target->getRawValueExpr());
1133+
if (!intExpr) {
1134+
return -1;
1135+
}
11341136
auto intType = getDiscriminatorType();
11351137

11361138
APInt intValue =

trunk/lib/SIL/SILProfiler.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static bool canCreateProfilerForAST(ASTNode N, SILDeclRef forDecl) {
135135
return true;
136136
} else if (auto *E = N.get<Expr *>()) {
137137
if (forDecl.isStoredPropertyInitializer() ||
138+
forDecl.isPropertyWrapperBackingInitializer() ||
138139
forDecl.getAbstractClosureExpr())
139140
return true;
140141
}
@@ -151,8 +152,10 @@ SILProfiler *SILProfiler::create(SILModule &M, ForDefinition_t forDefinition,
151152
if (!doesASTRequireProfiling(M, N) && Opts.UseProfile.empty())
152153
return nullptr;
153154

154-
if (!canCreateProfilerForAST(N, forDecl))
155+
if (!canCreateProfilerForAST(N, forDecl)) {
156+
N.dump(llvm::errs());
155157
llvm_unreachable("Invalid AST node for profiling");
158+
}
156159

157160
auto *Buf = M.allocate<SILProfiler>(1);
158161
auto *SP =

trunk/lib/SILGen/SILGen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,11 @@ emitPropertyWrapperBackingInitializer(VarDecl *var) {
11451145
preEmitFunction(constant, var, f, var);
11461146
PrettyStackTraceSILFunction X(
11471147
"silgen emitPropertyWrapperBackingInitializer", f);
1148-
f->createProfiler(var, constant, ForDefinition);
1149-
auto varDC = var->getInnermostDeclContext();
11501148
auto wrapperInfo = var->getPropertyWrapperBackingPropertyInfo();
11511149
assert(wrapperInfo.initializeFromOriginal);
1150+
f->createProfiler(wrapperInfo.initializeFromOriginal, constant,
1151+
ForDefinition);
1152+
auto varDC = var->getInnermostDeclContext();
11521153
SILGenFunction SGF(*this, *f, varDC);
11531154
SGF.emitGeneratorFunction(constant, wrapperInfo.initializeFromOriginal);
11541155
postEmitFunction(constant, f);

0 commit comments

Comments
 (0)