Skip to content

Commit aa55700

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents ab59e23 + d3b5996 commit aa55700

File tree

12 files changed

+129
-133
lines changed

12 files changed

+129
-133
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,6 +3009,8 @@ ERROR(lazy_must_be_property,none,
30093009
"lazy is only valid for members of a struct or class", ())
30103010
ERROR(lazy_not_strong,none,
30113011
"lazy properties cannot be %0", (ReferenceOwnership))
3012+
ERROR(lazy_var_storage_access,none,
3013+
"access to the underlying storage of a lazy property is not allowed", ())
30123014

30133015
// Debugger function attribute.
30143016
ERROR(attr_for_debugger_support_only,none,

lib/Sema/MiscDiagnostics.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4390,6 +4390,53 @@ static void maybeDiagnoseCallToKeyValueObserveMethod(const Expr *E,
43904390
const_cast<Expr *>(E)->walk(Walker);
43914391
}
43924392

4393+
static void diagnoseExplicitUseOfLazyVariableStorage(const Expr *E,
4394+
const DeclContext *DC) {
4395+
4396+
class ExplicitLazyVarStorageAccessFinder : public ASTWalker {
4397+
const ASTContext &C;
4398+
4399+
public:
4400+
ExplicitLazyVarStorageAccessFinder(ASTContext &ctx) : C(ctx) {}
4401+
4402+
void tryDiagnoseExplicitLazyStorageVariableUse(MemberRefExpr *MRE) {
4403+
if (MRE->isImplicit()) {
4404+
return;
4405+
}
4406+
auto VD = dyn_cast<VarDecl>(MRE->getMember().getDecl());
4407+
if (!VD) {
4408+
return;
4409+
}
4410+
auto sourceFileKind = VD->getDeclContext()->getParentSourceFile();
4411+
if (!sourceFileKind) {
4412+
return;
4413+
}
4414+
if (sourceFileKind->Kind != SourceFileKind::Library &&
4415+
sourceFileKind->Kind != SourceFileKind::Main) {
4416+
return;
4417+
}
4418+
if (VD->isLazyStorageProperty()) {
4419+
C.Diags.diagnose(MRE->getLoc(), diag::lazy_var_storage_access);
4420+
}
4421+
}
4422+
4423+
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
4424+
if (!E || isa<ErrorExpr>(E) || !E->getType())
4425+
return {false, E};
4426+
4427+
if (auto *MRE = dyn_cast<MemberRefExpr>(E)) {
4428+
tryDiagnoseExplicitLazyStorageVariableUse(MRE);
4429+
return {false, E};
4430+
}
4431+
4432+
return {true, E};
4433+
}
4434+
};
4435+
4436+
ExplicitLazyVarStorageAccessFinder Walker(DC->getASTContext());
4437+
const_cast<Expr *>(E)->walk(Walker);
4438+
}
4439+
43934440
//===----------------------------------------------------------------------===//
43944441
// High-level entry points.
43954442
//===----------------------------------------------------------------------===//
@@ -4405,6 +4452,7 @@ void swift::performSyntacticExprDiagnostics(const Expr *E,
44054452
diagnoseImplicitSelfUseInClosure(E, DC);
44064453
diagnoseUnintendedOptionalBehavior(E, DC);
44074454
maybeDiagnoseCallToKeyValueObserveMethod(E, DC);
4455+
diagnoseExplicitUseOfLazyVariableStorage(E, DC);
44084456
if (!ctx.isSwiftVersionAtLeast(5))
44094457
diagnoseDeprecatedWritableKeyPath(E, DC);
44104458
if (!ctx.LangOpts.DisableAvailabilityChecking)

lib/Sema/TypeCheckType.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,15 +2345,23 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
23452345
}
23462346
}
23472347

2348-
if (hasFunctionAttr && !fnRepr) {
2349-
if (attrs.has(TAK_autoclosure)) {
2348+
if (attrs.has(TAK_autoclosure)) {
2349+
// If this is a situation where function type is wrapped
2350+
// into a number of parens, let's try to look through them,
2351+
// because parens are insignificant here e.g.:
2352+
//
2353+
// let _: (@autoclosure (() -> Void)) -> Void = { _ in }
2354+
if (!ty->is<FunctionType>()) {
23502355
// @autoclosure is going to be diagnosed when type of
23512356
// the parameter is validated, because that attribute
23522357
// applies to the declaration now.
23532358
repr->setInvalid();
2354-
attrs.clearAttribute(TAK_autoclosure);
23552359
}
23562360

2361+
attrs.clearAttribute(TAK_autoclosure);
2362+
}
2363+
2364+
if (hasFunctionAttr && !fnRepr) {
23572365
const auto diagnoseInvalidAttr = [&](TypeAttrKind kind) {
23582366
if (kind == TAK_escaping) {
23592367
Type optionalObjectType = ty->getOptionalObjectType();

localization/diagnostics/en.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,9 @@
19931993
msg: >-
19941994
cannot declare entity named %0; the '$' prefix is reserved for
19951995
implicitly-synthesized declarations
1996+
- id: lazy_var_storage_access
1997+
msg: >-
1998+
access to the underlying storage of a lazy property is not allowed
19961999
19972000
- id: anon_closure_arg_not_in_closure
19982001
msg: >-

test/attr/attr_autoclosure.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,36 @@ struct SR_11938_S : @autoclosure SR_11938_P {} // expected-error {{'@autoclosure
295295

296296
// SR-9178
297297
func bar<T>(_ x: @autoclosure T) {} // expected-error 1{{@autoclosure attribute only applies to function types}}
298+
299+
func test_autoclosure_type_in_parens() {
300+
let _: (@autoclosure (() -> Void)) -> Void = { _ in } // Ok
301+
302+
struct Test {
303+
func bugSingle<T: RawRepresentable>(defaultValue: @autoclosure (() -> T)) -> T { // Ok
304+
defaultValue()
305+
}
306+
307+
func bugMultiple<T: RawRepresentable>(defaultValue: @autoclosure ((() -> T))) -> T { // Ok
308+
defaultValue()
309+
}
310+
}
311+
312+
enum E : String {
313+
case foo = "foo"
314+
case bar = "bar"
315+
}
316+
317+
_ = Test().bugSingle(defaultValue: E.foo) // Ok
318+
_ = Test().bugMultiple(defaultValue: E.bar) // Ok
319+
}
320+
321+
func test_autoclosure_with_typealias() {
322+
typealias ConcreteFunc = () -> Int
323+
typealias GenericFunc<T> = () -> T
324+
325+
func test(cr: @autoclosure ConcreteFunc) -> Int { cr() } // Ok
326+
func test<Q>(gn: @autoclosure GenericFunc<Q>) -> Q { gn() } // Ok
327+
328+
_ = test(cr: 0) // Ok
329+
_ = test(gn: 1) // Ok
330+
}

test/decl/var/lazy_properties.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,32 @@ class ReferenceStaticInLazyProperty {
189189
static var i = 42
190190
static func f() -> Int { return 0 }
191191
}
192+
193+
// Explicit access to the lazy variable storage
194+
class LazyVarContainer {
195+
lazy var foo: Int = {
196+
return 0
197+
}()
198+
199+
func accessLazyStorage() {
200+
$__lazy_storage_$_foo = nil // expected-error {{access to the underlying storage of a lazy property is not allowed}}
201+
print($__lazy_storage_$_foo!) // expected-error {{access to the underlying storage of a lazy property is not allowed}}
202+
_ = $__lazy_storage_$_foo == nil // expected-error {{access to the underlying storage of a lazy property is not allowed}}
203+
}
204+
}
205+
206+
// Make sure we can still access a synthesized variable with the same name as a lazy storage variable
207+
// i.e. $__lazy_storage_$_{property_name} when using property wrapper where the property name is
208+
// '__lazy_storage_$_{property_name}'.
209+
@propertyWrapper
210+
struct Wrapper {
211+
var wrappedValue: Int { 1 }
212+
var projectedValue: Int { 1 }
213+
}
214+
215+
struct PropertyWrapperContainer {
216+
@Wrapper var __lazy_storage_$_foo
217+
func test() {
218+
_ = $__lazy_storage_$_foo // This is okay.
219+
}
220+
}

utils/build-script

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ def validate_arguments(toolchain, args):
220220
'build_indexstoredb',
221221
'build_playgroundsupport',
222222
'build_sourcekitlsp',
223-
'build_tensorflow_swift_apis',
224223
'build_toolchainbenchmarks',
225224
'build_swift_inspect',
226225
'tsan_libdispatch_test',
@@ -273,7 +272,6 @@ def apply_default_arguments(toolchain, args):
273272
args.build_foundation or
274273
args.build_indexstoredb or
275274
args.build_sourcekitlsp or
276-
args.build_tensorflow_swift_apis or
277275
args.cmake_generator == 'Ninja'
278276
)
279277
if ninja_required and toolchain.ninja is None:
@@ -889,8 +887,6 @@ class BuildScriptInvocation(object):
889887
product_classes.append(products.IndexStoreDB)
890888
if self.args.build_playgroundsupport:
891889
product_classes.append(products.PlaygroundSupport)
892-
if self.args.build_tensorflow_swift_apis:
893-
product_classes.append(products.TensorFlowSwiftAPIs)
894890
if self.args.build_sourcekitlsp:
895891
product_classes.append(products.SourceKitLSP)
896892
if self.args.build_toolchainbenchmarks:

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -633,12 +633,6 @@ def create_argument_parser():
633633
store_true('install_playgroundsupport'),
634634
help='install playground support')
635635

636-
option('--tensorflow-swift-apis', store_true('build_tensorflow_swift_apis'),
637-
help='build TensorFlow Swift APIs')
638-
option('--install-tensorflow-swift-apis',
639-
store_true('install_tensorflow_swift_apis'),
640-
help='install TensorFlow Swift APIs')
641-
642636
option('--build-ninja', toggle_true,
643637
help='build the Ninja tool')
644638

utils/build_swift/tests/expected_options.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
'build_swiftpm': False,
9191
'build_swift_driver': False,
9292
'build_swiftsyntax': False,
93-
'build_tensorflow_swift_apis': False,
9493
'build_libparser_only': False,
9594
'build_skstresstester': False,
9695
'build_swiftformat': False,
@@ -107,7 +106,6 @@
107106
'install_sourcekitlsp': False,
108107
'install_skstresstester': False,
109108
'install_swiftevolve': False,
110-
'install_tensorflow_swift_apis': False,
111109
'build_toolchainbenchmarks': False,
112110
'build_tvos': True,
113111
'build_tvos_device': False,
@@ -467,9 +465,6 @@ class BuildScriptImplOption(_BaseOption):
467465
SetTrueOption('--playgroundsupport', dest='build_playgroundsupport'),
468466
SetTrueOption('--install-playgroundsupport',
469467
dest='install_playgroundsupport'),
470-
SetTrueOption('--tensorflow-swift-apis', dest='build_tensorflow_swift_apis'),
471-
SetTrueOption('--install-tensorflow-swift-apis',
472-
dest='install_tensorflow_swift_apis'),
473468
SetTrueOption('--skip-build'),
474469
SetTrueOption('--swiftpm', dest='build_swiftpm'),
475470
SetTrueOption('--swift-driver', dest='build_swift_driver'),

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from .swiftinspect import SwiftInspect
3232
from .swiftpm import SwiftPM
3333
from .swiftsyntax import SwiftSyntax
34-
from .tensorflow import TensorFlowSwiftAPIs
3534
from .tsan_libdispatch import TSanLibDispatch
3635
from .xctest import XCTest
3736

@@ -52,7 +51,6 @@
5251
'SwiftInspect',
5352
'SwiftPM',
5453
'SwiftDriver',
55-
'TensorFlowSwiftAPIs',
5654
'XCTest',
5755
'SwiftSyntax',
5856
'SKStressTester',

utils/swift_build_support/swift_build_support/products/tensorflow.py

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)