Skip to content

Commit f058b5d

Browse files
authored
---
yaml --- r: 278007 b: refs/heads/swift-5.1-old-llvm-branch c: 7989d3f h: refs/heads/master i: 278005: 2f7dfb9 278003: a1fd251 277999: a62e822
1 parent 3361cf3 commit f058b5d

File tree

64 files changed

+646
-264
lines changed

Some content is hidden

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

64 files changed

+646
-264
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-01-24-a: b6f62823aa5010b2ae53f15f72a57
12411241
refs/heads/marcrasi-astverifier-disable: 3fac766a23a77ebd0640296bfd7fc116ea60a4e0
12421242
refs/heads/revert-22227-a-tall-white-fountain-played: adfce60b2eaa54903ea189bed8a783bca609fa53
12431243
refs/heads/revert-22300-revert-22227-a-tall-white-fountain-played: 5f92040224df7dd4e618fdfb367349df64d8acad
1244-
refs/heads/swift-5.1-old-llvm-branch: 9b9d01ea5d3519e1b2c5bf8d03efdc2290eb2b7a
1244+
refs/heads/swift-5.1-old-llvm-branch: 7989d3f48c98aa24222eb9b3b359b2c814f936d8
12451245
refs/heads/swift-5.1-branch: 8060872acb4105d9655e020fe047e1ebcd77d0fb
12461246
refs/tags/swift-4.2.2-RELEASE: e429d1f1aaf59e69d38207a96e56265c7f6fccec
12471247
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-02-a: 3e5a03d32ff3b1e9af90d6c1198c14f938379a6e

branches/swift-5.1-old-llvm-branch/cmake/modules/AddSwift.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ endfunction()
3030
# Compute the library subdirectory to use for the given sdk and
3131
# architecture, placing the result in 'result_var_name'.
3232
function(compute_library_subdir result_var_name sdk arch)
33-
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}" PARENT_SCOPE)
33+
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS)
34+
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}" PARENT_SCOPE)
35+
else()
36+
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}" PARENT_SCOPE)
37+
endif()
3438
endfunction()
3539

3640
function(_compute_lto_flag option out_var)
@@ -1156,6 +1160,8 @@ function(_add_swift_library_single target name)
11561160
# Don't set PROPERTY COMPILE_FLAGS or LINK_FLAGS directly.
11571161
set(c_compile_flags ${SWIFTLIB_SINGLE_C_COMPILE_FLAGS})
11581162
set(link_flags ${SWIFTLIB_SINGLE_LINK_FLAGS})
1163+
1164+
set(library_search_subdir "${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}")
11591165
set(library_search_directories
11601166
"${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}"
11611167
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR}"
@@ -1300,6 +1306,7 @@ function(_add_swift_library_single target name)
13001306
if(target_static)
13011307
set_property(TARGET "${target_static}" APPEND_STRING PROPERTY
13021308
COMPILE_FLAGS " ${c_compile_flags}")
1309+
# FIXME: The fallback paths here are going to be dynamic libraries.
13031310
set(library_search_directories
13041311
"${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}"
13051312
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR}"

branches/swift-5.1-old-llvm-branch/cmake/modules/SwiftSource.cmake

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ function(handle_swift_sources
6161
endif()
6262

6363
if(swift_sources)
64-
compute_library_subdir(SWIFTSOURCES_LIBRARY_SUBDIR
65-
"${SWIFTSOURCES_SDK}" "${SWIFTSOURCES_ARCHITECTURE}")
66-
set(objsubdir "/${SWIFTSOURCES_LIBRARY_SUBDIR}")
64+
set(objsubdir "/${SWIFTSOURCES_SDK}/${SWIFTSOURCES_ARCHITECTURE}")
6765

6866
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${objsubdir}")
6967

@@ -255,6 +253,8 @@ function(_compile_swift_files
255253
"-nostdimport" "-parse-stdlib" "-module-name" "Swift")
256254
list(APPEND swift_flags "-Xfrontend" "-group-info-path"
257255
"-Xfrontend" "${GROUP_INFO_JSON_FILE}")
256+
else()
257+
list(APPEND swift_flags "-module-name" "${SWIFTFILE_MODULE_NAME}")
258258
endif()
259259

260260
# Force swift 5 mode for Standard Library.
@@ -313,19 +313,32 @@ function(_compile_swift_files
313313
list(APPEND swift_flags "-parse-as-library")
314314

315315
set(module_base "${module_dir}/${SWIFTFILE_MODULE_NAME}")
316+
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
317+
set(specific_module_dir "${module_base}.swiftmodule")
318+
set(module_base "${module_base}.swiftmodule/${SWIFTFILE_ARCHITECTURE}")
319+
endif()
316320
set(module_file "${module_base}.swiftmodule")
321+
set(module_doc_file "${module_base}.swiftdoc")
322+
323+
# FIXME: These don't really belong inside the swiftmodule, but there's not
324+
# an obvious alternate place to put them.
317325
set(sib_file "${module_base}.Onone.sib")
318326
set(sibopt_file "${module_base}.O.sib")
319327
set(sibgen_file "${module_base}.sibgen")
320-
set(module_doc_file "${module_base}.swiftdoc")
321328

322329
if(SWIFT_ENABLE_PARSEABLE_MODULE_INTERFACES)
323330
set(interface_file "${module_base}.swiftinterface")
324-
list(APPEND swift_flags "-emit-parseable-module-interface")
331+
list(APPEND swift_flags
332+
"-emit-parseable-module-interface-path" "${interface_file}")
325333
endif()
326334

327-
list(APPEND command_create_dirs
328-
COMMAND "${CMAKE_COMMAND}" -E make_directory "${module_dir}")
335+
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
336+
list(APPEND command_create_dirs
337+
COMMAND "${CMAKE_COMMAND}" -E make_directory "${specific_module_dir}")
338+
else()
339+
list(APPEND command_create_dirs
340+
COMMAND "${CMAKE_COMMAND}" -E make_directory "${module_dir}")
341+
endif()
329342

330343
# If we have extra regexp flags, check if we match any of the regexps. If so
331344
# add the relevant flags to our swift_flags.
@@ -349,10 +362,15 @@ function(_compile_swift_files
349362
set(optional_arg "OPTIONAL")
350363
endif()
351364

352-
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
353-
FILES ${module_outputs}
354-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
355-
"${optional_arg}")
365+
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
366+
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
367+
DIRECTORY "${specific_module_dir}"
368+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}")
369+
else()
370+
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
371+
FILES ${module_outputs}
372+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}")
373+
endif()
356374

357375
set(line_directive_tool "${SWIFT_SOURCE_DIR}/utils/line-directive")
358376
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")

branches/swift-5.1-old-llvm-branch/docs/SIL.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,6 +2937,7 @@ is_escaping_closure
29372937
```````````````````
29382938

29392939
::
2940+
29402941
sil-instruction ::= 'is_escaping_closure' sil-operand
29412942

29422943
%1 = is_escaping_closure %0 : $@callee_guaranteed () -> ()
@@ -2948,6 +2949,7 @@ true if it is.
29482949

29492950
copy_block
29502951
``````````
2952+
29512953
::
29522954

29532955
sil-instruction :: 'copy_block' sil-operand
@@ -2960,6 +2962,7 @@ if the block is copied from the stack to the heap.
29602962

29612963
copy_block_without_escaping
29622964
```````````````````````````
2965+
29632966
::
29642967

29652968
sil-instruction :: 'copy_block_without_escaping' sil-operand 'withoutEscaping' sil-operand

branches/swift-5.1-old-llvm-branch/docs/StandardLibraryProgrammersManual.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,65 @@ The standard library utilizes thread local storage (TLS) to cache expensive comp
171171
172172
See [ThreadLocalStorage.swift](https://github.com/apple/swift/blob/master/stdlib/public/core/ThreadLocalStorage.swift) for more details.
173173
174+
175+
## Working with Resilience
176+
177+
Maintaining ABI compatibility with previously released versions of the standard library makes things more complicated. This section details some of the extra rules to remember and patterns to use.
178+
179+
### The Curiously Recursive Inlinable Switch Pattern (CRISP)
180+
181+
When inlinable code switches over a non-frozen enum, it has to handle possible future cases (since it will be inlined into a module outside the standard library). You can see this in action with the implementation of `round(_:)` in FloatingPointTypes.swift.gyb, which takes a FloatingPointRoundingRule. It looks something like this:
182+
183+
```swift
184+
@_transparent
185+
public mutating func round(_ rule: FloatingPointRoundingRule) {
186+
switch rule {
187+
case .toNearestOrAwayFromZero:
188+
_value = Builtin.int_round_FPIEEE${bits}(_value)
189+
case .toNearestOrEven:
190+
_value = Builtin.int_rint_FPIEEE${bits}(_value)
191+
// ...
192+
@unknown default:
193+
self._roundSlowPath(rule)
194+
}
195+
}
196+
```
197+
198+
Making `round(_:)` inlinable but still have a default case is an attempt to get the best of both worlds: if the rounding rule is known at compile time, the call will compile down to a single instruction in optimized builds; and if it dynamically turns out to be a new kind of rounding rule added in Swift 25 (e.g. `.towardFortyTwo`), there's a fallback function, `_roundSlowPath(_:)`, that can handle it.
199+
200+
So what does `_roundSlowPath(_:)` look like? Well, it can't be inlinable, because that would defeat the purpose. It *could* just look like this:
201+
202+
```swift
203+
@usableFromInline
204+
internal mutating func _roundSlowPath(_ rule: FloatingPointRoundingRule) {
205+
switch rule {
206+
case .toNearestOrAwayFromZero:
207+
_value = Builtin.int_round_FPIEEE${bits}(_value)
208+
case .toNearestOrEven:
209+
_value = Builtin.int_rint_FPIEEE${bits}(_value)
210+
// ...
211+
}
212+
}
213+
```
214+
215+
...i.e. exactly the same as `round(_:)` but with no `default` case. That's guaranteed to be up to date if any new cases are added in the future. But it seems a little silly, since it's duplicating code that's in `round(_:)`. We *could* omit cases that have always existed, but there's a better answer:
216+
217+
```swift
218+
// Slow path for new cases that might have been inlined into an old
219+
// ABI-stable version of round(_:) called from a newer version. If this is
220+
// the case, this non-inlinable function will call into the _newer_ version
221+
// which _will_ support this rounding rule.
222+
@usableFromInline
223+
internal mutating func _roundSlowPath(_ rule: FloatingPointRoundingRule) {
224+
self.round(rule)
225+
}
226+
```
227+
228+
Because `_roundSlowPath(_:)` isn't inlinable, the version of `round(_:)` that gets called at run time will always be the version implemented in the standard library dylib. And since FloatingPointRoundingRule is *also* defined in the standard library, we know it'll never be out of sync with this version of `round(_:)`.
229+
230+
Maybe some day we'll have special syntax in the language to say "call this method without allowing inlining" to get the same effect, but for now, this Curiously Recursive Inlinable Switch Pattern allows for safe inlining of switches over non-frozen enums with less boilerplate than you might otherwise have. Not none, but less.
231+
232+
174233
## Productivity Hacks
175234

176235
### Be a Ninja

branches/swift-5.1-old-llvm-branch/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ static void updateRuntimeLibraryPath(SearchPathOptions &SearchPathOpts,
4949
llvm::sys::path::append(LibPath, getPlatformNameForTriple(Triple));
5050
SearchPathOpts.RuntimeLibraryPath = LibPath.str();
5151

52-
llvm::sys::path::append(LibPath, swift::getMajorArchitectureName(Triple));
52+
if (!Triple.isOSDarwin())
53+
llvm::sys::path::append(LibPath, swift::getMajorArchitectureName(Triple));
5354
SearchPathOpts.RuntimeLibraryImportPath = LibPath.str();
5455
}
5556

branches/swift-5.1-old-llvm-branch/lib/SILGen/SILGenPattern.cpp

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,38 +2847,47 @@ void SILGenFunction::emitSwitchFallthrough(FallthroughStmt *S) {
28472847

28482848
if (!caseStmt->hasBoundDecls()) {
28492849
Cleanups.emitBranchAndCleanups(sharedDest, S);
2850-
} else {
2851-
// Generate branch args to pass along current vars to fallthrough case.
2852-
SILModule &M = F.getModule();
2853-
ArrayRef<CaseLabelItem> labelItems = caseStmt->getCaseLabelItems();
2854-
SmallVector<SILValue, 4> args;
2855-
SmallVector<VarDecl *, 4> expectedVarOrder;
2856-
labelItems[0].getPattern()->collectVariables(expectedVarOrder);
2857-
2858-
for (auto *expected : expectedVarOrder) {
2859-
if (!expected->hasName())
2850+
return;
2851+
}
2852+
2853+
// Generate branch args to pass along current vars to fallthrough case.
2854+
SILModule &M = F.getModule();
2855+
ArrayRef<CaseLabelItem> labelItems = caseStmt->getCaseLabelItems();
2856+
SmallVector<SILValue, 4> args;
2857+
SmallVector<VarDecl *, 4> expectedVarOrder;
2858+
labelItems[0].getPattern()->collectVariables(expectedVarOrder);
2859+
2860+
for (auto *expected : expectedVarOrder) {
2861+
if (!expected->hasName())
2862+
continue;
2863+
for (auto var : VarLocs) {
2864+
auto varDecl = dyn_cast<VarDecl>(var.getFirst());
2865+
if (!varDecl || !varDecl->hasName() ||
2866+
varDecl->getName() != expected->getName()) {
28602867
continue;
2861-
for (auto var : VarLocs) {
2862-
auto varDecl = dyn_cast<VarDecl>(var.getFirst());
2863-
if (varDecl && varDecl->hasName() && varDecl->getName() == expected->getName()) {
2864-
SILValue value = var.getSecond().value;
2865-
2866-
if (value->getType().isAddressOnly(M)) {
2867-
context->Emission.emitAddressOnlyInitialization(expected, value);
2868-
} else if (var.getSecond().box) {
2869-
auto &lowering = getTypeLowering(value->getType());
2870-
auto argValue = lowering.emitLoad(B, CurrentSILLoc, value, LoadOwnershipQualifier::Copy);
2871-
args.push_back(argValue);
2872-
} else {
2873-
auto argValue = B.emitCopyValueOperation(CurrentSILLoc, value);
2874-
args.push_back(argValue);
2875-
}
2876-
break;
2877-
}
28782868
}
2869+
2870+
SILValue value = var.getSecond().value;
2871+
2872+
if (value->getType().isAddressOnly(M)) {
2873+
context->Emission.emitAddressOnlyInitialization(expected, value);
2874+
break;
2875+
}
2876+
2877+
if (var.getSecond().box) {
2878+
auto &lowering = getTypeLowering(value->getType());
2879+
auto argValue = lowering.emitLoad(B, CurrentSILLoc, value,
2880+
LoadOwnershipQualifier::Copy);
2881+
args.push_back(argValue);
2882+
break;
2883+
}
2884+
2885+
auto argValue = B.emitCopyValueOperation(CurrentSILLoc, value);
2886+
args.push_back(argValue);
2887+
break;
28792888
}
2880-
Cleanups.emitBranchAndCleanups(sharedDest, S, args);
28812889
}
2890+
Cleanups.emitBranchAndCleanups(sharedDest, S, args);
28822891
}
28832892

28842893

branches/swift-5.1-old-llvm-branch/lib/Sema/CSApply.cpp

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6677,7 +6677,24 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
66776677
break;
66786678
}
66796679

6680-
default:
6680+
#define SUGARED_TYPE(Name, Parent) case TypeKind::Name:
6681+
#define BUILTIN_TYPE(Name, Parent) case TypeKind::Name:
6682+
#define UNCHECKED_TYPE(Name, Parent) case TypeKind::Name:
6683+
#define ARTIFICIAL_TYPE(Name, Parent) case TypeKind::Name:
6684+
#define TYPE(Name, Parent)
6685+
#include "swift/AST/TypeNodes.def"
6686+
case TypeKind::Error:
6687+
case TypeKind::InOut:
6688+
case TypeKind::Module:
6689+
case TypeKind::Enum:
6690+
case TypeKind::Struct:
6691+
case TypeKind::Protocol:
6692+
case TypeKind::ProtocolComposition:
6693+
case TypeKind::BoundGenericEnum:
6694+
case TypeKind::BoundGenericStruct:
6695+
case TypeKind::GenericFunction:
6696+
case TypeKind::GenericTypeParam:
6697+
case TypeKind::DependentMember:
66816698
break;
66826699
}
66836700

@@ -6687,7 +6704,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
66876704
// Coercions from a type to an existential type.
66886705
case TypeKind::ExistentialMetatype:
66896706
case TypeKind::ProtocolComposition:
6690-
case TypeKind::Protocol: {
6707+
case TypeKind::Protocol:
66916708
return coerceExistential(expr, toType, locator);
66926709

66936710
// Coercion to Optional<T>.
@@ -6709,9 +6726,32 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
67096726
diagnoseOptionalInjection(result);
67106727
return result;
67116728
}
6712-
}
67136729

6714-
default:
6730+
#define SUGARED_TYPE(Name, Parent) case TypeKind::Name:
6731+
#define BUILTIN_TYPE(Name, Parent) case TypeKind::Name:
6732+
#define UNCHECKED_TYPE(Name, Parent) case TypeKind::Name:
6733+
#define ARTIFICIAL_TYPE(Name, Parent) case TypeKind::Name:
6734+
#define TYPE(Name, Parent)
6735+
#include "swift/AST/TypeNodes.def"
6736+
case TypeKind::Error:
6737+
case TypeKind::Module:
6738+
case TypeKind::Tuple:
6739+
case TypeKind::Enum:
6740+
case TypeKind::Struct:
6741+
case TypeKind::Class:
6742+
case TypeKind::BoundGenericClass:
6743+
case TypeKind::BoundGenericStruct:
6744+
case TypeKind::Metatype:
6745+
case TypeKind::DynamicSelf:
6746+
case TypeKind::PrimaryArchetype:
6747+
case TypeKind::OpenedArchetype:
6748+
case TypeKind::NestedArchetype:
6749+
case TypeKind::GenericTypeParam:
6750+
case TypeKind::DependentMember:
6751+
case TypeKind::Function:
6752+
case TypeKind::GenericFunction:
6753+
case TypeKind::LValue:
6754+
case TypeKind::InOut:
67156755
break;
67166756
}
67176757

branches/swift-5.1-old-llvm-branch/lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,21 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
301301

302302
// Search the runtime import path.
303303
isFramework = false;
304-
return !findModuleFilesInDirectory(
305-
moduleID, Ctx.SearchPathOpts.RuntimeLibraryImportPath,
306-
moduleFilename.str(), moduleDocFilename.str(), moduleBuffer,
307-
moduleDocBuffer);
304+
currPath = Ctx.SearchPathOpts.RuntimeLibraryImportPath;
305+
if (Ctx.LangOpts.Target.isOSDarwin()) {
306+
// Apple platforms always use architecture-specific files within a
307+
// .swiftmodule directory for the stdlib.
308+
llvm::sys::path::append(currPath, moduleFilename.str());
309+
return !findModuleFilesInDirectory(moduleID, currPath,
310+
archFileNames.first,
311+
archFileNames.second,
312+
moduleBuffer, moduleDocBuffer);
313+
}
314+
// Non-Apple platforms always use single-architecture swiftmodules.
315+
return !findModuleFilesInDirectory(moduleID, currPath,
316+
moduleFilename.str(),
317+
moduleDocFilename.str(),
318+
moduleBuffer, moduleDocBuffer);
308319
}
309320

310321
static std::pair<StringRef, clang::VersionTuple>

0 commit comments

Comments
 (0)