Skip to content

set_shape XML modeling claims a return value, but tf.Tensor.set_shape returns None #556

@khatchad

Description

@khatchad

Observation

Per the tf.Tensor.set_shape API docs, the method returns None. The TF source confirms this — set_shape is a side-effecting mutation that updates the receiver Tensor's static shape, not a return-value producer.

tensorflow.xml claims otherwise:

<class name="set_shape" allocatable="true">
  <method name="do" descriptor="()LRoot;" numArgs="2" paramNames="self shape">
    <return value="self" />
  </method>
</class>

(tensorflow.xml:1660-1664)

This <return value="self"/> claims the call returns self. In the callable-as-attribute context, self is the callable instance — not the receiver Tensor and not None. Misleading regardless of how it's read.

Surfaced By

Reviewing the explorations in ponder-lab/ML#338 (closed): a follow-up to #550 used a similar <return value="self"/> pattern for fresh <method name="set_shape"> declarations on Tensor classes. Comparing both modelings against the real TF API surfaced the mismatch.

Possible Fix

Two reasonable options:

  1. Empty body (no <return>): the WALA Python frontend can synthesize a None return for methods without an explicit <return> (verify this against existing void-returning models).
  2. Explicit None allocation: <new def="r" class="Lnone"/><return value="r"/> or similar, following whatever convention tensorflow.xml uses elsewhere for None returns.

Whichever pattern lands should be applied to:

Out of Scope

This is independent of the dispatch-mechanism debate in #550. The return-value mismatch is a separate API-correctness bug that applies regardless of whether set_shape is recognized via Java IR-syntactic scan, XML class-method dispatch, or XML callable-as-attribute.

Related

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions