Skip to content

Commit 4bc90cd

Browse files
authored
---
yaml --- r: 341373 b: refs/heads/rxwei-patch-1 c: 5cf7ce7 h: refs/heads/master i: 341371: e667e66
1 parent dce0cbd commit 4bc90cd

20 files changed

+167
-21
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: e0031d0b8f262a978f9f75e67cc14c00ed0cd928
1018+
refs/heads/rxwei-patch-1: 5cf7ce7ab4c22069bb63179ee349a05cb4e4caad
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/AnyFunctionRef.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ class AnyFunctionRef {
7676
return !TheFunction.get<AbstractClosureExpr *>()->getType().isNull();
7777
}
7878

79+
bool hasSingleExpressionBody() const {
80+
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
81+
return AFD->hasSingleExpressionBody();
82+
return TheFunction.get<AbstractClosureExpr *>()->hasSingleExpressionBody();
83+
}
84+
85+
Expr *getSingleExpressionBody() const {
86+
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
87+
return AFD->getSingleExpressionBody();
88+
return TheFunction.get<AbstractClosureExpr *>()->getSingleExpressionBody();
89+
}
90+
7991
Type getType() const {
8092
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
8193
return AFD->getInterfaceType();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,6 +3475,12 @@ class AbstractClosureExpr : public DeclContext, public Expr {
34753475
/// Whether this closure consists of a single expression.
34763476
bool hasSingleExpressionBody() const;
34773477

3478+
/// Retrieve the body for closure that has a single expression for
3479+
/// its body.
3480+
///
3481+
/// Only valid when \c hasSingleExpressionBody() is true.
3482+
Expr *getSingleExpressionBody() const;
3483+
34783484
static bool classof(const Expr *E) {
34793485
return E->getKind() >= ExprKind::First_AbstractClosureExpr &&
34803486
E->getKind() <= ExprKind::Last_AbstractClosureExpr;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#ifndef SWIFT_AST_RESILIENCE_EXPANSION_H
1414
#define SWIFT_AST_RESILIENCE_EXPANSION_H
1515

16+
#include "llvm/Support/raw_ostream.h"
17+
1618
namespace swift {
1719

1820
/// A specification for how much to expand resilient types.
@@ -44,6 +46,16 @@ enum class ResilienceExpansion : unsigned {
4446
Last_ResilienceExpansion = Maximal
4547
};
4648

49+
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
50+
ResilienceExpansion expansion) {
51+
switch (expansion) {
52+
case ResilienceExpansion::Minimal:
53+
return os << "Minimal";
54+
case ResilienceExpansion::Maximal:
55+
return os << "Maximal";
56+
}
57+
}
58+
4759
} // namespace swift
4860

4961
#endif // LLVM_SWIFT_AST_CAPTURE_INFO_H

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ class SearchPathOptions {
6464
/// Path to search for compiler-relative header files.
6565
std::string RuntimeResourcePath;
6666

67-
/// Path to search for compiler-relative stdlib dylibs.
68-
std::string RuntimeLibraryPath;
67+
/// Paths to search for compiler-relative stdlib dylibs, in order of
68+
/// preference.
69+
std::vector<std::string> RuntimeLibraryPaths;
6970

7071
/// Paths to search for stdlib modules. One of these will be compiler-relative.
7172
std::vector<std::string> RuntimeLibraryImportPaths;

branches/rxwei-patch-1/include/swift/Basic/SourceManager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ class SourceManager {
103103
rangeContainsTokenLoc(Enclosing, Inner.End);
104104
}
105105

106+
/// Returns true if range \p R contains the code-completion location, if any.
107+
bool rangeContainsCodeCompletionLoc(SourceRange R) const {
108+
return CodeCompletionBufferID
109+
? rangeContainsTokenLoc(R, getCodeCompletionLoc())
110+
: false;
111+
}
112+
106113
/// Returns the buffer ID for the specified *valid* location.
107114
///
108115
/// Because a valid source location always corresponds to a source buffer,

branches/rxwei-patch-1/include/swift/SIL/TypeLowering.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ class TypeLowering {
250250

251251
virtual ~TypeLowering() {}
252252

253+
/// Print out the internal state of this type lowering into \p os.
254+
void print(llvm::raw_ostream &os) const;
255+
256+
/// Dump out the internal state of this type lowering to llvm::dbgs().
257+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const, "Only for use in the debugger");
258+
253259
/// Are r-values of this type passed as arguments indirectly by formal
254260
/// convention?
255261
///

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,15 @@ bool AbstractClosureExpr::hasSingleExpressionBody() const {
19181918
return true;
19191919
}
19201920

1921+
Expr *AbstractClosureExpr::getSingleExpressionBody() const {
1922+
if (auto closure = dyn_cast<ClosureExpr>(this))
1923+
return closure->getSingleExpressionBody();
1924+
else if (auto autoclosure = dyn_cast<AutoClosureExpr>(this))
1925+
return autoclosure->getSingleExpressionBody();
1926+
1927+
return nullptr;
1928+
}
1929+
19211930
#define FORWARD_SOURCE_LOCS_TO(CLASS, NODE) \
19221931
SourceRange CLASS::getSourceRange() const { \
19231932
return (NODE)->getSourceRange(); \

branches/rxwei-patch-1/lib/Frontend/CompilerInvocation.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
using namespace swift;
3131
using namespace llvm::opt;
3232

33+
/// The path for Swift libraries in the OS on Darwin.
34+
#define DARWIN_OS_LIBRARY_PATH "/usr/lib/swift"
35+
3336
swift::CompilerInvocation::CompilerInvocation() {
3437
setTargetTriple(llvm::sys::getDefaultTargetTriple());
3538
}
@@ -66,7 +69,10 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
6669
llvm::SmallString<128> LibPath(SearchPathOpts.RuntimeResourcePath);
6770

6871
llvm::sys::path::append(LibPath, getPlatformNameForTriple(Triple));
69-
SearchPathOpts.RuntimeLibraryPath = LibPath.str();
72+
SearchPathOpts.RuntimeLibraryPaths.clear();
73+
SearchPathOpts.RuntimeLibraryPaths.push_back(LibPath.str());
74+
if (Triple.isOSDarwin())
75+
SearchPathOpts.RuntimeLibraryPaths.push_back(DARWIN_OS_LIBRARY_PATH);
7076

7177
// Set up the import paths containing the swiftmodules for the libraries in
7278
// RuntimeLibraryPath.

branches/rxwei-patch-1/lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ class ParseableInterfaceModuleLoaderImpl {
10661066
}
10671067

10681068
bool isInResourceDir(StringRef path) {
1069-
StringRef resourceDir = ctx.SearchPathOpts.RuntimeLibraryPath;
1069+
StringRef resourceDir = ctx.SearchPathOpts.RuntimeResourcePath;
10701070
if (resourceDir.empty()) return false;
10711071
return path.startswith(resourceDir);
10721072
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,23 @@ TypeConverter::TypeConverter(IRGenModule &IGM)
12271227
if (!doesPlatformUseLegacyLayouts(platformName, archName))
12281228
return;
12291229

1230-
defaultPath.append(IGM.Context.SearchPathOpts.RuntimeLibraryPath);
1230+
// Find the first runtime library path that exists.
1231+
bool found = false;
1232+
for (auto &RuntimeLibraryPath
1233+
: IGM.Context.SearchPathOpts.RuntimeLibraryPaths) {
1234+
if (llvm::sys::fs::exists(RuntimeLibraryPath)) {
1235+
defaultPath.append(RuntimeLibraryPath);
1236+
found = true;
1237+
break;
1238+
}
1239+
}
1240+
if (!found) {
1241+
auto joined = llvm::join(IGM.Context.SearchPathOpts.RuntimeLibraryPaths,
1242+
"', '");
1243+
llvm::report_fatal_error("Unable to find a runtime library path at '"
1244+
+ joined + "'");
1245+
}
1246+
12311247
llvm::sys::path::append(defaultPath, "layouts-");
12321248
defaultPath.append(archName);
12331249
defaultPath.append(".yaml");

branches/rxwei-patch-1/lib/Immediate/Immediate.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,26 @@ static void *loadRuntimeLib(StringRef runtimeLibPathWithName) {
5959
#endif
6060
}
6161

62-
static void *loadRuntimeLib(StringRef sharedLibName, StringRef runtimeLibPath) {
62+
static void *loadRuntimeLibAtPath(StringRef sharedLibName,
63+
StringRef runtimeLibPath) {
6364
// FIXME: Need error-checking.
6465
llvm::SmallString<128> Path = runtimeLibPath;
6566
llvm::sys::path::append(Path, sharedLibName);
6667
return loadRuntimeLib(Path);
6768
}
6869

69-
void *swift::immediate::loadSwiftRuntime(StringRef runtimeLibPath) {
70-
return loadRuntimeLib("libswiftCore" LTDL_SHLIB_EXT, runtimeLibPath);
70+
static void *loadRuntimeLib(StringRef sharedLibName,
71+
ArrayRef<std::string> runtimeLibPaths) {
72+
for (auto &runtimeLibPath : runtimeLibPaths) {
73+
if (void *handle = loadRuntimeLibAtPath(sharedLibName, runtimeLibPath))
74+
return handle;
75+
}
76+
return nullptr;
77+
}
78+
79+
void *swift::immediate::loadSwiftRuntime(ArrayRef<std::string>
80+
runtimeLibPaths) {
81+
return loadRuntimeLib("libswiftCore" LTDL_SHLIB_EXT, runtimeLibPaths);
7182
}
7283

7384
static bool tryLoadLibrary(LinkLibrary linkLib,
@@ -105,9 +116,9 @@ static bool tryLoadLibrary(LinkLibrary linkLib,
105116
if (!success)
106117
success = loadRuntimeLib(stem);
107118

108-
// If that fails, try our runtime library path.
119+
// If that fails, try our runtime library paths.
109120
if (!success)
110-
success = loadRuntimeLib(stem, searchPathOpts.RuntimeLibraryPath);
121+
success = loadRuntimeLib(stem, searchPathOpts.RuntimeLibraryPaths);
111122
break;
112123
}
113124
case LibraryKind::Framework: {
@@ -240,7 +251,7 @@ int swift::RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine,
240251
//
241252
// This must be done here, before any library loading has been done, to avoid
242253
// racing with the static initializers in user code.
243-
auto stdlib = loadSwiftRuntime(Context.SearchPathOpts.RuntimeLibraryPath);
254+
auto stdlib = loadSwiftRuntime(Context.SearchPathOpts.RuntimeLibraryPaths);
244255
if (!stdlib) {
245256
CI.getDiags().diagnose(SourceLoc(),
246257
diag::error_immediate_mode_missing_stdlib);

branches/rxwei-patch-1/lib/Immediate/ImmediateImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace immediate {
3737
/// Returns a handle to the runtime suitable for other \c dlsym or \c dlclose
3838
/// calls or \c null if an error occurred.
3939
///
40-
/// \param runtimeLibPath Path to search for compiler-relative stdlib dylibs.
41-
void *loadSwiftRuntime(StringRef runtimeLibPath);
40+
/// \param runtimeLibPaths Paths to search for stdlib dylibs.
41+
void *loadSwiftRuntime(ArrayRef<std::string> runtimeLibPaths);
4242
bool tryLoadLibraries(ArrayRef<LinkLibrary> LinkLibraries,
4343
SearchPathOptions SearchPathOpts,
4444
DiagnosticEngine &Diags);

branches/rxwei-patch-1/lib/Immediate/REPL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ class REPLEnvironment {
969969
ASTContext &Ctx = CI.getASTContext();
970970
Ctx.LangOpts.EnableAccessControl = false;
971971
if (!ParseStdlib) {
972-
if (!loadSwiftRuntime(Ctx.SearchPathOpts.RuntimeLibraryPath)) {
972+
if (!loadSwiftRuntime(Ctx.SearchPathOpts.RuntimeLibraryPaths)) {
973973
CI.getDiags().diagnose(SourceLoc(),
974974
diag::error_immediate_mode_missing_stdlib);
975975
return;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,3 +2687,22 @@ unsigned TypeConverter::countNumberOfFields(SILType Ty,
26872687
TypeFields[key] = fieldsCount;
26882688
return std::max(fieldsCount, 1U);
26892689
}
2690+
2691+
void TypeLowering::print(llvm::raw_ostream &os) const {
2692+
auto BOOL = [&](bool b) -> StringRef {
2693+
if (b)
2694+
return "true";
2695+
return "false";
2696+
};
2697+
os << "Type Lowering for lowered type: " << LoweredType << ".\n"
2698+
<< "Expansion: " << ResilienceExpansion(ForExpansion) << "\n"
2699+
<< "isTrivial: " << BOOL(Properties.isTrivial()) << ".\n"
2700+
<< "isFixedABI: " << BOOL(Properties.isFixedABI()) << ".\n"
2701+
<< "isAddressOnly: " << BOOL(Properties.isAddressOnly()) << ".\n"
2702+
<< "isResilient: " << BOOL(Properties.isResilient()) << ".\n"
2703+
<< "\n";
2704+
}
2705+
2706+
void TypeLowering::dump() const {
2707+
print(llvm::dbgs());
2708+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ bool TypeChecker::typeCheckFunctionBuilderFuncBody(FuncDecl *FD,
496496
options |= TypeCheckExprFlags::ConvertTypeIsOpaqueReturnType;
497497
}
498498

499+
// If we are performing code-completion inside the functions body, supress
500+
// diagnostics to workaround typechecking performance problems.
501+
if (Context.SourceMgr.rangeContainsCodeCompletionLoc(
502+
FD->getBody()->getSourceRange()))
503+
options |= TypeCheckExprFlags::SuppressDiagnostics;
504+
499505
// Type-check the single result expression.
500506
Type returnExprType = typeCheckExpression(returnExpr, FD,
501507
TypeLoc::withoutLoc(returnType),
@@ -574,6 +580,12 @@ ConstraintSystem::TypeMatchResult ConstraintSystem::applyFunctionBuilder(
574580
assert(!builderType->hasTypeParameter());
575581
}
576582

583+
// If we are performing code-completion inside the closure body, supress
584+
// diagnostics to workaround typechecking performance problems.
585+
if (getASTContext().SourceMgr.rangeContainsCodeCompletionLoc(
586+
closure->getSourceRange()))
587+
Options |= ConstraintSystemFlags::SuppressDiagnostics;
588+
577589
BuilderClosureVisitor visitor(getASTContext(), this,
578590
/*wantExpr=*/true, builderType);
579591
Expr *singleExpr = visitor.visit(closure->getBody());

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,29 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
443443
return RS;
444444
}
445445

446+
// If the body consisted of a single return without a result
447+
//
448+
// func foo() -> Int {
449+
// return
450+
// }
451+
//
452+
// in parseAbstractFunctionBody the return is given an empty, implicit tuple
453+
// as its result
454+
//
455+
// func foo() -> Int {
456+
// return ()
457+
// }
458+
//
459+
// Look for that case and diagnose it as missing return expression.
460+
if (!ResultTy->isVoid() && TheFunc->hasSingleExpressionBody()) {
461+
auto expr = TheFunc->getSingleExpressionBody();
462+
if (expr->isImplicit() && isa<TupleExpr>(expr) &&
463+
cast<TupleExpr>(expr)->getNumElements() == 0) {
464+
TC.diagnose(RS->getReturnLoc(), diag::return_expr_missing);
465+
return RS;
466+
}
467+
}
468+
446469
Expr *E = RS->getResult();
447470

448471
// In an initializer, the only expression allowed is "nil", which indicates

branches/rxwei-patch-1/test/Parse/omit_return_fail.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
func badIs<T>(_ value: Any, anInstanceOf type: T.Type) -> Bool {
44
value is type // expected-error {{use of undeclared type 'type'}}
55
}
6+
7+
func foo() -> Int {
8+
return // expected-error {{non-void function should return a value}}
9+
}

branches/rxwei-patch-1/test/stdlib/ObjCEvilClassInitialization.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import StdlibUnittest
1414
let tests = TestSuite("ObjCEvilClassInitialization")
1515

1616
tests.test("GenericOnEvilClass") {
17-
struct Generic<T> {
18-
var type: T.Type { return T.self }
17+
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) {
18+
struct Generic<T> {
19+
var type: T.Type { return T.self }
20+
}
21+
let g = Generic<EvilClass>()
22+
expectEqual("\(type(of: g))", "Generic<EvilClass>")
23+
expectEqual(g.type, EvilClass.self)
1924
}
20-
let g = Generic<EvilClass>()
21-
expectEqual("\(type(of: g))", "Generic<EvilClass>")
22-
expectEqual(g.type, EvilClass.self)
2325
}
2426

2527
runAllTests()

branches/rxwei-patch-1/utils/gyb_syntax_support/Token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def macro_name(self):
314314
classification='StringLiteral', serialization_code=113),
315315

316316
Misc('Unknown', 'unknown', serialization_code=115),
317-
Misc('Identifier', 'identifier', classification=None,
317+
Misc('Identifier', 'identifier', classification='Identifier',
318318
serialization_code=105),
319319
Misc('UnspacedBinaryOperator', 'oper_binary_unspaced',
320320
serialization_code=107),

0 commit comments

Comments
 (0)