Skip to content

Commit 6933af5

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 3181aef + 4a54598 commit 6933af5

File tree

11 files changed

+142
-59
lines changed

11 files changed

+142
-59
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,8 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
138138
case let initExRef as InitExistentialRefInst:
139139
if context.options.enableEmbeddedSwift {
140140
for c in initExRef.conformances where c.isConcrete {
141-
specializeWitnessTable(for: c, moduleContext) {
142-
worklist.addWitnessMethods(of: $0)
143-
}
141+
specializeWitnessTable(for: c, moduleContext)
142+
worklist.addWitnessMethods(of: c, moduleContext)
144143
}
145144
}
146145

@@ -149,9 +148,9 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
149148
case .BuildOrdinaryTaskExecutorRef,
150149
.BuildOrdinarySerialExecutorRef,
151150
.BuildComplexEqualitySerialExecutorRef:
152-
specializeWitnessTable(for: bi.substitutionMap.conformances[0], moduleContext) {
153-
worklist.addWitnessMethods(of: $0)
154-
}
151+
let conformance = bi.substitutionMap.conformances[0]
152+
specializeWitnessTable(for: conformance, moduleContext)
153+
worklist.addWitnessMethods(of: conformance, moduleContext)
155154

156155
default:
157156
break
@@ -515,15 +514,44 @@ extension FunctionWorklist {
515514
}
516515
}
517516

518-
mutating func addWitnessMethods(of witnessTable: WitnessTable) {
517+
mutating func addWitnessMethods(of conformance: Conformance, _ context: ModulePassContext) {
518+
var visited = Set<Conformance>()
519+
addWitnessMethodsRecursively(of: conformance, visited: &visited, context)
520+
}
521+
522+
private mutating func addWitnessMethodsRecursively(of conformance: Conformance,
523+
visited: inout Set<Conformance>,
524+
_ context: ModulePassContext)
525+
{
526+
guard conformance.isConcrete,
527+
visited.insert(conformance).inserted
528+
else {
529+
return
530+
}
531+
let witnessTable: WitnessTable
532+
if let wt = context.lookupWitnessTable(for: conformance) {
533+
witnessTable = wt
534+
} else if let wt = context.lookupWitnessTable(for: conformance.rootConformance) {
535+
witnessTable = wt
536+
} else {
537+
return
538+
}
519539
for entry in witnessTable.entries {
520-
if case .method(_, let witness) = entry,
521-
let method = witness,
522-
// A new witness table can still contain a generic function if the method couldn't be specialized for
523-
// some reason and an error has been printed. Exclude generic functions to not run into an assert later.
524-
!method.isGeneric
525-
{
526-
pushIfNotVisited(method)
540+
switch entry {
541+
case .invalid, .associatedType:
542+
break
543+
case .method(_, let witness):
544+
if let method = witness,
545+
// A new witness table can still contain a generic function if the method couldn't be specialized for
546+
// some reason and an error has been printed. Exclude generic functions to not run into an assert later.
547+
!method.isGeneric
548+
{
549+
pushIfNotVisited(method)
550+
}
551+
case .baseProtocol(_, let baseConf):
552+
addWitnessMethodsRecursively(of: baseConf, visited: &visited, context)
553+
case .associatedConformance(_, let assocConf):
554+
addWitnessMethodsRecursively(of: assocConf, visited: &visited, context)
527555
}
528556
}
529557
}

SwiftCompilerSources/Sources/Optimizer/Utilities/GenericSpecialization.swift

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ private struct VTableSpecializer {
106106
}
107107

108108
/// Specializes a witness table of `conformance` for the concrete type of the conformance.
109-
func specializeWitnessTable(for conformance: Conformance,
110-
_ context: ModulePassContext,
111-
_ notifyNewWitnessTable: (WitnessTable) -> ())
112-
{
109+
func specializeWitnessTable(for conformance: Conformance, _ context: ModulePassContext) {
113110
if let existingSpecialization = context.lookupWitnessTable(for: conformance),
114111
existingSpecialization.isSpecialized
115112
{
@@ -125,7 +122,7 @@ func specializeWitnessTable(for conformance: Conformance,
125122
let baseConf = conformance.isInherited ? conformance.inheritedConformance: conformance
126123
if !baseConf.isSpecialized {
127124
var visited = Set<Conformance>()
128-
specializeDefaultMethods(for: conformance, visited: &visited, context, notifyNewWitnessTable)
125+
specializeDefaultMethods(for: conformance, visited: &visited, context)
129126
return
130127
}
131128

@@ -158,7 +155,7 @@ func specializeWitnessTable(for conformance: Conformance,
158155
let baseConf = context.getSpecializedConformance(of: witness,
159156
for: conformance.type,
160157
substitutions: conformance.specializedSubstitutions)
161-
specializeWitnessTable(for: baseConf, context, notifyNewWitnessTable)
158+
specializeWitnessTable(for: baseConf, context)
162159
return .baseProtocol(requirement: requirement, witness: baseConf)
163160
case .associatedType(let requirement, let witness):
164161
let substType = witness.subst(with: conformance.specializedSubstitutions)
@@ -169,15 +166,14 @@ func specializeWitnessTable(for conformance: Conformance,
169166
let concreteAssociateConf = conformance.getAssociatedConformance(ofAssociatedType: requirement.rawType,
170167
to: assocConf.protocol)
171168
if concreteAssociateConf.isSpecialized {
172-
specializeWitnessTable(for: concreteAssociateConf, context, notifyNewWitnessTable)
169+
specializeWitnessTable(for: concreteAssociateConf, context)
173170
}
174171
return .associatedConformance(requirement: requirement,
175172
witness: concreteAssociateConf)
176173
}
177174
}
178-
let newWT = context.createSpecializedWitnessTable(entries: newEntries,conformance: conformance,
179-
linkage: .shared, serialized: false)
180-
notifyNewWitnessTable(newWT)
175+
context.createSpecializedWitnessTable(entries: newEntries,conformance: conformance,
176+
linkage: .shared, serialized: false)
181177
}
182178

183179
/// Specializes the default methods of a non-generic witness table.
@@ -186,8 +182,7 @@ func specializeWitnessTable(for conformance: Conformance,
186182
/// specialize inherited conformances so that the concrete self type is correct, even for derived classes.
187183
private func specializeDefaultMethods(for conformance: Conformance,
188184
visited: inout Set<Conformance>,
189-
_ context: ModulePassContext,
190-
_ notifyNewWitnessTable: (WitnessTable) -> ())
185+
_ context: ModulePassContext)
191186
{
192187
// Avoid infinite recursion, which may happen if an associated conformance is the conformance itself.
193188
guard visited.insert(conformance).inserted,
@@ -224,21 +219,20 @@ private func specializeDefaultMethods(for conformance: Conformance,
224219
specialized = true
225220
return .method(requirement: requirement, witness: specializedMethod)
226221
case .baseProtocol(_, let witness):
227-
specializeDefaultMethods(for: witness, visited: &visited, context, notifyNewWitnessTable)
222+
specializeDefaultMethods(for: witness, visited: &visited, context)
228223
return origEntry
229224
case .associatedType:
230225
return origEntry
231226
case .associatedConformance(_, let assocConf):
232-
specializeDefaultMethods(for: assocConf, visited: &visited, context, notifyNewWitnessTable)
227+
specializeDefaultMethods(for: assocConf, visited: &visited, context)
233228
return origEntry
234229
}
235230
}
236231
// If the witness table does not contain any default methods, there is no need to create a
237232
// specialized witness table.
238233
if specialized {
239-
let newWT = context.createSpecializedWitnessTable(entries: newEntries,conformance: conformance,
240-
linkage: .shared, serialized: false)
241-
notifyNewWitnessTable(newWT)
234+
context.createSpecializedWitnessTable(entries: newEntries,conformance: conformance,
235+
linkage: .shared, serialized: false)
242236
}
243237
}
244238

lib/Sema/MiscDiagnostics.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6471,7 +6471,7 @@ void swift::performStmtDiagnostics(const Stmt *S, DeclContext *DC) {
64716471

64726472
void swift::fixItAccess(InFlightDiagnostic &diag, ValueDecl *VD,
64736473
AccessLevel desiredAccess, bool isForSetter,
6474-
bool shouldUseDefaultAccess) {
6474+
bool shouldUseDefaultAccess, bool updateAttr) {
64756475
StringRef fixItString;
64766476
switch (desiredAccess) {
64776477
case AccessLevel::Private: fixItString = "private "; break;
@@ -6486,27 +6486,35 @@ void swift::fixItAccess(InFlightDiagnostic &diag, ValueDecl *VD,
64866486
AbstractAccessControlAttr *attr;
64876487
if (isForSetter) {
64886488
attr = attrs.getAttribute<SetterAccessAttr>();
6489-
cast<AbstractStorageDecl>(VD)->overwriteSetterAccess(desiredAccess);
6489+
if (updateAttr)
6490+
cast<AbstractStorageDecl>(VD)->overwriteSetterAccess(desiredAccess);
64906491
} else {
64916492
attr = attrs.getAttribute<AccessControlAttr>();
6492-
VD->overwriteAccess(desiredAccess);
6493+
if (updateAttr)
6494+
VD->overwriteAccess(desiredAccess);
64936495

64946496
if (auto *ASD = dyn_cast<AbstractStorageDecl>(VD)) {
6495-
if (auto *getter = ASD->getAccessor(AccessorKind::Get))
6496-
getter->overwriteAccess(desiredAccess);
6497+
if (auto *getter = ASD->getAccessor(AccessorKind::Get)) {
6498+
if (updateAttr)
6499+
getter->overwriteAccess(desiredAccess);
6500+
}
64976501

64986502
if (auto *setterAttr = attrs.getAttribute<SetterAccessAttr>()) {
64996503
if (setterAttr->getAccess() > desiredAccess)
6500-
fixItAccess(diag, VD, desiredAccess, true);
6504+
fixItAccess(diag, VD, desiredAccess, /*isForSetter=*/true,
6505+
/*shouldUseDefaultAccess=*/false, updateAttr);
65016506
} else {
6502-
ASD->overwriteSetterAccess(desiredAccess);
6507+
if (updateAttr)
6508+
ASD->overwriteSetterAccess(desiredAccess);
65036509
}
65046510
}
65056511
}
65066512

65076513
if (isForSetter && VD->getFormalAccess() == desiredAccess) {
65086514
assert(attr);
6509-
attr->setInvalid();
6515+
if (updateAttr)
6516+
attr->setInvalid();
6517+
65106518
// Remove the setter attribute.
65116519
diag.fixItRemove(attr->Range);
65126520

@@ -6526,7 +6534,8 @@ void swift::fixItAccess(InFlightDiagnostic &diag, ValueDecl *VD,
65266534
// replace the "(set)" part of a setter attribute.
65276535
diag.fixItReplace(attr->getLocation(), fixItString.drop_back());
65286536
}
6529-
attr->setInvalid();
6537+
if (updateAttr)
6538+
attr->setInvalid();
65306539
}
65316540

65326541
} else if (auto *override = VD->getAttrs().getAttribute<OverrideAttr>()) {

lib/Sema/MiscDiagnostics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ namespace swift {
5353

5454
/// Emit a fix-it to set the access of \p VD to \p desiredAccess.
5555
///
56-
/// This actually updates \p VD as well.
56+
/// This actually updates \p VD as well if \p updateAttr is true.
5757
void fixItAccess(InFlightDiagnostic &diag, ValueDecl *VD,
5858
AccessLevel desiredAccess, bool isForSetter = false,
59-
bool shouldUseDefaultAccess = false);
59+
bool shouldUseDefaultAccess = false, bool updateAttr = true);
6060

6161
/// Compute the location of the 'var' keyword for a 'var'-to-'let' Fix-It.
6262
SourceLoc getFixItLocForVarToLet(VarDecl *var);

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,9 @@ visitDynamicMemberLookupAttr(DynamicMemberLookupAttr *attr) {
21712171
diag::dynamic_member_lookup_candidate_inaccessible,
21722172
inaccessibleCandidate);
21732173
fixItAccess(diag, inaccessibleCandidate,
2174-
requiredAccessScope.requiredAccessForDiagnostics());
2174+
requiredAccessScope.requiredAccessForDiagnostics(),
2175+
/*isForSetter=*/false, /*useDefaultAccess=*/false,
2176+
/*updateAttr=*/false);
21752177
diag.warnUntilSwiftVersionIf(!shouldError, futureVersion);
21762178

21772179
if (shouldError) {

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,17 +2191,23 @@ static bool checkSingleOverride(ValueDecl *override, ValueDecl *base) {
21912191
auto domain = unavailableAttr.getDomain();
21922192
auto parsedAttr = unavailableAttr.getParsedAttr();
21932193

2194-
if (domain.isPlatform() || domain.isUniversal()) {
2194+
switch (domain.getKind()) {
2195+
case AvailabilityDomain::Kind::Universal:
2196+
case AvailabilityDomain::Kind::SwiftLanguage:
2197+
case AvailabilityDomain::Kind::PackageDescription:
2198+
case AvailabilityDomain::Kind::Platform:
21952199
// FIXME: [availability] Diagnose as an error in a future Swift version.
21962200
break;
2201+
case AvailabilityDomain::Kind::Embedded:
2202+
case AvailabilityDomain::Kind::Custom:
2203+
if (parsedAttr->getLocation().isValid())
2204+
ctx.Diags.diagnose(override, diag::override_unavailable, override)
2205+
.fixItRemove(parsedAttr->getRangeWithAt());
2206+
else
2207+
ctx.Diags.diagnose(override, diag::override_unavailable, override);
2208+
ctx.Diags.diagnose(base, diag::overridden_here);
2209+
break;
21972210
}
2198-
2199-
if (parsedAttr->getLocation().isValid())
2200-
ctx.Diags.diagnose(override, diag::override_unavailable, override)
2201-
.fixItRemove(parsedAttr->getRangeWithAt());
2202-
else
2203-
ctx.Diags.diagnose(override, diag::override_unavailable, override);
2204-
ctx.Diags.diagnose(base, diag::overridden_here);
22052211
break;
22062212
}
22072213
case OverrideAvailability::OverrideLessAvailable: {

stdlib/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ project(swift-stdlib LANGUAGES C CXX)
1111
# being built on Windows. Since we know that we only support `clang-cl` as the
1212
# compiler for the runtime due to the use of the Swift calling convention, we
1313
# simply override the CMake behaviour unconditionally.
14-
set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-Isystem")
15-
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-Isystem")
14+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
15+
set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-imsvc ")
16+
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-imsvc ")
17+
else()
18+
set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-Isystem")
19+
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-Isystem")
20+
endif()
1621

1722
# Add path for custom CMake modules.
1823
list(APPEND CMAKE_MODULE_PATH

test/Availability/availability_unavailable_overrides.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ func testOverrideOfUnavailableDeclFromUnavailableDerivedType() {
239239
}
240240
}
241241

242-
243242
func testImplicitSuperInit() {
244243
// FIXME: The diagnostics for the implicit call to super.init() could be
245244
// relaxed since both initializers are unreachable and the developer cannot
@@ -256,3 +255,19 @@ func testImplicitSuperInit() {
256255
// expected-note@-2 {{call to unavailable initializer 'init()' from superclass 'Base' occurs implicitly at the end of this initializer}}
257256
}
258257
}
258+
259+
func testUnavailableInSwiftOverrides() {
260+
class Base {
261+
func availableMethod() {}
262+
}
263+
264+
class Derived1: Base {
265+
@available(swift, introduced: 99)
266+
override func availableMethod() {}
267+
}
268+
269+
class Derived2: Base {
270+
@available(swift, obsoleted: 1)
271+
override func availableMethod() {}
272+
}
273+
}

test/ClangImporter/objc_override.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ class SomeCellSub5 : SomeCell {
8383
func otherIsEnabled() { } // should not conflict
8484
}
8585

86+
class SomeCellSub6 : SomeCell {
87+
@available(*, unavailable)
88+
@objc override init(string: String) {
89+
super.init(string: string)
90+
}
91+
}
92+
93+
class SomeCellSub7 : SomeCell {
94+
@available(swift, obsoleted: 4)
95+
@objc override init(string: String) {
96+
super.init(string: string)
97+
}
98+
}
99+
86100
class FailSub : FailBase {
87101
override init(value: Int) { try! super.init(value: value) } // expected-error {{overriding a throwing '@objc' initializer with a non-throwing initializer is not supported}}
88102
override class func processValue() {} // expected-error {{overriding a throwing '@objc' method with a non-throwing method is not supported}}

test/attr/attr_dynamic_member_lookup.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,8 @@ public struct Inaccessible1 {
253253

254254
@dynamicMemberLookup
255255
public struct Inaccessible2 {
256-
// expected-non-resilient-warning @+3 {{'@dynamicMemberLookup' requires 'subscript(dynamicMember:)' to be as accessible as its enclosing type; this will be an error in a future Swift language mode}}{{21-29=public}}
257-
// expected-resilient-error @+2 {{'@dynamicMemberLookup' requires 'subscript(dynamicMember:)' to be as accessible as its enclosing type}}{{21-29=public}}
258-
// expected-error @+1 {{'@usableFromInline' attribute can only be applied to internal or package declarations, but subscript 'subscript(dynamicMember:)' is public}}
256+
// expected-non-resilient-warning @+2 {{'@dynamicMemberLookup' requires 'subscript(dynamicMember:)' to be as accessible as its enclosing type; this will be an error in a future Swift language mode}}{{21-29=public}}
257+
// expected-resilient-error @+1 {{'@dynamicMemberLookup' requires 'subscript(dynamicMember:)' to be as accessible as its enclosing type}}{{21-29=public}}
259258
@usableFromInline internal subscript(dynamicMember member: String) -> Int {
260259
return 42
261260
}
@@ -279,6 +278,18 @@ private struct Inaccessible4 {
279278
}
280279
}
281280

281+
@dynamicMemberLookup
282+
public struct Inaccessible5 {
283+
internal struct Nested { }
284+
var nested: Nested
285+
286+
// expected-non-resilient-warning @+2 {{'@dynamicMemberLookup' requires 'subscript(dynamicMember:)' to be as accessible as its enclosing type; this will be an error in a future Swift language mode}}{{3-11=public}}
287+
// expected-resilient-error @+1 {{'@dynamicMemberLookup' requires 'subscript(dynamicMember:)' to be as accessible as its enclosing type}}{{3-11=public}}
288+
internal subscript<Value>(dynamicMember keyPath: KeyPath<Nested, Value>) -> Value {
289+
nested[keyPath: keyPath]
290+
}
291+
}
292+
282293
//===----------------------------------------------------------------------===//
283294
// Existentials
284295
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)