Skip to content

Commit 0f48f5c

Browse files
committed
[AST/Sema] TypeWrappers/NFC: Rename type wrapper init parameter to storage:
1 parent 49405aa commit 0f48f5c

10 files changed

+41
-43
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6600,7 +6600,7 @@ ERROR(cannot_use_multiple_type_wrappers,none,
66006600

66016601
ERROR(type_wrapper_requires_memberwise_init,none,
66026602
"type wrapper type %0 does not contain a required initializer"
6603-
" - init(memberwise:)",
6603+
" - init(storage:)",
66046604
(DeclName))
66056605

66066606
ERROR(type_wrapper_requires_subscript,none,

include/swift/AST/KnownIdentifiers.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ IDENTIFIER_WITH_NAME(builderSelf, "$builderSelf")
313313
IDENTIFIER_WITH_NAME(TypeWrapperStorage, "$Storage")
314314
IDENTIFIER_WITH_NAME(TypeWrapperProperty, "$_storage")
315315
IDENTIFIER(storageKeyPath)
316-
IDENTIFIER(memberwise)
317316
IDENTIFIER_WITH_NAME(localStorageVar, "_storage")
318317

319318
// Attribute options

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ namespace {
459459
/// corresponds to `self`.
460460
void injectActorHops();
461461

462-
/// Injects `self.$storage = .init(memberwise: $Storage(...))`
462+
/// Injects `self.$storage = .init(storage: $Storage(...))`
463463
/// assignment instructions into the function after each point
464464
/// where `_storage` becomes fully initialized via `assign_by_wrapper`.
465465
/// This is only necessary only for user-defined initializers of a
@@ -1117,7 +1117,7 @@ void LifetimeChecker::injectTypeWrapperStorageInitalization() {
11171117
auto storageType = F.getLoweredType(
11181118
ctor->mapTypeIntoContext(storageDecl->getDeclaredInterfaceType()));
11191119

1120-
// Argument value to use in call to <TypeWrapper>.init(memberwise:)
1120+
// Argument value to use in call to <TypeWrapper>.init(storage:)
11211121
SILValue storageObj = allocStack(storageType);
11221122

11231123
// let storageObj = $Storage(<destructured _storage tuple>)
@@ -1253,7 +1253,7 @@ void LifetimeChecker::injectTypeWrapperStorageInitalization() {
12531253
StoreOwnershipQualifier::Init);
12541254
}
12551255

1256-
// self.$storage = <TypeWrapper>(memberwise: storageObj))
1256+
// self.$storage = <TypeWrapper>(storage: storageObj))
12571257
{
12581258
bool isClass = isa<ClassDecl>(parentType);
12591259

@@ -1308,7 +1308,7 @@ void LifetimeChecker::injectTypeWrapperStorageInitalization() {
13081308
wrapperInitArgs.push_back(storageObj);
13091309
wrapperInitArgs.push_back(typeWrapperType);
13101310

1311-
// <wrapper-var> = <TypeWrapper>.init(memberwise: tmpStorage)
1311+
// <wrapper-var> = <TypeWrapper>.init(storage: tmpStorage)
13121312
auto wrapperInitResult = b.createApply(
13131313
loc, typeWrapperInitRef,
13141314
SubstitutionMap::get(typeWrapperInit->getGenericSignature(),

lib/Sema/TypeCheckAttr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3751,7 +3751,7 @@ void AttributeChecker::visitTypeWrapperAttr(TypeWrapperAttr *attr) {
37513751
// Check whether type marked as @typeWrapper is valid:
37523752
//
37533753
// - Has a single generic parameter <Storage>
3754-
// - Has `init(memberwise: <Storage>)`
3754+
// - Has `init(storage: <Storage>)`
37553755
// - Has at least one `subscript(storedKeyPath: KeyPath<...>)` overload
37563756

37573757
// Has a single generic parameter.
@@ -3765,10 +3765,10 @@ void AttributeChecker::visitTypeWrapperAttr(TypeWrapperAttr *attr) {
37653765
}
37663766
}
37673767

3768-
// `init(memberwise:)`
3768+
// `init(storage:)`
37693769
{
37703770
DeclName initName(ctx, DeclBaseName::createConstructor(),
3771-
ArrayRef<Identifier>(ctx.Id_memberwise));
3771+
ArrayRef<Identifier>(ctx.Id_storage));
37723772

37733773
SmallVector<ValueDecl *, 2> inits;
37743774
if (findMembersOrDiagnose(initName, inits,
@@ -3806,7 +3806,7 @@ void AttributeChecker::visitTypeWrapperAttr(TypeWrapperAttr *attr) {
38063806
break;
38073807

38083808
case UnviabilityReason::InvalidType:
3809-
llvm_unreachable("init(memberwise:) type is not checked");
3809+
llvm_unreachable("init(storage:) type is not checked");
38103810
}
38113811
}
38123812
}

lib/Sema/TypeCheckTypeWrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ BraceStmt *SynthesizeTypeWrappedTypeMemberwiseInitializerBody::evaluate(
403403
auto &ctx = ctor->getASTContext();
404404
auto *parent = ctor->getDeclContext()->getSelfNominalTypeDecl();
405405

406-
// self.$_storage = .init(memberwise: $Storage(...))
406+
// self.$_storage = .init(storage: $Storage(...))
407407
auto *storageType = parent->getTypeWrapperStorageDecl();
408408
assert(storageType);
409409

@@ -481,7 +481,7 @@ BraceStmt *SynthesizeTypeWrappedTypeMemberwiseInitializerBody::evaluate(
481481
// .init($Storage(...))
482482
Expr *typeWrapperInit = CallExpr::createImplicit(
483483
ctx, initRef,
484-
ArgumentList::forImplicitSingle(ctx, ctx.Id_memberwise, storageInit));
484+
ArgumentList::forImplicitSingle(ctx, ctx.Id_storage, storageInit));
485485

486486
body.push_back(new (ctx) AssignExpr(storageVarRef, /*EqualLoc=*/SourceLoc(),
487487
typeWrapperInit,
@@ -533,7 +533,7 @@ GetTypeWrapperInitializer::evaluate(Evaluator &evaluator,
533533
assert(typeWrapper->getAttrs().hasAttribute<TypeWrapperAttr>());
534534

535535
auto ctors = typeWrapper->lookupDirect(
536-
DeclName(ctx, DeclBaseName::createConstructor(), {ctx.Id_memberwise}));
536+
DeclName(ctx, DeclBaseName::createConstructor(), {ctx.Id_storage}));
537537

538538
if (ctors.size() != 1)
539539
return nullptr;

test/Interpreter/Inputs/type_wrapper_defs.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
public struct Wrapper<S> {
33
var underlying: S
44

5-
public init(memberwise: S) {
6-
print("Wrapper.init(\(memberwise))")
7-
self.underlying = memberwise
5+
public init(storage: S) {
6+
print("Wrapper.init(\(storage))")
7+
self.underlying = storage
88
}
99

1010
public subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {

test/SILOptimizer/type_wrapper_definite_init_diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
struct Wrapper<S> {
77
var underlying: S
88

9-
init(memberwise: S) { self.underlying = memberwise }
9+
init(storage: S) { self.underlying = storage }
1010

1111
subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {
1212
get { underlying[keyPath: path] }

test/SILOptimizer/type_wrapper_in_user_defined_init_lowering.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import SwiftShims
88

99
@typeWrapper class MyWrapper<S> {
1010
@_hasStorage var underlying: S { get set }
11-
init(memberwise s: S)
11+
init(storage s: S)
1212
subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V { get }
1313
subscript<V>(storageKeyPath path: WritableKeyPath<S, V>) -> V { get set }
1414
deinit

test/SILOptimizer/type_wrapper_init_transform.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
public struct Wrapper<S> {
77
var underlying: S
88

9-
public init(memberwise: S) {
10-
print("Wrapper.init(\(memberwise))")
11-
self.underlying = memberwise
9+
public init(storage: S) {
10+
self.underlying = storage
1211
}
1312

1413
public subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {
@@ -33,7 +32,7 @@ struct TrivialStruct {
3332
// CHECK: [[STORAGE_METATYPE:%.*]] = metatype $@thin TrivialStruct.$Storage.Type
3433
// CHECK: [[STORAGE_INIT_RES:%.*]] = apply [[STORAGE_INIT_REF]]([[STORAGE_METATYPE]]) : $@convention(method) (@thin TrivialStruct.$Storage.Type) -> TrivialStruct.$Storage
3534
// CHECK: store [[STORAGE_INIT_RES]] to [trivial] [[STORAGE_INST]] : $*TrivialStruct.$Storage
36-
// CHECK: [[WRAPPER_INIT_REF:%.*]] = function_ref @$s4test7WrapperV10memberwiseACyxGx_tcfC : $@convention(method) <τ_0_0> (@in τ_0_0, @thin Wrapper<τ_0_0>.Type) -> @out Wrapper<τ_0_0>
35+
// CHECK: [[WRAPPER_INIT_REF:%.*]] = function_ref @$s4test7WrapperV7storageACyxGx_tcfC : $@convention(method) <τ_0_0> (@in τ_0_0, @thin Wrapper<τ_0_0>.Type) -> @out Wrapper<τ_0_0>
3736
// CHECK: [[SELF_ACCESS:%.*]] = begin_access [modify] [static] %1 : $*TrivialStruct
3837
// CHECK: [[STORAGE_VAR_REF:%.*]] = struct_element_addr [[SELF_ACCESS]] : $*TrivialStruct, #TrivialStruct.$_storage
3938
// CHECK: [[WRAPPER_METATYPE:%.*]] = metatype $@thin Wrapper<TrivialStruct.$Storage>.Type
@@ -67,7 +66,7 @@ struct GenericStruct<T: Collection> {
6766
// CHECK: end_access [[LOCAL_STORAGE_ACCESS]] : $*(test: T)
6867
// CHECK: [[STORAGE_METATYPE:%.*]] = metatype $@thin GenericStruct<T>.$Storage.Type
6968
// CHECK: {{.*}} = apply [[STORAGE_INIT_REF]]<T>([[STORAGE_INST]], [[T_VAL]], [[STORAGE_METATYPE]]) : $@convention(method) <τ_0_0 where τ_0_0 : Collection> (@in τ_0_0, @thin GenericStruct<τ_0_0>.$Storage.Type) -> @out GenericStruct<τ_0_0>.$Storage
70-
// CHECK: [[WRAPPER_INIT_REF:%.*]] = function_ref @$s4test7WrapperV10memberwiseACyxGx_tcfC : $@convention(method) <τ_0_0> (@in τ_0_0, @thin Wrapper<τ_0_0>.Type) -> @out Wrapper<τ_0_0>
69+
// CHECK: [[WRAPPER_INIT_REF:%.*]] = function_ref @$s4test7WrapperV7storageACyxGx_tcfC : $@convention(method) <τ_0_0> (@in τ_0_0, @thin Wrapper<τ_0_0>.Type) -> @out Wrapper<τ_0_0>
7170
// CHECK: [[SELF_ACCESS:%.*]] = begin_access [modify] [static] [[SELF]] : $*GenericStruct<T>
7271
// CHECK: [[STORAGE_VAR:%.*]] = struct_element_addr [[SELF_ACCESS]] : $*GenericStruct<T>, #GenericStruct.$_storage
7372
// CHECK: [[WRAPPER_METATYPE:%.*]] = metatype $@thin Wrapper<GenericStruct<T>.$Storage>.Type
@@ -372,7 +371,7 @@ struct TypeWithLetProperties<T> {
372371
// CHECK-NEXT: [[STORAGE_METATYPE:%.*]] = metatype $@thin TypeWithLetProperties<T>.$Storage.Type
373372
// CHECK-NEXT: {{.*}} = apply [[STORAGE_INIT_REF]]<T>([[STORAGE]], [[T]], [[B_VAL]], [[STORAGE_METATYPE]])
374373

375-
// CHECK: [[WRAPPER_INIT_REF:%.*]] = function_ref @$s4test7WrapperV10memberwiseACyxGx_tcfC
374+
// CHECK: [[WRAPPER_INIT_REF:%.*]] = function_ref @$s4test7WrapperV7storageACyxGx_tcfC
376375
// CHECK: [[STORAGE_PROP:%.*]] = struct_element_addr [[SELF_ACCESS:%.*]] : $*TypeWithLetProperties<T>, #TypeWithLetProperties.$_storage
377376
// CHECK: [[WRAPPER_INST:%.*]] = alloc_stack $Wrapper<TypeWithLetProperties<T>.$Storage>
378377
// CHECK-NEXT: {{.*}} = apply [[WRAPPER_INIT_REF]]<TypeWithLetProperties<T>.$Storage>([[WRAPPER_INST]], [[STORAGE]], [[WRAPPER_METATYPE:%.*]])
@@ -402,7 +401,7 @@ struct TypeWithLetProperties<T> {
402401
// CHECK-NEXT: [[STORAGE_METATYPE:%.*]] = metatype $@thin TypeWithLetProperties<T>.$Storage.Type
403402
// CHECK-NEXT: {{.*}} = apply [[STORAGE_INIT_REF]]<T>([[STORAGE]], [[T]], [[B_VAL]], [[STORAGE_METATYPE]])
404403

405-
// CHECK: [[WRAPPER_INIT_REF:%.*]] = function_ref @$s4test7WrapperV10memberwiseACyxGx_tcfC
404+
// CHECK: [[WRAPPER_INIT_REF:%.*]] = function_ref @$s4test7WrapperV7storageACyxGx_tcfC
406405
// CHECK: [[STORAGE_PROP:%.*]] = struct_element_addr [[SELF_ACCESS:%.*]] : $*TypeWithLetProperties<T>, #TypeWithLetProperties.$_storage
407406
// CHECK: [[WRAPPER_INST:%.*]] = alloc_stack $Wrapper<TypeWithLetProperties<T>.$Storage>
408407
// CHECK-NEXT: {{.*}} = apply [[WRAPPER_INIT_REF]]<TypeWithLetProperties<T>.$Storage>([[WRAPPER_INST]], [[STORAGE]], [[WRAPPER_METATYPE:%.*]])

test/type/type_wrapper.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
@typeWrapper
66
struct ConcreteTypeWrapper { // expected-error {{type wrapper has to declare a single generic parameter for underlying storage type}}
7-
init(memberwise: Int) {}
7+
init(storage: Int) {}
88
}
99

1010
@typeWrapper
11-
struct EmptyTypeWrapper<S> { // expected-error {{type wrapper type 'EmptyTypeWrapper' does not contain a required initializer - init(memberwise:)}}
11+
struct EmptyTypeWrapper<S> { // expected-error {{type wrapper type 'EmptyTypeWrapper' does not contain a required initializer - init(storage:)}}
1212
}
1313

1414
@typeWrapper
1515
struct NoMemberwiseInit<S> {
16-
// expected-error@-1 {{type wrapper type 'NoMemberwiseInit' does not contain a required initializer - init(memberwise:)}}
16+
// expected-error@-1 {{type wrapper type 'NoMemberwiseInit' does not contain a required initializer - init(storage:)}}
1717

1818
subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {
1919
get { fatalError() }
@@ -22,24 +22,24 @@ struct NoMemberwiseInit<S> {
2222

2323
@typeWrapper
2424
struct FailableInit<S> {
25-
init?(memberwise: S) { // expected-error {{type wrapper initializer 'init(memberwise:)' cannot be failable}}
25+
init?(storage: S) { // expected-error {{type wrapper initializer 'init(storage:)' cannot be failable}}
2626
}
2727

2828
subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {
2929
get { fatalError() }
3030
}
3131
}
3232

33-
// Okay because there is a valid `init(memberwise:)` overload.
33+
// Okay because there is a valid `init(storage:)` overload.
3434
@typeWrapper
3535
struct FailableAndValidInit<S> {
3636
// expected-error@-1 {{type wrapper type 'FailableAndValidInit' does not contain a required writable subscript}}
3737
// expected-note@-2 {{do you want to add a stub?}} {{33-33=\nsubscript<Value>(storageKeyPath path: WritableKeyPath<<#Base#>, Value>) -> Value { get { <#code#> \} set { <#code#> \} \}}}
3838

39-
init(memberwise: S) {
39+
init(storage: S) {
4040
}
4141

42-
init?(memberwise: S) where S == Int {
42+
init?(storage: S) where S == Int {
4343
}
4444

4545
subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {
@@ -49,13 +49,13 @@ struct FailableAndValidInit<S> {
4949

5050
@typeWrapper
5151
public struct InaccessibleInit<S> {
52-
fileprivate init(memberwise: S) {
53-
// expected-error@-1 {{fileprivate initializer 'init(memberwise:)' cannot have more restrictive access than its enclosing type wrapper type 'InaccessibleInit' (which is public)}}
52+
fileprivate init(storage: S) {
53+
// expected-error@-1 {{fileprivate initializer 'init(storage:)' cannot have more restrictive access than its enclosing type wrapper type 'InaccessibleInit' (which is public)}}
5454
}
5555

56-
private init?(memberwise: S) where S: AnyObject {
57-
// expected-error@-1 {{private initializer 'init(memberwise:)' cannot have more restrictive access than its enclosing type wrapper type 'InaccessibleInit' (which is public)}}
58-
// expected-error@-2 {{type wrapper initializer 'init(memberwise:)' cannot be failable}}
56+
private init?(storage: S) where S: AnyObject {
57+
// expected-error@-1 {{private initializer 'init(storage:)' cannot have more restrictive access than its enclosing type wrapper type 'InaccessibleInit' (which is public)}}
58+
// expected-error@-2 {{type wrapper initializer 'init(storage:)' cannot be failable}}
5959
}
6060

6161
subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {
@@ -66,12 +66,12 @@ public struct InaccessibleInit<S> {
6666
@typeWrapper
6767
struct NoSubscripts<S> {
6868
// expected-error@-1 {{type wrapper type 'NoSubscripts' does not contain a required subscript - subscript(storedKeyPath:)}}
69-
init(memberwise: S) {}
69+
init(storage: S) {}
7070
}
7171

7272
@typeWrapper
7373
struct InaccessibleOrInvalidSubscripts<S> {
74-
init(memberwise: S) {}
74+
init(storage: S) {}
7575

7676
fileprivate subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {
7777
// expected-error@-1 {{fileprivate subscript 'subscript(storageKeyPath:)' cannot have more restrictive access than its enclosing type wrapper type 'InaccessibleOrInvalidSubscripts' (which is internal)}}
@@ -95,7 +95,7 @@ struct InaccessibleOrInvalidSubscripts<S> {
9595

9696
@typeWrapper
9797
struct NoopWrapper<S> {
98-
init(memberwise: S) {}
98+
init(storage: S) {}
9999

100100
subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {
101101
get { fatalError() }
@@ -138,7 +138,7 @@ func testWrappedTypeAccessChecking() {
138138
struct Parent {
139139
@typeWrapper
140140
struct Wrapper<S> {
141-
init(memberwise: S) {}
141+
init(storage: S) {}
142142

143143
subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {
144144
get { fatalError() }
@@ -460,7 +460,7 @@ func testMissingReadOnlyAndWritableSubscriptsAreDiagnosed() {
460460
// expected-error@-1 {{type wrapper type 'MissingReadOnly' does not contain a required ready-only subscript}}
461461
// expected-note@-2 {{do you want to add a stub?}} {{30-30=\nsubscript<Value>(storageKeyPath path: KeyPath<<#Base#>, Value>) -> Value { get { <#code#> \} \}}}
462462

463-
init(memberwise: S) {}
463+
init(storage: S) {}
464464

465465
subscript<V>(storageKeyPath path: WritableKeyPath<S, V>) -> V {
466466
get { fatalError() }
@@ -473,7 +473,7 @@ func testMissingReadOnlyAndWritableSubscriptsAreDiagnosed() {
473473
// expected-error@-1 {{type wrapper type 'MissingWritable' does not contain a required writable subscript}}
474474
// expected-note@-2 {{do you want to add a stub?}} {{30-30=\nsubscript<Value>(storageKeyPath path: WritableKeyPath<<#Base#>, Value>) -> Value { get { <#code#> \} set { <#code#> \} \}}}
475475

476-
init(memberwise: S) {}
476+
init(storage: S) {}
477477

478478
subscript<V>(storageKeyPath path: KeyPath<S, V>) -> V {
479479
get { fatalError() }

0 commit comments

Comments
 (0)