Skip to content

Commit fe45ac1

Browse files
committed
Refactor and enhance error handling across multiple modules
- Updated `geo_index_hooks.cpp` to mark `validateCoordinatePair` as maybe unused and suppress unused variable warnings in `onEntityPut` and `onEntityDelete`. - Modified `cdc_materialized_view.cpp`, `outbox.cpp`, and `tenant_buffer_manager.cpp` to undefine `DELETE` and `ERROR` macros to avoid conflicts. - Added `spdlog` include in `flash_attention.cpp` for improved logging. - Enhanced error handling in `infini_attention_hip.cpp` and `infini_attention_vulkan.cpp` by replacing generic error statuses with more specific ones. - Removed the deprecated `infini_attention_cpu.cpp` implementation and replaced it with minimal inline definitions. - Fixed potential issues in `kv_cache_manager.cpp` and `distributed_dataloader.cpp` by ensuring proper type handling for size calculations. - Introduced new PowerShell scripts for syntax checking and build warning extraction to improve code quality assurance.
1 parent f22283a commit fe45ac1

38 files changed

Lines changed: 650 additions & 375 deletions
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Extract compile options from compile_commands.json and check syntax per module
2+
# Uses actual CMake-generated flags for accurate validation
3+
4+
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Continue
5+
$PSNativeCommandUseErrorActionPreference = $false
6+
7+
if (-not (Test-Path "build-msvc-windows-debug/compile_commands.json")) {
8+
Write-Error "compile_commands.json not found"
9+
exit 1
10+
}
11+
12+
$db = Get-Content "build-msvc-windows-debug/compile_commands.json" | ConvertFrom-Json
13+
Write-Host "Loaded $($db.Count) compilation commands"
14+
15+
# Find one sample command to extract base flags
16+
$sampleCmd = $db | Where-Object { $_.file -like "*/src/*/*.cpp" } | Select-Object -First 1
17+
if (-not $sampleCmd) {
18+
Write-Error "No .cpp files found in compilation database"
19+
exit 1
20+
}
21+
22+
Write-Host "Sample command: $($sampleCmd.command)" | head -1
23+
Write-Host ""
24+
25+
# Group errors/warnings by module
26+
$errorsByModule = @{}
27+
$checkedCount = 0
28+
29+
# Check each source file in src/
30+
$srcFiles = Get-ChildItem -Path "src" -Recurse -File -Include *.cpp,*.cc,*.cxx
31+
foreach ($file in $srcFiles) {
32+
$moduleName = ($file.FullName -replace "\\", "/" -split "/")[1]
33+
34+
# Find matching compile command
35+
$compCmd = $db | Where-Object { $_.file -match [regex]::Escape($file.FullName) } | Select-Object -First 1
36+
if (-not $compCmd) {
37+
continue
38+
}
39+
40+
$checkedCount++
41+
Write-Host "[$('{0:0000}' -f $checkedCount)] $moduleName/$($file.BaseName)"
42+
43+
# Extract directory and command
44+
$cmdDir = $compCmd.directory
45+
$cmdLine = $compCmd.command
46+
47+
# Replace /E with /Zs for syntax-only check
48+
$syntaxCmd = $cmdLine -replace "/E(\s|$)", "/Zs "
49+
50+
# Run from the specified directory
51+
try {
52+
Push-Location $cmdDir
53+
$output = Invoke-Expression $syntaxCmd 2>&1
54+
Pop-Location
55+
56+
# Check for errors in output
57+
$hasError = $output | Where-Object { $_ -match "error C\d+:" }
58+
if ($hasError) {
59+
if (-not $errorsByModule[$moduleName]) {
60+
$errorsByModule[$moduleName] = @()
61+
}
62+
$errorsByModule[$moduleName] += @{
63+
File = $file.BaseName
64+
Errors = $hasError
65+
}
66+
Write-Host " [ERROR]"
67+
$hasError | ForEach-Object { Write-Host " $_" }
68+
}
69+
} catch {
70+
Write-Host " [SKIP - error running command]"
71+
}
72+
}
73+
74+
Write-Host ""
75+
Write-Host "======== SUMMARY ========" -ForegroundColor Cyan
76+
Write-Host "Files checked: $checkedCount"
77+
Write-Host "Modules with errors: $($errorsByModule.Count)"
78+
79+
if ($errorsByModule.Count -gt 0) {
80+
Write-Host ""
81+
Write-Host "ERRORS BY MODULE:" -ForegroundColor Red
82+
foreach ($module in ($errorsByModule.Keys | Sort-Object)) {
83+
$issues = $errorsByModule[$module]
84+
Write-Host " ${module}: $($issues.Count) file(s) with errors"
85+
$issues | ForEach-Object {
86+
Write-Host " - $($_.File)"
87+
}
88+
}
89+
exit 1
90+
}
91+
92+
Write-Host "[OK] No syntax errors found." -ForegroundColor Green
93+
exit 0

.vscode/clang-tidy-batch.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ if (-not $clangTidy) {
3737
exit 1
3838
}
3939

40-
$files = Get-ChildItem -Path "src" -Recurse -File -Include *.cpp,*.cc,*.cxx |
40+
$files = Get-ChildItem -Path "src" -Recurse -File -Include *.c,*.cpp,*.cc,*.cxx |
4141
Where-Object { $_.FullName -notmatch $excludePathPattern }
4242
if (-not $files) {
4343
Write-Host "No C++ source files found under src."

.vscode/cmake-check-syntax.ps1

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Syntax and warning check using CMake's compile_commands.json and clang-tidy
2+
# This approach uses actual compilation database from CMake for accurate include paths
3+
4+
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Continue
5+
$PSNativeCommandUseErrorActionPreference = $false
6+
7+
# Check for compile_commands.json
8+
$dbPath = "build-msvc-windows-debug/compile_commands.json"
9+
if (-not (Test-Path $dbPath)) {
10+
Write-Host "Attempting CMake configuration with compile_commands.json export..."
11+
& cmake --preset windows-release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON 2>&1 | Select-Object -Last 20
12+
if (-not (Test-Path $dbPath)) {
13+
Write-Error "compile_commands.json not found after configure. Please run: cmake --preset windows-release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
14+
exit 1
15+
}
16+
}
17+
18+
Write-Host "Using compile_commands.json for syntax validation..."
19+
20+
# Try clang-tidy first (most reliable)
21+
$clangTidy = $null
22+
if (Get-Command clang-tidy -ErrorAction SilentlyContinue) {
23+
$clangTidy = "clang-tidy"
24+
} else {
25+
# Try to find in Visual Studio LLVM bundle
26+
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
27+
if (Test-Path $vswhere) {
28+
$vsInstall = & $vswhere -latest -products * -property installationPath
29+
if ($vsInstall) {
30+
$tidyPath = Join-Path $vsInstall "VC\Tools\Llvm\x64\bin\clang-tidy.exe"
31+
if (Test-Path $tidyPath) {
32+
$clangTidy = $tidyPath
33+
}
34+
}
35+
}
36+
}
37+
38+
if (-not $clangTidy) {
39+
Write-Error "clang-tidy not found. Install Visual Studio C++ Clang tools or LLVM."
40+
exit 1
41+
}
42+
43+
Write-Host "Using clang-tidy: $clangTidy"
44+
45+
# Get all source files from src/
46+
$files = Get-ChildItem -Path "src" -Recurse -File -Include *.c,*.cpp,*.cc,*.cxx
47+
if (-not $files) {
48+
Write-Host "No C++ source files found under src."
49+
exit 0
50+
}
51+
52+
$errorsByModule = @{}
53+
$warningsByModule = @{}
54+
$totalErrors = 0
55+
$totalWarnings = 0
56+
$checkedFiles = 0
57+
58+
foreach ($f in $files) {
59+
$relPath = ($f.FullName).Replace("$PWD\", "").Replace("\", "/")
60+
$moduleName = ($relPath -split "/")[1]
61+
62+
$checkedFiles++
63+
Write-Host "[$('{0:0000}' -f $checkedFiles)] $relPath" -ForegroundColor Cyan
64+
65+
# Run clang-tidy with quiet output
66+
$output = & $clangTidy $f.FullName -p build-msvc-windows-debug --header-filter="^(src|include)/" --quiet 2>&1
67+
68+
# Parse output for errors and warnings
69+
$fileErrors = @()
70+
$fileWarnings = @()
71+
72+
foreach ($line in $output) {
73+
$lineStr = "$line"
74+
# Skip external/vcpkg warnings
75+
if ($lineStr -match "vcpkg|external" -or $lineStr -eq "") {
76+
continue
77+
}
78+
79+
if ($lineStr -match "error:") {
80+
$fileErrors += $lineStr
81+
$totalErrors++
82+
if (-not $errorsByModule[$moduleName]) {
83+
$errorsByModule[$moduleName] = @()
84+
}
85+
$errorsByModule[$moduleName] += @{ File = $relPath; Message = $lineStr }
86+
} elseif ($lineStr -match "warning:") {
87+
$fileWarnings += $lineStr
88+
$totalWarnings++
89+
if (-not $warningsByModule[$moduleName]) {
90+
$warningsByModule[$moduleName] = @()
91+
}
92+
$warningsByModule[$moduleName] += @{ File = $relPath; Message = $lineStr }
93+
}
94+
}
95+
96+
# Show errors for this file
97+
if ($fileErrors.Count -gt 0) {
98+
Write-Host " ERRORS: $($fileErrors.Count)" -ForegroundColor Red
99+
$fileErrors | ForEach-Object { Write-Host " $_" }
100+
}
101+
102+
# Show warnings summary (grouped by type)
103+
if ($fileWarnings.Count -gt 0) {
104+
Write-Host " WARNINGS: $($fileWarnings.Count)" -ForegroundColor Yellow
105+
}
106+
}
107+
108+
Write-Host ""
109+
Write-Host "========================================" -ForegroundColor Cyan
110+
Write-Host "SUMMARY" -ForegroundColor Cyan
111+
Write-Host "========================================" -ForegroundColor Cyan
112+
Write-Host "Files checked: $checkedFiles"
113+
Write-Host "Total errors: $totalErrors" -ForegroundColor Red
114+
Write-Host "Total warnings: $totalWarnings" -ForegroundColor Yellow
115+
116+
if ($errorsByModule.Count -gt 0) {
117+
Write-Host ""
118+
Write-Host "ERRORS BY MODULE:" -ForegroundColor Red
119+
foreach ($module in ($errorsByModule.Keys | Sort-Object)) {
120+
$issues = $errorsByModule[$module]
121+
Write-Host " ${module}: $($issues.Count) error(s)"
122+
$issues | Group-Object { ($_.Message -split ":")[3] } | ForEach-Object {
123+
Write-Host " - $($_.Name): $($_.Count) occurrences"
124+
}
125+
}
126+
}
127+
128+
if ($warningsByModule.Count -gt 0) {
129+
Write-Host ""
130+
Write-Host "WARNINGS BY MODULE:" -ForegroundColor Yellow
131+
foreach ($module in ($warningsByModule.Keys | Sort-Object)) {
132+
$issues = $warningsByModule[$module]
133+
Write-Host " ${module}: $($issues.Count) warning(s)"
134+
}
135+
}
136+
137+
Write-Host ""
138+
if ($totalErrors -gt 0) {
139+
Write-Error "Found $totalErrors error(s). Fix them to continue."
140+
exit 1
141+
}
142+
143+
Write-Host "[OK] No errors found. $totalWarnings warning(s) remain." -ForegroundColor Green
144+
exit 0

.vscode/extract-build-warnings.ps1

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Extract compile warnings and errors from CMake build output
2+
# Filters to only show issues in src/ modules (not vcpkg, external)
3+
4+
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Continue
5+
$PSNativeCommandUseErrorActionPreference = $false
6+
7+
$buildDir = "build-msvc-windows-release"
8+
if (-not (Test-Path $buildDir)) {
9+
Write-Host "Build directory not found. Running CMake configure..."
10+
& cmake --preset windows-release 2>&1 | tail -20
11+
}
12+
13+
Write-Host "Running clean build to capture all warnings..."
14+
$buildOutput = & cmake --build $buildDir --parallel 16 2>&1
15+
$warningsByModule = @{}
16+
$errorsByModule = @{}
17+
18+
# Process output line by line
19+
$currentModule = "unknown"
20+
foreach ($line in $buildOutput) {
21+
$lineStr = "$line"
22+
23+
# Skip noise
24+
if ($lineStr -eq "" -or $lineStr -match "^\[|^Built|^Linking|^Consolidating") {
25+
continue
26+
}
27+
28+
# Detect module from file path
29+
if ($lineStr -match "src\\([a-z_]+)" ) {
30+
$currentModule = $matches[1]
31+
}
32+
33+
# Detect warnings and errors in our source code (not vcpkg/external)
34+
if ($lineStr -match "warning:|error:" -and $lineStr -match "src\\" -and $lineStr -notmatch "vcpkg|external") {
35+
if ($lineStr -match "error:") {
36+
if (-not $errorsByModule[$currentModule]) {
37+
$errorsByModule[$currentModule] = @()
38+
}
39+
$errorsByModule[$currentModule] += $lineStr
40+
Write-Host "[ERROR] $lineStr" -ForegroundColor Red
41+
} else {
42+
if (-not $warningsByModule[$currentModule]) {
43+
$warningsByModule[$currentModule] = @()
44+
}
45+
$warningsByModule[$currentModule] += $lineStr
46+
Write-Host "[WARN] $lineStr" -ForegroundColor Yellow
47+
}
48+
}
49+
}
50+
51+
Write-Host ""
52+
Write-Host "======== SUMMARY ========" -ForegroundColor Cyan
53+
54+
if ($errorsByModule.Count -gt 0) {
55+
Write-Host "ERRORS BY MODULE:" -ForegroundColor Red
56+
foreach ($module in ($errorsByModule.Keys | Sort-Object)) {
57+
Write-Host " ${module}: $($errorsByModule[$module].Count) error(s)"
58+
}
59+
}
60+
61+
if ($warningsByModule.Count -gt 0) {
62+
Write-Host "WARNINGS BY MODULE:" -ForegroundColor Yellow
63+
foreach ($module in ($warningsByModule.Keys | Sort-Object)) {
64+
Write-Host " ${module}: $($warningsByModule[$module].Count) warning(s)"
65+
}
66+
}
67+
68+
if ($errorsByModule.Count -gt 0) {
69+
Write-Error "Found errors in build. See details above."
70+
exit 1
71+
}
72+
73+
Write-Host ""
74+
Write-Host "[OK] Build completed." -ForegroundColor Green
75+
if ($warningsByModule.Count -gt 0) {
76+
Write-Host " $($warningsByModule.Values | Measure-Object -Sum).Sum warnings remain in $($warningsByModule.Count) module(s)."
77+
}
78+
exit 0

0 commit comments

Comments
 (0)