-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strip dead branch code #164
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…dn't matter but it's tidier.
to @jump. (Glulx already did this.)
it off by setting it to 0).
DavidKinder
pushed a commit
that referenced
this pull request
Mar 20, 2022
Kroc
added a commit
to Kroc/Inform6
that referenced
this pull request
Apr 28, 2022
commit 75dae0b Author: David Kinder <david.kinder@david.kinder> Date: Tue Apr 5 20:40:28 2022 +0100 Update release notes for changes in DavidKinder#169 commit cea150b Merge: 9ec3355 d63d57a Author: David Kinder <440452+DavidKinder@users.noreply.github.com> Date: Tue Apr 5 18:56:39 2022 +0100 Merge pull request DavidKinder#169 from erkyrath/fold-short-and-or Improve dead-code stripping and warnings commit d63d57a Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Apr 3 22:46:07 2022 -0400 Fix blank line. commit 92d6b40 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Apr 3 22:45:49 2022 -0400 Fix blank line. commit 3d8287b Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Apr 3 21:37:08 2022 -0400 One more warning tweak. commit 9da8d5f Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Apr 3 16:32:01 2022 -0400 Omit unneeded logical-expression code (when short-circuited). commit e9d249a Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Apr 3 16:23:55 2022 -0400 Use forward labels. commit cf70258 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Apr 3 16:22:48 2022 -0400 Logical expression output is easier to read with a temp label variable. commit 3808186 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Apr 3 01:40:22 2022 -0400 Simplify test. commit e624455 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Apr 3 01:38:04 2022 -0400 Comment. commit 50ed360 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Apr 3 01:28:34 2022 -0400 Let's try this optimization. commit 9ec3355 Author: David Kinder <david.kinder@david.kinder> Date: Fri Apr 1 13:31:38 2022 +0100 Mention DavidKinder#167 in release notes commit 81ee575 Merge: fc3bd13 ffdce9c Author: David Kinder <440452+DavidKinder@users.noreply.github.com> Date: Fri Apr 1 13:24:27 2022 +0100 Merge pull request DavidKinder#167 from erkyrath/symbolic-abbrev Extended dynamic-string syntax commit ffdce9c Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Mar 29 19:53:53 2022 -0400 Tidy error message. commit fcd8d6e Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 27 13:50:56 2022 -0400 Improve MAX_DYNAMIC_STRINGS=0 error message. commit 83dc65a Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 27 13:47:15 2022 -0400 Simplify limit check. commit 9e67231 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 27 13:44:34 2022 -0400 Better error fallback case. commit 0200d35 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 27 13:36:22 2022 -0400 Generate abbrev 0 for error cases. commit 33301d3 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 27 12:41:04 2022 -0400 Remove debug lines. commit 8e06d74 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 27 12:40:00 2022 -0400 Remove the limit of MAX_DYNAMIC_STRINGS=100 for Glulx. It is now unlimited. commit c413044 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 27 12:32:16 2022 -0400 Glulx symbol abbrev. commit d60c5a7 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 27 12:20:39 2022 -0400 Just use atoi(). commit 3afc25c Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Mar 26 18:15:20 2022 -0400 Range check on dynamic string commit f5a6f98 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Mar 26 17:57:48 2022 -0400 First draft of symbol abbreviations. commit fc3bd13 Merge: e1d4897 6a7d151 Author: David Kinder <440452+DavidKinder@users.noreply.github.com> Date: Tue Mar 22 09:03:34 2022 +0000 Merge pull request DavidKinder#166 from erkyrath/clang-warning Avoid variable-not-used warning on throw_style commit 6a7d151 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Mar 21 23:16:18 2022 -0400 Avoid variable-not-used warning on throw_style. commit e1d4897 Author: David Kinder <david.kinder@david.kinder> Date: Sun Mar 20 15:06:09 2022 +0000 Mention DavidKinder#164 in release notes commit 0af8bcf Merge: e1c7929 1958380 Author: David Kinder <440452+DavidKinder@users.noreply.github.com> Date: Sun Mar 20 14:46:32 2022 +0000 Merge pull request DavidKinder#164 from erkyrath/strip-dead-branch Strip dead branch code commit 1958380 Merge: 46d3036 bb5bd85 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Mar 15 20:50:32 2022 -0400 Merge branch 'strip-dead-branch' into strip-dead-branch-onif commit bb5bd85 Merge: 67c4d7f e1c7929 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Mar 15 20:50:07 2022 -0400 Merge branch 'master' into strip-dead-branch commit 46d3036 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Mar 15 00:15:59 2022 -0400 Avoid one weird warning case in the strict checking code. commit 9c211cd Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Mar 15 00:06:29 2022 -0400 Tidier handling of the saved_unreach flag. commit 8a648b1 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Mar 14 23:28:41 2022 -0400 Forgot two bits. commit 1e5c5f7 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Mar 14 23:26:46 2022 -0400 Try applying change to Glulx. commit cf43043 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Mar 14 20:46:05 2022 -0400 Further comment adjustment. commit 5e9cafc Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Mar 14 20:41:32 2022 -0400 Comments. commit 592cedd Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Mar 14 20:32:52 2022 -0400 Comments. commit 8da7e12 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Mar 14 19:59:07 2022 -0400 One more tweak. commit 692ba09 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 13 22:24:34 2022 -0400 Skip one case. commit e9283cd Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 13 21:53:12 2022 -0400 Trying to fix the else clause. commit 370bc09 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 13 21:05:38 2022 -0400 Put the NOWARN check in a different place. commit 0fc1fcf Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Mar 13 17:26:28 2022 -0400 Try moving the NOWARN optimization elsewhere. commit e1c7929 Merge: a2c25ae 035a140 Author: David Kinder <440452+DavidKinder@users.noreply.github.com> Date: Thu Mar 10 13:07:03 2022 +0000 Merge pull request DavidKinder#161 from erkyrath/linker-overflow Check for overflow of the Link "..." directive commit 035a140 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Wed Mar 9 20:38:53 2022 -0500 Check for overflow of the Link "..." directive, and the buffers used by that. commit 67c4d7f Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Mar 8 18:56:49 2022 -0500 assemble_forward_label_no() returns a flag. commit a2c25ae Author: David Kinder <david.kinder@david.kinder> Date: Tue Mar 8 09:46:26 2022 +0000 Remove outdated email address, use project GitHub URL instead commit 747d404 Merge: 6902a07 8503cff Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Fri Mar 4 19:34:44 2022 -0500 Merge branch 'master' into strip-dead-branch commit 8503cff Author: David Kinder <david.kinder@david.kinder> Date: Fri Mar 4 14:41:26 2022 +0000 Mention DavidKinder#156 and DavidKinder#158 in release notes commit d955063 Merge: 2500f4c d3d0b04 Author: David Kinder <440452+DavidKinder@users.noreply.github.com> Date: Fri Mar 4 14:32:42 2022 +0000 Merge pull request DavidKinder#158 from erkyrath/percentage-map Display percentages better commit 2500f4c Merge: 4ef3880 c0fbc3a Author: David Kinder <440452+DavidKinder@users.noreply.github.com> Date: Fri Mar 4 14:32:27 2022 +0000 Merge pull request DavidKinder#156 from erkyrath/dictionary-sysconst Add #grammar_table, #dictionary_table to Z-code commit d3d0b04 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Thu Feb 24 20:21:43 2022 -0500 Update comment. commit 208f375 Merge: 0d219c4 1a05bc8 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Thu Feb 24 20:18:44 2022 -0500 Merge branch 'master' into percentage-map commit 6902a07 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Thu Feb 24 20:05:40 2022 -0500 Apply the STRIP_UNREACHABLE_LABELS setting. commit 016ed0e Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Thu Feb 24 19:59:52 2022 -0500 Add a $STRIP_UNREACHABLE_LABELS setting (default 1, but you can turn it off by setting it to 0). commit 4ef3880 Author: David Kinder <david.kinder@david.kinder> Date: Thu Feb 24 20:27:40 2022 +0000 The version number in README.md should be 6.36 as that is the most recent release commit c0fbc3a Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Feb 22 21:46:01 2022 -0500 Gotta include grammar table in debug output. commit ac281e3 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Feb 22 21:05:19 2022 -0500 Add #grammar_table, #dictionary_table to Z-code. commit 85347d6 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Feb 21 20:46:12 2022 -0500 Consistent trace output. commit 8cf3366 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Feb 21 20:20:23 2022 -0500 Glulx dead branch elimination. commit 10f8240 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Feb 21 19:18:56 2022 -0500 Eliminate no-op branches in Z-code. commit d00cb5d Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Feb 21 18:57:09 2022 -0500 Comments. commit e51fd9c Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 20 23:47:33 2022 -0500 One more comment. commit 282030d Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 20 23:37:04 2022 -0500 Big long comment about compilation strategy. commit 2cda29f Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 20 22:57:51 2022 -0500 More comment. commit 78f9381 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 20 22:56:14 2022 -0500 Clarify comment. commit dbc9cc6 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 20 22:49:59 2022 -0500 More comments. commit 8b2e1f0 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 20 22:43:53 2022 -0500 Comments about assemble_label_no(). commit 7679774 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 20 22:40:45 2022 -0500 Remove debug lines. commit bacf4b4 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 20 22:37:20 2022 -0500 Combine all flags back into the execution_never_reaches_here variable. commit d28b90f Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 20 18:33:20 2022 -0500 Don't ref a function if it's called from unreachable code. commit 7f335b9 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 20 14:29:33 2022 -0500 Debug line. commit 0778eea Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 20 14:16:10 2022 -0500 Take a stab at the string optimization. commit 0cf1b4b Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Feb 19 21:44:05 2022 -0500 And switch statements too. commit 6ece125 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Feb 19 10:20:27 2022 -0500 Forward labels on else clauses. This handles if/else where both branches return. commit 53c3e16 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Feb 19 01:13:57 2022 -0500 Forward labels for the "for (::)" case. commit 1ba0ee9 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Feb 19 01:05:39 2022 -0500 Forward labels for for loops. commit 9a69f11 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Feb 19 00:36:38 2022 -0500 Forward branches in do/until. commit b136a76 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Fri Feb 18 23:33:08 2022 -0500 Forward label skipping in "while". commit 49bdf3f Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Fri Feb 18 23:14:33 2022 -0500 Okay, put that back. commit 8094b4f Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Fri Feb 18 22:53:57 2022 -0500 Try a different approach. commit 60c85cb Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Fri Feb 18 18:23:01 2022 -0500 This is tidier. commit b3f9070 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Fri Feb 18 18:19:58 2022 -0500 C99 fix commit ce69a7c Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Fri Feb 18 18:19:21 2022 -0500 Correct flag nesting. commit f51ad18 Merge: fdbbe8d 64afbd0 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Fri Feb 18 18:10:04 2022 -0500 Merge branch 'label-refactor' into strip-dead-branch commit 64afbd0 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Fri Feb 18 18:06:20 2022 -0500 Move the bit of parse_statement that parses labels into its own function. commit fdbbe8d Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Fri Feb 18 00:11:08 2022 -0500 Comments. commit 800b503 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Wed Feb 16 23:59:41 2022 -0500 Only show the unreachable warning once (at a time). commit 3d0d59f Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Wed Feb 16 20:23:48 2022 -0500 Catch another unreachable jump case. commit 3b19848 Merge: 02ce5e9 1a05bc8 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Wed Feb 16 19:15:14 2022 -0500 Merge branch 'master' into strip-dead-branch commit 1a05bc8 Author: David Kinder <david.kinder@david.kinder> Date: Wed Feb 16 21:46:40 2022 +0000 Mention DavidKinder#154 in release notes commit 30669c5 Merge: 8e8f80a 411b057 Author: David Kinder <440452+DavidKinder@users.noreply.github.com> Date: Wed Feb 16 21:43:40 2022 +0000 Merge pull request DavidKinder#154 from erkyrath/less-dict-bug Fix for array overrun with $ZCODE_LESS_DICT_DATA commit 8e8f80a Author: David Kinder <david.kinder@david.kinder> Date: Wed Feb 16 21:41:56 2022 +0000 Remove readme.txt, combine with readme.md commit 02ce5e9 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Wed Feb 16 00:12:15 2022 -0500 Make use of forward branch checking. commit 415d8eb Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Wed Feb 16 00:00:55 2022 -0500 Additional label setup call. commit 411b057 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Feb 15 23:48:27 2022 -0500 Fix for array overrun bug. commit 2b48c59 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Feb 15 23:36:17 2022 -0500 Track which labels get branched to. commit f68213e Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Feb 15 22:34:35 2022 -0500 Move end-routine cleanup to a better place. commit 911fbe3 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Feb 15 20:11:08 2022 -0500 Comments (for later). commit 2e8d44d Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Tue Feb 15 18:58:49 2022 -0500 First draft of dead-branch optimization. Needs more testing. commit c7ad0ad Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Feb 14 20:17:06 2022 -0500 Don't compile @jz branches that will never trigger. commit e71e723 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Feb 14 18:13:53 2022 -0500 Initialize numeric variable to 0, not FALSE. commit f8ba476 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Mon Feb 14 18:13:14 2022 -0500 Comments. commit 9789197 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 13 15:30:17 2022 -0500 Z-code branch optimization for @jz CONSTANT. These cases are converted to @jump. (Glulx already did this.) commit d9df1d6 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 13 11:52:20 2022 -0500 Hopefully this does dead-branch stripping the way we want. commit 9db6712 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 13 11:36:39 2022 -0500 Ensure that AI is never left with a dangling text pointer. This shouldn't matter but it's tidier. commit a9f45b5 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sun Feb 13 11:23:58 2022 -0500 Mark assembly_instruction arguments "const". commit 0d219c4 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Feb 5 17:19:03 2022 -0500 Space before the percent sign. commit 3e53128 Merge: c262991 e2a204c Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Feb 5 17:09:41 2022 -0500 Merge branch 'master' into percentage-map commit c262991 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Aug 28 14:08:16 2021 -0400 Remove unused variables. commit a3a9e30 Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Aug 28 13:53:36 2021 -0400 Comment. commit 140918a Author: Andrew Plotkin <zarf@ZarfLent.local> Date: Sat Aug 28 13:49:33 2021 -0400 Remove the separate percentages output, which was wrong for Glulx anyhow. -p now shows the memory map with percentages. commit b702570 Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 19:12:40 2021 -0400 More info in help page. commit 95bcb1d Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 19:09:35 2021 -0400 Clarify help output line. commit 9ff5527 Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 18:51:48 2021 -0400 Comment. commit 786afb6 Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 18:50:23 2021 -0400 Remaining percentages. commit dc052e6 Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 18:07:20 2021 -0400 More percentages. commit 22cb368 Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 18:03:23 2021 -0400 Remove two memory-map display lines that don't exist in Glulx. commit 0bbb6fa Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 17:58:19 2021 -0400 More percentages. commit 7539164 Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 17:31:03 2021 -0400 Percentages. commit 1c6b2ec Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 12:33:46 2021 -0400 One more. commit 401839f Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 12:28:26 2021 -0400 A few more percentages. commit 74c826c Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 12:26:34 2021 -0400 More percentages. commit 0be17a0 Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 12:19:17 2021 -0400 Reformat. commit ace6299 Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 12:03:55 2021 -0400 More percentages. commit 3612d23 Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 11:48:47 2021 -0400 Better rounding on percentages. commit a8c1881 Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 11:43:50 2021 -0400 More percentage numbers. commit edd665e Author: Andrew Plotkin <zarf@ZarfLeaf.local> Date: Fri Aug 27 11:24:33 2021 -0400 Show percentages inline.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Improved dead-code stripping! This change goes fairly deep into the code generation system. Happily, it doesn't touch too much code.
Here is a long essay about it.
Overview
The key is the
execution_never_reaches_here
flag. This was once a simple boolean: do we know that this line is unreachable? (The flag gets turned on after areturn
statement, for example.) This was used solely to print "Execution never reaches here" warnings.(Really it had a third state: "yes, but we don't need to print a warning about it." This gets set after the first warning, and also in another case which I'll explain later.)
The new code-stripping trick goes like this: if
execution_never_reaches_here
is nonzero, don't generate opcodes! Theassemblez_instruction()
/assembleg_instruction()
routines just quietly exit in this case. Or rather, they exit with a "never reaches here" warning unless we've already printed one.compile_string()
also checks this flag and skips writing strings to the string table.I have now piled some more state into
execution_never_reaches_here
; enough to require named bitmask constants. TheEXECSTATE_UNREACHABLE
bit is set if the current line is unreachable. TheEXECSTATE_NOWARN
bit is set if we don't need to print a warning. TheEXECSTATE_ENTIRE
bit is set if the entire current statement or code block is unreachable. (This is important for better code-stripping.)Footnote 1: If
UNREACHABLE
is zero, the other bits must be zero too. The constantEXECSTATE_REACHABLE
is defined as (all bits) zero, but we can just testif (execution_never_reaches_here)
as a shortcut.Footnote 2: If we're between functions,
execution_never_reaches_here
is zero (REACHABLE
). Anything defined outside a function is a global symbol, guaranteed reachable. (Forgetting this was the source of my "violence is not the answer" bug!)In general, every time we compile a JUMP or RETURN opcode, the
UNREACHABLE
flag gets set. Every time we compile a label, the flag gets cleared. This makes sense if you consider a common while-true loop:This is compiled as:
Code after an unconditional JUMP is obviously unreachable. But the next thing that happens is the
.ExitLabel
, which is the target of a branch, so the next line is reachable again.However, we need to be a little more clever. If the unreachable flag is set when we start the while loop, then the entire loop should be unreachable, even the labels.
This is where the
ENTIRE
flag comes in. We set this flag when we enter an unreachable statement, or a braced block of statements; we reset it upon leaving. TheENTIRE
flag prevents labels from clearingUNREACHABLE
.Backwards compatibility
This change is an optimization. It should not change the behavior of compiled code. It just makes smaller game files.
However, there are a few cases where previously-valid I6 code is now rejected. These cases look like this:
If
DOSTUFF
is defined as a constant zero, the entire while statement is considered unreachable. The.MiddleLabel
in the loop is therefore not compiled. Attempting to jump to that label will be caught as a compile-time error.This is a baroque code pattern, and I don't expect that it's ever been used in real life. However, for the sake of perfect backwards compatibility, you can give the compiler setting
$STRIP_UNREACHABLE_LABELS=0
. This effectively disables theENTIRE
flag. All defined labels will be jumpable, at the cost of less effective optimization.Never-reachable warnings
The "execution never reaches here" warning is simple in principle. If
assemble_instruction()
skips generating code becauseUNREACHABLE
is set, we print a warning. Then we setNOWARN
so that no more warnings will be printed (for this stretch of code).However, there are exceptions. It's pretty common to write code like:
The constant may be defined true or false to enable or disable the code. The Inform library does this in a few places, for example.
We want to strip out these code blocks when appropriate. But we don't want to generate unreachability warnings. They are, by convention, "unreachable on purpose".
This makes the if-statement logic in states.c rather messy. However, the mess is confined to the if statement, and it only affects the
NOWARN
flag.(A simpler version of this hack previously existed in the
assemble_branch()
routines. However, that was the wrong place; it messed up the warnings around certain while loops. I moved it all to the if statement.)An exhaustive test for this logic can be found in branchprune.inf.
Code changes
The low-level
set_label_offset()
routine now takesoffset<0
to mean that the label should be marked as unusable. Jumping to an unusable label is a compile-time error.We keep a list of labels which have been used (as a branch target) in the current routine. This is the
labeluse
memlist. Themark_label_used()
helper function sets this flag when a branch/jump opcode is assembled.(We can't keep this flag in the
labelinfo
structure because of back-jumps, where the label is used before itslabelinfo
is allocated.)Some labels are known to only be used by forward-jumps, if at all. (For example, the branches in an if statement.) When assembling these, we use the new function
assemble_forward_label_no()
. This checkslabeluse
to see whether the label has been used. If not, the label can safely be ignored (marked unusable).(Note that named labels are never assembled this way, because they can be used by both forward and backward jumps.
assemble_forward_label_no()
is only used when constructing if statements, while loops, and so on.)When making long/short decisions for branches (in
transfer_routine_z()
/transfer_routine_g()
), we look for zero-distance branches. That is, branches which are aimed at the very next instruction. These branches are eliminated (by markingDELETED_MV
over the entire opcode).Footnote 3: Why do zero-distance branches exist at all? When we compile a forward branch, we don't always know whether the following code will be unreachable or not. If it's unreachable, no opcodes will be generated until the next label.
Footnote to the footnote: Zero-distance branches are eliminated after the assembly-trace stage. This means that if you do
inform -a
, you'll see a lot of this:Disassembling the game file will show that these lines are gone.
In
assemblez_1_branch()
, we check for the case of@jz CONSTANT
and compile either nothing or an unconditional branch. (The Glulx version of this routine already did that.)The
parse_statement_z()
/parse_statement_g()
routines have been refactored slightly. The code that looks for a named label (which is identical in G/Z) has been pulled out into a separate function,parse_named_label_statements()
, which is now called fromparse_statement()
.parse_statement()
andparse_code_block()
now set and restore theENTIRE
flag.In
parse_statement_z()
/parse_statement_g()
, theIF_CODE
parser (for if statements) now does a complicated dance withNOWARN
. See discussion above.In
check_nonzero_at_runtime_g()
, a constant argument is compiled as an unconditional branch. We set theNOWARN
flag to avoid spurious warnings. (This doesn't come up in Z-code, because the check is slightly different.)We now have the
STRIP_UNREACHABLE_LABELS
memory setting (defaults to 1).Other trivial cleanup:
execution_never_reaches_here
flag is cleared at startup and when finishing a routine. (See footnote 2, above.)execution_never_reaches_here
toREACHABLE
orUNREACHABLE
, other flags cleared. (The compiler has always done this but now it's more explicit.)AI.text
is always cleared after use. (We don't like leaving dangling pointers to token text.)assemblez_instruction()
/assembleg_instruction()
routines now take aconst
argument.