[Mlir-commits] [mlir] 7f703ca - [MLIR][AsmParser] Fix non-deterministic SSA value completion order under LLVM_REVERSE_ITERATION (#192150)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Apr 22 06:20:43 PDT 2026
Author: Mehdi Amini
Date: 2026-04-22T15:20:38+02:00
New Revision: 7f703cabf728f3f9942c5e403900c991cde8876c
URL: https://github.com/llvm/llvm-project/commit/7f703cabf728f3f9942c5e403900c991cde8876c
DIFF: https://github.com/llvm/llvm-project/commit/7f703cabf728f3f9942c5e403900c991cde8876c.diff
LOG: [MLIR][AsmParser] Fix non-deterministic SSA value completion order under LLVM_REVERSE_ITERATION (#192150)
codeCompleteSSAUse() iterated IsolatedSSANameScope::values, a StringMap,
whose hash-based iteration order reverses under LLVM_REVERSE_ITERATION.
This caused the SSA value completion items in the LSP server to appear
in a non-deterministic order, breaking the CHECK-NEXT assertions in
mlir-lsp-server/completion.test.
Sort SSA value names alphabetically before emitting completion items.
Assisted-by: Claude Code
Co-authored-by: Claude Sonnet 4.6 <noreply at anthropic.com>
Added:
Modified:
mlir/lib/AsmParser/Parser.cpp
Removed:
################################################################################
diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp
index 06a3dfa65e933..952d7e460c6e2 100644
--- a/mlir/lib/AsmParser/Parser.cpp
+++ b/mlir/lib/AsmParser/Parser.cpp
@@ -2555,10 +2555,15 @@ ParseResult OperationParser::parseOptionalBlockArgList(Block *owner) {
ParseResult OperationParser::codeCompleteSSAUse() {
for (IsolatedSSANameScope &scope : isolatedNameScopes) {
- for (auto &it : scope.values) {
- if (it.second.empty())
- continue;
- Value frontValue = it.second.front().value;
+ // Collect and sort SSA value names for deterministic completion ordering.
+ SmallVector<StringRef> sortedNames;
+ for (auto &it : scope.values)
+ if (!it.second.empty())
+ sortedNames.push_back(it.getKey());
+ llvm::sort(sortedNames);
+
+ for (StringRef name : sortedNames) {
+ Value frontValue = scope.values[name].front().value;
std::string detailData;
llvm::raw_string_ostream detailOS(detailData);
@@ -2579,11 +2584,11 @@ ParseResult OperationParser::codeCompleteSSAUse() {
// FIXME: We should define a policy for packed values, e.g. with a limit
// on the detail size, but it isn't clear what would be useful right now.
// For now we just only emit the first type.
- if (it.second.size() > 1)
+ if (scope.values[name].size() > 1)
detailOS << ", ...";
state.codeCompleteContext->appendSSAValueCompletion(
- it.getKey(), std::move(detailData));
+ name, std::move(detailData));
}
}
More information about the Mlir-commits
mailing list