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
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:
| ... | ... | @@ -11,3 +11,20 @@ TLinkable_Prep: |
| 11 | 11 | TLinkable2_Prep:
|
| 12 | 12 | ./genSplices TLinkable2
|
| 13 | 13 | '$(TEST_HC)' $(TEST_HC_OPTS) $(ghcThWayFlags) --make -fprefer-byte-code -fwrite-byte-code -v0 TLinkable2.hs
|
| 14 | + |
|
| 15 | +.PHONY: linkable_bytecodelib_Prep linkable_bytecodelib
|
|
| 16 | +PKGCONF01=bytecode.package.conf
|
|
| 17 | +LOCAL_GHC_PKG01='$(GHC_PKG)' --no-user-package-db -f $(PKGCONF01)
|
|
| 18 | +MAIN_MOD=BytecodeUsage
|
|
| 19 | +linkable_bytecodelib_Prep:
|
|
| 20 | + $(LOCAL_GHC_PKG01) init $(PKGCONF01)
|
|
| 21 | + mkdir outdir
|
|
| 22 | + cd outdir && ../genSplices2 $(MAIN_MOD)
|
|
| 23 | + mv outdir/$(MAIN_MOD).hs $(MAIN_MOD).hs
|
|
| 24 | + cd outdir && $(TEST_HC) -bytecodelib -hisuf=$(ghciWayExt) $(ghciWayFlags) \
|
|
| 25 | + -o testpkg-1.2.3.4-XXX.bytecodelib -fbyte-code -fwrite-interface -fwrite-byte-code -this-unit-id=testpkg-1.2.3.4-XXX \
|
|
| 26 | + *.hs
|
|
| 27 | + $(LOCAL_GHC_PKG01) register --force outdir/bytecode.pkg
|
|
| 28 | + |
|
| 29 | +linkable_bytecodelib:
|
|
| 30 | + $(TEST_HC) $(TEST_HC_OPTS) $(ghcThWayFlags) --make -fprefer-byte-code $(MAIN_MOD) -package testpkg -package-db $(PKGCONF01) +RTS -l -hT -i0.001 -RTS |
| ... | ... | @@ -2,6 +2,9 @@ |
| 2 | 2 | # Bytecode libraries
|
| 3 | 3 | # Depend on that bytecode, look at the bytecode library tests to make sure this ends up in the EPS
|
| 4 | 4 | |
| 5 | +def normaliseDynlibNames(str):
|
|
| 6 | + return re.sub(r'-ghc[0-9.]+\.', '-ghc<VERSION>.', str)
|
|
| 7 | + |
|
| 5 | 8 | test('TLinkable',
|
| 6 | 9 | [ collect_compiler_stats('bytes allocated',2),
|
| 7 | 10 | pre_cmd('$MAKE -s --no-print-directory TLinkable_Prep'),
|
| ... | ... | @@ -19,3 +22,12 @@ test('TLinkable2', |
| 19 | 22 | ],
|
| 20 | 23 | compile,
|
| 21 | 24 | ['-fprefer-byte-code -fforce-recomp ' + config.ghc_th_way_flags])
|
| 25 | + |
|
| 26 | +test('linkable_bytecodelib',
|
|
| 27 | + [ extra_files(["genSplices2"])
|
|
| 28 | + , normalise_errmsg_fun(normaliseDynlibNames)
|
|
| 29 | + , pre_cmd('$MAKE -s --no-print-directory linkable_bytecodelib_Prep')
|
|
| 30 | + , copy_files
|
|
| 31 | + , req_bco ],
|
|
| 32 | + makefile_test,
|
|
| 33 | + []) |
| 1 | +#!/bin/bash
|
|
| 2 | + |
|
| 3 | +MODNAME=${1}
|
|
| 4 | +NMOD=${2:-20} # Default 20 modules
|
|
| 5 | +NDEF=${3:-50} # Default 50 functions per module
|
|
| 6 | + |
|
| 7 | +# Generate the modules
|
|
| 8 | +for ((i=1; i<=NMOD; i++)); do
|
|
| 9 | + module_name="Module$(printf "%03d" $i)"
|
|
| 10 | + file_path="${module_name}.hs"
|
|
| 11 | + |
|
| 12 | + cat > "$file_path" << EOF
|
|
| 13 | +module ${module_name} where
|
|
| 14 | + |
|
| 15 | +EOF
|
|
| 16 | + |
|
| 17 | + for ((j=1; j<=NDEF; j++)); do
|
|
| 18 | + func_name="func$(printf "%03d" $j)"
|
|
| 19 | + cat >> "$file_path" << EOF
|
|
| 20 | +{-# NOINLINE ${func_name} #-}
|
|
| 21 | +${func_name} :: Int -> Int
|
|
| 22 | +${func_name} x = x + ${j}
|
|
| 23 | + |
|
| 24 | +EOF
|
|
| 25 | + done
|
|
| 26 | +done
|
|
| 27 | + |
|
| 28 | +# Generate imports section
|
|
| 29 | +imports=""
|
|
| 30 | +for ((i=1; i<=NMOD; i++)); do
|
|
| 31 | + imports="${imports}import splice Module$(printf "%03d" $i)
|
|
| 32 | +"
|
|
| 33 | +done
|
|
| 34 | + |
|
| 35 | +# Generate the hard-coded TH expression
|
|
| 36 | +# Build: Module001.func001 1 + Module001.func002 2 + ... + Module{NMOD}.func{NDEF} {NMOD*NDEF}
|
|
| 37 | +expressions=""
|
|
| 38 | +all_mods=""
|
|
| 39 | +for ((i=1; i<=NMOD; i++)); do
|
|
| 40 | + mod_name="Module$(printf "%03d" $i)"
|
|
| 41 | + all_mods="${all_mods} ${mod_name}"
|
|
| 42 | + single_expression=""
|
|
| 43 | + count=1
|
|
| 44 | + for ((j=1; j<=NDEF; j++)); do
|
|
| 45 | + func_name="func$(printf "%03d" $j)"
|
|
| 46 | + if [ $count -gt 1 ]; then
|
|
| 47 | + single_expression="${single_expression} + "
|
|
| 48 | + fi
|
|
| 49 | + single_expression="${single_expression}${mod_name}.${func_name} ${count}"
|
|
| 50 | + ((count++))
|
|
| 51 | + done
|
|
| 52 | + |
|
| 53 | + expressions="comp$(printf "%03d" $i) = \$(lift \$ ${single_expression})\\n\\n${expressions}"
|
|
| 54 | +done
|
|
| 55 | + |
|
| 56 | +# Generate the TH splice file
|
|
| 57 | +cat > bytecode.pkg << EOF
|
|
| 58 | +name: testpkg
|
|
| 59 | +version: 1.2.3.4
|
|
| 60 | +id: testpkg-1.2.3.4-XXX
|
|
| 61 | +key: testpkg-1.2.3.4-XXX
|
|
| 62 | +license: BSD3
|
|
| 63 | +copyright: (c) The Univsersity of Glasgow 2004
|
|
| 64 | +maintainer: glasgow-haskell-users@haskell.org
|
|
| 65 | +stability: stable
|
|
| 66 | +homepage: http://www.haskell.org/ghc
|
|
| 67 | +package-url: http://www.haskell.org/ghc
|
|
| 68 | +description: A Test Package
|
|
| 69 | +category: none
|
|
| 70 | +author: simonmar@microsoft.com
|
|
| 71 | +exposed: True
|
|
| 72 | +exposed-modules: ${all_mods}
|
|
| 73 | +import-dirs: \${pkgroot}/outdir
|
|
| 74 | +library-dirs: \${pkgroot}/outdir
|
|
| 75 | +include-dirs:
|
|
| 76 | +bytecode-library-dirs: \${pkgroot}/outdir
|
|
| 77 | +hs-libraries: testpkg-1.2.3.4-XXX
|
|
| 78 | +EOF
|
|
| 79 | + |
|
| 80 | +# Generate the TH splice file
|
|
| 81 | +cat > "${MODNAME}".hs << EOF
|
|
| 82 | +{-# LANGUAGE TemplateHaskell #-}
|
|
| 83 | +{-# LANGUAGE NumericUnderscores #-}
|
|
| 84 | +{-# LANGUAGE ExplicitLevelImports #-}
|
|
| 85 | + |
|
| 86 | +module ${MODNAME} where
|
|
| 87 | + |
|
| 88 | +import splice Language.Haskell.TH.Syntax (Lift(..))
|
|
| 89 | +import Control.Concurrent (threadDelay)
|
|
| 90 | +import splice Prelude (Num(..), ($), Monad(..), pure)
|
|
| 91 | + |
|
| 92 | +-- Import all generated modules
|
|
| 93 | +${imports}
|
|
| 94 | + |
|
| 95 | +-- Use from each module
|
|
| 96 | +$(echo -e -n "${expressions}")
|
|
| 97 | + |
|
| 98 | +EOF |
| 1 | +[1 of 1] Compiling BytecodeUsage ( BytecodeUsage.hs, BytecodeUsage.o ) |