Skip to content

Handle IOException locally in TensorType.shapeArg#352

Open
khatchad wants to merge 1 commit into
masterfrom
fix-shapeArg-io-exception
Open

Handle IOException locally in TensorType.shapeArg#352
khatchad wants to merge 1 commit into
masterfrom
fix-shapeArg-io-exception

Conversation

@khatchad
Copy link
Copy Markdown
Member

Summary

TensorType.shapeArg declared throws IOException because new SourceBuffer(p) inside the body reads the source file at the SSA-instruction's Position (and can fail when the position is synthetic or the source file isn't available). The issue's premise that "no I/O happens" was incomplete — I/O does happen via SourceBuffer. But the conclusion (drop the throws clause) was right: the analysis has a symbolic-dim fallback already and can degrade gracefully on I/O failure instead of bubbling up as RuntimeException and crashing.

This PR:

  • Catches IOException inside shapeArg (around the SourceBuffer block), logs at FINE, and falls through to the existing symbolic-dim fallback.
  • Drops the throws IOException clauses on shapeArg and handleShapeSourceOp.
  • Removes the four try/catch (IOException) { throw new RuntimeException(...); } wrappers in getShapeSourceCalls, getSetShapeCallsSyntactic, and the two handleShapeSourceOp call sites.
  • Drops two System.err.println debug prints in the shapeArg source-buffer block (they should never have been there; one short-line cleanup since the surrounding block was being rewritten anyway).

Test Plan

  • Full mvn test passes in CI.
  • Locally mvn clean install -DskipTests passes (Java -Xlint -failOnWarning would catch unused-import / dead-throws).
  • No callers were missed (verified via grep -rn 'shapeArg\|handleShapeSourceOp').

Fixes wala#555.

🤖 Generated with Claude Code

`shapeArg` declared `throws IOException` because `new SourceBuffer(p)`
inside the body can throw when the underlying source file is
unavailable (e.g. for a synthetic / detached `Position`). The two
direct callers in `PythonTensorAnalysisEngine` and the indirect
caller `handleShapeSourceOp` then wrapped the exception as
`RuntimeException`, which just crashed the analysis with no
useful information.

Catch `IOException` inside `shapeArg` instead, log at `FINE`, and
fall through to the symbolic-dim fallback already present further
down the loop — graceful degradation instead of analysis abort.

Drop the now-unnecessary `throws IOException` clause on `shapeArg`
and `handleShapeSourceOp`, and the `try/catch (IOException)`
wrappers in `getShapeSourceCalls`, `getSetShapeCallsSyntactic`,
and the two `handleShapeSourceOp` call sites.

Also drop the two `System.err.println` debug prints in the
`shapeArg` source-buffer block.

Fixes wala#555.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 27, 2026 22:30
@khatchad khatchad enabled auto-merge May 27, 2026 22:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the tensor-shape inference path to handle IOException locally inside TensorType.shapeArg, allowing the analysis to degrade gracefully (symbolic-dim fallback) when source text cannot be read, instead of forcing callers to handle/propagate I/O failures.

Changes:

  • Catch IOException around the SourceBuffer(Position) logic in TensorType.shapeArg, log at FINE, and fall back to symbolic dims.
  • Remove throws IOException from TensorType.shapeArg and PythonTensorAnalysisEngine.handleShapeSourceOp, and simplify call sites by removing try/catch wrappers that rethrew RuntimeException.
  • Remove unused IOException import in PythonTensorAnalysisEngine.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/types/TensorType.java Handles IOException locally in shapeArg while keeping the existing symbolic-dim fallback path.
com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/client/PythonTensorAnalysisEngine.java Removes now-unnecessary IOException plumbing/wrappers and simplifies internal helper signatures and call sites.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 630 to +639
if (du.getDef(val) != null && node.getMethod() instanceof AstMethod) {
Position p =
((AstMethod) node.getMethod())
.debugInfo()
.getInstructionPosition(du.getDef(val).iIndex());
System.err.println(p);
SourceBuffer b = new SourceBuffer(p);
String expr = b.toString();
System.err.println(expr);
Integer ival = PythonInterpreter.interpretAsInt(expr);
if (ival != null) {
dims.put(index, new NumericDim(ival));
continue;
// `SourceBuffer(Position)` reads the underlying source file. If the file
// is unavailable (synthetic / detached position), fall through to the
// symbolic-dim fallback below rather than propagating the I/O failure.
try {
SourceBuffer b = new SourceBuffer(p);
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 63.63636% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.28%. Comparing base (c753eee) to head (a6e7a80).

Files with missing lines Patch % Lines
.../com/ibm/wala/cast/python/ml/types/TensorType.java 0.00% 8 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #352      +/-   ##
============================================
+ Coverage     71.26%   71.28%   +0.01%     
  Complexity     2667     2667              
============================================
  Files           268      268              
  Lines         20125    20114      -11     
  Branches       3253     3253              
============================================
- Hits          14343    14339       -4     
+ Misses         4486     4479       -7     
  Partials       1296     1296              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TensorType.shapeArg declares throws IOException without doing I/O

2 participants