[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 01:11:29 PDT 2024
https://github.com/Harini0924 updated https://github.com/llvm/llvm-project/pull/101590
>From f7aab483320e92d4acf52a7035553e6766034f43 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Wed, 31 Jul 2024 20:44:28 +0000
Subject: [PATCH 1/3] [llvm-lit] Unhashable type Support
Used expand_glob_expressions to resolve all GlobItem instances in args
list to their acutal paths. Checked and converted args[0] if it is a
Glob instance and ensured the resolved path is a string (hashable) before
using it as a key in the inproc_builtins dictionary. To sum
everything, this patch eliminates the 'unhashable type: GlobItem' error.
---
llvm/utils/lit/lit/TestRunner.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index da7fa86fd39173..ca8028f380ae8a 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -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)
+ if expanded_args:
+ args[0] = expanded_args[0]
+
inproc_builtin = inproc_builtins.get(args[0], None)
if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1):
# env calling an in-process builtin is useless, so we take the safe
>From 24080401e918cb9a4dd61cd6ed73dcdf91160f31 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Wed, 7 Aug 2024 06:04:25 +0000
Subject: [PATCH 2/3] [llvm-lit] Fix handling of GlobItem in args[0] to ensure
it is hashable
Removed the previous complex implementation to a simipler verison.
Added direct expansion and conversion of args[0] to ensure it is
always a resolved path string. This patch ensures that args[0] is
consistently a string, preventing TypeError when args[0] is used as
a dictionary key or in other contexts that require a hashable type.
---
llvm/utils/lit/lit/TestRunner.py | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index ca8028f380ae8a..144362841c472d 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -768,12 +768,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
# 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)
- if expanded_args:
- args[0] = expanded_args[0]
-
+ args[0] = expand_glob(args[0], cmd_shenv.cwd)[0]
inproc_builtin = inproc_builtins.get(args[0], None)
if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1):
# env calling an in-process builtin is useless, so we take the safe
>From 25b1bd77ce192b5a096ad8c66042a508269e3513 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Thu, 8 Aug 2024 08:03:01 +0000
Subject: [PATCH 3/3] [llvm-lit] Simplify args[0] Hashability Check and
Expansion
Refactored the code to simplify the hashability check and expansion
of args[0]. The pervious commit included a conditional check to
determine if args[0] was a GlobItem and subsequently expanded it.
The new implementation directly assigns the expanded value of args[0].
This patch simplifies the logic by removing unnecessary conditionals
and ensures that args[0] is always assigned an expanded value.
---
llvm/utils/lit/lit/TestRunner.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 144362841c472d..b4d53eeb6f0ff1 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -768,7 +768,9 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
# FIXME: Standardize on the builtin echo implementation. We can use a
# temporary file to sidestep blocking pipe write issues.
+ # Ensure args[0] is hashable
args[0] = expand_glob(args[0], cmd_shenv.cwd)[0]
+
inproc_builtin = inproc_builtins.get(args[0], None)
if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1):
# env calling an in-process builtin is useless, so we take the safe
More information about the llvm-commits
mailing list