Skip to content

Commit 008e58a

Browse files
authored
Merge branch 'apple:main' into fix-init-accessor-71578
2 parents e298a66 + 6968a9e commit 008e58a

21 files changed

+156
-42
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3766,8 +3766,9 @@ void ASTMangler::appendClosureEntity(const AbstractClosureExpr *closure) {
37663766

37673767
auto type = closure->getType();
37683768

3769-
// FIXME: CodeCompletionResultBuilder calls printValueDeclUSR() but the
3770-
// closure hasn't been type checked yet.
3769+
// FIXME: We can end up with a null type here in the presence of invalid
3770+
// code; the type-checker currently isn't strict about producing typed
3771+
// expression nodes when it fails. Once we enforce that, we can remove this.
37713772
if (!type)
37723773
type = ErrorType::get(closure->getASTContext());
37733774

lib/AST/Decl.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,8 @@ bool ExtensionDecl::hasValidParent() const {
17681768
return getDeclContext()->canBeParentOfExtension();
17691769
}
17701770

1771+
/// Does the extension's generic signature impose additional generic requirements
1772+
/// not stated on the extended nominal type itself?
17711773
bool ExtensionDecl::isConstrainedExtension() const {
17721774
auto nominal = getExtendedNominal();
17731775
if (!nominal)
@@ -1786,12 +1788,26 @@ bool ExtensionDecl::isConstrainedExtension() const {
17861788
return !typeSig->isEqual(extSig);
17871789
}
17881790

1791+
/// Is the extension written as an unconstrained extension? This is not the same
1792+
/// as isConstrainedExtension() in the case where the extended nominal type has
1793+
/// inverse requirements, because an extension of such a type introduces default
1794+
/// conformance requirements unless they're suppressed on the extension.
1795+
///
1796+
/// enum Optional<Wrapped> where Wrapped: ~Copyable {}
1797+
///
1798+
/// extension Optional {}
1799+
/// --> isConstrainedExtension(): true
1800+
/// --> isWrittenWithConstraints(): false
1801+
///
1802+
/// extension Optional where Wrapped: ~Copyable {}
1803+
/// --> isConstrainedExtension(): false
1804+
/// --> isWrittenWithConstraints(): true
17891805
bool ExtensionDecl::isWrittenWithConstraints() const {
17901806
auto nominal = getExtendedNominal();
17911807
if (!nominal)
17921808
return false;
17931809

1794-
// If there's no generic signature, then it's written without constraints.
1810+
// If there's no generic signature, then it's unconstrained.
17951811
CanGenericSignature extSig = getGenericSignature().getCanonicalSignature();
17961812
if (!extSig)
17971813
return false;
@@ -1808,37 +1824,18 @@ bool ExtensionDecl::isWrittenWithConstraints() const {
18081824
SmallVector<InverseRequirement, 2> typeInverseReqs;
18091825
typeSig->getRequirementsWithInverses(typeReqs, typeInverseReqs);
18101826

1811-
// If the (non-inverse) requirements are different between the extension and
1827+
// If the non-inverse requirements are different between the extension and
18121828
// the original type, it's written with constraints.
1813-
if (extReqs.size() != typeReqs.size()) {
1829+
if (extReqs != typeReqs)
18141830
return true;
1815-
}
1816-
1817-
// In case of equal number of constraints, we have to check the specific
1818-
// requirements. Extensions can end up with fewer requirements than the type
1819-
// extended, due to a same-type requirement in the extension.
1820-
//
1821-
// This mirrors the 'same' check in `ASTMangler::gatherGenericSignatureParts`
1822-
for (size_t i = 0; i < extReqs.size(); i++) {
1823-
if (extReqs[i] != typeReqs[i])
1824-
return true;
1825-
}
18261831

1827-
// If the type has no inverse requirements, there are no extra constraints
1828-
// to write.
1829-
if (typeInverseReqs.empty()) {
1830-
assert(extInverseReqs.empty() && "extension retroactively added inverse?");
1831-
return false;
1832-
}
1833-
1834-
// If the extension has no inverse requirements, then there are no constraints
1835-
// that need to be written down.
1836-
if (extInverseReqs.empty()) {
1837-
return false;
1838-
}
1832+
// If the extension has inverse requirements, then it's written with
1833+
// constraints.
1834+
if (!extInverseReqs.empty())
1835+
return true;
18391836

1840-
// We have inverses that need to be written out.
1841-
return true;
1837+
// Otherwise, the extension is written as an unconstrained extension.
1838+
return false;
18421839
}
18431840

18441841
bool ExtensionDecl::isInSameDefiningModule() const {

lib/IDE/CodeCompletionResultBuilder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ static bool shouldCopyAssociatedUSRForDecl(const ValueDecl *VD) {
3636
if (VD->hasClangNode() && !VD->getClangDecl())
3737
return false;
3838

39+
// Avoid generating USRs for decls in local contexts, we cannot guarantee
40+
// any parent closures will be type-checked, which is needed for mangling.
41+
if (VD->getDeclContext()->getLocalContext())
42+
return false;
43+
3944
return true;
4045
}
4146

lib/Macros/Sources/ObservationMacros/Availability.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import SwiftSyntax
1313
import SwiftSyntaxMacros
1414
import SwiftDiagnostics
15-
import SwiftOperators
1615
import SwiftSyntaxBuilder
1716

1817

lib/Macros/Sources/ObservationMacros/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ add_swift_macro_library(ObservationMacros
1616
ObservableMacro.swift
1717
SWIFT_DEPENDENCIES
1818
SwiftDiagnostics
19-
SwiftOperators
2019
SwiftSyntaxBuilder
2120
SwiftSyntax
2221
SwiftSyntaxMacros

lib/Macros/Sources/ObservationMacros/Extensions.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import SwiftSyntax
1313
import SwiftSyntaxMacros
1414
import SwiftDiagnostics
15-
import SwiftOperators
1615
import SwiftSyntaxBuilder
1716

1817
extension VariableDeclSyntax {

lib/Macros/Sources/SwiftMacros/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ add_swift_macro_library(SwiftMacros
1818
TaskLocalMacro.swift
1919
SWIFT_DEPENDENCIES
2020
SwiftDiagnostics
21-
SwiftOperators
2221
SwiftSyntax
2322
SwiftSyntaxBuilder
2423
SwiftSyntaxMacros

lib/Macros/Sources/SwiftMacros/DistributedResolvableMacro.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import SwiftSyntax
1313
import SwiftSyntaxMacros
1414
import SwiftDiagnostics
15-
import SwiftOperators
1615
import SwiftSyntaxBuilder
1716

1817
/// Introduces:

lib/SILGen/SILGenEpilog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void SILGenFunction::prepareEpilog(
6565

6666
if (errorType) {
6767
auto genericSig = DC->getGenericSignatureOfContext();
68+
errorType = (*errorType)->getReducedType(genericSig);
6869
AbstractionPattern origErrorType = TypeContext
6970
? *TypeContext->OrigType.getFunctionThrownErrorType()
7071
: AbstractionPattern(genericSig.getCanonicalSignature(),

lib/SILGen/SILGenProlog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,8 @@ uint16_t SILGenFunction::emitBasicProlog(
15391539
// Create the indirect result parameters.
15401540
auto genericSig = DC->getGenericSignatureOfContext();
15411541
resultType = resultType->getReducedType(genericSig);
1542+
if (errorType)
1543+
errorType = (*errorType)->getReducedType(genericSig);
15421544

15431545
std::optional<AbstractionPattern> origClosureType;
15441546
if (TypeContext) origClosureType = TypeContext->OrigType;

0 commit comments

Comments
 (0)