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

lib/AST/ASTDumper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ getSILFunctionTypeRepresentationString(SILFunctionType::Representation value) {
129129
case SILFunctionType::Representation::Thick: return "thick";
130130
case SILFunctionType::Representation::Block: return "block";
131131
case SILFunctionType::Representation::CFunctionPointer: return "c";
132+
case SILFunctionType::Representation::CXXMethod:
133+
return "cxx_method";
132134
case SILFunctionType::Representation::Thin: return "thin";
133135
case SILFunctionType::Representation::Method: return "method";
134136
case SILFunctionType::Representation::ObjCMethod: return "objc_method";

lib/AST/ASTMangler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,7 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
18451845
OpArgs.push_back('B');
18461846
appendClangTypeToVec(OpArgs);
18471847
break;
1848+
case SILFunctionTypeRepresentation::CXXMethod:
18481849
case SILFunctionTypeRepresentation::CFunctionPointer:
18491850
if (!mangleClangType) {
18501851
OpArgs.push_back('C');
@@ -3314,7 +3315,8 @@ void ASTMangler::appendAnyProtocolConformance(
33143315
conformance.getAbstract());
33153316
appendDependentProtocolConformance(path, genericSig);
33163317
} else if (auto opaqueType = conformingType->getAs<OpaqueTypeArchetypeType>()) {
3317-
GenericSignature opaqueSignature = opaqueType->getBoundSignature();
3318+
GenericSignature opaqueSignature =
3319+
opaqueType->getDecl()->getOpaqueInterfaceGenericSignature();
33183320
ConformanceAccessPath conformanceAccessPath =
33193321
opaqueSignature->getConformanceAccessPath(
33203322
opaqueType->getInterfaceType(),

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4886,6 +4886,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
48864886
case SILFunctionType::Representation::Method:
48874887
Printer << "method";
48884888
break;
4889+
case SILFunctionType::Representation::CXXMethod:
4890+
Printer << "cxx_method";
4891+
break;
48894892
case SILFunctionType::Representation::ObjCMethod:
48904893
Printer << "objc_method";
48914894
break;
@@ -4964,6 +4967,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
49644967
case SILFunctionType::Representation::Method:
49654968
Printer << "method";
49664969
break;
4970+
case SILFunctionType::Representation::CXXMethod:
4971+
Printer << "cxx_method";
4972+
break;
49674973
case SILFunctionType::Representation::ObjCMethod:
49684974
Printer << "objc_method";
49694975
break;

lib/AST/ClangTypeConverter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ const clang::Type *ClangTypeConverter::getFunctionType(
212212
return nullptr;
213213

214214
switch (repr) {
215+
case SILFunctionType::Representation::CXXMethod:
215216
case SILFunctionType::Representation::CFunctionPointer:
216217
return ClangASTContext.getPointerType(fn).getTypePtr();
217218
case SILFunctionType::Representation::Block:

lib/AST/ExtInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Optional<UnexpectedClangTypeError> UnexpectedClangTypeError::checkClangType(
6868
#else
6969
bool isBlock = true;
7070
switch (silRep) {
71+
case SILFunctionTypeRepresentation::CXXMethod:
7172
case SILFunctionTypeRepresentation::CFunctionPointer:
7273
isBlock = false;
7374
LLVM_FALLTHROUGH;

lib/AST/GenericEnvironment.cpp

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -50,58 +50,6 @@ size_t GenericEnvironment::numTrailingObjects(OverloadToken<Type>) const {
5050
return getGenericParams().size();
5151
}
5252

53-
GenericSignature GenericEnvironment::getRawGenericSignature() const {
54-
switch (getKind()) {
55-
case Kind::Normal:
56-
case Kind::OpenedExistential:
57-
return SignatureAndKind.getPointer();
58-
59-
case Kind::Opaque:
60-
return getOpaqueTypeDecl()->getOpaqueInterfaceGenericSignature();
61-
}
62-
}
63-
64-
GenericSignature GenericEnvironment::getGenericSignature() const {
65-
switch (getKind()) {
66-
case Kind::Normal:
67-
case Kind::OpenedExistential:
68-
return SignatureAndKind.getPointer();
69-
70-
case Kind::Opaque:
71-
if (auto sig = SignatureAndKind.getPointer())
72-
return sig;
73-
74-
// Build signature below.
75-
break;
76-
}
77-
78-
// Create a new opaque archetype.
79-
// It lives in an environment in which the interface generic arguments of the
80-
// decl have all been same-type-bound to the arguments from our substitution
81-
// map.
82-
SmallVector<Requirement, 2> newRequirements;
83-
84-
// Same-type-constrain the arguments in the outer signature to their
85-
// replacements in the substitution map.
86-
auto opaqueDecl = getOpaqueTypeDecl();
87-
auto subs = getOpaqueSubstitutions();
88-
if (auto outerSig = opaqueDecl->getGenericSignature()) {
89-
for (auto outerParam : outerSig.getGenericParams()) {
90-
auto boundType = Type(outerParam).subst(subs);
91-
newRequirements.push_back(
92-
Requirement(RequirementKind::SameType, Type(outerParam), boundType));
93-
}
94-
}
95-
96-
auto signature = buildGenericSignature(
97-
opaqueDecl->getASTContext(),
98-
opaqueDecl->getOpaqueInterfaceGenericSignature(),
99-
/*genericParams=*/{ },
100-
std::move(newRequirements));
101-
SignatureAndKind.setPointer(signature);
102-
return signature;
103-
}
104-
10553
/// Retrieve the array containing the context types associated with the
10654
/// generic parameters, stored in parallel with the generic parameters of the
10755
/// generic signature.
@@ -120,7 +68,7 @@ ArrayRef<Type> GenericEnvironment::getContextTypes() const {
12068

12169
TypeArrayView<GenericTypeParamType>
12270
GenericEnvironment::getGenericParams() const {
123-
return getRawGenericSignature().getGenericParams();
71+
return getGenericSignature().getGenericParams();
12472
}
12573

12674
OpaqueTypeDecl *GenericEnvironment::getOpaqueTypeDecl() const {
@@ -272,7 +220,7 @@ Type TypeBase::mapTypeOutOfContext() {
272220

273221
Type
274222
GenericEnvironment::getOrCreateArchetypeFromInterfaceType(Type depType) {
275-
auto genericSig = getRawGenericSignature();
223+
auto genericSig = getGenericSignature();
276224
LookUpConformanceInSignature conformanceLookupFn(genericSig.getPointer());
277225

278226
auto requirements = genericSig->getLocalRequirements(depType);
@@ -425,7 +373,7 @@ Type GenericEnvironment::mapTypeIntoContext(
425373
}
426374

427375
Type GenericEnvironment::mapTypeIntoContext(Type type) const {
428-
auto sig = getRawGenericSignature();
376+
auto sig = getGenericSignature();
429377
return mapTypeIntoContext(type, LookUpConformanceInSignature(sig.getPointer()));
430378
}
431379

lib/AST/Type.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,10 +3320,6 @@ GenericEnvironment *OpaqueTypeArchetypeType::getGenericEnvironment() const {
33203320
return Environment;
33213321
}
33223322

3323-
GenericSignature OpaqueTypeArchetypeType::getBoundSignature() const {
3324-
return getGenericEnvironment()->getGenericSignature();
3325-
}
3326-
33273323
OpaqueTypeDecl *OpaqueTypeArchetypeType::getDecl() const {
33283324
return Environment->getOpaqueTypeDecl();
33293325
}

0 commit comments

Comments
 (0)