swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.49k stars 10.35k forks source link

[SR-8613] [blocker] @inlinable functions defined in separate Jupyter/REPL units do not get inlined during deabstraction #51128

Closed 83b09dda-53f5-4663-b44c-87fd2a9a8717 closed 5 years ago

83b09dda-53f5-4663-b44c-87fd2a9a8717 commented 6 years ago
Previous ID SR-8613
Radar None
Original Reporter @marcrasi
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Swift for TensorFlow | |Labels | Bug, GPE, s4tf-iris-tutorial | |Assignee | bgogul (JIRA) | |Priority | Medium | md5: 2d05d092c84c845d553659edb032ed74

Issue Description:

For a minimal reproducer, execute the following two cells in Juptyer or REPL:

import TensorFlow

@inlinable @inline(__always)
public func dataset() -> Tensor<Float> {
    return Tensor(1)
}
_hostOp(dataset())

You should get the following error:

 !!! Compiler bug -- Tensor op builtin __tfop_tfc.scalarToTensor,$in cannot be lowered to LLVM IR !!!

I'll attach a `-tf-dump-intermediates` for the compilation of the `_hostOp(dataset())` cell. If you look at it, you'll see that the dataset function is not getting inlined during deabstraction.

This blocks us from defining a single `dataset()` function that constructs a dataset in the tutorial.

This error is suspiciously similar to SR-8589.

swift-ci commented 6 years ago

Comment by Gogul Balakrishnan (JIRA)

As noted in SR-8589, lldb throws away SIL modules after parsing a REPL line and prevent us from seeing the bodies of some functions during deabstraction. This bug is also caused by the same problem.

One way to deal with this is to serialize the SIL module of every REPL line and make them an additional import when evaluating subsequent lines. lldb_serialize.patch (based off of commit 46dcbd5a551749b1e497013368e9252e9c0b886f) is an POC hack to implement this idea. The hack makes this example work, but is not robust enough to push to upstream yet.