Handle IOException locally in TensorType.shapeArg#352
Open
khatchad wants to merge 1 commit into
Open
Conversation
`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>
There was a problem hiding this comment.
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
IOExceptionaround theSourceBuffer(Position)logic inTensorType.shapeArg, log atFINE, and fall back to symbolic dims. - Remove
throws IOExceptionfromTensorType.shapeArgandPythonTensorAnalysisEngine.handleShapeSourceOp, and simplify call sites by removingtry/catchwrappers that rethrewRuntimeException. - Remove unused
IOExceptionimport inPythonTensorAnalysisEngine.
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TensorType.shapeArgdeclaredthrows IOExceptionbecausenew SourceBuffer(p)inside the body reads the source file at the SSA-instruction'sPosition(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 viaSourceBuffer. 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 asRuntimeExceptionand crashing.This PR:
IOExceptioninsideshapeArg(around theSourceBufferblock), logs atFINE, and falls through to the existing symbolic-dim fallback.throws IOExceptionclauses onshapeArgandhandleShapeSourceOp.try/catch (IOException) { throw new RuntimeException(...); }wrappers ingetShapeSourceCalls,getSetShapeCallsSyntactic, and the twohandleShapeSourceOpcall sites.System.err.printlndebug prints in theshapeArgsource-buffer block (they should never have been there; one short-line cleanup since the surrounding block was being rewritten anyway).Test Plan
mvn clean install -DskipTestspasses (Java-Xlint -failOnWarningwould catch unused-import / dead-throws).grep -rn 'shapeArg\|handleShapeSourceOp').Fixes wala#555.
🤖 Generated with Claude Code