Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
-
7250fc0c
by Matthew Pickering at 2025-04-22T16:24:04-04:00
-
d2dc89b4
by Matthew Pickering at 2025-04-22T16:24:04-04:00
2 changed files:
Changes:
| ... | ... | @@ -947,6 +947,71 @@ enableCodeGenWhen logger tmpfs staticLife dynLife unit_env mod_graph = do |
| 947 | 947 | hostFullWays
|
| 948 | 948 | in dflags_c
|
| 949 | 949 | |
| 950 | +{- Note [-fno-code mode]
|
|
| 951 | +~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 952 | +GHC offers the flag -fno-code for the purpose of parsing and typechecking a
|
|
| 953 | +program without generating object files. This is intended to be used by tooling
|
|
| 954 | +and IDEs to provide quick feedback on any parser or type errors as cheaply as
|
|
| 955 | +possible.
|
|
| 956 | + |
|
| 957 | +When GHC is invoked with -fno-code, no object files or linked output will be
|
|
| 958 | +generated. As many errors and warnings as possible will be generated, as if
|
|
| 959 | +-fno-code had not been passed. The session DynFlags will have
|
|
| 960 | +backend == NoBackend.
|
|
| 961 | + |
|
| 962 | +-fwrite-interface
|
|
| 963 | +~~~~~~~~~~~~~~~~
|
|
| 964 | +Whether interface files are generated in -fno-code mode is controlled by the
|
|
| 965 | +-fwrite-interface flag. The -fwrite-interface flag is a no-op if -fno-code is
|
|
| 966 | +not also passed. Recompilation avoidance requires interface files, so passing
|
|
| 967 | +-fno-code without -fwrite-interface should be avoided. If -fno-code were
|
|
| 968 | +re-implemented today, there would be no need for -fwrite-interface as it
|
|
| 969 | +would considered always on; this behaviour is as it is for backwards compatibility.
|
|
| 970 | + |
|
| 971 | +================================================================
|
|
| 972 | +IN SUMMARY: ALWAYS PASS -fno-code AND -fwrite-interface TOGETHER
|
|
| 973 | +================================================================
|
|
| 974 | + |
|
| 975 | +Template Haskell
|
|
| 976 | +~~~~~~~~~~~~~~~~
|
|
| 977 | +A module using Template Haskell may invoke an imported function from inside a
|
|
| 978 | +splice. This will cause the type-checker to attempt to execute that code, which
|
|
| 979 | +would fail if no object files had been generated. See #8025. To rectify this,
|
|
| 980 | +during the downsweep we patch the DynFlags in the ModSummary of any home module
|
|
| 981 | +that is imported by a module that uses Template Haskell to generate object
|
|
| 982 | +code.
|
|
| 983 | + |
|
| 984 | +The flavour of the generated code depends on whether `-fprefer-byte-code` is enabled
|
|
| 985 | +or not in the module which needs the code generation. If the module requires byte-code then
|
|
| 986 | +dependencies will generate byte-code, otherwise they will generate object files.
|
|
| 987 | +In the case where some modules require byte-code and some object files, both are
|
|
| 988 | +generated by enabling `-fbyte-code-and-object-code`, the test "fat015" tests these
|
|
| 989 | +configurations.
|
|
| 990 | + |
|
| 991 | +The object files (and interface files if -fwrite-interface is disabled) produced
|
|
| 992 | +for Template Haskell are written to temporary files.
|
|
| 993 | + |
|
| 994 | +Note that since Template Haskell can run arbitrary IO actions, -fno-code mode
|
|
| 995 | +is no more secure than running without it.
|
|
| 996 | + |
|
| 997 | +Potential TODOS:
|
|
| 998 | +~~~~~
|
|
| 999 | +* Remove -fwrite-interface and have interface files always written in -fno-code
|
|
| 1000 | + mode
|
|
| 1001 | +* Both .o and .dyn_o files are generated for template haskell, but we only need
|
|
| 1002 | + .dyn_o. Fix it.
|
|
| 1003 | +* In make mode, a message like
|
|
| 1004 | + Compiling A (A.hs, /tmp/ghc_123.o)
|
|
| 1005 | + is shown if downsweep enabled object code generation for A. Perhaps we should
|
|
| 1006 | + show "nothing" or "temporary object file" instead. Note that one
|
|
| 1007 | + can currently use -keep-tmp-files and inspect the generated file with the
|
|
| 1008 | + current behaviour.
|
|
| 1009 | +* Offer a -no-codedir command line option, and write what were temporary
|
|
| 1010 | + object files there. This would speed up recompilation.
|
|
| 1011 | +* Use existing object files (if they are up to date) instead of always
|
|
| 1012 | + generating temporary ones.
|
|
| 1013 | +-}
|
|
| 1014 | + |
|
| 950 | 1015 | -- | Populate the Downsweep cache with the root modules.
|
| 951 | 1016 | mkRootMap
|
| 952 | 1017 | :: [ModuleNodeInfo]
|
| ... | ... | @@ -1246,70 +1246,6 @@ addSptEntries hsc_env mlinkable = |
| 1246 | 1246 | , spt <- bc_spt_entries bco
|
| 1247 | 1247 | ]
|
| 1248 | 1248 | |
| 1249 | -{- Note [-fno-code mode]
|
|
| 1250 | -~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 1251 | -GHC offers the flag -fno-code for the purpose of parsing and typechecking a
|
|
| 1252 | -program without generating object files. This is intended to be used by tooling
|
|
| 1253 | -and IDEs to provide quick feedback on any parser or type errors as cheaply as
|
|
| 1254 | -possible.
|
|
| 1255 | - |
|
| 1256 | -When GHC is invoked with -fno-code no object files or linked output will be
|
|
| 1257 | -generated. As many errors and warnings as possible will be generated, as if
|
|
| 1258 | --fno-code had not been passed. The session DynFlags will have
|
|
| 1259 | -backend == NoBackend.
|
|
| 1260 | - |
|
| 1261 | --fwrite-interface
|
|
| 1262 | -~~~~~~~~~~~~~~~~
|
|
| 1263 | -Whether interface files are generated in -fno-code mode is controlled by the
|
|
| 1264 | --fwrite-interface flag. The -fwrite-interface flag is a no-op if -fno-code is
|
|
| 1265 | -not also passed. Recompilation avoidance requires interface files, so passing
|
|
| 1266 | --fno-code without -fwrite-interface should be avoided. If -fno-code were
|
|
| 1267 | -re-implemented today, -fwrite-interface would be discarded and it would be
|
|
| 1268 | -considered always on; this behaviour is as it is for backwards compatibility.
|
|
| 1269 | - |
|
| 1270 | -================================================================
|
|
| 1271 | -IN SUMMARY: ALWAYS PASS -fno-code AND -fwrite-interface TOGETHER
|
|
| 1272 | -================================================================
|
|
| 1273 | - |
|
| 1274 | -Template Haskell
|
|
| 1275 | -~~~~~~~~~~~~~~~~
|
|
| 1276 | -A module using template haskell may invoke an imported function from inside a
|
|
| 1277 | -splice. This will cause the type-checker to attempt to execute that code, which
|
|
| 1278 | -would fail if no object files had been generated. See #8025. To rectify this,
|
|
| 1279 | -during the downsweep we patch the DynFlags in the ModSummary of any home module
|
|
| 1280 | -that is imported by a module that uses template haskell, to generate object
|
|
| 1281 | -code.
|
|
| 1282 | - |
|
| 1283 | -The flavour of the generated code depends on whether `-fprefer-byte-code` is enabled
|
|
| 1284 | -or not in the module which needs the code generation. If the module requires byte-code then
|
|
| 1285 | -dependencies will generate byte-code, otherwise they will generate object files.
|
|
| 1286 | -In the case where some modules require byte-code and some object files, both are
|
|
| 1287 | -generated by enabling `-fbyte-code-and-object-code`, the test "fat015" tests these
|
|
| 1288 | -configurations.
|
|
| 1289 | - |
|
| 1290 | -The object files (and interface files if -fwrite-interface is disabled) produced
|
|
| 1291 | -for template haskell are written to temporary files.
|
|
| 1292 | - |
|
| 1293 | -Note that since template haskell can run arbitrary IO actions, -fno-code mode
|
|
| 1294 | -is no more secure than running without it.
|
|
| 1295 | - |
|
| 1296 | -Potential TODOS:
|
|
| 1297 | -~~~~~
|
|
| 1298 | -* Remove -fwrite-interface and have interface files always written in -fno-code
|
|
| 1299 | - mode
|
|
| 1300 | -* Both .o and .dyn_o files are generated for template haskell, but we only need
|
|
| 1301 | - .dyn_o. Fix it.
|
|
| 1302 | -* In make mode, a message like
|
|
| 1303 | - Compiling A (A.hs, /tmp/ghc_123.o)
|
|
| 1304 | - is shown if downsweep enabled object code generation for A. Perhaps we should
|
|
| 1305 | - show "nothing" or "temporary object file" instead. Note that one
|
|
| 1306 | - can currently use -keep-tmp-files and inspect the generated file with the
|
|
| 1307 | - current behaviour.
|
|
| 1308 | -* Offer a -no-codedir command line option, and write what were temporary
|
|
| 1309 | - object files there. This would speed up recompilation.
|
|
| 1310 | -* Use existing object files (if they are up to date) instead of always
|
|
| 1311 | - generating temporary ones.
|
|
| 1312 | --}
|
|
| 1313 | 1249 | |
| 1314 | 1250 | -- Note [When source is considered modified]
|
| 1315 | 1251 | -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|