Skip to content
19 changes: 13 additions & 6 deletions format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ ALL_FILES=''
ONLY_CHANGED=''
FILES=()
if (($# == 0)); then
if [[ -n "$(git status --porcelain --ignore-submodules --untracked-files=no)" ]]; then
echo "Detected uncommitted changes. Please commit or stash them before running $0." >&2
exit 1
fi
# Default: allow dirty workspace; run on changed files (committed + worktree)
ONLY_CHANGED='true'
else
while (($# > 0)); do
Expand Down Expand Up @@ -78,7 +75,7 @@ if [[ -n "${ALL_FILES}" ]]; then
echo "Checking all files..." >&2
elif [[ -n "${ONLY_CHANGED}" ]]; then
MERGE_BASE="$(get_merge_base)"
echo "Checking changed files compared to merge base (${MERGE_BASE})..." >&2
echo "Checking changed files vs merge base (${MERGE_BASE}) and working tree..." >&2
elif [[ "${#FILES[@]}" -gt 0 ]]; then
echo "Checking specified files: ${FILES[*]}..." >&2
fi
Expand All @@ -93,7 +90,17 @@ echo 'tile-lang pre-commit: Check Start'
if [[ -n "${ALL_FILES}" ]]; then
python3 -m pre_commit run --all-files
elif [[ -n "${ONLY_CHANGED}" ]]; then
python3 -m pre_commit run --from-ref "${MERGE_BASE}" --to-ref HEAD
# Collect changed files (committed since merge-base + current worktree)
CHANGED_FILES="$(git diff --name-only --diff-filter=ACM "${MERGE_BASE}" 2>/dev/null || true)"
if [[ -n "${CHANGED_FILES}" ]]; then
echo "Running pre-commit on changed files:"
echo "${CHANGED_FILES}"
# Convert newline-separated files to space-separated and run pre-commit once
CHANGED_FILES_SPACE="$(echo "${CHANGED_FILES}" | tr '\n' ' ')"
python3 -m pre_commit run --files ${CHANGED_FILES_SPACE}
else
echo "No files changed relative to merge base and worktree. Skipping pre-commit."
fi
Comment on lines +93 to +103
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Changed-files list misses untracked files and is unsafe for spaces.

  • git diff "${MERGE_BASE}" does not include untracked files; newly created files won’t be formatted.
  • ${CHANGED_FILES_SPACE} relies on word splitting; breaks on spaces or glob characters.

Use an array and include untracked files:

-    # Collect changed files (committed since merge-base + current worktree)
-    CHANGED_FILES="$(git diff --name-only --diff-filter=ACM "${MERGE_BASE}" 2>/dev/null || true)"
-    if [[ -n "${CHANGED_FILES}" ]]; then
-        echo "Running pre-commit on changed files:"
-        echo "${CHANGED_FILES}"
-        # Convert newline-separated files to space-separated and run pre-commit once
-        CHANGED_FILES_SPACE="$(echo "${CHANGED_FILES}" | tr '\n' ' ')"
-        python3 -m pre_commit run --files ${CHANGED_FILES_SPACE}
+    # Collect changed (tracked) and untracked files vs merge-base + worktree
+    mapfile -t CHANGED_FILES_ARR < <( \
+        { git diff --name-only --diff-filter=ACMR "${MERGE_BASE}" 2>/dev/null || true; \
+          git ls-files --others --exclude-standard; } \
+        | sed '/^\s*$/d' | sort -u )
+    if ((${#CHANGED_FILES_ARR[@]} > 0)); then
+        echo "Running pre-commit on changed files:"
+        printf '%s\n' "${CHANGED_FILES_ARR[@]}"
+        python3 -m pre_commit run --files "${CHANGED_FILES_ARR[@]}"
     else
         echo "No files changed relative to merge base and worktree. Skipping pre-commit."
     fi

Notes:

  • Adds untracked via git ls-files --others --exclude-standard.
  • Uses an array to avoid word-splitting bugs and handles odd filenames safely.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Collect changed files (committed since merge-base + current worktree)
CHANGED_FILES="$(git diff --name-only --diff-filter=ACM "${MERGE_BASE}" 2>/dev/null || true)"
if [[ -n "${CHANGED_FILES}" ]]; then
echo "Running pre-commit on changed files:"
echo "${CHANGED_FILES}"
# Convert newline-separated files to space-separated and run pre-commit once
CHANGED_FILES_SPACE="$(echo "${CHANGED_FILES}" | tr '\n' ' ')"
python3 -m pre_commit run --files ${CHANGED_FILES_SPACE}
else
echo "No files changed relative to merge base and worktree. Skipping pre-commit."
fi
# Collect changed (tracked) and untracked files vs merge-base + worktree
mapfile -t CHANGED_FILES_ARR < <( \
{ git diff --name-only --diff-filter=ACMR "${MERGE_BASE}" 2>/dev/null || true; \
git ls-files --others --exclude-standard; } \
| sed '/^\s*$/d' | sort -u )
if ((${#CHANGED_FILES_ARR[@]} > 0)); then
echo "Running pre-commit on changed files:"
printf '%s\n' "${CHANGED_FILES_ARR[@]}"
python3 -m pre_commit run --files "${CHANGED_FILES_ARR[@]}"
else
echo "No files changed relative to merge base and worktree. Skipping pre-commit."
fi

elif [[ "${#FILES[@]}" -gt 0 ]]; then
python3 -m pre_commit run --files "${FILES[@]}"
fi
Expand Down
36 changes: 36 additions & 0 deletions testing/python/transform/test_tilelang_transform_thread_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,41 @@ def expected(A: T.Buffer((8192,), "float32")):
tvm.ir.assert_structural_equal(mod["main"], expected)


@tilelang.testing.requires_cuda
def test_sync_shared_dyn_stmatrix_loop_hoist():

@T.prim_func
def func():
buf_dyn_shmem = T.alloc_buffer((98304,), "uint8", scope="shared.dyn")
tx = T.launch_thread("threadIdx.x", 384)
for i in T.unroll(8):
off = (
i // 4 * 8192 + tx // 32 * 1024 + tx % 16 * 64 +
(tx % 8 // 4 + i % 4 // 2) % 2 * 32 + (tx % 4 // 2 + i % 2) % 2 * 16 +
(tx % 32 // 16 + tx % 2) % 2 * 8)
T.evaluate(
T.call_intrin(
"handle",
tvm.tir.op.Op.get("tl.ptx_stmatrix"),
T.int32(0),
T.int32(4),
T.tvm_access_ptr(
T.type_annotation("uint8"),
buf_dyn_shmem.data,
off,
98304 - off,
2,
),
T.int32(2),
))

mod = tvm.IRModule({"main": func})
mod = tilelang.transform.ThreadSync("shared.dyn")(mod)
s = str(mod)
assert 'T.tvm_storage_sync("shared.dyn")' in s
# Ensure the sync appears before the unrolled loop
assert s.index('T.tvm_storage_sync("shared.dyn")') < s.index("for i in T.unroll(8)")


if __name__ == "__main__":
tilelang.testing.main()
Loading