Skip to content

Commit 4b6b3bf

Browse files
authored
Merge pull request #1904 from swiftwasm/main
[pull] swiftwasm from main
2 parents 1734144 + f190342 commit 4b6b3bf

File tree

86 files changed

+4793
-282
lines changed

Some content is hidden

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

86 files changed

+4793
-282
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,9 @@ macro(add_swift_tool_symlink name dest component)
632632
add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
633633
llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE COMPONENT ${component})
634634
endmacro()
635+
636+
# Declare that files in this library are built with LLVM's support
637+
# libraries available.
638+
macro(set_swift_llvm_is_available)
639+
add_compile_options(-DSWIFT_LLVM_SUPPORT_IS_AVAILABLE)
640+
endmacro()

include/swift/ABI/Metadata.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include "swift/Basic/RelativePointer.h"
3939
#include "swift/Demangling/Demangle.h"
4040
#include "swift/Demangling/ManglingMacros.h"
41-
#include "swift/Runtime/Unreachable.h"
41+
#include "swift/Basic/Unreachable.h"
4242
#include "../../../stdlib/public/SwiftShims/HeapObject.h"
4343
#if SWIFT_OBJC_INTEROP
4444
#include <objc/runtime.h>
@@ -4664,7 +4664,7 @@ int32_t TargetTypeContextDescriptor<Runtime>::getGenericArgumentOffset() const {
46644664
return llvm::cast<TargetStructDescriptor<Runtime>>(this)
46654665
->getGenericArgumentOffset();
46664666
default:
4667-
swift_runtime_unreachable("Not a type context descriptor.");
4667+
swift_unreachable("Not a type context descriptor.");
46684668
}
46694669
}
46704670

@@ -4682,7 +4682,7 @@ TargetTypeContextDescriptor<Runtime>::getFullGenericContextHeader() const {
46824682
return llvm::cast<TargetStructDescriptor<Runtime>>(this)
46834683
->getFullGenericContextHeader();
46844684
default:
4685-
swift_runtime_unreachable("Not a type context descriptor.");
4685+
swift_unreachable("Not a type context descriptor.");
46864686
}
46874687
}
46884688

@@ -4699,7 +4699,7 @@ TargetTypeContextDescriptor<Runtime>::getGenericParams() const {
46994699
case ContextDescriptorKind::OpaqueType:
47004700
return llvm::cast<TargetOpaqueTypeDescriptor<Runtime>>(this)->getGenericParams();
47014701
default:
4702-
swift_runtime_unreachable("Not a type context descriptor.");
4702+
swift_unreachable("Not a type context descriptor.");
47034703
}
47044704
}
47054705

@@ -4717,7 +4717,7 @@ TargetTypeContextDescriptor<Runtime>::getForeignMetadataInitialization() const {
47174717
return llvm::cast<TargetStructDescriptor<Runtime>>(this)
47184718
->getForeignMetadataInitialization();
47194719
default:
4720-
swift_runtime_unreachable("Not a type context descriptor.");
4720+
swift_unreachable("Not a type context descriptor.");
47214721
}
47224722
}
47234723

@@ -4735,7 +4735,7 @@ TargetTypeContextDescriptor<Runtime>::getSingletonMetadataInitialization() const
47354735
return llvm::cast<TargetClassDescriptor<Runtime>>(this)
47364736
->getSingletonMetadataInitialization();
47374737
default:
4738-
swift_runtime_unreachable("Not a enum, struct or class type descriptor.");
4738+
swift_unreachable("Not a enum, struct or class type descriptor.");
47394739
}
47404740
}
47414741

@@ -4753,7 +4753,7 @@ TargetTypeContextDescriptor<Runtime>::getCanonicicalMetadataPrespecializations()
47534753
return llvm::cast<TargetClassDescriptor<Runtime>>(this)
47544754
->getCanonicicalMetadataPrespecializations();
47554755
default:
4756-
swift_runtime_unreachable("Not a type context descriptor.");
4756+
swift_unreachable("Not a type context descriptor.");
47574757
}
47584758
}
47594759

include/swift/ABI/MetadataValues.h

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#define SWIFT_ABI_METADATAVALUES_H
2121

2222
#include "swift/ABI/KeyPath.h"
23+
#include "swift/ABI/ProtocolDispatchStrategy.h"
2324
#include "swift/AST/Ownership.h"
2425
#include "swift/Basic/LLVM.h"
2526
#include "swift/Basic/FlagSet.h"
26-
#include "swift/Runtime/Unreachable.h"
2727

2828
#include <stdlib.h>
2929
#include <stdint.h>
@@ -410,20 +410,6 @@ enum class SpecialProtocol: uint8_t {
410410
Error = 1,
411411
};
412412

413-
/// Identifiers for protocol method dispatch strategies.
414-
enum class ProtocolDispatchStrategy: uint8_t {
415-
/// Uses ObjC method dispatch.
416-
///
417-
/// This must be 0 for ABI compatibility with Objective-C protocol_t records.
418-
ObjC = 0,
419-
420-
/// Uses Swift protocol witness table dispatch.
421-
///
422-
/// To invoke methods of this protocol, a pointer to a protocol witness table
423-
/// corresponding to the protocol conformance must be available.
424-
Swift = 1,
425-
};
426-
427413
/// Flags for protocol descriptors.
428414
class ProtocolDescriptorFlags {
429415
typedef uint32_t int_type;
@@ -486,18 +472,7 @@ class ProtocolDescriptorFlags {
486472

487473
/// Does the protocol require a witness table for method dispatch?
488474
bool needsWitnessTable() const {
489-
return needsWitnessTable(getDispatchStrategy());
490-
}
491-
492-
static bool needsWitnessTable(ProtocolDispatchStrategy strategy) {
493-
switch (strategy) {
494-
case ProtocolDispatchStrategy::ObjC:
495-
return false;
496-
case ProtocolDispatchStrategy::Swift:
497-
return true;
498-
}
499-
500-
swift_runtime_unreachable("Unhandled ProtocolDispatchStrategy in switch.");
475+
return swift::protocolRequiresWitnessTable(getDispatchStrategy());
501476
}
502477

503478
/// Return the identifier if this is a special runtime-known protocol.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===--- ProtocolDispatchStrategy.h - ---------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This header declares the ProtocolDispatchStrategy enum and some
14+
// related operations. It's split out because we would otherwise need
15+
// to include MetadataValues.h in some relatively central headers.s
16+
//
17+
//===----------------------------------------------------------------------===//
18+
19+
#ifndef SWIFT_ABI_PROTOCOLDISPATCHSTRATEGY_H
20+
#define SWIFT_ABI_PROTOCOLDISPATCHSTRATEGY_H
21+
22+
#include "swift/Basic/Unreachable.h"
23+
24+
namespace swift {
25+
26+
/// Identifiers for protocol method dispatch strategies.
27+
enum class ProtocolDispatchStrategy: uint8_t {
28+
/// Uses ObjC method dispatch.
29+
///
30+
/// This must be 0 for ABI compatibility with Objective-C protocol_t records.
31+
ObjC = 0,
32+
33+
/// Uses Swift protocol witness table dispatch.
34+
///
35+
/// To invoke methods of this protocol, a pointer to a protocol witness table
36+
/// corresponding to the protocol conformance must be available.
37+
Swift = 1,
38+
};
39+
40+
/// Does a protocol using the given strategy require a witness table?
41+
inline bool protocolRequiresWitnessTable(ProtocolDispatchStrategy strategy) {
42+
switch (strategy) {
43+
case ProtocolDispatchStrategy::ObjC:
44+
return false;
45+
case ProtocolDispatchStrategy::Swift:
46+
return true;
47+
}
48+
49+
swift_unreachable("Unhandled ProtocolDispatchStrategy in switch.");
50+
}
51+
52+
}
53+
54+
#endif

include/swift/AST/ASTScope.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,10 +1023,8 @@ class AbstractPatternEntryScope : public ASTScopeImpl {
10231023
public:
10241024
PatternBindingDecl *const decl;
10251025
const unsigned patternEntryIndex;
1026-
const bool isLocalBinding;
10271026

1028-
AbstractPatternEntryScope(PatternBindingDecl *, unsigned entryIndex,
1029-
bool);
1027+
AbstractPatternEntryScope(PatternBindingDecl *, unsigned entryIndex);
10301028
virtual ~AbstractPatternEntryScope() {}
10311029

10321030
const PatternBindingEntry &getPatternEntry() const;
@@ -1041,10 +1039,14 @@ class AbstractPatternEntryScope : public ASTScopeImpl {
10411039
};
10421040

10431041
class PatternEntryDeclScope final : public AbstractPatternEntryScope {
1042+
const bool isLocalBinding;
1043+
Optional<SourceLoc> endLoc;
1044+
10441045
public:
10451046
PatternEntryDeclScope(PatternBindingDecl *pbDecl, unsigned entryIndex,
1046-
bool isLocalBinding)
1047-
: AbstractPatternEntryScope(pbDecl, entryIndex, isLocalBinding) {}
1047+
bool isLocalBinding, Optional<SourceLoc> endLoc)
1048+
: AbstractPatternEntryScope(pbDecl, entryIndex),
1049+
isLocalBinding(isLocalBinding), endLoc(endLoc) {}
10481050
virtual ~PatternEntryDeclScope() {}
10491051

10501052
protected:
@@ -1070,9 +1072,8 @@ class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
10701072
Expr *initAsWrittenWhenCreated;
10711073

10721074
public:
1073-
PatternEntryInitializerScope(PatternBindingDecl *pbDecl, unsigned entryIndex,
1074-
bool isLocalBinding)
1075-
: AbstractPatternEntryScope(pbDecl, entryIndex, isLocalBinding),
1075+
PatternEntryInitializerScope(PatternBindingDecl *pbDecl, unsigned entryIndex)
1076+
: AbstractPatternEntryScope(pbDecl, entryIndex),
10761077
initAsWrittenWhenCreated(pbDecl->getOriginalInit(entryIndex)) {}
10771078
virtual ~PatternEntryInitializerScope() {}
10781079

@@ -1400,7 +1401,8 @@ class WhileStmtScope final : public LabeledConditionalStmtScope {
14001401
class GuardStmtScope final : public LabeledConditionalStmtScope {
14011402
public:
14021403
GuardStmt *const stmt;
1403-
GuardStmtScope(GuardStmt *e) : stmt(e) {}
1404+
SourceLoc endLoc;
1405+
GuardStmtScope(GuardStmt *e, SourceLoc endLoc) : stmt(e), endLoc(endLoc) {}
14041406
virtual ~GuardStmtScope() {}
14051407

14061408
protected:
@@ -1413,6 +1415,8 @@ class GuardStmtScope final : public LabeledConditionalStmtScope {
14131415
public:
14141416
std::string getClassName() const override;
14151417
LabeledConditionalStmt *getLabeledConditionalStmt() const override;
1418+
SourceRange
1419+
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
14161420
};
14171421

14181422
/// A scope after a guard statement that follows lookups into the conditions
@@ -1427,9 +1431,11 @@ class LookupParentDiversionScope final : public ASTScopeImpl {
14271431
public:
14281432
ASTScopeImpl *const lookupParent;
14291433
const SourceLoc startLoc;
1434+
const SourceLoc endLoc;
14301435

1431-
LookupParentDiversionScope(ASTScopeImpl *lookupParent, SourceLoc startLoc)
1432-
: lookupParent(lookupParent), startLoc(startLoc) {}
1436+
LookupParentDiversionScope(ASTScopeImpl *lookupParent,
1437+
SourceLoc startLoc, SourceLoc endLoc)
1438+
: lookupParent(lookupParent), startLoc(startLoc), endLoc(endLoc) {}
14331439

14341440
SourceRange
14351441
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;

include/swift/Basic/Compiler.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,59 @@
3434
#define SWIFT_ASSUME(x)
3535
#endif
3636

37+
/// Attributes.
38+
3739
#if __has_attribute(constructor)
3840
#define SWIFT_CONSTRUCTOR __attribute__((constructor))
3941
#else
4042
#define SWIFT_CONSTRUCTOR
4143
#endif
4244

45+
/// \macro SWIFT_GNUC_PREREQ
46+
/// Extend the default __GNUC_PREREQ even if glibc's features.h isn't
47+
/// available.
48+
#ifndef SWIFT_GNUC_PREREQ
49+
# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
50+
# define SWIFT_GNUC_PREREQ(maj, min, patch) \
51+
((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
52+
((maj) << 20) + ((min) << 10) + (patch))
53+
# elif defined(__GNUC__) && defined(__GNUC_MINOR__)
54+
# define SWIFT_GNUC_PREREQ(maj, min, patch) \
55+
((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
56+
# else
57+
# define SWIFT_GNUC_PREREQ(maj, min, patch) 0
58+
# endif
59+
#endif
60+
61+
62+
/// SWIFT_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
63+
/// mark a method "not for inlining".
64+
#if __has_attribute(noinline) || SWIFT_GNUC_PREREQ(3, 4, 0)
65+
#define SWIFT_ATTRIBUTE_NOINLINE __attribute__((noinline))
66+
#elif defined(_MSC_VER)
67+
#define SWIFT_ATTRIBUTE_NOINLINE __declspec(noinline)
68+
#else
69+
#define SWIFT_ATTRIBUTE_NOINLINE
70+
#endif
71+
72+
/// SWIFT_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
73+
/// so, mark a method "always inline" because it is performance sensitive. GCC
74+
/// 3.4 supported this but is buggy in various cases and produces unimplemented
75+
/// errors, just use it in GCC 4.0 and later.
76+
#if __has_attribute(always_inline) || SWIFT_GNUC_PREREQ(4, 0, 0)
77+
#define SWIFT_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
78+
#elif defined(_MSC_VER)
79+
#define SWIFT_ATTRIBUTE_ALWAYS_INLINE __forceinline
80+
#else
81+
#define SWIFT_ATTRIBUTE_ALWAYS_INLINE
82+
#endif
83+
84+
#ifdef __GNUC__
85+
#define SWIFT_ATTRIBUTE_NORETURN __attribute__((noreturn))
86+
#elif defined(_MSC_VER)
87+
#define SWIFT_ATTRIBUTE_NORETURN __declspec(noreturn)
88+
#else
89+
#define SWIFT_ATTRIBUTE_NORETURN
90+
#endif
91+
4392
#endif // SWIFT_BASIC_COMPILER_H
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- Unreachable.h - Implements swift_runtime_unreachable ---*- C++ -*-===//
1+
//===--- Unreachable.h - Implements swift_unreachable ---*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,24 +10,38 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// This file defines swift_runtime_unreachable, an LLVM-independent
14-
// implementation of llvm_unreachable.
13+
// This file defines swift_unreachable, which provides the
14+
// functionality of llvm_unreachable without necessarily depending on
15+
// the LLVM support libraries.
1516
//
1617
//===----------------------------------------------------------------------===//
1718

18-
#ifndef SWIFT_RUNTIME_UNREACHABLE_H
19-
#define SWIFT_RUNTIME_UNREACHABLE_H
19+
#ifndef SWIFT_BASIC_UNREACHABLE_H
20+
#define SWIFT_BASIC_UNREACHABLE_H
21+
22+
#ifdef SWIFT_LLVM_SUPPORT_IS_AVAILABLE
23+
24+
// The implementation when LLVM is available.
25+
26+
#include "llvm/Support/ErrorHandling.h"
27+
#define swift_unreachable llvm_unreachable
28+
29+
#else
30+
31+
// The implementation when LLVM is not available.
2032

2133
#include <assert.h>
2234
#include <stdlib.h>
2335

2436
#include "swift/Runtime/Config.h"
2537

2638
SWIFT_RUNTIME_ATTRIBUTE_NORETURN
27-
inline static void swift_runtime_unreachable(const char *msg) {
39+
inline static void swift_unreachable(const char *msg) {
2840
assert(false && msg);
2941
(void)msg;
3042
abort();
3143
}
3244

33-
#endif // SWIFT_RUNTIME_UNREACHABLE_H
45+
#endif
46+
47+
#endif

include/swift/Demangling/TypeDecoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "swift/Demangling/Demangler.h"
2525
#include "swift/Demangling/NamespaceMacros.h"
2626
#include "swift/Runtime/Portability.h"
27-
#include "swift/Runtime/Unreachable.h"
27+
#include "swift/Basic/Unreachable.h"
2828
#include "swift/Strings.h"
2929
#include "llvm/ADT/ArrayRef.h"
3030
#include <vector>

include/swift/Option/Options.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,11 @@ def scan_clang_dependencies : Flag<["-"], "scan-clang-dependencies">,
11021102

11031103
def disable_parser_lookup : Flag<["-"], "disable-parser-lookup">,
11041104
Flags<[FrontendOption]>,
1105-
HelpText<"Disable parser lookup & use ast scope lookup only (experimental)">;
1105+
HelpText<"Disable parser lookup & use ASTScope lookup only (experimental)">;
1106+
1107+
def enable_parser_lookup : Flag<["-"], "enable-parser-lookup">,
1108+
Flags<[FrontendOption]>,
1109+
HelpText<"Enable parser lookup">;
11061110

11071111
def enable_request_based_incremental_dependencies : Flag<["-"],
11081112
"enable-request-based-incremental-dependencies">,

0 commit comments

Comments
 (0)