Simon Jakobi pushed to branch wip/sjakobi/T16720 at Glasgow Haskell Compiler / GHC

Commits:

7 changed files:

Changes:

  • .gitlab/ci.sh
    ... ... @@ -644,6 +644,10 @@ function test_hadrian() {
    644 644
       check_msys2_deps _build/stage1/bin/ghc --version
    
    645 645
       check_release_build
    
    646 646
     
    
    647
    +  # GitLab's log viewer renders ANSI colors, but stdout here is not a tty,
    
    648
    +  # so the driver must be told to emit them.
    
    649
    +  RUNTEST_ARGS="${RUNTEST_ARGS:-} --force-colors"
    
    650
    +
    
    647 651
       # Ensure that statically-linked builds are actually static
    
    648 652
       if [[ "${BUILD_FLAVOUR}" = *static* ]]; then
    
    649 653
         bad_execs=""
    

  • compiler/GHC/Core/Opt/Simplify/Utils.hs
    ... ... @@ -2432,12 +2432,10 @@ abstractFloats uf_opts top_lvl main_tvs floats body
    2432 2432
         -- for why we need to re-do dependency analysis
    
    2433 2433
         to_sccs :: OutBind -> [SCC (Id, CoreExpr, VarSet)]
    
    2434 2434
         to_sccs (NonRec id e) = [AcyclicSCC (id, e, emptyVarSet)] -- emptyVarSet: abstract doesn't need it
    
    2435
    -    to_sccs (Rec prs)     = sccs
    
    2436
    -      where
    
    2437
    -        (ids,rhss) = unzip prs
    
    2438
    -        sccs = depAnal (\(id,_rhs,_fvs) -> [getName id])
    
    2439
    -                       (\(_id,_rhs,fvs) -> nonDetStrictFoldVarSet ((:) . getName) [] fvs) -- Wrinkle (AB3)
    
    2440
    -                       (zip3 ids rhss (map exprFreeVars rhss))
    
    2435
    +    to_sccs (Rec prs)
    
    2436
    +      = depAnal (\(id,_rhs,_fvs) -> [getName id])
    
    2437
    +                (\(_id,_rhs,fvs) -> nonDetStrictFoldVarSet ((:) . getName) [] fvs) -- Wrinkle (AB3)
    
    2438
    +                [ (id, rhs, fvs) | (id, rhs) <- prs, let !fvs = exprFreeVars rhs ]
    
    2441 2439
     
    
    2442 2440
         abstract :: GHC.Core.Subst.Subst -> SCC (Id, CoreExpr, VarSet) -> SimplM (GHC.Core.Subst.Subst, OutBind)
    
    2443 2441
         abstract subst (AcyclicSCC (id, rhs, _empty_var_set))
    
    ... ... @@ -2452,14 +2450,15 @@ abstractFloats uf_opts top_lvl main_tvs floats body
    2452 2450
             tvs_here = choose_tvs (exprSomeFreeVars isTyVar rhs')
    
    2453 2451
     
    
    2454 2452
         abstract subst (CyclicSCC trpls)
    
    2455
    -      = do { (poly_ids, poly_apps) <- mapAndUnzipM (mk_poly1 tvs_here) ids
    
    2456
    -           ; let subst' = GHC.Core.Subst.extendSubstList subst (ids `zip` poly_apps)
    
    2457
    -                 poly_pairs = [ mk_poly2 poly_id tvs_here rhs'
    
    2458
    -                              | (poly_id, rhs) <- poly_ids `zip` rhss
    
    2459
    -                              , let rhs' = GHC.Core.Subst.substExpr subst' rhs ]
    
    2453
    +      = do { (subst', poly_prs) <- mapAccumLM mk1 subst trpls
    
    2454
    +           ; let poly_pairs = [ mk_poly2 poly_id tvs_here
    
    2455
    +                                  (GHC.Core.Subst.substExpr subst' rhs)
    
    2456
    +                              | (poly_id, rhs) <- poly_prs ]
    
    2460 2457
                ; return (subst', Rec poly_pairs) }
    
    2461 2458
           where
    
    2462
    -        (ids,rhss,_fvss) = unzip3 trpls
    
    2459
    +        mk1 s (id, rhs, _fvs)
    
    2460
    +          = do { (poly_id, poly_app) <- mk_poly1 tvs_here id
    
    2461
    +               ; return (GHC.Core.Subst.extendIdSubst s id poly_app, (poly_id, rhs)) }
    
    2463 2462
     
    
    2464 2463
             -- tvs_here: see Note [Which type variables to abstract over]
    
    2465 2464
             tvs_here = choose_tvs (mapUnionVarSet get_bind_fvs trpls)
    

  • testsuite/driver/runtests.py
    ... ... @@ -94,6 +94,8 @@ parser.add_argument("--ignore-perf-failures", choices=['increases','decreases','
    94 94
                             help="Do not fail due to out-of-tolerance perf tests")
    
    95 95
     parser.add_argument("--only-report-hadrian-deps", type=Path,
    
    96 96
                             help="Dry run the testsuite and report all extra hadrian dependencies needed on the given file")
    
    97
    +parser.add_argument("--force-colors", action="store_true",
    
    98
    +                        help="emit ANSI colors even when stdout is not a tty (e.g. for CI logs)")
    
    97 99
     
    
    98 100
     args = parser.parse_args()
    
    99 101
     
    
    ... ... @@ -259,7 +261,9 @@ def supports_colors():
    259 261
         return True
    
    260 262
     
    
    261 263
     config.supports_colors = supports_colors()
    
    262
    -term_color.enable_color = config.supports_colors
    
    264
    +# config.supports_colors deliberately stays tty-based: it also guards
    
    265
    +# terminal-title updates, which must not end up in a CI log.
    
    266
    +term_color.enable_color = config.supports_colors or args.force_colors
    
    263 267
     
    
    264 268
     # This has to come after arg parsing as the args can change the compiler
    
    265 269
     get_compiler_info()
    
    ... ... @@ -587,7 +591,7 @@ else:
    587 591
             print(Perf.allow_changes_string([(m.change, m.stat) for m in t.metrics]))
    
    588 592
             print('-' * 25)
    
    589 593
     
    
    590
    -    summary(t, sys.stdout, color=config.supports_colors)
    
    594
    +    summary(t, sys.stdout, color=term_color.enable_color)
    
    591 595
     
    
    592 596
         # Write perf stats if any exist or if a metrics file is specified.
    
    593 597
         stats_metrics = [stat for (_, stat, __) in t.metrics] # type: List[PerfStat]
    

  • testsuite/driver/testlib.py
    ... ... @@ -2442,7 +2442,9 @@ async def simple_run(name: TestName, way: WayName, prog: str, extra_run_opts: st
    2442 2442
                 dump_stdout(name)
    
    2443 2443
                 dump_stderr(name)
    
    2444 2444
             message = format_bad_exit_code_message(exit_code)
    
    2445
    -        return failBecause(message)
    
    2445
    +        return failBecause(message,
    
    2446
    +                           stderr=read_stderr(name),
    
    2447
    +                           stdout=read_stdout(name))
    
    2446 2448
     
    
    2447 2449
         if not (opts.ignore_stderr or await stderr_ok(name, way) or opts.combined_output):
    
    2448 2450
             return failBecause('bad stderr',
    
    ... ... @@ -3541,7 +3543,8 @@ def summary(t: TestRun, file: TextIO, color=False) -> None:
    3541 3543
             summary_color = Color.GREEN
    
    3542 3544
     
    
    3543 3545
         assert t.start_time is not None
    
    3544
    -    file.write(colored(summary_color, 'SUMMARY') + ' for test run started at '
    
    3546
    +    summary_header = colored(summary_color, 'SUMMARY') if color else 'SUMMARY'
    
    3547
    +    file.write(summary_header + ' for test run started at '
    
    3545 3548
                    + t.start_time.strftime("%c %Z") + '\n'
    
    3546 3549
                    + str(datetime.datetime.now() - t.start_time).rjust(8)
    
    3547 3550
                    + ' spent to go through\n'
    
    ... ... @@ -3593,6 +3596,10 @@ def summary(t: TestRun, file: TextIO, color=False) -> None:
    3593 3596
             file.write('Framework warnings:\n')
    
    3594 3597
             printTestInfosSummary(file, t.framework_warnings)
    
    3595 3598
     
    
    3599
    +    if t.unexpected_failures:
    
    3600
    +        file.write('Output of unexpected failures:\n\n')
    
    3601
    +        printTestOutputSummary(file, t.unexpected_failures, color)
    
    3602
    +
    
    3596 3603
         if stopping():
    
    3597 3604
             file.write('WARNING: Testsuite run was terminated early\n')
    
    3598 3605
     
    
    ... ... @@ -3606,6 +3613,34 @@ def printUnexpectedTests(file: TextIO, testInfoss):
    3606 3613
             file.write('TEST="' + ' '.join(sorted(unexpected)) + '"\n')
    
    3607 3614
             file.write('\n')
    
    3608 3615
     
    
    3616
    +# Per-stream cap on a failing test's output repeated in the final summary.
    
    3617
    +MAX_SUMMARY_OUTPUT_LINES = 100
    
    3618
    +
    
    3619
    +def printTestOutputSummary(file: TextIO, testInfos, color: bool=False) -> None:
    
    3620
    +    # Repeat failing tests' captured output in the summary, so one needn't
    
    3621
    +    # hunt for it earlier in a possibly very long log; see #16720.
    
    3622
    +    for result in sorted(testInfos, key=lambda r: (r.testname.lower(), r.way, r.directory)):
    
    3623
    +        header = '=====> {}({}) [{}]'.format(result.testname, result.way, result.reason)
    
    3624
    +        if color:
    
    3625
    +            header = colored(Color.RED, header)
    
    3626
    +        file.write(header + '\n')
    
    3627
    +        for stream_name, contents in [('stdout', result.stdout), ('stderr', result.stderr)]:
    
    3628
    +            if contents and contents.strip():
    
    3629
    +                label = 'Captured {}:'.format(stream_name)
    
    3630
    +                if color:
    
    3631
    +                    label = colored(Color.CYAN, label)
    
    3632
    +                lines = contents.rstrip('\n').split('\n')
    
    3633
    +                if len(lines) > MAX_SUMMARY_OUTPUT_LINES:
    
    3634
    +                    omitted = len(lines) - MAX_SUMMARY_OUTPUT_LINES
    
    3635
    +                    lines = lines[:MAX_SUMMARY_OUTPUT_LINES] \
    
    3636
    +                        + ['... ({} more lines omitted, see junit.xml)'.format(omitted)]
    
    3637
    +                s = label + '\n' + ''.join(l + '\n' for l in lines)
    
    3638
    +                # Test output can contain characters that file's encoding
    
    3639
    +                # cannot represent; replace rather than crash (cf safe_print).
    
    3640
    +                enc = getattr(file, 'encoding', None) or 'utf-8'
    
    3641
    +                file.write(s.encode(enc, errors='replace').decode(enc))
    
    3642
    +        file.write('\n')
    
    3643
    +
    
    3609 3644
     def printTestInfosSummary(file: TextIO, testInfos):
    
    3610 3645
         maxDirLen = max(len(tr.directory) for tr in testInfos)
    
    3611 3646
         for result in sorted(testInfos, key=lambda r: (r.testname.lower(), r.way, r.directory)):
    

  • testsuite/tests/codeGen/should_run/cgrun001.stdout
    1
    --42
    1
    +-43

  • testsuite/tests/codeGen/should_run/cgrun002.hs
    1
    -main = print ((f id2) (10 + thirty_two))
    
    1
    +import System.Exit
    
    2
    +import System.IO
    
    3
    +
    
    4
    +main = do
    
    5
    +    print ((f id2) (10 + thirty_two))
    
    6
    +    hPutStrLn stderr "deliberate breakage to test summary output"
    
    7
    +    exitWith (ExitFailure 3)
    
    2 8
       where
    
    3 9
         f x = g x
    
    4 10
           where
    

  • testsuite/tests/numeric/should_run/T18619.stderr
    1 1
     T18619: Uncaught exception ghc-internal:GHC.Internal.Exception.Type.ArithException:
    
    2 2
     
    
    3
    -arithmetic overflow
    3
    +arithmetic underflow