[Git][ghc/ghc][wip/explicit-perf-baseline] Further refactoring

Ben Gamari gitlab at gitlab.haskell.org
Sun Jul 5 23:16:58 UTC 2020



Ben Gamari pushed to branch wip/explicit-perf-baseline at Glasgow Haskell Compiler / GHC


Commits:
33f843d7 by Ben Gamari at 2020-07-05T19:16:49-04:00
Further refactoring

- - - - -


7 changed files:

- hadrian/src/Settings/Builders/RunTest.hs
- testsuite/driver/runtests.py
- testsuite/driver/testglobals.py
- testsuite/driver/testlib.py
- testsuite/config/testsuite_config.py → testsuite/driver/testsuite_config.py
- testsuite/mk/test.mk
- testsuite/tests/concurrent/prog002/all.T


Changes:

=====================================
hadrian/src/Settings/Builders/RunTest.hs
=====================================
@@ -105,38 +105,38 @@ runTestBuilderArgs = builder RunTest ? do
             , pure [ "--rootdir=" ++ testdir | testdir <- rootdirs ]
             , arg "-e", arg $ "windows=" ++ show windowsHost
             , arg "-e", arg $ "darwin=" ++ show osxHost
-            , arg "-e", arg $ "config.local=False"
-            , arg "-e", arg $ "config.cleanup=" ++ show (not keepFiles)
-            , arg "-e", arg $ "config.accept=" ++ show accept
-            , arg "-e", arg $ "config.accept_platform=" ++ show acceptPlatform
-            , arg "-e", arg $ "config.accept_os=" ++ show acceptOS
-            , arg "-e", arg $ "config.exeext=" ++ quote (if null exe then "" else "."<>exe)
-            , arg "-e", arg $ "config.compiler_debugged=" ++
+            , arg "--config", arg $ "local=False"
+            , arg "--config", arg $ "cleanup=" ++ show (not keepFiles)
+            , arg "--config", arg $ "accept=" ++ show accept
+            , arg "--config", arg $ "accept_platform=" ++ show acceptPlatform
+            , arg "--config", arg $ "accept_os=" ++ show acceptOS
+            , arg "--config", arg $ "exeext=" ++ quote (if null exe then "" else "."<>exe)
+            , arg "--config", arg $ "compiler_debugged=" ++
               show debugged
             , arg "-e", arg $ asBool "ghc_with_native_codegen=" withNativeCodeGen
 
-            , arg "-e", arg $ "config.have_interp=" ++ show withInterpreter
-            , arg "-e", arg $ "config.unregisterised=" ++ show unregisterised
+            , arg "--config", arg $ "have_interp=" ++ show withInterpreter
+            , arg "--config", arg $ "unregisterised=" ++ show unregisterised
 
-            , arg "-e", arg $ "ghc_compiler_always_flags=" ++ quote ghcFlags
-            , arg "-e", arg $ asBool "ghc_with_dynamic_rts="  (hasRtsWay "dyn")
-            , arg "-e", arg $ asBool "ghc_with_threaded_rts=" (hasRtsWay "thr")
-            , arg "-e", arg $ asBool "config.have_vanilla="   (hasLibWay vanilla)
-            , arg "-e", arg $ asBool "config.have_dynamic="   (hasLibWay dynamic)
-            , arg "-e", arg $ asBool "config.have_profiling=" (hasLibWay profiling)
-            , arg "-e", arg $ asBool "config.have_fast_bignum=" (bignumBackend /= "native" && not bignumCheck)
-            , arg "-e", arg $ asBool "ghc_with_smp=" withSMP
-            , arg "-e", arg $ asBool "ghc_with_llvm=" withLlvm
+            , arg "--extra-hc-flag", arg (quote ghcFlags)
+            , arg "--config", arg $ asBool "ghc_with_dynamic_rts="  (hasRtsWay "dyn")
+            , arg "--config", arg $ asBool "ghc_with_threaded_rts=" (hasRtsWay "thr")
+            , arg "--config", arg $ asBool "have_vanilla="   (hasLibWay vanilla)
+            , arg "--config", arg $ asBool "have_dynamic="   (hasLibWay dynamic)
+            , arg "--config", arg $ asBool "have_profiling=" (hasLibWay profiling)
+            , arg "--config", arg $ asBool "have_fast_bignum=" (bignumBackend /= "native" && not bignumCheck)
+            , arg "--config", arg $ asBool "ghc_with_smp=" withSMP
+            , arg "--config", arg $ asBool "ghc_with_llvm=" withLlvm
 
 
-            , arg "-e", arg $ "config.ghc_dynamic_by_default=" ++ show hasDynamicByDefault
-            , arg "-e", arg $ "config.ghc_dynamic=" ++ show hasDynamic
+            , arg "--config", arg $ "ghc_dynamic_by_default=" ++ show hasDynamicByDefault
+            , arg "--config", arg $ "ghc_dynamic=" ++ show hasDynamic
 
-            , arg "-e", arg $ "config.top=" ++ show (top -/- "testsuite")
-            , arg "-e", arg $ "config.wordsize=" ++ show wordsize
-            , arg "-e", arg $ "config.os="       ++ show os
-            , arg "-e", arg $ "config.arch="     ++ show arch
-            , arg "-e", arg $ "config.platform=" ++ show platform
+            , arg "--config", arg $ "top=" ++ show (top -/- "testsuite")
+            , arg "--config", arg $ "wordsize=" ++ show wordsize
+            , arg "--config", arg $ "os="       ++ show os
+            , arg "--config", arg $ "arch="     ++ show arch
+            , arg "--config", arg $ "platform=" ++ show platform
 
             , arg "--config", arg $ "gs=gs"                           -- Use the default value as in test.mk
             , arg "--config", arg $ "timeout_prog=" ++ show (top -/- timeoutProg)


=====================================
testsuite/driver/runtests.py
=====================================
@@ -5,6 +5,7 @@
 #
 
 import argparse
+from copy import copy
 import signal
 import sys
 import os
@@ -264,6 +265,7 @@ def main() -> None:
     parser.add_argument("--verbose", type=int, choices=[0,1,2,3,4,5], help="verbose (Values 0 through 5 accepted)")
     parser.add_argument("--junit", type=argparse.FileType('wb'), help="output testsuite summary in JUnit format")
     parser.add_argument("--broken-test", action="append", default=[], help="a test name to mark as broken for this run")
+    parser.add_argument('--extra-hc-flag', action="append", default=[], help="extra flags to pass to the Haskell compiler")
     parser.add_argument("--test-env", default='local', help="Override default chosen test-env.")
     parser.add_argument("--perf-baseline", type=GitRef, metavar='COMMIT', help="Baseline commit for performance comparsons.")
     perf_group.add_argument("--skip-perf-tests", action="store_true", help="skip performance tests")
@@ -280,7 +282,7 @@ def main() -> None:
             exec(e)
 
     ts_config = testsuite_config.GHCTestsuiteConfig
-    ts_config.init_config()
+    ts_config_globals = ts_config.init_config(config)
 
     if args.config:
         for arg in args.config:
@@ -292,6 +294,8 @@ def main() -> None:
     if args.rootdir:
         config.rootdirs = args.rootdir
 
+    config.compiler_always_flags = args.extra_hc_flag
+
     config.metrics_file = args.metrics_file
     hasMetricsFile = config.metrics_file is not None
     config.summary_file = args.summary_file
@@ -440,6 +444,8 @@ def main() -> None:
 
     # First collect all the tests to be run
     t_files_ok = True
+    test_globals = copy(testlib.__dict__)
+    test_globals.update(ts_config_globals)
     for file in t_files:
         testlib.if_verbose(2, '====> Scanning %s' % file)
         testlib.newTestDir(tempdir, os.path.dirname(file))
@@ -447,7 +453,7 @@ def main() -> None:
             with io.open(file, encoding='utf8') as f:
                 src = f.read()
 
-            exec(src)
+            exec(src, test_globals)
         except Exception as e:
             traceback.print_exc()
             testlib.framework_fail(None, None, 'exception: %s' % e)


=====================================
testsuite/driver/testglobals.py
=====================================
@@ -189,6 +189,13 @@ class TestConfig:
         # I have no idea what this does
         self.package_conf_cache_file = None # type: Optional[Path]
 
+        self.ghc_compiler_always_flags = [] # type: List[str]
+        self.ghc_with_native_codegen = False
+        self.ghc_dynamic_by_default = False
+        self.ghc_with_dynamic_rts = False
+        self.ghc_with_threaded_rts = False
+        self.ghc_with_smp = False
+        self.ghc_with_llvm = False
 
 global config
 config = TestConfig()


=====================================
testsuite/driver/testlib.py
=====================================
@@ -502,6 +502,9 @@ def doing_ghci() -> bool:
 def ghc_dynamic() -> bool:
     return config.ghc_dynamic
 
+def ghc_with_threaded_rts() -> bool:
+    return config.ghc_with_threaded_rts
+
 def fast() -> bool:
     return config.speed == 2
 


=====================================
testsuite/config/testsuite_config.py → testsuite/driver/testsuite_config.py
=====================================
@@ -1,10 +1,12 @@
 # vim: set filetype=python:
 
 import re
+from testglobals import TestConfig
+from testutil import getStdout
 
 class TestsuiteConfig:
     @staticmethod
-    def init_config(config: TestConfig)
+    def init_config(config: TestConfig) -> None:
         raise NotImplemented
 
     @staticmethod
@@ -18,8 +20,6 @@ class GHCTestsuiteConfig(TestsuiteConfig):
 
     @staticmethod
     def init_config(config: TestConfig):
-        config.compiler_always_flags = ghc_compiler_always_flags.split()
-
         # By default, the 'normal' and 'hpc' ways are enabled. In addition, certain
         # ways are enabled automatically if this GHC supports them. Ways that fall in
         # this group are 'optasm', 'optllvm', 'profasm', 'threaded1', 'threaded2',
@@ -45,7 +45,7 @@ class GHCTestsuiteConfig(TestsuiteConfig):
                                     'compacting_gc',
                                     ]
 
-        if ghc_with_native_codegen:
+        if config.ghc_with_native_codegen:
             config.compile_ways.append('optasm')
             config.run_ways.append('optasm')
 
@@ -56,27 +56,27 @@ class GHCTestsuiteConfig(TestsuiteConfig):
         if config.have_interp:
             config.run_ways.append('ghci')
 
-        if ghc_with_threaded_rts:
+        if config.ghc_with_threaded_rts:
             config.run_ways.append('threaded1')
-            if ghc_with_smp:
+            if config.ghc_with_smp:
                 config.have_smp = True
                 config.run_ways.append('threaded2')
                 if config.speed == 0:
                     config.run_ways.append('nonmoving_thr')
 
-        if ghc_with_dynamic_rts:
+        if config.ghc_with_dynamic_rts:
             config.have_shared_libs = True
 
         if config.ghc_dynamic_by_default and config.have_vanilla == 1:
             config.run_ways.append('static')
         else:
-            if ghc_with_dynamic_rts:
+            if config.ghc_with_dynamic_rts:
                 config.run_ways.append('dyn')
 
         if (config.have_profiling and ghc_with_threaded_rts):
             config.run_ways.append('profthreaded')
 
-        if (ghc_with_llvm and not config.unregisterised):
+        if (config.ghc_with_llvm and not config.unregisterised):
             config.compile_ways.append('optllvm')
             config.run_ways.append('optllvm')
 
@@ -166,26 +166,31 @@ class GHCTestsuiteConfig(TestsuiteConfig):
 
         # Useful classes of ways that can be used with only_ways(), omit_ways() and
         # expect_broken_for().
-
-        prof_ways     = [x[0] for x in config.way_flags.items()
-                            if '-prof' in x[1]]
-
-        threaded_ways = [x[0] for x in config.way_flags.items()
-                            if '-threaded' in x[1] or 'ghci' == x[0]]
-
-        # Ways which run with multiple capabilities
-        concurrent_ways = [name for name, flags in config.way_flags.items()
-                                if '-threaded' in flags or 'ghci' == name
-                                if '-N2' in config.way_rts_flags.get(name, [])]
-
-        opt_ways      = [x[0] for x in config.way_flags.items()
-                            if '-O' in x[1]]
-
-        llvm_ways     = [x[0] for x in config.way_flags.items()
-                            if '-fflvm' in x[1]]
+        # 
+        # These are injected into the global scope which the tests are
+        # evaluated within.
+        globals = {
+            'prof_ways'       : [x[0] for x in config.way_flags.items()
+                                      if '-prof' in x[1]],
+
+            'threaded_ways'   : [x[0] for x in config.way_flags.items()
+                                      if '-threaded' in x[1] or 'ghci' == x[0]],
+
+            # Ways which run with multiple capabilities
+            'concurrent_ways' : [name for name, flags in config.way_flags.items()
+                                      if '-threaded' in flags or 'ghci' == name
+                                      if '-N2' in config.way_rts_flags.get(name, [])],
+
+            'opt_ways'        : [x[0] for x in config.way_flags.items()
+                                      if '-O' in x[1]],
+
+            'llvm_ways'       : [x[0] for x in config.way_flags.items()
+                                      if '-fflvm' in x[1]],
+        }
+        return globals
 
     @staticmethod
-    def get_compiler_info():
+    def get_compiler_info(config):
         s = getStdout([config.compiler, '--info'])
         s = re.sub('[\r\n]', '', s)
         compilerInfoDict = dict(eval(s))


=====================================
testsuite/mk/test.mk
=====================================
@@ -79,18 +79,18 @@ else
 dllext = .so
 endif
 
-RUNTEST_OPTS += -e "ghc_compiler_always_flags='$(TEST_HC_OPTS)'"
+RUNTEST_OPTS += --extra-hc-flag='$(TEST_HC_OPTS)'
 
 ifeq "$(GhcDebugged)" "YES"
-RUNTEST_OPTS += -e "config.compiler_debugged=True"
+RUNTEST_OPTS += --config "compiler_debugged=True"
 else
-RUNTEST_OPTS += -e "config.compiler_debugged=False"
+RUNTEST_OPTS += --config "compiler_debugged=False"
 endif
 
 ifeq "$(GhcWithNativeCodeGen)" "YES"
-RUNTEST_OPTS += -e ghc_with_native_codegen=True
+RUNTEST_OPTS += --config "ghc_with_native_codegen=True"
 else
-RUNTEST_OPTS += -e ghc_with_native_codegen=False
+RUNTEST_OPTS += --config "ghc_with_native_codegen=False"
 endif
 
 GHC_PRIM_LIBDIR := $(subst library-dirs: ,,$(shell "$(GHC_PKG)" field ghc-prim library-dirs --simple-output))
@@ -105,21 +105,21 @@ HAVE_READELF := $(shell if readelf --version > /dev/null 2> /dev/null; then echo
 BIGNUM_GMP := $(shell "$(GHC_PKG)" field ghc-bignum exposed-modules | grep GMP)
 
 ifeq "$(HAVE_VANILLA)" "YES"
-RUNTEST_OPTS += -e config.have_vanilla=True
+RUNTEST_OPTS += --config have_vanilla=True
 else
-RUNTEST_OPTS += -e config.have_vanilla=False
+RUNTEST_OPTS += --config have_vanilla=False
 endif
 
 ifeq "$(HAVE_DYNAMIC)" "YES"
-RUNTEST_OPTS += -e config.have_dynamic=True
+RUNTEST_OPTS += --config have_dynamic=True
 else
-RUNTEST_OPTS += -e config.have_dynamic=False
+RUNTEST_OPTS += --config have_dynamic=False
 endif
 
 ifeq "$(HAVE_PROFILING)" "YES"
-RUNTEST_OPTS += -e config.have_profiling=True
+RUNTEST_OPTS += --config have_profiling=True
 else
-RUNTEST_OPTS += -e config.have_profiling=False
+RUNTEST_OPTS += --config have_profiling=False
 endif
 
 ifeq "$(filter thr, $(GhcRTSWays))" "thr"
@@ -135,50 +135,50 @@ RUNTEST_OPTS += -e ghc_with_dynamic_rts=False
 endif
 
 ifeq "$(GhcWithInterpreter)" "NO"
-RUNTEST_OPTS += -e config.have_interp=False
+RUNTEST_OPTS += --config have_interp=False
 else ifeq "$(GhcStage)" "1"
-RUNTEST_OPTS += -e config.have_interp=False
+RUNTEST_OPTS += --config have_interp=False
 else
-RUNTEST_OPTS += -e config.have_interp=True
+RUNTEST_OPTS += --config have_interp=True
 endif
 
 ifeq "$(GhcUnregisterised)" "YES"
-RUNTEST_OPTS += -e config.unregisterised=True
+RUNTEST_OPTS += --config unregisterised=True
 else
-RUNTEST_OPTS += -e config.unregisterised=False
+RUNTEST_OPTS += --config unregisterised=False
 endif
 
 ifeq "$(HAVE_GDB)" "YES"
-RUNTEST_OPTS += -e config.have_gdb=True
+RUNTEST_OPTS += --config have_gdb=True
 else
-RUNTEST_OPTS += -e config.have_gdb=False
+RUNTEST_OPTS += --config have_gdb=False
 endif
 
 ifeq "$(HAVE_READELF)" "YES"
-RUNTEST_OPTS += -e config.have_readelf=True
+RUNTEST_OPTS += --config have_readelf=True
 else
-RUNTEST_OPTS += -e config.have_readelf=False
+RUNTEST_OPTS += --config have_readelf=False
 endif
 
 ifeq "$(BIGNUM_GMP)" ""
-RUNTEST_OPTS += -e config.have_fast_bignum=False
+RUNTEST_OPTS += --config have_fast_bignum=False
 else
-RUNTEST_OPTS += -e config.have_fast_bignum=True
+RUNTEST_OPTS += --config have_fast_bignum=True
 endif
 
 ifeq "$(GhcDynamicByDefault)" "YES"
-RUNTEST_OPTS += -e config.ghc_dynamic_by_default=True
+RUNTEST_OPTS += --config ghc_dynamic_by_default=True
 CABAL_MINIMAL_BUILD = --enable-shared --disable-library-vanilla
 else
-RUNTEST_OPTS += -e config.ghc_dynamic_by_default=False
+RUNTEST_OPTS += --config ghc_dynamic_by_default=False
 CABAL_MINIMAL_BUILD = --enable-library-vanilla --disable-shared
 endif
 
 ifeq "$(GhcDynamic)" "YES"
-RUNTEST_OPTS += -e config.ghc_dynamic=True
+RUNTEST_OPTS += --config ghc_dynamic=True
 CABAL_PLUGIN_BUILD = --enable-shared --disable-library-vanilla
 else
-RUNTEST_OPTS += -e config.ghc_dynamic=False
+RUNTEST_OPTS += --config ghc_dynamic=False
 CABAL_PLUGIN_BUILD = --enable-library-vanilla --disable-shared
 endif
 
@@ -213,9 +213,9 @@ RUNTEST_OPTS += -e darwin=False
 endif
 
 ifeq "$(IN_TREE_COMPILER)" "YES"
-RUNTEST_OPTS += -e config.in_tree_compiler=True
+RUNTEST_OPTS += --config in_tree_compiler=True
 else
-RUNTEST_OPTS += -e config.in_tree_compiler=False
+RUNTEST_OPTS += --config in_tree_compiler=False
 endif
 
 ifneq "$(THREADS)" ""
@@ -243,20 +243,20 @@ RUNTEST_OPTS += --test-env="$(TEST_ENV)"
 endif
 
 ifeq "$(CLEANUP)" "0"
-RUNTEST_OPTS += -e config.cleanup=False
+RUNTEST_OPTS += --config cleanup=False
 else ifeq "$(CLEANUP)" "NO"
-RUNTEST_OPTS += -e config.cleanup=False
+RUNTEST_OPTS += --config cleanup=False
 else
-RUNTEST_OPTS += -e config.cleanup=True
+RUNTEST_OPTS += --config cleanup=True
 endif
 
 ifeq "$(LOCAL)" "0"
 # See Note [Running tests in /tmp].
-RUNTEST_OPTS += -e config.local=False
+RUNTEST_OPTS += --config local=False
 else ifeq "$(LOCAL)" "NO"
-RUNTEST_OPTS += -e config.local=False
+RUNTEST_OPTS += --config local=False
 else
-RUNTEST_OPTS += -e config.local=True
+RUNTEST_OPTS += --config local=True
 endif
 
 RUNTEST_OPTS +=  \
@@ -315,30 +315,30 @@ RUNTEST_OPTS +=  \
 	$(EXTRA_RUNTEST_OPTS)
 
 ifeq "$(list_broken)" "YES"
-set_list_broken = -e config.list_broken=True
+set_list_broken = --config list_broken=True
 else
 set_list_broken =
 endif
 
 # See Note [validate and testsuite speed] in toplevel Makefile.
 ifneq "$(SPEED)" ""
-setspeed = -e config.speed="$(SPEED)"
+setspeed = --config speed="$(SPEED)"
 else ifeq "$(fast)" "YES"
 # Backward compatibility. Maybe some people are running 'make accept fast=YES'?
-setspeed = -e config.speed=2
+setspeed = --config speed=2
 else
 setspeed =
 endif
 
 ifeq "$(accept)" "YES"
-setaccept = -e config.accept=True
+setaccept = --config accept=True
 
 ifeq "$(PLATFORM)" "YES"
-setaccept += -e config.accept_platform=True
+setaccept += --config accept_platform=True
 endif
 
 ifeq "$(OS)" "YES"
-setaccept += -e config.accept_os=True
+setaccept += --config accept_os=True
 endif
 
 else


=====================================
testsuite/tests/concurrent/prog002/all.T
=====================================
@@ -1,7 +1,7 @@
 # Test for bug #713, results in crashes in GHC prior to 20060315 with +RTS -N2
 
 # Add 'threaded2_hT' so that we have at least one test for bug #5127
-if ghc_with_threaded_rts and ghc_with_smp:
+if ghc_with_threaded_rts():
    ways = ['threaded2_hT']
 else:
    ways = []



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/33f843d7e9466beebac1913b033f0e71f39491e3

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/33f843d7e9466beebac1913b033f0e71f39491e3
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200705/e2a57f9d/attachment-0001.html>


More information about the ghc-commits mailing list