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;

lib/SILOptimizer/Mandatory/MoveOnlyWrappedTypeEliminator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ struct SILMoveOnlyWrappedTypeEliminatorVisitor
180180
NO_UPDATE_NEEDED(MarkDependence)
181181
NO_UPDATE_NEEDED(DestroyAddr)
182182
NO_UPDATE_NEEDED(DeallocStack)
183+
NO_UPDATE_NEEDED(DeallocBox)
183184
NO_UPDATE_NEEDED(Branch)
184185
NO_UPDATE_NEEDED(ExplicitCopyAddr)
185186
NO_UPDATE_NEEDED(CopyAddr)

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,14 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
683683
static void addHighLevelFunctionPipeline(SILPassPipelinePlan &P) {
684684
P.startPipeline("HighLevel,Function+EarlyLoopOpt",
685685
true /*isFunctionPassPipeline*/);
686-
P.addEagerSpecializer();
686+
687+
// Skip EagerSpecializer on embedded Swift, which already specializes
688+
// everything. Otherwise this would create metatype references for functions
689+
// with @_specialize attribute and those are incompatible with Emebdded Swift.
690+
if (!P.getOptions().EmbeddedSwift) {
691+
P.addEagerSpecializer();
692+
}
693+
687694
P.addObjCBridgingOptimization();
688695

689696
addFunctionPasses(P, OptimizationLevelKind::HighLevel);

lib/Sema/SyntacticElementTarget.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,15 @@ bool SyntacticElementTarget::contextualTypeIsOnlyAHint() const {
303303

304304
void SyntacticElementTarget::markInvalid() const {
305305
class InvalidationWalker : public ASTWalker {
306+
ASTContext &Ctx;
307+
308+
public:
309+
InvalidationWalker(ASTContext &ctx) : Ctx(ctx) {}
310+
306311
PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
307-
// TODO: We ought to fill in ErrorTypes for expressions here; ultimately
308-
// type-checking should always produce typed AST.
312+
if (!E->getType())
313+
E->setType(ErrorType::get(Ctx));
314+
309315
return Action::Continue(E);
310316
}
311317

@@ -321,7 +327,7 @@ void SyntacticElementTarget::markInvalid() const {
321327
return Action::VisitNodeIf(isa<PatternBindingDecl>(D));
322328
}
323329
};
324-
InvalidationWalker walker;
330+
InvalidationWalker walker(getDeclContext()->getASTContext());
325331
walk(walker);
326332
}
327333

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2706,7 +2706,7 @@ namespace {
27062706
PreWalkResult<Expr *> walkToExprPre(Expr *expr) override {
27072707
// Skip expressions that didn't make it to solution application
27082708
// because the constraint system diagnosed an error.
2709-
if (!expr->getType())
2709+
if (!expr->getType() || expr->getType()->hasError())
27102710
return Action::SkipNode(expr);
27112711

27122712
if (auto *openExistential = dyn_cast<OpenExistentialExpr>(expr)) {

lib/Sema/TypeCheckEffects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ class ApplyClassifier {
12831283
thrownValue = removeErasureToExistentialError(thrownValue);
12841284

12851285
Type thrownType = thrownValue->getType();
1286-
if (!thrownType)
1286+
if (!thrownType || thrownType->hasError())
12871287
return Classification::forInvalidCode();
12881288

12891289
// FIXME: Add a potential effect reason for a throw site.

stdlib/public/Concurrency/AsyncSequence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public protocol AsyncSequence<Element, Failure> {
8181

8282
/// The type of errors produced when iteration over the sequence fails.
8383
@available(SwiftStdlib 6.0, *)
84-
associatedtype Failure: Error = AsyncIterator.Failure
84+
associatedtype Failure: Error = any Error
8585
where AsyncIterator.Failure == Failure
8686

8787
/// Creates the asynchronous iterator that produces elements of this

test/SILGen/typed_throws_generic.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,12 @@ struct GSF2<F: Error, T>: P2 {
378378
struct GSA<T>: P2 {
379379
typealias Failure = any Error
380380
}
381+
382+
struct ReducedError<T: Error> {}
383+
384+
extension ReducedError where T == MyError {
385+
// CHECK-LABEL: sil hidden [ossa] @$s20typed_throws_generic12ReducedErrorVA2A02MyE0ORszrlE05throwfE0yyAEYKF : $@convention(method) (ReducedError<MyError>) -> @error MyError {
386+
func throwMyError() throws(T) {
387+
throw MyError.fail
388+
}
389+
}

test/SILOptimizer/moveonly_type_eliminator.sil

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,24 @@ bb0(%x : @owned $Klass):
578578
%retval = tuple ()
579579
return %retval : $()
580580
}
581+
582+
// SILGen occasionally uses dealloc_box instead of destroy_value. dealloc_box is needed when we don't want to destroy
583+
// the contents of the box. It seems to happen with property wrappers.
584+
//
585+
// CHECK-LABEL: sil [ossa] @dealoc_box : $@convention(thin) (@owned Klass) -> () {
586+
// CHECK: [[BOX:%.*]] = alloc_box [moveable_value_debuginfo] ${ var Klass }
587+
// CHECK: dealloc_box [[BOX]] : ${ var Klass }
588+
// CHECK-LABEL: } // end sil function 'dealoc_box'
589+
sil [ossa] @dealoc_box : $@convention(thin) (@owned Klass) -> () {
590+
bb0(%x : @owned $Klass):
591+
%box = alloc_box ${ var @moveOnly Klass }
592+
%addr = project_box %box : ${ var @moveOnly Klass }, 0
593+
%unwrapped_addr = moveonlywrapper_to_copyable_addr %addr : $*@moveOnly Klass
594+
store %x to [init] %unwrapped_addr : $*Klass
595+
debug_value %addr : $*@moveOnly Klass, var, name "s", argno 1, expr op_deref
596+
destroy_addr %addr : $*@moveOnly Klass
597+
debug_value undef : $*@moveOnly Klass, var, name "s", argno 1, expr op_deref
598+
dealloc_box %box : ${ var @moveOnly Klass }
599+
%retval = tuple ()
600+
return %retval : $()
601+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// rdar://128294522 - Make sure we don't generate USRs for decls in local contexts.
2+
3+
func test1() {
4+
let loclVar = 0 // This typo is intentional; otherwise mangling applies a substitution for 'local'.
5+
// RUN: %sourcekitd-test -req=complete -pos=%(line):3 %s -- %s | %FileCheck %s --check-prefix LOCAL_VAR
6+
// LOCAL_VAR-NOT: key.associated_usrs: "s:{{.*}}loclVar{{.*}}"
7+
// LOCAL_VAR: key.name: "loclVar"
8+
// LOCAL_VAR-NOT: key.associated_usrs: "s:{{.*}}loclVar{{.*}}"
9+
}
10+
11+
func test2() {
12+
let _ = {
13+
struct S {
14+
func nestedMethod() {
15+
// RUN: %sourcekitd-test -req=complete -pos=%(line):3 %s -- %s | %FileCheck %s --check-prefix LOCAL_METHOD
16+
// RUN: %sourcekitd-test -req=complete -pos=%(line+1):14 %s -- %s | %FileCheck %s --check-prefix LOCAL_METHOD
17+
self.
18+
// LOCAL_METHOD-NOT: key.associated_usrs: "s:{{.*}}nestedMethod{{.*}}"
19+
// LOCAL_METHOD: key.name: "nestedMethod()"
20+
// LOCAL_METHOD-NOT: key.associated_usrs: "s:{{.*}}nestedMethod{{.*}}"
21+
}
22+
}
23+
}
24+
}
25+
26+
// Just to make sure 'key.associated_usrs' is produced for a non-local decl
27+
// so the above CHECK-NOT's are working. If this fails, make sure to update the
28+
// above checks too.
29+
// RUN: %sourcekitd-test -req=complete -pos=%(line):1 %s -- %s | %FileCheck %s --check-prefix NON_LOCAL
30+
// NON_LOCAL: key.associated_usrs: "s:{{.*}}test2{{.*}}"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %sourcekitd-test -req=cursor -pos=12:11 %s -- %s
2+
3+
private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
4+
5+
override func visitAny(_ node: Syntax) -> Syntax? {
6+
if var declSyntax = node.as(DeclSyntax.self),
7+
let attributedNode = node.asProtocol(WithAttributesSyntax.self),
8+
!attributedNode.attributes.isEmpty
9+
{
10+
for (attribute, spec) in attributesToRemove {
11+
if let index = self.expandedAttributes.firstIndex(where: { expandedAttribute in
12+
expandedAttribute.position == attribute.position
13+
}) {
14+
} else {
15+
}
16+
}
17+
}
18+
}
19+
}

test/embedded/specialize-attrs2.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-run-simple-swift(-parse-as-library -Onone -enable-experimental-feature Embedded -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop -Xlinker -dead_strip) | %FileCheck %s
2+
// RUN: %target-run-simple-swift(-parse-as-library -O -enable-experimental-feature Embedded -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop -Xlinker -dead_strip) | %FileCheck %s
3+
// RUN: %target-run-simple-swift(-parse-as-library -Osize -enable-experimental-feature Embedded -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop -Xlinker -dead_strip) | %FileCheck %s
4+
5+
// REQUIRES: swift_in_compiler
6+
// REQUIRES: executable_test
7+
// REQUIRES: optimized_stdlib
8+
// REQUIRES: OS=macosx
9+
10+
@main
11+
struct Main {
12+
static func main() {
13+
let chars: [Character] = ["a", "b", "c"]
14+
let s = Substring.init(chars)
15+
print(s)
16+
print("OK!")
17+
}
18+
}
19+
20+
// CHECK: OK!

0 commit comments

Comments
 (0)