Skip to content

Commit 07a71e5

Browse files
committed
Forbid lazy with @abi
It’s not clear how `@abi` would apply to the auxiliary decl used for `lazy`.
1 parent 4b1c507 commit 07a71e5

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
@@ -8430,6 +8430,9 @@ ERROR(attr_abi_no_default_arguments,none,
84308430
ERROR(attr_abi_no_macros,none,
84318431
"%kind0 cannot be expanded in '@abi' attribute",
84328432
(Decl *))
8433+
ERROR(attr_abi_no_lazy,none,
8434+
"'lazy' is not compatible with '@abi' attribute",
8435+
())
84338436
84348437
// These macros insert 'final', 'non-final', or nothing depending on both the
84358438
// 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
@@ -1088,6 +1088,11 @@ void AttributeChecker::visitLazyAttr(LazyAttr *attr) {
10881088
// are already lazily initialized).
10891089
if (VD->isStatic() || varDC->isModuleScopeContext())
10901090
diagnoseAndRemoveAttr(attr, diag::lazy_on_already_lazy_global);
1091+
1092+
// 'lazy' can't be used in or with `@abi` because it has auxiliary decls.
1093+
auto abiRole = ABIRoleInfo(D);
1094+
if (!abiRole.providesABI() || !abiRole.providesAPI())
1095+
diagnoseAndRemoveAttr(attr, diag::attr_abi_no_lazy);
10911096
}
10921097

10931098
bool AttributeChecker::visitAbstractAccessControlAttr(

test/attr/attr_abi.swift

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

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

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

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

19621963
// @_fixed_layout -- banned in @abi

0 commit comments

Comments
 (0)