Skip to content

Commit 30e9e15

Browse files
authored
Merge pull request #4160 from swiftwasm/main
[pull] swiftwasm from main
2 parents 24a0aaf + 83484f8 commit 30e9e15

File tree

29 files changed

+179
-222
lines changed

29 files changed

+179
-222
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ Types
621621
type-list ::= empty-list
622622

623623
// FIXME: Consider replacing 'h' with a two-char code
624-
list-type ::= type identifier? 'Yk'? 'z'? 'h'? 'n'? 'Yi'? 'd'? // type with optional label, '@noDerivative', inout convention, shared convention, owned convention, actor 'isolated', and variadic specifier
624+
list-type ::= type identifier? 'Yk'? 'z'? 'h'? 'n'? 'Yi'? 'd'? 'Yt'? // type with optional label, '@noDerivative', inout convention, shared convention, owned convention, actor 'isolated', variadic specifier, and compile-time constant
625625

626626
METATYPE-REPR ::= 't' // Thin metatype representation
627627
METATYPE-REPR ::= 'T' // Thick metatype representation

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ NODE(AsyncSuspendResumePartialFunction)
328328

329329
// Added in Swift 5.6
330330
NODE(AccessibleFunctionRecord)
331+
NODE(CompileTimeConst)
331332

332333
// Added in Swift 5.7
333334
NODE(OpaqueReturnTypeIndexed)

lib/AST/ASTMangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,9 @@ void ASTMangler::appendTypeListElement(Identifier name, Type elementType,
26832683
if (flags.isIsolated())
26842684
appendOperator("Yi");
26852685

2686+
if (flags.isCompileTimeConst())
2687+
appendOperator("Yt");
2688+
26862689
if (!name.empty())
26872690
appendIdentifier(name.str());
26882691
if (flags.isVariadic())

lib/AST/Type.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,11 +3875,6 @@ static Type getMemberForBaseType(LookupConformanceFn lookupConformances,
38753875
if (auto *selfType = substBase->getAs<DynamicSelfType>())
38763876
substBase = selfType->getSelfType();
38773877

3878-
// Error recovery path.
3879-
// FIXME: Generalized existentials will look here.
3880-
if (substBase->isOpenedExistential())
3881-
return failed();
3882-
38833878
// If the parent is an archetype, extract the child archetype with the
38843879
// given name.
38853880
if (auto archetypeParent = substBase->getAs<ArchetypeType>()) {

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,9 @@ NodePointer Demangler::demangleTypeAnnotation() {
777777
case 'k':
778778
return createType(
779779
createWithChild(Node::Kind::NoDerivative, popTypeAndGetChild()));
780+
case 't':
781+
return createType(
782+
createWithChild(Node::Kind::CompileTimeConst, popTypeAndGetChild()));
780783
default:
781784
return nullptr;
782785
}

lib/Demangling/NodePrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ class NodePrinter {
421421
case Node::Kind::InfixOperator:
422422
case Node::Kind::Initializer:
423423
case Node::Kind::Isolated:
424+
case Node::Kind::CompileTimeConst:
424425
case Node::Kind::PropertyWrapperBackingInitializer:
425426
case Node::Kind::PropertyWrapperInitFromProjectedValue:
426427
case Node::Kind::KeyPathGetterThunkHelper:
@@ -1463,6 +1464,10 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
14631464
Printer << "isolated ";
14641465
print(Node->getChild(0), depth + 1);
14651466
return nullptr;
1467+
case Node::Kind::CompileTimeConst:
1468+
Printer << "_const ";
1469+
print(Node->getChild(0), depth + 1);
1470+
return nullptr;
14661471
case Node::Kind::Shared:
14671472
Printer << "__shared ";
14681473
print(Node->getChild(0), depth + 1);

lib/Demangling/OldRemangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,11 @@ ManglingError Remangler::mangleIsolated(Node *node, unsigned depth) {
18231823
return mangleSingleChildNode(node, depth + 1); // type
18241824
}
18251825

1826+
ManglingError Remangler::mangleCompileTimeConst(Node *node, unsigned depth) {
1827+
Buffer << "Yt";
1828+
return mangleSingleChildNode(node, depth + 1); // type
1829+
}
1830+
18261831
ManglingError Remangler::mangleNoDerivative(Node *node, unsigned depth) {
18271832
Buffer << 'k';
18281833
return mangleSingleChildNode(node, depth + 1); // type

lib/Demangling/Remangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,12 @@ ManglingError Remangler::mangleIsolated(Node *node, unsigned depth) {
19691969
return ManglingError::Success;
19701970
}
19711971

1972+
ManglingError Remangler::mangleCompileTimeConst(Node *node, unsigned depth) {
1973+
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
1974+
Buffer << "Yt";
1975+
return ManglingError::Success;
1976+
}
1977+
19721978
ManglingError Remangler::mangleShared(Node *node, unsigned depth) {
19731979
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
19741980
Buffer << 'h';

lib/IDE/CompileInstance.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ bool CompileInstance::setupCI(
263263
return false;
264264
}
265265

266+
// Since LLVM arguments are parsed into a global state, LLVM can't handle
267+
// multiple argument sets in a process simultaneously. So let's ignore them.
268+
// FIXME: Remove this if possible.
269+
invocation.getFrontendOptions().LLVMArgs.clear();
270+
266271
/// Declare the frontend to be used for multiple compilations.
267272
invocation.getFrontendOptions().ReuseFrontendForMutipleCompilations = true;
268273

@@ -289,7 +294,7 @@ void CompileInstance::performSema(
289294
if (CI && ArgsHash == CachedArgHash &&
290295
CachedReuseCount < Opts.MaxASTReuseCount) {
291296
CI->getASTContext().CancellationFlag = CancellationFlag;
292-
if (performCachedSemaIfPossible(DiagC)) {
297+
if (!performCachedSemaIfPossible(DiagC)) {
293298
// If we compileted cacehd Sema operation. We're done.
294299
++CachedReuseCount;
295300
return;
@@ -307,6 +312,9 @@ void CompileInstance::performSema(
307312
return;
308313
}
309314

315+
CI->addDiagnosticConsumer(DiagC);
316+
SWIFT_DEFER { CI->removeDiagnosticConsumer(DiagC); };
317+
310318
// CI is potentially reusable.
311319
CachedArgHash = ArgsHash;
312320

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4157,35 +4157,6 @@ void ConformanceChecker::checkNonFinalClassWitness(ValueDecl *requirement,
41574157
}
41584158
}
41594159

4160-
static bool isSwiftRawRepresentableEnum(Type adoptee) {
4161-
auto *enumDecl = dyn_cast<EnumDecl>(adoptee->getAnyNominal());
4162-
return (enumDecl && enumDecl->hasRawType() && !enumDecl->isObjC());
4163-
}
4164-
4165-
// If the given witness matches a generic RawRepresentable function conforming
4166-
// with a given protocol e.g. `func == <T : RawRepresentable>(lhs: T, rhs: T) ->
4167-
// Bool where T.RawValue : Equatable`
4168-
static bool isRawRepresentableGenericFunction(
4169-
ASTContext &ctx, const ValueDecl *witness,
4170-
const NormalProtocolConformance *conformance) {
4171-
auto *fnDecl = dyn_cast<AbstractFunctionDecl>(witness);
4172-
if (!fnDecl || !fnDecl->isStdlibDecl())
4173-
return false;
4174-
4175-
return fnDecl->isGeneric() && fnDecl->getGenericParams()->size() == 1 &&
4176-
fnDecl->getGenericRequirements().size() == 2 &&
4177-
llvm::all_of(
4178-
fnDecl->getGenericRequirements(), [&](Requirement genericReq) {
4179-
if (genericReq.getKind() != RequirementKind::Conformance)
4180-
return false;
4181-
return genericReq.getProtocolDecl() ==
4182-
ctx.getProtocol(
4183-
KnownProtocolKind::RawRepresentable) ||
4184-
genericReq.getProtocolDecl() ==
4185-
conformance->getProtocol();
4186-
});
4187-
}
4188-
41894160
ResolveWitnessResult
41904161
ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
41914162
assert(!isa<AssociatedTypeDecl>(requirement) && "Use resolveTypeWitnessVia*");
@@ -4238,9 +4209,6 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
42384209
!canDerive && !requirement->getAttrs().hasAttribute<OptionalAttr>() &&
42394210
!requirement->getAttrs().isUnavailable(getASTContext());
42404211

4241-
auto &ctx = getASTContext();
4242-
bool isEquatableConformance = (Conformance->getProtocol() ==
4243-
ctx.getProtocol(KnownProtocolKind::Equatable));
42444212
if (findBestWitness(requirement,
42454213
considerRenames ? &ignoringNames : nullptr,
42464214
Conformance,
@@ -4249,28 +4217,6 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
42494217
const auto &best = matches[bestIdx];
42504218
auto witness = best.Witness;
42514219

4252-
if (canDerive &&
4253-
isEquatableConformance &&
4254-
isSwiftRawRepresentableEnum(Adoptee) &&
4255-
!Conformance->getDeclContext()->getParentModule()->isResilient()) {
4256-
// For swift enum types that can derive an Equatable conformance,
4257-
// if the best witness is the default implementation
4258-
//
4259-
// func == <T : RawRepresentable>(lhs: T, rhs: T) -> Bool
4260-
// where T.RawValue : Equatable
4261-
//
4262-
// let's return as missing and derive the conformance, since it will be
4263-
// more efficient than comparing rawValues.
4264-
//
4265-
// However, we only do this if the module is non-resilient. If it is
4266-
// resilient, this change can break ABI by publishing a synthesized ==
4267-
// declaration that may not exist in versions of the framework built
4268-
// with an older compiler.
4269-
if (isRawRepresentableGenericFunction(ctx, witness, Conformance)) {
4270-
return ResolveWitnessResult::Missing;
4271-
}
4272-
}
4273-
42744220
// If the name didn't actually line up, complain.
42754221
if (ignoringNames &&
42764222
requirement->getName() != best.Witness->getName() &&

0 commit comments

Comments
 (0)