Skip to content

Commit c64b8b9

Browse files
Merge pull request #3806 from swiftwasm/katei/merge-main-2021-10-29
Merge main 2021-10-29
2 parents 211f95a + 2424048 commit c64b8b9

File tree

186 files changed

+4908
-1171
lines changed

Some content is hidden

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

186 files changed

+4908
-1171
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ function(add_libswift name)
732732
733733
set(libswift_compile_options
734734
"-Xfrontend" "-validate-tbd-against-ir=none"
735-
"-Xfrontend" "-enable-cxx-interop")
735+
"-Xfrontend" "-enable-cxx-interop"
736+
"-Xcc" "-UIBOutlet" "-Xcc" "-UIBAction" "-Xcc" "-UIBInspectable")
736737
737738
if(CMAKE_BUILD_TYPE STREQUAL Debug)
738739
list(APPEND libswift_compile_options "-g")

cmake/modules/SwiftWindowsSupport.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ endfunction()
8181
# NOTE(compnerd) we use a macro here as this modifies global variables
8282
macro(swift_swap_compiler_if_needed target)
8383
if(NOT CMAKE_C_COMPILER_ID MATCHES Clang)
84-
if(CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
84+
if(CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME AND CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR)
8585
if(SWIFT_BUILT_STANDALONE)
8686
get_target_property(CLANG_LOCATION clang LOCATION)
8787
get_filename_component(CLANG_LOCATION ${CLANG_LOCATION} DIRECTORY)

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,3 +620,8 @@ within Swift 5 code that has adopted concurrency, but non-`@MainActor`
620620

621621
See the forum post on [Concurrency in Swift 5 and 6](https://forums.swift.org/t/concurrency-in-swift-5-and-6/49337)
622622
for more details.
623+
624+
## `@_noImplicitCopy`
625+
626+
Marks a var decl as a variable that must be copied explicitly using the builtin
627+
function Builtin.copy.

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,12 @@ class SDKNodeDecl: public SDKNode {
360360
Optional<uint8_t> FixedBinaryOrder;
361361
PlatformIntroVersion introVersions;
362362
StringRef ObjCName;
363-
mutable Optional<StringRef> demangledName;
363+
364364
protected:
365365
SDKNodeDecl(SDKNodeInitInfo Info, SDKNodeKind Kind);
366366
virtual ~SDKNodeDecl() = default;
367367
public:
368368
StringRef getUsr() const { return Usr; }
369-
StringRef getDemangledName() const;
370369
StringRef getLocation() const { return Location; }
371370
StringRef getModuleName() const {return ModuleName;}
372371
StringRef getHeaderName() const;

include/swift/AST/Attr.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,13 @@ DECL_ATTR(_nonSendable, NonSendable,
672672
APIStableToAdd | APIBreakingToRemove,
673673
121)
674674

675+
SIMPLE_DECL_ATTR(_noImplicitCopy, NoImplicitCopy,
676+
UserInaccessible |
677+
ABIStableToAdd | ABIBreakingToRemove |
678+
APIStableToAdd | APIBreakingToRemove |
679+
OnVar,
680+
122)
681+
675682
// If you're adding a new underscored attribute here, please document it in
676683
// docs/ReferenceGuides/UnderscoredAttributes.md.
677684

include/swift/AST/Builtins.def

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,6 @@ BUILTIN_SIL_OPERATION(WithUnsafeThrowingContinuation, "withUnsafeThrowingContinu
515515
/// Force the current task to be rescheduled on the specified actor.
516516
BUILTIN_SIL_OPERATION(HopToActor, "hopToActor", None)
517517

518-
/// Generate a move_value instruction to convert a T to a @_moveOnly T.
519-
BUILTIN_SIL_OPERATION(Move, "move", Special)
520-
521518
#undef BUILTIN_SIL_OPERATION
522519

523520
// BUILTIN_RUNTIME_CALL - A call into a runtime function.
@@ -603,6 +600,29 @@ BUILTIN_MISC_OPERATION(AllocRaw, "allocRaw", "", Special)
603600
/// was allocated.
604601
BUILTIN_MISC_OPERATION(DeallocRaw, "deallocRaw", "", Special)
605602

603+
/// StackAlloc has type (Int, Int, Int) -> Builtin.RawPointer
604+
///
605+
/// Parameters: capacity, stride, alignment
606+
///
607+
/// The resulting pointer comes from the stack (as in the non-standard C
608+
/// extension `alloca()`.) It is at least as aligned as specified and is valid
609+
/// until the end of the calling scope.
610+
///
611+
/// The count and stride are multiplied together to get the byte count to use
612+
/// for the allocation.
613+
///
614+
/// The passed alignment must be a positive power of two. If the alignment value
615+
/// is not known at compile time, MaximumAlignment is assumed.
616+
BUILTIN_MISC_OPERATION(StackAlloc, "stackAlloc", "", Special)
617+
618+
/// StackDealloc has type (Builtin.RawPointer) -> ()
619+
///
620+
/// Parameters: address.
621+
///
622+
/// The range starting at `address`, previously allocated with
623+
/// Builtin.stackAlloc(), is deallocated from the stack.
624+
BUILTIN_MISC_OPERATION(StackDealloc, "stackDealloc", "", Special)
625+
606626
/// Fence has type () -> ().
607627
BUILTIN_MISC_OPERATION(Fence, "fence", "", None)
608628

@@ -757,6 +777,19 @@ BUILTIN_MISC_OPERATION(CreateTaskGroup,
757777
BUILTIN_MISC_OPERATION(DestroyTaskGroup,
758778
"destroyTaskGroup", "", Special)
759779

780+
781+
/// A builtin that can only be called from a transparent generic function. Takes
782+
/// two operands, the first operand the result address, the second operand the
783+
/// input address. Transforms into load [take] + move_value + store [init] when
784+
/// transparently inlined into a caller that has the generic of the callee
785+
/// specialized into a loadable type. If the transparent inlining does not
786+
/// specialize the type (due to being inlined into a non-generic context, the
787+
/// SILVerifier will abort).
788+
///
789+
/// Illegal to call except for in Swift._move in the stdlib. This is enforced by
790+
/// the SILVerifier.
791+
BUILTIN_MISC_OPERATION(Move, "move", "", Special)
792+
760793
// BUILTIN_MISC_OPERATION_WITH_SILGEN - Miscellaneous operations that are
761794
// specially emitted during SIL generation.
762795
//

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ ERROR(error_mode_cannot_emit_module_semantic_info,none,
136136
ERROR(cannot_emit_ir_skipping_function_bodies,none,
137137
"the -experimental-skip-*-function-bodies* flags do not support "
138138
"emitting IR", ())
139+
ERROR(cannot_emit_ir_checking_api_availability_only,none,
140+
"the flag -check-api-availability-only does not support "
141+
"emitting IR", ())
139142

140143
WARNING(emit_reference_dependencies_without_primary_file,none,
141144
"ignoring -emit-reference-dependencies (requires -primary-file)", ())

include/swift/AST/DiagnosticsIRGen.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,14 @@ ERROR(alignment_more_than_maximum,none,
5050
"@_alignment cannot increase alignment above maximum alignment of %0",
5151
(unsigned))
5252

53+
ERROR(temporary_allocation_size_negative,none,
54+
"allocation capacity must be greater than or equal to zero", ())
55+
ERROR(temporary_allocation_size_overflow,none,
56+
"allocation byte count too large", ())
57+
ERROR(temporary_allocation_alignment_not_positive,none,
58+
"alignment value must be greater than zero", ())
59+
ERROR(temporary_allocation_alignment_not_power_of_2,none,
60+
"alignment value must be a power of two", ())
61+
5362
#define UNDEFINE_DIAGNOSTIC_MACROS
5463
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsSIL.def

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,5 +686,20 @@ NOTE(capturepromotion_concurrentcapture_capturinguse_here, none,
686686
NOTE(capturepromotion_variable_defined_here,none,
687687
"variable defined here", ())
688688

689+
// move operator used on generic or evalue
690+
ERROR(move_operator_used_on_generic_or_existential_value, none,
691+
"move() used on a generic or existential value", ())
692+
693+
// noimplicitcopy on generic or existential binding
694+
ERROR(noimplicitcopy_used_on_generic_or_existential, none,
695+
"@_noImplicitCopy can not be used on a generic or existential typed "
696+
"binding or a nominal type containing such typed things", ())
697+
698+
// move only checker diagnostics
699+
ERROR(sil_moveonlychecker_value_consumed_more_than_once, none,
700+
"'%0' consumed more than once", (StringRef))
701+
NOTE(sil_moveonlychecker_consuming_use_here, none,
702+
"consuming use", ())
703+
689704
#define UNDEFINE_DIAGNOSTIC_MACROS
690705
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsSema.def

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,11 @@ NOTE(associated_type_witness_conform_impossible,none,
22632263
"candidate can not infer %0 = %1 because %1 "
22642264
"is not a nominal type and so can't conform to %2",
22652265
(Identifier, Type, Type))
2266+
NOTE(suggest_opaque_type_witness,none,
2267+
"cannot infer %0 = %1 because %1 as a type cannot "
2268+
"conform to protocols; did you mean to use an opaque "
2269+
"result type?",
2270+
(Identifier, Type, Type))
22662271
NOTE(associated_type_witness_inherit_impossible,none,
22672272
"candidate can not infer %0 = %1 because %1 "
22682273
"is not a class type and so can't inherit from %2",
@@ -6029,5 +6034,16 @@ ERROR(wrap_invalid_attr_added_by_access_note, none,
60296034

60306035
#undef WHICH_ACCESS_NOTE
60316036

6037+
// Move Only diagnostics
6038+
6039+
ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
6040+
none, "Can not use feature when experimental move only is disabled! Pass"
6041+
" the frontend flag -enable-experimental-move-only to swift to enable "
6042+
"the usage of this language feature", ())
6043+
ERROR(noimplicitcopy_attr_valid_only_on_local_let,
6044+
none, "'@_noImplicitCopy' attribute can only be applied to local lets", ())
6045+
ERROR(noimplicitcopy_attr_invalid_in_generic_context,
6046+
none, "'@_noImplicitCopy' attribute cannot be applied to entities in generic contexts", ())
6047+
60326048
#define UNDEFINE_DIAGNOSTIC_MACROS
60336049
#include "DefineDiagnosticMacros.h"

include/swift/AST/SemanticAttrs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,7 @@ SEMANTICS_ATTR(FORCE_EMIT_OPT_REMARK_PREFIX, "optremark")
113113
/// for testing purposes.
114114
SEMANTICS_ATTR(OBJC_FORBID_ASSOCIATED_OBJECTS, "objc.forbidAssociatedObjects")
115115

116+
SEMANTICS_ATTR(LIFETIMEMANAGEMENT_MOVE, "lifetimemanagement.move")
117+
116118
#undef SEMANTICS_ATTR
117119

include/swift/AST/Type.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,6 @@ class Type {
317317
LookupConformanceFn conformances,
318318
SubstOptions options=None) const;
319319

320-
/// Replace references to substitutable types with error types.
321-
Type substDependentTypesWithErrorTypes() const;
322-
323320
bool isPrivateStdlibType(bool treatNonBuiltinProtocolsAsPublic = true) const;
324321

325322
SWIFT_DEBUG_DUMP;

include/swift/AST/USRGeneration.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ bool printExtensionUSR(const ExtensionDecl *ED, raw_ostream &OS);
6363
/// \returns true if it failed, false on success.
6464
bool printDeclUSR(const Decl *D, raw_ostream &OS);
6565

66-
/// Get mangled name from a USR.
67-
std::string getMangledNameFromUSR(StringRef usr);
68-
69-
/// Demangle a mangled name to a human readable name.
70-
std::string demangleMangledName(StringRef mangled);
66+
/// Demangle a mangle-name-based USR to a human readable name.
67+
std::string demangleUSR(StringRef mangled);
7168

7269
} // namespace ide
7370
} // namespace swift

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ LANGUAGE_FEATURE(ImplicitSelfCapture, 0, "@_implicitSelfCapture attribute", true
5454
LANGUAGE_FEATURE(BuiltinBuildExecutor, 0, "Executor-building builtins", true)
5555
LANGUAGE_FEATURE(BuiltinBuildMainExecutor, 0, "MainActor executor building builtin", true)
5656
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroup, 0, "MainActor executor building builtin", true)
57+
LANGUAGE_FEATURE(BuiltinMove, 0, "Builtin.move()", true)
5758

5859
#undef LANGUAGE_FEATURE

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ namespace swift {
320320
/// Enable experimental 'distributed' actors and functions.
321321
bool EnableExperimentalDistributed = false;
322322

323+
/// Enable experimental 'move only' features.
324+
bool EnableExperimentalMoveOnly = false;
325+
323326
/// Disable the implicit import of the _Concurrency module.
324327
bool DisableImplicitConcurrencyModuleImport =
325328
!SWIFT_IMPLICIT_CONCURRENCY_IMPORT;

include/swift/Demangling/Demangle.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#define SWIFT_DEMANGLING_DEMANGLE_H
2121

2222
#include "swift/Demangling/NamespaceMacros.h"
23-
#include "swift/Runtime/Config.h"
2423
#include "llvm/ADT/StringRef.h"
24+
#include "llvm/Support/Compiler.h"
2525
#include <cassert>
2626
#include <cstdint>
2727
#include <memory>
@@ -514,7 +514,7 @@ enum class OperatorKind {
514514
};
515515

516516
/// A mangling error, which consists of an error code and a Node pointer
517-
struct SWIFT_NODISCARD ManglingError {
517+
struct LLVM_NODISCARD ManglingError {
518518
enum Code {
519519
Success = 0,
520520
AssertionFailed,
@@ -556,7 +556,7 @@ struct SWIFT_NODISCARD ManglingError {
556556

557557
/// Used as a return type for mangling functions that may fail
558558
template <typename T>
559-
class SWIFT_NODISCARD ManglingErrorOr {
559+
class LLVM_NODISCARD ManglingErrorOr {
560560
private:
561561
ManglingError err_;
562562
T value_;

include/swift/Demangling/TypeLookupError.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ static TypeLookupError TypeLookupErrorImpl(const char *fmt, Args... args) {
209209
char *str;
210210
#pragma clang diagnostic push
211211
#pragma clang diagnostic ignored "-Wformat-security"
212+
#pragma clang diagnostic ignored "-Wformat-nonliteral"
212213
swift_asprintf(&str, fmt, args...);
213214
#pragma clang diagnostic pop
214215
return str;

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ def enable_experimental_lexical_lifetimes :
259259
Flag<["-"], "enable-experimental-lexical-lifetimes">,
260260
HelpText<"Enable experimental lexical lifetimes">;
261261

262+
def enable_experimental_move_only :
263+
Flag<["-"], "enable-experimental-move-only">,
264+
HelpText<"Enable experimental move only">;
265+
262266
def enable_experimental_distributed :
263267
Flag<["-"], "enable-experimental-distributed">,
264268
HelpText<"Enable experimental 'distributed' actors and functions">;
@@ -469,10 +473,6 @@ def disable_availability_checking : Flag<["-"],
469473
"disable-availability-checking">,
470474
HelpText<"Disable checking for potentially unavailable APIs">;
471475

472-
def check_api_availability_only : Flag<["-"],
473-
"check-api-availability-only">,
474-
HelpText<"Only check the availability of the APIs, ignore function bodies">;
475-
476476
def enable_conformance_availability_errors : Flag<["-"],
477477
"enable-conformance-availability-errors">,
478478
HelpText<"Diagnose conformance availability violations as errors">;

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ def define_availability : Separate<["-"], "define-availability">,
422422
HelpText<"Define an availability macro in the format 'macroName : iOS 13.0, macOS 10.15'">,
423423
MetaVarName<"<macro>">;
424424

425+
def check_api_availability_only : Flag<["-"], "check-api-availability-only">,
426+
Flags<[HelpHidden, FrontendOption, NoInteractiveOption]>,
427+
HelpText<"Only check the availability of the APIs, ignore function bodies">;
428+
425429
def library_level : Separate<["-"], "library-level">,
426430
MetaVarName<"<level>">,
427431
Flags<[HelpHidden, FrontendOption, ModuleInterfaceOption]>,

include/swift/Runtime/Config.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@ extern uintptr_t __COMPATIBILITY_LIBRARIES_CANNOT_CHECK_THE_IS_SWIFT_BIT_DIRECTL
226226
// so changing this value is not sufficient.
227227
#define SWIFT_DEFAULT_LLVM_CC llvm::CallingConv::C
228228

229+
// SWIFT_FORMAT(fmt,first) marks a function as taking a format string argument
230+
// at argument `fmt`, with the first argument for the format string as `first`.
231+
#if __has_attribute(format)
232+
#define SWIFT_FORMAT(fmt,first) __attribute__((format(printf, fmt, first)))
233+
#else
234+
#define SWIFT_FORMAT(fmt,first)
235+
#endif
236+
237+
// SWIFT_VFORMAT(fmt) marks a function as taking a format string argument at
238+
// argument `fmt`, with the arguments in a `va_list`.
239+
#if __has_attribute(format)
240+
#define SWIFT_VFORMAT(fmt) __attribute__((format(printf, fmt, 0)))
241+
#else
242+
#define SWIFT_VFORMAT(fmt)
243+
#endif
244+
229245
// Pointer authentication.
230246
#if __has_feature(ptrauth_calls)
231247
#define SWIFT_PTRAUTH 1

include/swift/Runtime/Debug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,18 @@ static inline void crash(const char *message) {
8585
// swift::fatalError() halts with a crash log message,
8686
// but makes no attempt to preserve register state.
8787
SWIFT_RUNTIME_ATTRIBUTE_NORETURN
88+
SWIFT_FORMAT(2, 3)
8889
extern void
8990
fatalError(uint32_t flags, const char *format, ...);
9091

9192
/// swift::warning() emits a warning from the runtime.
9293
extern void
94+
SWIFT_VFORMAT(2)
9395
warningv(uint32_t flags, const char *format, va_list args);
9496

9597
/// swift::warning() emits a warning from the runtime.
9698
extern void
99+
SWIFT_FORMAT(2, 3)
97100
warning(uint32_t flags, const char *format, ...);
98101

99102
// swift_dynamicCastFailure halts using fatalError()

include/swift/SIL/DebugUtils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ inline SILInstruction *getSingleNonDebugUser(SILValue V) {
174174
return I->getUser();
175175
}
176176

177+
/// If \p value has a single debug user, return the operand associated with that
178+
/// use. Otherwise, returns nullptr.
179+
inline Operand *getSingleDebugUse(SILValue value) {
180+
auto range = getDebugUses(value);
181+
auto ii = range.begin(), ie = range.end();
182+
if (ii == ie)
183+
return nullptr;
184+
if (std::next(ii) != ie)
185+
return nullptr;
186+
return *ii;
187+
}
188+
177189
/// Erases the instruction \p I from it's parent block and deletes it, including
178190
/// all debug instructions which use \p I.
179191
/// Precondition: The instruction may only have debug instructions as uses.

include/swift/SIL/MemAccessUtils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ SILValue findReferenceRoot(SILValue ref);
204204
/// Find the first owned root of the reference.
205205
SILValue findOwnershipReferenceRoot(SILValue ref);
206206

207+
/// Look through all ownership forwarding instructions to find the values which
208+
/// were originally borrowed.
209+
void findGuaranteedReferenceRoots(SILValue value,
210+
SmallVectorImpl<SILValue> &roots);
211+
207212
/// Find the aggregate containing the first owned root of the
208213
/// reference. Identical to findOwnershipReferenceRoot, but looks through
209214
/// struct_extract, tuple_extract, etc.

include/swift/SIL/SILType.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,9 @@ class SILType {
620620
/// Get the SIL token type.
621621
static SILType getSILTokenType(const ASTContext &C);
622622

623+
/// Return '()'
624+
static SILType getEmptyTupleType(const ASTContext &C);
625+
623626
//
624627
// Utilities for treating SILType as a pointer-like type.
625628
//

0 commit comments

Comments
 (0)