Skip to content

Commit e485f11

Browse files
authored
Merge pull request #29678 from apple/tensorflow-merge
Merging swift-DEVELOPMENT-SNAPSHOT-2020-01-31-a into tensorflow
2 parents 78968d5 + 240a7af commit e485f11

File tree

194 files changed

+5091
-2255
lines changed

Some content is hidden

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

194 files changed

+5091
-2255
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ function(add_dependencies_multiple_targets)
2828
endif()
2929
endfunction()
3030

31-
# Compute the library subdirectory to use for the given sdk and
32-
# architecture, placing the result in 'result_var_name'.
33-
function(compute_library_subdir result_var_name sdk arch)
34-
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS OR sdk STREQUAL "MACCATALYST")
35-
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}" PARENT_SCOPE)
36-
else()
37-
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}" PARENT_SCOPE)
38-
endif()
39-
endfunction()
40-
4131
function(_compute_lto_flag option out_var)
4232
string(TOLOWER "${option}" lowercase_option)
4333
if (lowercase_option STREQUAL "full")
@@ -163,9 +153,12 @@ function(_add_variant_c_compile_link_flags)
163153
endif()
164154

165155
if(IS_DARWIN)
156+
# We collate -F with the framework path to avoid unwanted deduplication
157+
# of options by target_compile_options -- this way no undesired
158+
# side effects are introduced should a new search path be added.
166159
list(APPEND result
167160
"-arch" "${CFLAGS_ARCH}"
168-
"-F" "${SWIFT_SDK_${CFLAGS_SDK}_PATH}/../../../Developer/Library/Frameworks")
161+
"-F${SWIFT_SDK_${CFLAGS_SDK}_PATH}/../../../Developer/Library/Frameworks")
169162

170163
set(add_explicit_version TRUE)
171164

@@ -351,7 +344,7 @@ function(_add_variant_c_compile_flags)
351344
swift_android_libcxx_include_paths(CFLAGS_CXX_INCLUDES)
352345
swift_android_include_for_arch("${CFLAGS_ARCH}" "${CFLAGS_ARCH}_INCLUDE")
353346
foreach(path IN LISTS CFLAGS_CXX_INCLUDES ${CFLAGS_ARCH}_INCLUDE)
354-
list(APPEND result -isystem;${path})
347+
list(APPEND result "SHELL:${CMAKE_INCLUDE_SYSTEM_FLAG_C}${path}")
355348
endforeach()
356349
list(APPEND result "-D__ANDROID_API__=${SWIFT_ANDROID_API_LEVEL}")
357350
endif()
@@ -405,8 +398,11 @@ function(_add_variant_swift_compile_flags
405398
endif()
406399

407400
if(IS_DARWIN)
401+
# We collate -F with the framework path to avoid unwanted deduplication
402+
# of options by target_compile_options -- this way no undesired
403+
# side effects are introduced should a new search path be added.
408404
list(APPEND result
409-
"-F" "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/../../../Developer/Library/Frameworks")
405+
"-F${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/../../../Developer/Library/Frameworks")
410406
endif()
411407

412408
is_build_type_optimized("${build_type}" optimized)
@@ -1500,7 +1496,7 @@ function(_add_swift_library_single target name)
15001496
endif()
15011497

15021498
if(target_static)
1503-
target_link_options(${target_static} PRIVATE
1499+
target_compile_options(${target_static} PRIVATE
15041500
${c_compile_flags})
15051501
# FIXME: The fallback paths here are going to be dynamic libraries.
15061502

@@ -2175,7 +2171,10 @@ function(add_swift_target_library name)
21752171

21762172
list(APPEND swiftlib_swift_compile_flags_all "-Fsystem" "${ios_support_frameworks_path}")
21772173
list(APPEND swiftlib_c_compile_flags_all "-iframework" "${ios_support_frameworks_path}")
2178-
list(APPEND swiftlib_link_flags_all "-F" "${ios_support_frameworks_path}")
2174+
# We collate -F with the framework path to avoid unwanted deduplication
2175+
# of options by target_compile_options -- this way no undesired
2176+
# side effects are introduced should a new search path be added.
2177+
list(APPEND swiftlib_link_flags_all "-F${ios_support_frameworks_path}")
21792178
endif()
21802179

21812180
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS AND SWIFTLIB_IS_SDK_OVERLAY)

cmake/modules/SwiftSource.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
include(macCatalystUtils)
22
include(SwiftUtils)
33

4+
# Compute the library subdirectory to use for the given sdk and
5+
# architecture, placing the result in 'result_var_name'.
6+
function(compute_library_subdir result_var_name sdk arch)
7+
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS OR sdk STREQUAL "MACCATALYST")
8+
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}" PARENT_SCOPE)
9+
else()
10+
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}" PARENT_SCOPE)
11+
endif()
12+
endfunction()
13+
414
# Process the sources within the given variable, pulling out any Swift
515
# sources to be compiled with 'swift' directly. This updates
616
# ${sourcesvar} in place with the resulting list and ${externalvar} with the

docs/SIL.rst

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,46 +3495,8 @@ partial_apply
34953495
// %r will be of the substituted thick function type $(Z'...) -> R'
34963496

34973497
Creates a closure by partially applying the function ``%0`` to a partial
3498-
sequence of its arguments. In the instruction syntax, the type of the callee is
3499-
specified after the argument list; the types of the argument and of the defined
3500-
value are derived from the function type of the callee. If the ``partial_apply``
3501-
has an escaping function type (not ``[on_stack]``) the closure context will be
3502-
allocated with retain count 1 and initialized to contain the values ``%1``,
3503-
``%2``, etc. The closed-over values will not be retained; that must be done
3504-
separately before the ``partial_apply``. The closure does however take ownership
3505-
of the partially applied arguments (except for ``@inout_aliasable`` parameters);
3506-
when the closure reference count reaches zero, the contained values will be
3507-
destroyed. If the ``partial_apply`` has a ``@noescape`` function type
3508-
(``partial_apply [on_stack]``) the closure context is allocated on the stack and
3509-
initialized to contain the closed-over values. The closed-over values are not
3510-
retained, lifetime of the closed-over values must be managed separately. The
3511-
lifetime of the stack context of a ``partial_apply [on_stack]`` must be
3512-
terminated with a ``dealloc_stack``.
3513-
3514-
If the callee is generic, all of its generic parameters must be bound by the
3515-
given substitution list. The arguments are given with these generic
3516-
substitutions applied, and the resulting closure is of concrete function
3517-
type with the given substitutions applied. The generic parameters themselves
3518-
cannot be partially applied; all of them must be bound. The result is always
3519-
a concrete function.
3520-
3521-
If an address argument has ``@inout_aliasable`` convention, the closure
3522-
obtained from ``partial_apply`` will not own its underlying value.
3523-
The ``@inout_aliasable`` parameter convention is used when a ``@noescape``
3524-
closure captures an ``inout`` argument.
3525-
3526-
TODO: The instruction, when applied to a generic function,
3527-
currently implicitly performs abstraction difference transformations enabled
3528-
by the given substitutions, such as promoting address-only arguments and returns
3529-
to register arguments. This should be fixed.
3530-
3531-
By default, ``partial_apply`` creates a closure whose invocation takes ownership
3532-
of the context, meaning that a call implicitly releases the closure. The
3533-
``[callee_guaranteed]`` change this to a caller-guaranteed model, where the
3534-
caller promises not to release the closure while the function is being called.
3535-
3536-
This instruction is used to implement both curry thunks and closures. A
3537-
curried function in Swift::
3498+
sequence of its arguments. This instruction is used to implement both curry
3499+
thunks and closures. A curried function in Swift::
35383500

35393501
func foo(_ a:A)(b:B)(c:C)(d:D) -> E { /* body of foo */ }
35403502

@@ -3607,6 +3569,54 @@ lowers to an uncurried entry point and is curried in the enclosing function::
36073569
return %ret : $Int
36083570
}
36093571

3572+
**Ownership Semantics of Closure Context during Invocation**: By default, an
3573+
escaping ``partial_apply`` (``partial_apply`` without ``[on_stack]]`` creates a
3574+
closure whose invocation takes ownership of the context, meaning that a call
3575+
implicitly releases the closure. If the ``partial_apply`` is marked with the
3576+
flag ``[callee_guaranteed]`` the invocation instead uses a caller-guaranteed
3577+
model, where the caller promises not to release the closure while the function
3578+
is being called.
3579+
3580+
**Captured Value Ownership Semantics**: In the instruction syntax, the type of
3581+
the callee is specified after the argument list; the types of the argument and
3582+
of the defined value are derived from the function type of the callee. Even so,
3583+
the ownership requirements of the partial apply are not the same as that of the
3584+
callee function (and thus said signature). Instead:
3585+
3586+
1. If the ``partial_apply`` has a ``@noescape`` function type (``partial_apply
3587+
[on_stack]``) the closure context is allocated on the stack and is
3588+
initialized to contain the closed-over values without taking ownership of
3589+
those values. The closed-over values are not retained and the lifetime of the
3590+
closed-over values must be managed by other instruction independently of the
3591+
``partial_apply``. The lifetime of the stack context of a ``partial_apply
3592+
[on_stack]`` must be terminated with a ``dealloc_stack``.
3593+
3594+
2. If the ``partial_apply`` has an escaping function type (not ``[on_stack]``)
3595+
then the closure context will be heap allocated with a retain count of 1. Any
3596+
closed over parameters (except for ``@inout`` parameters) will be consumed by
3597+
the partial_apply. This ensures that no matter when the ``partial_apply`` is
3598+
called, the captured arguments are alive. When the closure context's
3599+
reference count reaches zero, the contained values are destroyed. If the
3600+
callee requires an owned parameter, then the implicit partial_apply forwarder
3601+
created by IRGen will copy the underlying argument and pass it to the callee.
3602+
3603+
3. If an address argument has ``@inout_aliasable`` convention, the closure
3604+
obtained from ``partial_apply`` will not own its underlying value. The
3605+
``@inout_aliasable`` parameter convention is used when a ``@noescape``
3606+
closure captures an ``inout`` argument.
3607+
3608+
**NOTE:** If the callee is generic, all of its generic parameters must be bound
3609+
by the given substitution list. The arguments are given with these generic
3610+
substitutions applied, and the resulting closure is of concrete function type
3611+
with the given substitutions applied. The generic parameters themselves cannot
3612+
be partially applied; all of them must be bound. The result is always a concrete
3613+
function.
3614+
3615+
**TODO:** The instruction, when applied to a generic function, currently
3616+
implicitly performs abstraction difference transformations enabled by the given
3617+
substitutions, such as promoting address-only arguments and returns to register
3618+
arguments. This should be fixed.
3619+
36103620
builtin
36113621
```````
36123622
::

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ SWIFT_TYPEID_NAMED(SourceFile *, SourceFile)
5353
SWIFT_TYPEID_NAMED(TypeAliasDecl *, TypeAliasDecl)
5454
SWIFT_TYPEID_NAMED(ValueDecl *, ValueDecl)
5555
SWIFT_TYPEID_NAMED(VarDecl *, VarDecl)
56+
SWIFT_TYPEID(FingerprintAndMembers)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct TypePair;
6161
struct TypeWitnessAndDecl;
6262
enum class AncestryFlags : uint8_t;
6363
enum class ImplicitMemberAction : uint8_t;
64+
struct FingerprintAndMembers;
6465

6566
// Define the AST type zone (zone 1)
6667
#define SWIFT_TYPEID_ZONE AST

include/swift/AST/DeclContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,12 @@ class IterableDeclContext {
802802
// Some Decls are IterableDeclContexts, but not all.
803803
static bool classof(const Decl *D);
804804

805+
/// Return a hash of all tokens in the body for dependency analysis, if
806+
/// available.
807+
Optional<std::string> getBodyFingerprint() const;
808+
809+
bool areDependenciesUsingTokenHashesForTypeBodies() const;
810+
805811
private:
806812
/// Add a member to the list for iteration purposes, but do not notify the
807813
/// subclass that we have done so.

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ ERROR(error_unknown_arg,none,
9494
"unknown argument: '%0'", (StringRef))
9595
ERROR(error_invalid_arg_value,none,
9696
"invalid value '%1' in '%0'", (StringRef, StringRef))
97+
WARNING(warning_type_fingerprints_require_fine_grained_dependencies,none,
98+
"Type fingerprints require fine-grained dependencies", ())
9799
WARNING(warning_cannot_multithread_batch_mode,none,
98100
"ignoring -num-threads argument; cannot multithread batch mode", ())
99101
ERROR(error_unsupported_option_argument,none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ ERROR(cannot_convert_initializer_value,none,
338338
"cannot convert value of type %0 to specified type %1", (Type,Type))
339339
ERROR(cannot_convert_initializer_value_protocol,none,
340340
"value of type %0 does not conform to specified type %1", (Type,Type))
341+
ERROR(cannot_convert_initializer_value_anyobject,none,
342+
"value of type %0 expected to be instance of class or "
343+
"class-constrained type",
344+
(Type, Type))
341345
ERROR(cannot_convert_initializer_value_nil,none,
342346
"'nil' cannot initialize specified type %0", (Type))
343347

@@ -346,6 +350,10 @@ ERROR(cannot_convert_to_return_type,none,
346350
(Type,Type))
347351
ERROR(cannot_convert_to_return_type_protocol,none,
348352
"return expression of type %0 does not conform to %1", (Type,Type))
353+
ERROR(cannot_convert_return_type_to_anyobject,none,
354+
"return expression of type %0 expected to be an instance of "
355+
"a class or class-constrained type",
356+
(Type, Type))
349357
ERROR(cannot_convert_to_return_type_nil,none,
350358
"'nil' is incompatible with return type %0", (Type))
351359

@@ -440,7 +448,10 @@ NOTE(candidate_performs_illegal_ephemeral_conv,none,
440448

441449
ERROR(cannot_convert_argument_value_protocol,none,
442450
"argument type %0 does not conform to expected type %1", (Type, Type))
443-
451+
ERROR(cannot_convert_argument_value_anyobject,none,
452+
"argument type %0 expected to be an instance of "
453+
"a class or class-constrained type",
454+
(Type, Type))
444455
ERROR(cannot_convert_argument_value_nil,none,
445456
"'nil' is not compatible with expected argument type %0", (Type))
446457

@@ -536,6 +547,10 @@ NOTE(assign_protocol_conformance_fix_it,none,
536547
ERROR(cannot_convert_assign_protocol,none,
537548
"value of type %0 does not conform to %1 in assignment",
538549
(Type, Type))
550+
ERROR(cannot_convert_assign_anyobject,none,
551+
"value of type %0 expected to be an instance of "
552+
"a class or class-constrained type in assignment",
553+
(Type, Type))
539554
ERROR(cannot_convert_assign_nil,none,
540555
"'nil' cannot be assigned to type %0", (Type))
541556

include/swift/AST/FineGrainedDependencies.h

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/Basic/Debug.h"
1717
#include "swift/Basic/LLVM.h"
18+
#include "swift/Basic/NullablePtr.h"
1819
#include "swift/Basic/Range.h"
1920
#include "llvm/ADT/Hashing.h"
2021
#include "llvm/Support/MD5.h"
@@ -139,6 +140,11 @@ template <typename Key1, typename Key2, typename Value> class TwoStageMap {
139140
return iter2 == iter->second.end() ? None : Optional<Value>(iter2->second);
140141
}
141142

143+
NullablePtr<const InnerMap> find(const Key1 &k1) const {
144+
auto iter = map.find(k1);
145+
return iter == map.end() ? nullptr : &iter->second;
146+
}
147+
142148
/// The sought value must be present.
143149
Value findAndErase(const Key1 &k1, const Key2 &k2) {
144150
auto &submap = map[k1];
@@ -237,6 +243,20 @@ class BiIndexedTwoStageMap {
237243
}
238244
Optional<Value> find(const Key2 &k2, Key1 &k1) const { return find(k1, k2); }
239245

246+
/// Return the submap for a given Key1. May create one, after the fashion of
247+
/// the standard libary.
248+
const Key2Map &operator[](const Key1 &k1) { return map1[k1]; }
249+
/// Return the submap for a given Key2. May create one, after the fashion of
250+
/// the standard libary.
251+
const Key1Map &operator[](const Key2 &k2) { return map2[k2]; }
252+
253+
NullablePtr<const Key2Map> find(const Key1 &k1) const {
254+
return map1.find(k1);
255+
}
256+
NullablePtr<const Key1Map> find(const Key2 &k2) const {
257+
return map2.find(k2);
258+
}
259+
240260
/// Element must be present.
241261
/// Return the erased value.
242262
Value findAndErase(const Key1 &k1, const Key2 &k2) {
@@ -250,12 +270,6 @@ class BiIndexedTwoStageMap {
250270
Value findAndErase(const Key2 &k2, const Key1 &k1) {
251271
return findAndErase(k1, k2);
252272
}
253-
/// Return the submap for a given Key1. May create one, after the fashion of
254-
/// the standard libary.
255-
const Key2Map &operator[](const Key1 &k1) { return map1[k1]; }
256-
/// Return the submap for a given Key2. May create one, after the fashion of
257-
/// the standard libary.
258-
const Key1Map &operator[](const Key2 &k2) { return map2[k2]; }
259273

260274
/// Invoke \p fn on each Key2 and Value matching (\p k1, *)
261275
void forEachValueMatching(
@@ -500,8 +514,7 @@ class DependencyKey {
500514
template <NodeKind kind>
501515
static DependencyKey createDependedUponKey(StringRef);
502516

503-
static DependencyKey
504-
createTransitiveKeyForWholeSourceFile(StringRef swiftDeps);
517+
static DependencyKey createKeyForWholeSourceFile(StringRef swiftDeps);
505518

506519
std::string humanReadableName() const;
507520

@@ -786,6 +799,13 @@ class SourceFileDepGraph {
786799
compoundNamesByRDK);
787800

788801
static constexpr char noncascadingOrPrivatePrefix = '#';
802+
static constexpr char nameFingerprintSeparator = ',';
803+
804+
static std::string noncascading(std::string name);
805+
806+
LLVM_ATTRIBUTE_UNUSED
807+
static std::string privatize(std::string name);
808+
789809

790810
/// Nodes are owned by the graph.
791811
~SourceFileDepGraph() {

include/swift/AST/ParseRequests.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,31 @@ template<typename Request>
2727
void reportEvaluatedRequest(UnifiedStatsReporter &stats,
2828
const Request &request);
2929

30+
struct FingerprintAndMembers {
31+
Optional<std::string> fingerprint = None;
32+
ArrayRef<Decl *> members = {};
33+
bool operator==(const FingerprintAndMembers &x) const {
34+
return fingerprint == x.fingerprint && members == x.members;
35+
}
36+
};
37+
38+
void simple_display(llvm::raw_ostream &out, const FingerprintAndMembers &value);
39+
3040
/// Parse the members of a nominal type declaration or extension.
31-
class ParseMembersRequest :
32-
public SimpleRequest<ParseMembersRequest,
33-
ArrayRef<Decl *>(IterableDeclContext *),
34-
CacheKind::Cached>
35-
{
41+
/// Return a fingerprint and the members.
42+
class ParseMembersRequest
43+
: public SimpleRequest<ParseMembersRequest,
44+
FingerprintAndMembers(IterableDeclContext *),
45+
CacheKind::Cached> {
3646
public:
3747
using SimpleRequest::SimpleRequest;
3848

3949
private:
4050
friend SimpleRequest;
4151

4252
// Evaluation.
43-
ArrayRef<Decl *> evaluate(Evaluator &evaluator,
44-
IterableDeclContext *idc) const;
53+
FingerprintAndMembers evaluate(Evaluator &evaluator,
54+
IterableDeclContext *idc) const;
4555

4656
public:
4757
// Caching

0 commit comments

Comments
 (0)