Skip to content

Commit a60da75

Browse files
committed
fix bug with unidentified custom attribute during serialization
In Swift 5 mode, I only warned about the global-actor attribute becoming unnecessary in the future, yet I was still returning None for the global-actor attribute checking request. This led to the attribute remaining unidentified, but also not removed. During module serialization, this problem was manifesting as emitting a typeless attribute, which when deserialized would trigger a segfault.
1 parent bd024ca commit a60da75

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,15 @@ GlobalActorAttributeRequest::evaluate(
360360
if (!var->isStatic() && var->isOrdinaryStoredProperty()) {
361361
if (auto *nominal = var->getDeclContext()->getSelfNominalTypeDecl()) {
362362
if (nominal->isValueType()) {
363+
363364
var->diagnose(diag::global_actor_on_storage_of_value_type,
364365
var->getName(), nominal->getDescriptiveKind())
365366
.highlight(globalActorAttr->getRangeWithAt())
366367
.warnUntilSwiftVersion(6);
367-
return None;
368+
369+
// In Swift 6, once the diag above is an error, it is disallowed.
370+
if (var->getASTContext().isSwiftVersionAtLeast(6))
371+
return None;
368372
}
369373
}
370374
}

test/Concurrency/Inputs/dynamically_replaceable.swift

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
// dynamically_replaceable
3+
@MainActor
4+
public dynamic func dynamicOnMainActor() { }
5+
6+
// property wrapper + main actor
7+
@propertyWrapper
8+
public struct IntWrapper {
9+
10+
public init(wrappedValue: Int) {
11+
self.wrappedValue = wrappedValue
12+
}
13+
14+
@MainActor public var wrappedValue: Int
15+
}

test/Concurrency/global_actor_inference.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/dynamically_replaceable.swiftmodule -module-name dynamically_replaceable -warn-concurrency %S/Inputs/dynamically_replaceable.swift
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/other_global_actor_inference.swiftmodule -module-name other_global_actor_inference -warn-concurrency %S/Inputs/other_global_actor_inference.swift
33
// RUN: %target-typecheck-verify-swift -I %t -disable-availability-checking
44
// REQUIRES: concurrency
5-
import dynamically_replaceable
5+
import other_global_actor_inference
66

77
actor SomeActor { }
88

@@ -31,6 +31,14 @@ struct GenericGlobalActor<T> {
3131
@MainActor class Copper {}
3232
@MainActor func iron() {}
3333

34+
struct Carbon {
35+
@IntWrapper var atomicWeight: Int
36+
37+
func getWeight() -> Int {
38+
return atomicWeight
39+
}
40+
}
41+
3442
// ----------------------------------------------------------------------
3543
// Check that @MainActor(blah) doesn't work
3644
// ----------------------------------------------------------------------

0 commit comments

Comments
 (0)