Skip to content

Conversation

@dan-zheng
Copy link
Contributor

Introduce callables: values that can be "called" like functions.

struct Adder {
    var base: Int
    call func(_ x: Int) -> Int {
        return base + x
    }
}
let add3 = Adder(base: 3)
add3(10) // 13

This is experimental functionality and highly subject to change:
the design will be updated based on feedback for SE-0253.

@dan-zheng dan-zheng added the tensorflow This is for "tensorflow" branch PRs. label Apr 17, 2019
@dan-zheng dan-zheng requested review from lattner, rxwei and saeta April 17, 2019 06:51
@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

@dan-zheng dan-zheng force-pushed the tf-callable branch 4 times, most recently from 562a0f9 to abeafa9 Compare April 17, 2019 07:37
@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow macOS

Introduce callables: values that can be "called" like functions.

```
struct Adder {
    var base: Int
    call func(_ x: Int) -> Int {
        return base + x
    }
}
let add3 = Adder(base: 3)
add3(10) // 13
```

This is experimental functionality and highly subject to change:
the design will be updated based on feedback for SE-0253.
@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

Copy link
Contributor

@lattner lattner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch looks generally great to me, thank you Dan. I appreciate that you switched the syntax to the likely result.

For the eventual final patch (not necessary in the 0.3 release) I think it would be better to model this as a normal FuncDecl with a special name. I don't think it is necessary to have a CallDecl node.

Copy link
Contributor

@rxwei rxwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to change "call member" to "call function" or "call method" in diagnostics.

@dan-zheng
Copy link
Contributor Author

For the eventual final patch (not necessary in the 0.3 release) I think it would be better to model this as a normal FuncDecl with a special name. I don't think it is necessary to have a CallDecl node.

Yes, switching to a normal FuncDecl with a "callable" bit and special name is definitely the direction.

@dan-zheng
Copy link
Contributor Author

It'd be nice to change "call member" to "call function" or "call method" in diagnostics.

I believe this is already done, please let me know if you found places I missed.

@dan-zheng dan-zheng merged commit f7c7edf into swiftlang:tensorflow Apr 17, 2019
@rxwei rxwei deleted the tf-callable branch April 17, 2019 16:48
dan-zheng added a commit to dan-zheng/swift that referenced this pull request Apr 18, 2019
rxwei pushed a commit that referenced this pull request Apr 18, 2019
* Revert "[TF] Introduce callables. (#24086)"

This reverts commit f7c7edf.

* Revert "Fix `call` declaration serialization. (#24121)"

This reverts commit 6466a84.

* Reimplement callables using `func call`.

Remove `call` declarations.
Treat methods named `func call` as call-syntax delegate methods.
rxwei pushed a commit to rxwei/swift that referenced this pull request May 11, 2019
Introduce callables: values that can be "called" like functions.

```
struct Adder {
    var base: Int
    call func(_ x: Int) -> Int {
        return base + x
    }
}
let add3 = Adder(base: 3)
add3(10) // 13
```

This is experimental functionality and highly subject to change:
the design will be updated based on feedback for SE-0253.
rxwei pushed a commit to rxwei/swift that referenced this pull request May 11, 2019
* Revert "[TF] Introduce callables. (swiftlang#24086)"

This reverts commit f7c7edf.

* Revert "Fix `call` declaration serialization. (swiftlang#24121)"

This reverts commit 6466a84.

* Reimplement callables using `func call`.

Remove `call` declarations.
Treat methods named `func call` as call-syntax delegate methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tensorflow This is for "tensorflow" branch PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants