Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

[Tensor] Add precondition in 'Tensor.init(arrayLiteral:)' to reject 'init()' calls. #336

Merged
merged 2 commits into from
Jul 8, 2019

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Jul 8, 2019

A long-standing issue in Swift is that labeled variadic parameters can accept 0 arguments when a label does not exist. Here is a related discussion on Swift Evolution: Should labeled variadic parameters accept 0 arguments?

When there is no Tensor.init(), an init() expression will resolve to a call to init(arrayLiteral:) with no arguments, which is semantically invalid for Tensor, ShapedArray, and ShapedArraySlice. Declaring an init() with an @available(*, unavailable) does not work becuase the type checker would still resolve init() calls to init(arrayLiteral:). Before Swift supports finer control over labeled variadic parameters, the only thing we can do is to fail early at run-time.

XCTest does not yet provide test utilities for crashers. We can add such a test utility along with tests for such run-time errors later.

Resolves TF-644.

…init()' calls.

A long-standing issue in Swift is that labeled variadic parameters can accept 0 arguments when a label does not exist. Here is a related discussion on Swift Evolution: [Should labeled variadic parameters accept 0 arguments?](https://forums.swift.org/t/should-labeled-variadic-parameters-accept-0-arguments/12500/15)

When there is no `Tensor.init()`, an `init()` expression will resolve to a call to `init(arrayLiteral:)` with no arguments, which is semantically invalid for `Tensor`, `ShapedArray`, and `ShapedArraySlice`. Declaring an `init()` with an `@available(*, unavailable)` does not work becuase the type checker would still resolve `init()` calls to `init(arrayLiteral:)`. Before Swift supports finer control over labeled variadic parameters, the only thing we can do is to fail early at run-time.

Resolves [TF-644](https://bugs.swift.org/browse/TF-644).
@rxwei rxwei added the bug Something isn't working label Jul 8, 2019
@rxwei rxwei requested a review from dan-zheng July 8, 2019 17:58
@rxwei rxwei merged commit ee09712 into tensorflow:master Jul 8, 2019
@rxwei rxwei deleted the variadic-insanity branch July 8, 2019 18:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants