Skip to content

Commit d62beac

Browse files
authored
Merge pull request #60864 from xedin/type-wrappers-on-actors
[Sema] TypeWrappers: Don't try to manage compiler synthesized properties
2 parents 8214b85 + 325b54d commit d62beac

File tree

5 files changed

+79
-7
lines changed

5 files changed

+79
-7
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ static ConstructorDecl *createImplicitConstructor(NominalTypeDecl *decl,
381381
continue;
382382

383383
if (!var->isAccessedViaTypeWrapper()) {
384-
// $_storage itself.
385-
if (var->getName() == ctx.Id_TypeWrapperProperty)
384+
// Compiler synthesized properties are not included.
385+
if (var->isImplicit())
386386
continue;
387387

388388
// Computed properties are not included.

lib/Sema/TypeCheckTypeWrapper.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,6 @@ bool IsPropertyAccessedViaTypeWrapper::evaluate(Evaluator &evaluator,
312312
if (!(parent && parent->hasTypeWrapper()))
313313
return false;
314314

315-
// Don't attempt to wrap the `$_storage` property.
316-
if (property->getName() == property->getASTContext().Id_TypeWrapperProperty)
317-
return false;
318-
319315
if (property->isStatic() || property->isLet())
320316
return false;
321317

@@ -346,6 +342,11 @@ bool IsPropertyAccessedViaTypeWrapper::evaluate(Evaluator &evaluator,
346342
return true;
347343
}
348344

345+
// Don't wrap any compiler synthesized properties except to
346+
// property wrapper backing storage (checked above).
347+
if (property->isImplicit())
348+
return false;
349+
349350
// Check whether this is a computed property.
350351
{
351352
auto declaresAccessor = [&](ArrayRef<AccessorKind> kinds) -> bool {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -target %target-cpu-apple-macosx10.15 -enable-experimental-feature TypeWrappers -parse-as-library -emit-library -emit-module-path %t/type_wrapper_defs.swiftmodule -module-name type_wrapper_defs %S/Inputs/type_wrapper_defs.swift -o %t/%target-library-name(type_wrapper_defs)
3+
// RUN: %target-build-swift -target %target-cpu-apple-macosx10.15 -ltype_wrapper_defs -module-name main -I %t -L %t %s -o %t/main %target-rpath(%t)
4+
// RUN: %target-codesign %t/main
5+
// RUN: %target-run %t/main %t/%target-library-name(type_wrapper_defs) | %FileCheck %s
6+
7+
// REQUIRES: executable_test
8+
// REQUIRES: asserts
9+
// REQUIRES: concurrency
10+
11+
// rdar://76038845
12+
// REQUIRES: concurrency_runtime
13+
// UNSUPPORTED: back_deployment_runtime
14+
15+
// REQUIRES: OS=macosx
16+
17+
// This requires executable tests to be run on the same machine as the compiler,
18+
// as it links with a dylib that it doesn't arrange to get uploaded to remote executors.
19+
// (rdar://99051588)
20+
// UNSUPPORTED: remote_run || device_run
21+
22+
import type_wrapper_defs
23+
24+
@Wrapper
25+
public actor Actor {
26+
public var name: String
27+
@PropWrapper public var age: Int? = nil
28+
29+
public func setAge(_ newAge: Int) async {
30+
age = newAge
31+
}
32+
}
33+
34+
let a = Actor(name: "Arhtur Dent")
35+
await print(a.name)
36+
// CHECK: in getter
37+
// CHECK-NEXT: Arhtur Dent
38+
await print(a.age)
39+
// CHECK: in getter
40+
// CHECK-NEXT: nil
41+
42+
await a.setAge(30)
43+
// CHECK: in getter
44+
// CHECK-NEXT: in setter => PropWrapper<Optional<Int>>(value: Optional(30))
45+
46+
await print(a.age)
47+
// CHECK: in getter
48+
// CHECK-NEXT: 30

test/Interpreter/type_wrappers.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
// REQUIRES: executable_test
88
// REQUIRES: asserts
99

10+
// This requires executable tests to be run on the same machine as the compiler,
11+
// as it links with a dylib that it doesn't arrange to get uploaded to remote executors.
12+
// (rdar://99051588)
13+
// UNSUPPORTED: remote_run || device_run
14+
1015
import type_wrapper_defs
1116

1217
var p: Person<String> = .init(name: "P", projects: ["A", "B"])

test/type/type_wrapper.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature TypeWrappers
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature TypeWrappers
22

33
// REQUIRES: asserts
44

@@ -380,3 +380,21 @@ func testDeclarationsWithUnmanagedProperties() {
380380

381381
_ = OnlyLazyLetAndComputed(name: "Arthur Dent") // Ok
382382
}
383+
384+
func testActors() async {
385+
@NoopWrapper
386+
actor Person {
387+
var name: String
388+
// expected-note@-1 {{mutation of this property is only permitted within the actor}}
389+
var age: Int
390+
// expected-note@-1 {{mutation of this property is only permitted within the actor}}
391+
}
392+
393+
let person = Person(name: "Arthur Dent", age: 30)
394+
395+
_ = await person.name
396+
_ = await person.age
397+
398+
person.name = "NoName" // expected-error {{actor-isolated property 'name' can not be mutated from a non-isolated context}}
399+
person.age = 0 // expected-error {{actor-isolated property 'age' can not be mutated from a non-isolated context}}
400+
}

0 commit comments

Comments
 (0)