Skip to content

Fix TensorFlow module compilation. #28023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/Sema/DerivedConformanceKeyPathIterable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ deriveBodyKeyPathIterable_allKeyPaths(AbstractFunctionDecl *funcDecl, void *) {
auto *parentDC = funcDecl->getDeclContext();
auto *nominal = parentDC->getSelfNominalTypeDecl();
auto &C = nominal->getASTContext();
auto allKeyPathsInterfaceType = computeAllKeyPathsType(nominal);
auto allKeyPathsType = parentDC->mapTypeIntoContext(allKeyPathsInterfaceType);
auto partialKeyPathInterfaceType = computePartialKeyPathType(nominal);
auto partialKeyPathType =
parentDC->mapTypeIntoContext(partialKeyPathInterfaceType);

auto *nominalTypeExpr = TypeExpr::createForDecl(SourceLoc(), nominal,
funcDecl, /*Implicit*/ true);
Expand All @@ -97,17 +98,17 @@ deriveBodyKeyPathIterable_allKeyPaths(AbstractFunctionDecl *funcDecl, void *) {
auto *dotExpr = new (C)
UnresolvedDotExpr(nominalTypeExpr, SourceLoc(), member->getFullName(),
DeclNameLoc(), /*Implicit*/ true);
auto *keyPathExpr =
Expr *keyPathExpr =
new (C) KeyPathExpr(SourceLoc(), dotExpr, nullptr, /*Implicit*/ true);
// NOTE(TF-575): Adding an explicit coercion expression here is necessary
// due to type-checker changes.
keyPathExpr = new (C) CoerceExpr(
keyPathExpr, SourceLoc(), TypeLoc::withoutLoc(partialKeyPathType));
keyPathExprs.push_back(keyPathExpr);
}
// Return array of all key path expressions.
Expr *keyPathsArrayExpr =
ArrayExpr::create(C, SourceLoc(), keyPathExprs, {}, SourceLoc());
// NOTE(TF-575): Adding an explicit coercion expression here is necessary due
// to a missing regression.
keyPathsArrayExpr = new (C) CoerceExpr(
keyPathsArrayExpr, SourceLoc(), TypeLoc::withoutLoc(allKeyPathsType));
auto *returnStmt = new (C) ReturnStmt(SourceLoc(), keyPathsArrayExpr);
auto *body = BraceStmt::create(C, SourceLoc(), {returnStmt}, SourceLoc(),
/*Implicit*/ true);
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ endif()
# dependency for `numpy.ndarray` bridging to `ShapedArray`/`Tensor`.
if(SWIFT_BUILD_STDLIB AND SWIFT_ENABLE_TENSORFLOW)
# TODO: Add TensorFlow support for iOS/Raspberry Pi.
# add_subdirectory(CTensorFlow)
# add_subdirectory(TensorFlow)
add_subdirectory(CTensorFlow)
add_subdirectory(TensorFlow)
endif()

if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR)
Expand Down
20 changes: 20 additions & 0 deletions test/Sema/struct_key_path_iterable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ struct DummyOptimizer<P : KeyPathIterable, Scalar : BinaryFloatingPoint>
}
}

// TF-575: Test overloaded key path component name.
protocol NameLookupConflictProtocol {}
extension NameLookupConflictProtocol {
func member() {}
}
struct NameLookupConflict: NameLookupConflictProtocol & KeyPathIterable {
// Note: `NameLookupConflict.member` is overloaded with
// `MemberNameConflictProtocol.member`.
// This makes the following generated code fail:
//
// var allKeyPaths: [PartialKeyPath<Self>] {
// [\Self.member]
// }
//
// error: cannot convert value of type
// 'WritableKeyPath<NameLookupConflict, Float>' to expected element type
// 'PartialKeyPath<NameLookupConflict>'
var member: Float
}

// Test derived conformances in disallowed contexts.

// expected-error @+3 {{type 'OtherFileNonconforming' does not conform to protocol 'KeyPathIterable'}}
Expand Down