Skip to content

Commit b72fcd4

Browse files
authored
Merge pull request #4085 from swiftwasm/main
[pull] swiftwasm from main
2 parents b911ec2 + e5ecc9d commit b72fcd4

File tree

81 files changed

+861
-324
lines changed

Some content is hidden

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

81 files changed

+861
-324
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ option(SWIFT_BUILD_STATIC_STDLIB
9797
option(SWIFT_STDLIB_STATIC_PRINT
9898
"Build compile-time evaluated vprintf()"
9999
FALSE)
100+
101+
option(SWIFT_STDLIB_ENABLE_UNICODE_DATA
102+
"Include Unicode data files in the standard library.
103+
NOTE: Disabling this will cause many String methods to crash."
104+
TRUE)
100105

101106
option(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY
102107
"Build dynamic variants of the Swift SDK overlay"
@@ -1025,6 +1030,7 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
10251030
message(STATUS "Concurrency Support: ${SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY}")
10261031
message(STATUS "Distributed Support: ${SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED}")
10271032
message(STATUS "String Processing Support: ${SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING}")
1033+
message(STATUS "Unicode Support: ${SWIFT_STDLIB_ENABLE_UNICODE_DATA}")
10281034
message(STATUS "")
10291035
else()
10301036
message(STATUS "Not building Swift standard library, SDK overlays, and runtime")

docs/ABI/Mangling.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ Types
591591
FUNCTION-KIND ::= 'B' // objc block function type
592592
FUNCTION-KIND ::= 'zB' C-TYPE // objc block type with non-canonical C type
593593
FUNCTION-KIND ::= 'L' // objc block function type with canonical C type (escaping) (DWARF only; otherwise use 'B' or 'zB' C-TYPE)
594-
FUNCTION-KIND ::= 'C' // C function pointer type
595-
FUNCTION-KIND ::= 'zC' C-TYPE // C function pointer type with with non-canonical C type
594+
FUNCTION-KIND ::= 'C' // C function pointer / C++ method type
595+
FUNCTION-KIND ::= 'zC' C-TYPE // C function pointer / C++ method type with with non-canonical C type
596596
FUNCTION-KIND ::= 'A' // @auto_closure function type (escaping)
597597
FUNCTION-KIND ::= 'E' // function type (noescape)
598598

include/swift/AST/ASTContext.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ class ASTContext final {
368368
/// i.e. true if the entry is [key: alias_name, value: (real_name, true)].
369369
mutable llvm::DenseMap<Identifier, std::pair<Identifier, bool>> ModuleAliasMap;
370370

371+
/// The maximum arity of `_StringProcessing.Tuple{n}`.
372+
static constexpr unsigned StringProcessingTupleDeclMaxArity = 8;
373+
/// Cached `_StringProcessing.Tuple{n}` declarations.
374+
mutable SmallVector<StructDecl *, StringProcessingTupleDeclMaxArity - 2>
375+
StringProcessingTupleDecls;
376+
371377
/// Retrieve the allocator for the given arena.
372378
llvm::BumpPtrAllocator &
373379
getAllocator(AllocationArena arena = AllocationArena::Permanent) const;
@@ -623,7 +629,15 @@ class ASTContext final {
623629

624630
/// Retrieve _StringProcessing.Regex.init(_regexString: String, version: Int).
625631
ConcreteDeclRef getRegexInitDecl(Type regexType) const;
626-
632+
633+
/// Retrieve the max arity that `_StringProcessing.Tuple{arity}` was
634+
/// instantiated for.
635+
unsigned getStringProcessingTupleDeclMaxArity() const;
636+
637+
/// Retrieve the `_StringProcessing.Tuple{arity}` declaration for the given
638+
/// arity.
639+
StructDecl *getStringProcessingTupleDecl(unsigned arity) const;
640+
627641
/// Retrieve the declaration of Swift.<(Int, Int) -> Bool.
628642
FuncDecl *getLessThanIntDecl() const;
629643

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4772,6 +4772,9 @@ ERROR(string_processing_lib_missing,none,
47724772
ERROR(regex_capture_types_failed_to_decode,none,
47734773
"failed to decode capture types for regular expression literal; this may "
47744774
"be a compiler bug", ())
4775+
ERROR(regex_too_many_captures,none,
4776+
"too many captures in regular expression literal; the current limit is "
4777+
"%0", (unsigned))
47754778

47764779
//------------------------------------------------------------------------------
47774780
// MARK: Type Check Types

include/swift/AST/ExtInfo.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ enum class SILFunctionTypeRepresentation : uint8_t {
167167

168168
/// A closure invocation function that has not been bound to a context.
169169
Closure,
170+
171+
/// A C++ method that takes a "this" argument (not a static C++ method or
172+
/// constructor). Except for
173+
/// handling the "this" argument, has the same behavior as "CFunctionPointer".
174+
CXXMethod,
170175
};
171176

172177
/// Returns true if the function with this convention doesn't carry a context.
@@ -196,6 +201,7 @@ isThinRepresentation(SILFunctionTypeRepresentation rep) {
196201
case SILFunctionTypeRepresentation::WitnessMethod:
197202
case SILFunctionTypeRepresentation::CFunctionPointer:
198203
case SILFunctionTypeRepresentation::Closure:
204+
case SILFunctionTypeRepresentation::CXXMethod:
199205
return true;
200206
}
201207
llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
@@ -232,6 +238,7 @@ convertRepresentation(SILFunctionTypeRepresentation rep) {
232238
return {FunctionTypeRepresentation::Block};
233239
case SILFunctionTypeRepresentation::Thin:
234240
return {FunctionTypeRepresentation::Thin};
241+
case SILFunctionTypeRepresentation::CXXMethod:
235242
case SILFunctionTypeRepresentation::CFunctionPointer:
236243
return {FunctionTypeRepresentation::CFunctionPointer};
237244
case SILFunctionTypeRepresentation::Method:
@@ -252,6 +259,7 @@ constexpr bool canBeCalledIndirectly(SILFunctionTypeRepresentation rep) {
252259
case SILFunctionTypeRepresentation::CFunctionPointer:
253260
case SILFunctionTypeRepresentation::Block:
254261
case SILFunctionTypeRepresentation::Closure:
262+
case SILFunctionTypeRepresentation::CXXMethod:
255263
return false;
256264
case SILFunctionTypeRepresentation::ObjCMethod:
257265
case SILFunctionTypeRepresentation::Method:
@@ -269,6 +277,7 @@ template <typename Repr> constexpr bool shouldStoreClangType(Repr repr) {
269277
switch (static_cast<SILFunctionTypeRepresentation>(repr)) {
270278
case SILFunctionTypeRepresentation::CFunctionPointer:
271279
case SILFunctionTypeRepresentation::Block:
280+
case SILFunctionTypeRepresentation::CXXMethod:
272281
return true;
273282
case SILFunctionTypeRepresentation::ObjCMethod:
274283
case SILFunctionTypeRepresentation::Thick:
@@ -392,6 +401,7 @@ class ASTExtInfoBuilder {
392401
case SILFunctionTypeRepresentation::ObjCMethod:
393402
case SILFunctionTypeRepresentation::Method:
394403
case SILFunctionTypeRepresentation::WitnessMethod:
404+
case SILFunctionTypeRepresentation::CXXMethod:
395405
return true;
396406
}
397407
llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
@@ -618,6 +628,7 @@ SILFunctionLanguage getSILFunctionLanguage(SILFunctionTypeRepresentation rep) {
618628
case SILFunctionTypeRepresentation::ObjCMethod:
619629
case SILFunctionTypeRepresentation::CFunctionPointer:
620630
case SILFunctionTypeRepresentation::Block:
631+
case SILFunctionTypeRepresentation::CXXMethod:
621632
return SILFunctionLanguage::C;
622633
case SILFunctionTypeRepresentation::Thick:
623634
case SILFunctionTypeRepresentation::Thin:
@@ -750,6 +761,7 @@ class SILExtInfoBuilder {
750761
case Representation::ObjCMethod:
751762
case Representation::Method:
752763
case Representation::WitnessMethod:
764+
case SILFunctionTypeRepresentation::CXXMethod:
753765
return true;
754766
}
755767
llvm_unreachable("Unhandled Representation in switch.");
@@ -767,6 +779,7 @@ class SILExtInfoBuilder {
767779
case Representation::Method:
768780
case Representation::WitnessMethod:
769781
case Representation::Closure:
782+
case SILFunctionTypeRepresentation::CXXMethod:
770783
return false;
771784
}
772785
llvm_unreachable("Unhandled Representation in switch.");

include/swift/AST/GenericEnvironment.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,10 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
107107
/// This is only useful when lazily populating a generic environment.
108108
Optional<Type> getMappingIfPresent(GenericParamKey key) const;
109109

110-
/// Get the "raw" generic signature, without substituting into opaque
111-
/// type's signature.
112-
GenericSignature getRawGenericSignature() const;
113-
114110
public:
115-
GenericSignature getGenericSignature() const;
111+
GenericSignature getGenericSignature() const {
112+
return SignatureAndKind.getPointer();
113+
}
116114

117115
Kind getKind() const { return SignatureAndKind.getInt(); }
118116

include/swift/AST/Types.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5578,12 +5578,6 @@ class OpaqueTypeArchetypeType final : public ArchetypeType,
55785578
/// Retrieve the set of substitutions applied to the opaque type.
55795579
SubstitutionMap getSubstitutions() const;
55805580

5581-
/// Get the generic signature used to build out this archetype. This is
5582-
/// equivalent to the OpaqueTypeDecl's interface generic signature, with
5583-
/// all of the generic parameters aside from the opaque type's interface
5584-
/// type same-type-constrained to their substitutions for this type.
5585-
GenericSignature getBoundSignature() const;
5586-
55875581
/// Get a generic environment that has this opaque archetype bound within it.
55885582
GenericEnvironment *getGenericEnvironment() const;
55895583

include/swift/Runtime/Debug.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ void swift_abortDynamicReplacementEnabling();
142142
SWIFT_RUNTIME_ATTRIBUTE_NORETURN SWIFT_RUNTIME_ATTRIBUTE_NOINLINE
143143
void swift_abortDynamicReplacementDisabling();
144144

145+
// Halt due to trying to use unicode data on platforms that don't have it.
146+
SWIFT_RUNTIME_ATTRIBUTE_NORETURN SWIFT_RUNTIME_ATTRIBUTE_NOINLINE
147+
void swift_abortDisabledUnicodeSupport();
148+
145149
/// This function dumps one line of a stack trace. It is assumed that \p framePC
146150
/// is the address of the stack frame at index \p index. If \p shortOutput is
147151
/// true, this functions prints only the name of the symbol and offset, ignores

include/swift/SIL/ApplySite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class ApplySite {
237237
bool isCalleeThin() const {
238238
switch (getSubstCalleeType()->getRepresentation()) {
239239
case SILFunctionTypeRepresentation::CFunctionPointer:
240+
case SILFunctionTypeRepresentation::CXXMethod:
240241
case SILFunctionTypeRepresentation::Thin:
241242
case SILFunctionTypeRepresentation::Method:
242243
case SILFunctionTypeRepresentation::ObjCMethod:

lib/AST/ASTContext.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,30 @@ ConcreteDeclRef ASTContext::getRegexInitDecl(Type regexType) const {
12351235
return ConcreteDeclRef(foundDecl, subs);
12361236
}
12371237

1238-
static
1238+
unsigned ASTContext::getStringProcessingTupleDeclMaxArity() const {
1239+
return StringProcessingTupleDeclMaxArity;
1240+
}
1241+
1242+
StructDecl *ASTContext::getStringProcessingTupleDecl(unsigned arity) const {
1243+
assert(arity >= 2);
1244+
if (arity > StringProcessingTupleDeclMaxArity)
1245+
return nullptr;
1246+
if (StringProcessingTupleDecls.empty())
1247+
StringProcessingTupleDecls.append(
1248+
StringProcessingTupleDeclMaxArity - 1, nullptr);
1249+
auto &decl = StringProcessingTupleDecls[arity - 2];
1250+
if (decl)
1251+
return decl;
1252+
SmallVector<ValueDecl *, 1> results;
1253+
auto *spModule = getLoadedModule(Id_StringProcessing);
1254+
auto typeName = getIdentifier("Tuple" + llvm::utostr(arity));
1255+
spModule->lookupQualified(
1256+
spModule, DeclNameRef(typeName), NL_OnlyTypes, results);
1257+
assert(results.size() == 1);
1258+
return (decl = cast<StructDecl>(results[0]));
1259+
}
1260+
1261+
static
12391262
FuncDecl *getBinaryComparisonOperatorIntDecl(const ASTContext &C, StringRef op,
12401263
FuncDecl *&cached) {
12411264
if (cached)
@@ -4592,7 +4615,7 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
45924615
size_t bytes = totalSizeToAlloc<OpaqueTypeDecl *, SubstitutionMap, Type>(
45934616
1, 1, numGenericParams);
45944617
void *mem = ctx.Allocate(bytes, alignof(GenericEnvironment), arena);
4595-
auto env = new (mem) GenericEnvironment(GenericSignature(), opaque, subs);
4618+
auto env = new (mem) GenericEnvironment(signature, opaque, subs);
45964619
return env;
45974620
}
45984621

0 commit comments

Comments
 (0)