Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • testsuite/driver/runtests.py
    ... ... @@ -28,7 +28,7 @@ import subprocess
    28 28
     
    
    29 29
     import asyncio
    
    30 30
     
    
    31
    -from testutil import getStdout, str_warn, str_info, print_table, shorten_metric_name
    
    31
    +from testutil import getStdout, str_warn, str_info, print_table, shorten_metric_name, str_removeprefix
    
    32 32
     from testglobals import getConfig, ghc_env, TestConfig, t, \
    
    33 33
                             TestOptions, brokens, PerfMetric
    
    34 34
     from my_typing import TestName
    
    ... ... @@ -291,7 +291,7 @@ if windows:
    291 291
         for line in pkginfo.split('\n'):
    
    292 292
             if line.startswith('library-dirs:'):
    
    293 293
                 path = line.rstrip()
    
    294
    -            path = re.sub('^library-dirs: ', '', path)
    
    294
    +            path = str_removeprefix(path, 'library-dirs: ')
    
    295 295
                 # Use string.replace instead of re.sub, because re.sub
    
    296 296
                 # interprets backslashes in the replacement string as
    
    297 297
                 # escape sequences.
    

  • testsuite/driver/testlib.py
    ... ... @@ -25,7 +25,7 @@ from testglobals import config, ghc_env, default_testopts, brokens, t, \
    25 25
     from testutil import strip_quotes, lndir, link_or_copy_file, passed, \
    
    26 26
                          failBecause, testing_metrics, residency_testing_metrics, \
    
    27 27
                          stable_perf_counters, \
    
    28
    -                     PassFail, badResult, memoize
    
    28
    +                     PassFail, badResult, memoize, str_removeprefix
    
    29 29
     from term_color import Color, colored
    
    30 30
     import testutil
    
    31 31
     from cpu_features import have_cpu_feature
    
    ... ... @@ -1792,7 +1792,7 @@ async def do_test(name: TestName,
    1792 1792
         if opts.expect not in ['pass', 'fail', 'missing-lib']:
    
    1793 1793
             framework_fail(name, way, 'bad expected ' + opts.expect)
    
    1794 1794
     
    
    1795
    -    directory = re.sub(r'^\.[/\\]', '', str(opts.testdir))
    
    1795
    +    directory = str_removeprefix(str_removeprefix(str(opts.testdir), './'), '.\\')
    
    1796 1796
     
    
    1797 1797
         if way in opts.fragile_ways:
    
    1798 1798
             if_verbose(1, '*** fragile test %s resulted in %s' % (full_name, 'pass' if result.passed else 'fail'))
    
    ... ... @@ -1830,7 +1830,7 @@ async def do_test(name: TestName,
    1830 1830
     # if found and instead have the testsuite decide on what to do
    
    1831 1831
     # with the output.
    
    1832 1832
     def override_options(pre_cmd):
    
    1833
    -    if config.verbose >= 5 and bool(re.match(r'\$make', pre_cmd, re.I)):
    
    1833
    +    if config.verbose >= 5 and pre_cmd.lower().startswith('$make'):
    
    1834 1834
             return pre_cmd.replace(' -s'     , '') \
    
    1835 1835
                           .replace('--silent', '') \
    
    1836 1836
                           .replace('--quiet' , '')
    
    ... ... @@ -1843,7 +1843,7 @@ def framework_fail(name: Optional[TestName], way: Optional[WayName], reason: str
    1843 1843
         # so we need to take care not to blow up with the wrong way
    
    1844 1844
         # and report the actual reason for the failure.
    
    1845 1845
         try:
    
    1846
    -      directory = re.sub(r'^\.[/\\]', '', str(opts.testdir))
    
    1846
    +      directory = str_removeprefix(str_removeprefix(str(opts.testdir), './'), '.\\')
    
    1847 1847
         except:
    
    1848 1848
           directory = ''
    
    1849 1849
         full_name = '%s(%s)' % (name, way)
    
    ... ... @@ -1856,7 +1856,7 @@ def framework_fail(name: Optional[TestName], way: Optional[WayName], reason: str
    1856 1856
     
    
    1857 1857
     def framework_warn(name: TestName, way: WayName, reason: str) -> None:
    
    1858 1858
         opts = getTestOpts()
    
    1859
    -    directory = re.sub(r'^\.[/\\]', '', str(opts.testdir))
    
    1859
    +    directory = str_removeprefix(str_removeprefix(str(opts.testdir), './'), '.\\')
    
    1860 1860
         full_name = name + '(' + way + ')'
    
    1861 1861
         if_verbose(1, '*** framework warning for %s %s ' % (full_name, reason))
    
    1862 1862
         t.framework_warnings.append(TestResult(directory, name, reason, way))
    
    ... ... @@ -2550,7 +2550,7 @@ def split_file(in_fn: Path, delimiter: str, out1_fn: Path, out2_fn: Path):
    2550 2550
             with out1_fn.open('w', encoding='utf8', newline='') as out1:
    
    2551 2551
                 with out2_fn.open('w', encoding='utf8', newline='') as out2:
    
    2552 2552
                     line = infile.readline()
    
    2553
    -                while re.sub(r'^\s*','',line) != delimiter and line != '':
    
    2553
    +                while line.lstrip() != delimiter and line != '':
    
    2554 2554
                         out1.write(line)
    
    2555 2555
                         line = infile.readline()
    
    2556 2556
     
    
    ... ... @@ -2933,6 +2933,14 @@ def normalise_callstacks(s: str) -> str:
    2933 2933
     
    
    2934 2934
     tyCon_re = re.compile(r'TyCon\s*\d+\#\#\d?\d?\s*\d+\#\#\d?\d?\s*', flags=re.MULTILINE)
    
    2935 2935
     
    
    2936
    +def drop_lines_containing(s: str, needle: str) -> str:
    
    2937
    +    """
    
    2938
    +    Drop lines from `s` which contain `needle`.
    
    2939
    +    """
    
    2940
    +    if needle not in s:
    
    2941
    +        return s
    
    2942
    +    return ''.join(line for line in s.splitlines(keepends=True) if needle not in line)
    
    2943
    +
    
    2936 2944
     def normalise_type_reps(s: str) -> str:
    
    2937 2945
         """ Normalise out fingerprints from Typeable TyCon representations """
    
    2938 2946
         return re.sub(tyCon_re, 'TyCon FINGERPRINT FINGERPRINT ', s)
    
    ... ... @@ -2944,8 +2952,8 @@ def normalise_errmsg(s: str) -> str:
    2944 2952
             s = s.replace('ld: 0706-027 The -x flag is ignored.\n', '')
    
    2945 2953
         # remove " error:" and lower-case " Warning:" to make patch for
    
    2946 2954
         # trac issue #10021 smaller
    
    2947
    -    s = modify_lines(s, lambda l: re.sub(' error:', '', l))
    
    2948
    -    s = modify_lines(s, lambda l: re.sub(' Warning:', ' warning:', l))
    
    2955
    +    s = modify_lines(s, lambda l: l.replace(' error:', ''))
    
    2956
    +    s = modify_lines(s, lambda l: l.replace(' Warning:', ' warning:'))
    
    2949 2957
         s = normalise_callstacks(s)
    
    2950 2958
         s = normalise_type_reps(s)
    
    2951 2959
     
    
    ... ... @@ -2960,7 +2968,7 @@ def normalise_errmsg(s: str) -> str:
    2960 2968
         #   a target prefix (e.g. `aarch64-linux-gnu-ghc`)
    
    2961 2969
         # * On Windows the executable name may mention the
    
    2962 2970
         #   versioned name (e.g. `ghc-9.2.1`)
    
    2963
    -    s = re.sub(Path(config.compiler).name + ':', 'ghc:', s)
    
    2971
    +    s = s.replace(Path(config.compiler).name + ':', 'ghc:')
    
    2964 2972
     
    
    2965 2973
         # If somefile ends in ".exe" or ".exe:", zap ".exe" (for Windows)
    
    2966 2974
         #    the colon is there because it appears in error messages; this
    
    ... ... @@ -2973,11 +2981,13 @@ def normalise_errmsg(s: str) -> str:
    2973 2981
         s = re.sub(r'([^\s])\.jsexe', r'\1', s)
    
    2974 2982
     
    
    2975 2983
         # hpc executable is given ghc suffix
    
    2976
    -    s = re.sub('hpc-ghc', 'hpc', s)
    
    2984
    +    s = s.replace('hpc-ghc', 'hpc')
    
    2977 2985
     
    
    2978 2986
         # The inplace ghc's are called ghc-stage[123] to avoid filename
    
    2979 2987
         # collisions, so we need to normalise that to just "ghc"
    
    2980
    -    s = re.sub('ghc-stage[123]', 'ghc', s)
    
    2988
    +    s = (s.replace('ghc-stage1', 'ghc')
    
    2989
    +           .replace('ghc-stage2', 'ghc')
    
    2990
    +           .replace('ghc-stage3', 'ghc'))
    
    2981 2991
         # Remove platform prefix (e.g. javascript-unknown-ghcjs) for cross-compiled tools
    
    2982 2992
         # (ghc, ghc-pkg, unlit, etc.)
    
    2983 2993
         s = re.sub(r'\w+(-\w+)*-ghc', 'ghc', s)
    
    ... ... @@ -3000,7 +3010,7 @@ def normalise_errmsg(s: str) -> str:
    3000 3010
         # Also filter out bullet characters.  This is because bullets are used to
    
    3001 3011
         # separate error sections, and tests shouldn't be sensitive to how the
    
    3002 3012
         # the division happens.
    
    3003
    -    bullet = ''.encode('utf8') if isinstance(s, bytes) else ''
    
    3013
    +    bullet = ''
    
    3004 3014
         s = s.replace(bullet, '')
    
    3005 3015
     
    
    3006 3016
         # Windows only, this is a bug in hsc2hs but it is preventing
    
    ... ... @@ -3015,19 +3025,19 @@ def normalise_errmsg(s: str) -> str:
    3015 3025
         s = modify_lines(s, lambda l: re.sub(r'^(.+)warning: (.+): unsupported GNU_PROPERTY_TYPE (?:\(5\) )?type: 0xc000000(.*)$', '', l))
    
    3016 3026
     
    
    3017 3027
         s = re.sub(r'ld: warning: passed .* min versions \(.*\) for platform macOS. Using [\.0-9]+.','',s)
    
    3018
    -    s = re.sub('ld: warning: -sdk_version and -platform_version are not compatible, ignoring -sdk_version','',s)
    
    3028
    +    s = s.replace('ld: warning: -sdk_version and -platform_version are not compatible, ignoring -sdk_version', '')
    
    3019 3029
         # ignore superfluous dylibs passed to the linker.
    
    3020
    -    s = re.sub('ld: warning: .*, ignoring unexpected dylib file\n','',s)
    
    3030
    +    s = drop_lines_containing(s, 'ignoring unexpected dylib file')
    
    3021 3031
         # ignore LLVM Version mismatch garbage; this will just break tests.
    
    3022
    -    s = re.sub('You are using an unsupported version of LLVM!.*\n','',s)
    
    3023
    -    s = re.sub('Currently only [\\.0-9]+ is supported. System LLVM version: [\\.0-9]+.*\n','',s)
    
    3024
    -    s = re.sub('We will try though\\.\\.\\..*\n','',s)
    
    3032
    +    s = drop_lines_containing(s, 'You are using an unsupported version of LLVM!')
    
    3033
    +    s = drop_lines_containing(s, 'System LLVM version:')
    
    3034
    +    s = drop_lines_containing(s, 'We will try though...')
    
    3025 3035
         # ignore warning about strip invalidating signatures
    
    3026
    -    s = re.sub('.*strip: changes being made to the file will invalidate the code signature in.*\n','',s)
    
    3036
    +    s = drop_lines_containing(s, 'strip: changes being made to the file will invalidate the code signature in')
    
    3027 3037
         # clang may warn about unused argument when used as assembler
    
    3028
    -    s = re.sub('.*warning: argument unused during compilation:.*\n', '', s)
    
    3038
    +    s = drop_lines_containing(s, 'warning: argument unused during compilation:')
    
    3029 3039
         # Emscripten displays cache info and old emcc doesn't support EMCC_LOGGING=0
    
    3030
    -    s = re.sub('cache:INFO: .*\n', '', s)
    
    3040
    +    s = drop_lines_containing(s, 'cache:INFO:')
    
    3031 3041
         # Old emcc warns when we export HEAP8 but new one requires it (see #26290)
    
    3032 3042
         s = s.replace('warning: invalid item in EXPORTED_RUNTIME_METHODS: HEAP8\nwarning: invalid item in EXPORTED_RUNTIME_METHODS: HEAPU8\nemcc: warning: warnings in JS library compilation [-Wjs-compiler]\n','')
    
    3033 3043
     
    
    ... ... @@ -3050,7 +3060,7 @@ def normalise_prof (s: str) -> str:
    3050 3060
     
    
    3051 3061
         # The next step assumes none of the fields have no spaces in, which is broke
    
    3052 3062
         # when the src = <no location info>
    
    3053
    -    s = re.sub('no location info','no-location-info', s)
    
    3063
    +    s = s.replace('no location info', 'no-location-info')
    
    3054 3064
     
    
    3055 3065
         # Source locations from internal libraries, remove the source location
    
    3056 3066
         # > libraries/ghc-internal/src/path/Foo.hs:204:1-18
    
    ... ... @@ -3103,21 +3113,21 @@ def normalise_prof (s: str) -> str:
    3103 3113
         return s
    
    3104 3114
     
    
    3105 3115
     def normalise_slashes_( s: str ) -> str:
    
    3106
    -    s = re.sub(r'\\', '/', s)
    
    3107
    -    s = re.sub(r'//', '/', s)
    
    3116
    +    s = s.replace('\\', '/')
    
    3117
    +    s = s.replace('//', '/')
    
    3108 3118
         return s
    
    3109 3119
     
    
    3110 3120
     def normalise_exe_( s: str ) -> str:
    
    3111
    -    s = re.sub(r'\.exe', '', s)
    
    3112
    -    s = re.sub(r'\.wasm', '', s)
    
    3113
    -    s = re.sub(r'\.jsexe', '', s)
    
    3121
    +    s = s.replace('.exe', '')
    
    3122
    +    s = s.replace('.wasm', '')
    
    3123
    +    s = s.replace('.jsexe', '')
    
    3114 3124
         return s
    
    3115 3125
     
    
    3116 3126
     def normalise_output( s: str ) -> str:
    
    3117 3127
         # remove " error:" and lower-case " Warning:" to make patch for
    
    3118 3128
         # trac issue #10021 smaller
    
    3119
    -    s = modify_lines(s, lambda l: re.sub(' error:', '', l))
    
    3120
    -    s = modify_lines(s, lambda l: re.sub(' Warning:', ' warning:', l))
    
    3129
    +    s = modify_lines(s, lambda l: l.replace(' error:', ''))
    
    3130
    +    s = modify_lines(s, lambda l: l.replace(' Warning:', ' warning:'))
    
    3121 3131
         # Remove a .exe extension (for Windows)
    
    3122 3132
         # and .wasm extension (for the Wasm backend)
    
    3123 3133
         # and .jsexe extension (for the JS backend)
    
    ... ... @@ -3129,19 +3139,19 @@ def normalise_output( s: str ) -> str:
    3129 3139
         s = normalise_type_reps(s)
    
    3130 3140
         # ghci outputs are pretty unstable with -fexternal-dynamic-refs, which is
    
    3131 3141
         # requires for -fPIC
    
    3132
    -    s = re.sub('  -fexternal-dynamic-refs\n','',s)
    
    3142
    +    s = s.replace('  -fexternal-dynamic-refs\n', '')
    
    3133 3143
         s = re.sub(r'ld: warning: passed .* min versions \(.*\) for platform macOS. Using [\.0-9]+.','',s)
    
    3134
    -    s = re.sub('ld: warning: -sdk_version and -platform_version are not compatible, ignoring -sdk_version','',s)
    
    3144
    +    s = s.replace('ld: warning: -sdk_version and -platform_version are not compatible, ignoring -sdk_version', '')
    
    3135 3145
         # ignore superfluous dylibs passed to the linker.
    
    3136
    -    s = re.sub('ld: warning: .*, ignoring unexpected dylib file\n','',s)
    
    3146
    +    s = drop_lines_containing(s, 'ignoring unexpected dylib file')
    
    3137 3147
         # ignore LLVM Version mismatch garbage; this will just break tests.
    
    3138
    -    s = re.sub('You are using an unsupported version of LLVM!.*\n','',s)
    
    3139
    -    s = re.sub('Currently only [\\.0-9]+ is supported. System LLVM version: [\\.0-9]+.*\n','',s)
    
    3140
    -    s = re.sub('We will try though\\.\\.\\..*\n','',s)
    
    3148
    +    s = drop_lines_containing(s, 'You are using an unsupported version of LLVM!')
    
    3149
    +    s = drop_lines_containing(s, 'System LLVM version:')
    
    3150
    +    s = drop_lines_containing(s, 'We will try though...')
    
    3141 3151
         # ignore warning about strip invalidating signatures
    
    3142
    -    s = re.sub('.*strip: changes being made to the file will invalidate the code signature in.*\n','',s)
    
    3152
    +    s = drop_lines_containing(s, 'strip: changes being made to the file will invalidate the code signature in')
    
    3143 3153
         # clang may warn about unused argument when used as assembler
    
    3144
    -    s = re.sub('.*warning: argument unused during compilation:.*\n', '', s)
    
    3154
    +    s = drop_lines_containing(s, 'warning: argument unused during compilation:')
    
    3145 3155
     
    
    3146 3156
         # strip the cross prefix if any
    
    3147 3157
         s = re.sub(r'\w+(-\w+)*-ghc', 'ghc', s)
    

  • testsuite/driver/testutil.py
    ... ... @@ -40,6 +40,12 @@ def strip_quotes(s: str) -> str:
    40 40
         # Don't wrap commands to subprocess.call/Popen in quotes.
    
    41 41
         return s.strip('\'"')
    
    42 42
     
    
    43
    +# Python 3.7 compatibility shim for str.removeprefix (added in Python 3.9).
    
    44
    +def str_removeprefix(s: str, prefix: str) -> str:
    
    45
    +    if s.startswith(prefix):
    
    46
    +        return s.replace(prefix, '', 1)
    
    47
    +    return s
    
    48
    +
    
    43 49
     def str_warn(s: str) -> str:
    
    44 50
         return colored(Color.YELLOW, s)
    
    45 51