Hannes Siebenhandl pushed to branch wip/fendor/linkable-usage at Glasgow Haskell Compiler / GHC Commits: 47420bcb by fendor at 2026-02-17T15:03:49+01:00 Add linkable regression test - - - - - 5 changed files: - + testsuite/ghc-config/ghc-config - testsuite/tests/bytecode/TLinkable/Makefile - testsuite/tests/bytecode/TLinkable/all.T - + testsuite/tests/bytecode/TLinkable/genSplices2 - + testsuite/tests/bytecode/TLinkable/linkable_bytecodelib.stdout Changes: ===================================== testsuite/ghc-config/ghc-config ===================================== Binary files /dev/null and b/testsuite/ghc-config/ghc-config differ ===================================== testsuite/tests/bytecode/TLinkable/Makefile ===================================== @@ -11,3 +11,20 @@ TLinkable_Prep: TLinkable2_Prep: ./genSplices TLinkable2 '$(TEST_HC)' $(TEST_HC_OPTS) $(ghcThWayFlags) --make -fprefer-byte-code -fwrite-byte-code -v0 TLinkable2.hs + +.PHONY: linkable_bytecodelib_Prep linkable_bytecodelib +PKGCONF01=bytecode.package.conf +LOCAL_GHC_PKG01='$(GHC_PKG)' --no-user-package-db -f $(PKGCONF01) +MAIN_MOD=BytecodeUsage +linkable_bytecodelib_Prep: + $(LOCAL_GHC_PKG01) init $(PKGCONF01) + mkdir outdir + cd outdir && ../genSplices2 $(MAIN_MOD) + mv outdir/$(MAIN_MOD).hs $(MAIN_MOD).hs + cd outdir && $(TEST_HC) -bytecodelib -hisuf=$(ghciWayExt) $(ghciWayFlags) \ + -o testpkg-1.2.3.4-XXX.bytecodelib -fbyte-code -fwrite-interface -fwrite-byte-code -this-unit-id=testpkg-1.2.3.4-XXX \ + *.hs + $(LOCAL_GHC_PKG01) register --force outdir/bytecode.pkg + +linkable_bytecodelib: + $(TEST_HC) $(TEST_HC_OPTS) $(ghcThWayFlags) --make -fprefer-byte-code $(MAIN_MOD) -package testpkg -package-db $(PKGCONF01) +RTS -l -hT -i0.001 -RTS ===================================== testsuite/tests/bytecode/TLinkable/all.T ===================================== @@ -2,6 +2,9 @@ # Bytecode libraries # Depend on that bytecode, look at the bytecode library tests to make sure this ends up in the EPS +def normaliseDynlibNames(str): + return re.sub(r'-ghc[0-9.]+\.', '-ghc<VERSION>.', str) + test('TLinkable', [ collect_compiler_stats('bytes allocated',2), pre_cmd('$MAKE -s --no-print-directory TLinkable_Prep'), @@ -19,3 +22,12 @@ test('TLinkable2', ], compile, ['-fprefer-byte-code -fforce-recomp ' + config.ghc_th_way_flags]) + +test('linkable_bytecodelib', + [ extra_files(["genSplices2"]) + , normalise_errmsg_fun(normaliseDynlibNames) + , pre_cmd('$MAKE -s --no-print-directory linkable_bytecodelib_Prep') + , copy_files + , req_bco ], + makefile_test, + []) ===================================== testsuite/tests/bytecode/TLinkable/genSplices2 ===================================== @@ -0,0 +1,98 @@ +#!/bin/bash + +MODNAME=${1} +NMOD=${2:-20} # Default 20 modules +NDEF=${3:-50} # Default 50 functions per module + +# Generate the modules +for ((i=1; i<=NMOD; i++)); do + module_name="Module$(printf "%03d" $i)" + file_path="${module_name}.hs" + + cat > "$file_path" << EOF +module ${module_name} where + +EOF + + for ((j=1; j<=NDEF; j++)); do + func_name="func$(printf "%03d" $j)" + cat >> "$file_path" << EOF +{-# NOINLINE ${func_name} #-} +${func_name} :: Int -> Int +${func_name} x = x + ${j} + +EOF + done +done + +# Generate imports section +imports="" +for ((i=1; i<=NMOD; i++)); do + imports="${imports}import splice Module$(printf "%03d" $i) +" +done + +# Generate the hard-coded TH expression +# Build: Module001.func001 1 + Module001.func002 2 + ... + Module{NMOD}.func{NDEF} {NMOD*NDEF} +expressions="" +all_mods="" +for ((i=1; i<=NMOD; i++)); do + mod_name="Module$(printf "%03d" $i)" + all_mods="${all_mods} ${mod_name}" + single_expression="" + count=1 + for ((j=1; j<=NDEF; j++)); do + func_name="func$(printf "%03d" $j)" + if [ $count -gt 1 ]; then + single_expression="${single_expression} + " + fi + single_expression="${single_expression}${mod_name}.${func_name} ${count}" + ((count++)) + done + + expressions="comp$(printf "%03d" $i) = \$(lift \$ ${single_expression})\\n\\n${expressions}" +done + +# Generate the TH splice file +cat > bytecode.pkg << EOF +name: testpkg +version: 1.2.3.4 +id: testpkg-1.2.3.4-XXX +key: testpkg-1.2.3.4-XXX +license: BSD3 +copyright: (c) The Univsersity of Glasgow 2004 +maintainer: glasgow-haskell-users@haskell.org +stability: stable +homepage: http://www.haskell.org/ghc +package-url: http://www.haskell.org/ghc +description: A Test Package +category: none +author: simonmar@microsoft.com +exposed: True +exposed-modules: ${all_mods} +import-dirs: \${pkgroot}/outdir +library-dirs: \${pkgroot}/outdir +include-dirs: +bytecode-library-dirs: \${pkgroot}/outdir +hs-libraries: testpkg-1.2.3.4-XXX +EOF + +# Generate the TH splice file +cat > "${MODNAME}".hs << EOF +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE NumericUnderscores #-} +{-# LANGUAGE ExplicitLevelImports #-} + +module ${MODNAME} where + +import splice Language.Haskell.TH.Syntax (Lift(..)) +import Control.Concurrent (threadDelay) +import splice Prelude (Num(..), ($), Monad(..), pure) + +-- Import all generated modules +${imports} + +-- Use from each module +$(echo -e -n "${expressions}") + +EOF ===================================== testsuite/tests/bytecode/TLinkable/linkable_bytecodelib.stdout ===================================== @@ -0,0 +1 @@ +[1 of 1] Compiling BytecodeUsage ( BytecodeUsage.hs, BytecodeUsage.o ) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/47420bcbe490a7a36bbcb04fc329ab47... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/47420bcbe490a7a36bbcb04fc329ab47... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Hannes Siebenhandl (@fendor)