[llvm] [llvm-lit] Fix Unhashable TypeError when using lit's internal shell (PR #101590)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 09:45:32 PDT 2024
================
@@ -767,6 +767,13 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
# echo-appending to a file.
# FIXME: Standardize on the builtin echo implementation. We can use a
# temporary file to sidestep blocking pipe write issues.
+
+ # Ensure args[0] is hashable before using it in inproc_builtins
+ if isinstance(args[0], GlobItem):
+ expanded_args = expand_glob(args[0], cmd_shenv.cwd)
----------------
Harini0924 wrote:
I have updated the implementation to ensure `args[0]` is hashable before using it in inproc_builtins. The previous code:
```
# Ensure args[0] is hashable before using it in inproc_builtins
if isinstance(args[0], GlobItem):
expanded_args = expand_glob(args[0], cmd_shenv.cwd)
if expanded_args:
args[0] = expanded_args[0]
```
has been modifed to:
```
# Ensure args[0] is hashable
args[0] = expand_glob(args[0], cmd_shenv.cwd)[0]
```
You raised a valid point about performing the expansion at the call site, as `expand_glob()` already checks if `args[0]` is a `GlobItem` and does not modify `args[0]`, which aligns with the approach taken by `expand_glob_expressions()`. However, the current error `TypeError: unhashable type: 'GlobItem'` occurs on the line:
```
inproc_builtin = inproc_builtins.get(args[0], None)
```
After changing this line to:
```
inproc_builtin = inproc_builtins.get(expand_glob(args[0], cmd_shenv.cwd)[0], None)
```
the same `TypeError` occurs on subsequent lines where `args[0]` is called. Instead of repeatedly applying the same functionality to `args[0]` until line 866 where args is expanded with:
```# Expand all glob expressions
args = expand_glob_expressions(args, cmd_shenv.cwd)
```
it would be more efficient to expand args[0] before invoking any in-process built-ins. This approach resolves the `TypeError` for this and all subsequent lines where `args[0]` is used.
By making this change, we address the issue holistically, ensuring the robustness of the implementation against unhashable types like `GlobItem`.
Let me know if this approach works for you or if you have any further suggestions.
https://github.com/llvm/llvm-project/pull/101590
More information about the llvm-commits
mailing list