Skip to content

Commit 054a403

Browse files
committed
Forbid lazy with @abi
It’s not clear how `@abi` would apply to the auxiliary decl used for `lazy`.
1 parent a39bb0b commit 054a403

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

include/swift/AST/DeclAttr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ SIMPLE_DECL_ATTR(NSManaged, NSManaged,
143143

144144
CONTEXTUAL_SIMPLE_DECL_ATTR(lazy, Lazy,
145145
OnVar,
146-
DeclModifier | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | InferredInABIAttr,
146+
DeclModifier | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | UnconstrainedInABIAttr,
147147
16)
148148

149149
SIMPLE_DECL_ATTR(LLDBDebuggerFunction, LLDBDebuggerFunction,

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8501,6 +8501,9 @@ ERROR(attr_abi_no_default_arguments,none,
85018501
ERROR(attr_abi_no_macros,none,
85028502
"%kind0 cannot be expanded in '@abi' attribute",
85038503
(Decl *))
8504+
ERROR(attr_abi_no_lazy,none,
8505+
"'lazy' is not compatible with '@abi' attribute",
8506+
())
85048507
85058508
// These macros insert 'final', 'non-final', or nothing depending on both the
85068509
// current decl and its counterpart, such that 'non-final' is used if the

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,11 @@ void AttributeChecker::visitLazyAttr(LazyAttr *attr) {
11101110
// are already lazily initialized).
11111111
if (VD->isStatic() || varDC->isModuleScopeContext())
11121112
diagnoseAndRemoveAttr(attr, diag::lazy_on_already_lazy_global);
1113+
1114+
// 'lazy' can't be used in or with `@abi` because it has auxiliary decls.
1115+
auto abiRole = ABIRoleInfo(D);
1116+
if (!abiRole.providesABI() || !abiRole.providesAPI())
1117+
diagnoseAndRemoveAttr(attr, diag::attr_abi_no_lazy);
11131118
}
11141119

11151120
bool AttributeChecker::visitAbstractAccessControlAttr(

test/attr/attr_abi.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,16 +1946,17 @@ class Required {
19461946
required init(i3: Void) { fatalError() } // expected-note {{should match modifier here}}
19471947
}
19481948

1949-
// lazy -- automatically cloned into @abi
1949+
// lazy -- banned both in and with @abi
1950+
// This introduces auxiliary decls whose ABI could not be controlled.
19501951
class Lazy {
1951-
@abi(lazy var v1: Int)
1952-
lazy var v1: Int = 0
1952+
@abi(lazy var v1: Int) // expected-error {{'lazy' is not compatible with '@abi' attribute}} {{8-12=}}
1953+
lazy var v1: Int = 0 // expected-error {{'lazy' is not compatible with '@abi' attribute}} {{3-8=}}
19531954

1954-
@abi(lazy var v2: Int) // expected-error {{extra 'lazy' modifier in '@abi'}} {{8-12=}}
1955+
@abi(lazy var v2: Int) // expected-error {{'lazy' is not compatible with '@abi' attribute}} {{8-12=}}
19551956
var v2: Int = 0
19561957

1957-
@abi(var v3: Int) // expected-remark {{inferred 'lazy' in '@abi' to match modifier on API}}
1958-
lazy var v3: Int = 0 // expected-note {{matches modifier here}}
1958+
@abi(var v3: Int)
1959+
lazy var v3: Int = 0 // expected-error {{'lazy' is not compatible with '@abi' attribute}} {{3-8=}}
19591960
}
19601961

19611962
// @_fixed_layout -- banned in @abi

0 commit comments

Comments
 (0)