Skip to content

RTS does not clear output file before writing with -t<file>

Summary

Running a program twice, outputting to the same file with +RTS -t leads to issues if the second run produces a shorter output, as output is only overwritten. So we end up with trash at the end.

Steps to reproduce

Andi@Horzube MINGW64 /e/ghc_inferTags
$ ghc nofib/spectral/simple/Main.hs -c -O0 +RTS --machine-readable -trts4

nofib\spectral\simple\Main.hs:80:1: warning: [-Wtabs]
    Tab character found here, and in 46 further locations.
    Please use spaces instead.
   |
80 |                         in [show "RESULT ",show "U",show mat0,show "V",show mat1,show "R",
   | ^^^^^^^^

Andi@Horzube MINGW64 /e/ghc_inferTags
$ ghc nofib/spectral/simple/Main.hs -c -O0 +RTS --machine-readable -trts4
compilation IS NOT required


Andi@Horzube MINGW64 /e/ghc_inferTags
$ cat rts4
C:\ghc\msys64\opt\ghc\bin\ghc.exe nofib/spectral/simple/Main.hs -c -O +RTS --machine-readable -trts1
 [("bytes allocated", "55237264")
 ,("num_GCs", "39")
 ,("average_bytes_used", "3084713")
 ,("max_bytes_used", "8111448")
 ,("num_byte_usage_samples", "6")
 ,("peak_megabytes_allocated", "18")
 ,("init_cpu_seconds", "0.000000")
 ,("init_wall_seconds", "0.000347")
 ,("mut_cpu_seconds", "0.015625")
 ,("mut_wall_seconds", "0.047965")
 ,("GC_cpu_seconds", "0.078125")
 ,("GC_wall_seconds", "0.077720")
 ,("exit_cpu_seconds", "0.000000")
 ,("exit_wall_seconds", "0.000138")
 ,("total_cpu_seconds", "0.093750")
 ,("total_wall_seconds", "0.126173")
 ,("major_gcs", "6")
 ,("allocated_bytes", "55237264")
 ,("max_live_bytes", "8111448")
 ,("max_large_objects_bytes", "1876928")
 ,("max_compact_bytes", "0")
 ,("max_slop_bytes", "150184")
 ,("max_mem_in_use_bytes", "18874368")
 ,("cumulative_live_bytes", "18508280")
 ,("copied_bytes", "33135056")
 ,("par_copied_bytes", "0")
 ,("cumulative_par_max_copied_bytes", "0")
 ,("cumulative_par_balanced_copied_bytes", "0")
 ,("fragmentation_bytes", "0")
 ,("alloc_rate", "3535184896")
 ,("productivity_cpu_percent", "0.166667")
 ,("productivity_wall_percent", "0.380168")
 ,("bound_task_count", "1")
 ,("sparks_count", "0")
 ,("sparks_converted", "0")
 ,("sparks_overflowed", "0")
 ,("sparks_dud ", "0")
 ,("sparks_gcd", "0")
 ,("sparks_fizzled", "0")
 ,("work_balance", "0.000000")
 ,("n_capabilities", "1")
 ,("task_count", "5")
 ,("peak_worker_count", "4")
 ,("worker_count", "4")
 ,("gc_alloc_block_sync_spin", "0")
 ,("gc_alloc_block_sync_yield", "0")
 ,("gc_alloc_block_sync_spin", "0")
 ,("gc_spin_spin", "0")
 ,("gc_spin_yield", "0")
 ,("mut_spin_spin", "0")
 ,("mut_spin_yield", "0")
 ,("waitForGcThreads_spin", "0")
 ,("waitForGcThreads_yield", "0")
 ,("whitehole_gc_spin", "0")
 ,("whitehole_lockClosure_spin", "0")
 ,("whitehole_lockClosure_yield", "0")
 ,("whitehole_executeMessage_spin", "0")
 ,("whitehole_threadPaused_spin", "0")
 ,("any_work", "0")
 ,("no_work", "0")
 ,("scav_find_work", "0")
 ,("gen_0_collections", "33")
 ,("gen_0_par_collections", "0")
 ,("gen_0_cpu_seconds", "0.000000")
 ,("gen_0_wall_seconds", "0.018906")
 ,("gen_0_max_pause_seconds", "0.002074")
 ,("gen_0_avg_pause_seconds", "0.000573")
 ,("gen_0_sync_spin", "0")
 ,("gen_0_sync_yield", "0")
 ,("gen_1_collections", "6")
 ,("gen_1_par_collections", "0")
 ,("gen_1_cpu_seconds", "0.078125")
 ,("gen_1_wall_seconds", "0.058814")
 ,("gen_1_max_pause_seconds", "0.021239")
 ,("gen_1_avg_pause_seconds", "0.009802")
 ,("gen_1_sync_spin", "0")
 ,("gen_1_sync_yield", "0")
 ]
yield", "0")
 ]

Expected behavior

File should be truncated at the length written.

Environment

  • GHC version used: 8.6.5

Optional:

  • Operating System: windows
  • System Architecture: x64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information