0
Fork 0
mirror of https://codeberg.org/ziglang/zig synced 2026-11-18 07:05:05 +00:00
zig/test
Andrew Kelley 040c6eaaa0 stage2: garbage collect unused anon decls
After this change, the frontend and backend cooperate to keep track of
which Decls are actually emitted into the machine code. When any backend
sees a `decl_ref` Value, it must mark the corresponding Decl `alive`
field to true.

This prevents unused comptime data from spilling into the output object
files. For example, if you do an `inline for` loop, previously, any
intermediate value calculations would have gone into the object file.
Now they are garbage collected immediately after the owner Decl has its
machine code generated.

In the frontend, when it is time to send a Decl to the linker, if it has
not been marked "alive" then it is deleted instead.

Additional improvements:
 * Resolve type ABI layouts after successful semantic analysis of a
   Decl. This is needed so that the backend has access to struct fields.
 * Sema: fix incorrect logic in resolveMaybeUndefVal. It should return
   "not comptime known" instead of a compile error for global variables.
 * `Value.pointerDeref` now returns `null` in the case that the pointer
   deref cannot happen at compile-time. This is true for global
   variables, for example. Another example is if a comptime known
   pointer has a hard coded address value.
 * Binary arithmetic sets the requireRuntimeBlock source location to the
   lhs_src or rhs_src as appropriate instead of on the operator node.
 * Fix LLVM codegen for slice_elem_val which had the wrong logic for
   when the operand was not a pointer.

As noted in the comment in the implementation of deleteUnusedDecl, a
future improvement will be to rework the frontend/linker interface to
remove the frontend's responsibility of calling allocateDeclIndexes.

I discovered some issues with the plan9 linker backend that are related
to this, and worked around them for now.
History 2021-07-29 19:30:37 -07:00
..
behavior stage1: fix anon struct naming in certain cases 2021-07-28 18:17:11 -04:00
src std.build: don't default to static linkage 2021-06-12 14:23:07 +03:00
stage1/c_abi stage1: Expand SysV C ABI support for small structs 2021-07-28 18:13:17 -04:00
stage2 stage2: garbage collect unused anon decls 2021-07-29 19:30:37 -07:00
standalone cleanups related to unused params 2021-06-21 17:03:04 -07:00
assemble_and_link.zig update std lib to new Target API 2020-02-28 14:51:54 -05:00
behavior.zig stage2: implement @boolToInt 2021-07-27 17:08:37 -07:00
cases.zig stage2: more principled approach to comptime references 2021-07-29 15:59:51 -07:00
cli.zig update godbolt test case for unused parameter 2021-06-23 10:44:46 -07:00
compare_output.zig fix unused parameters in compare_output test cases 2021-06-23 10:44:46 -07:00
compile_errors.zig stage2 astgen: error for return outside of function scope 2021-07-11 10:03:35 -04:00
gen_h.zig run zig fmt on src/ and test/ 2020-10-31 12:21:49 +02:00
run_translated_c.zig translate-c: handle signed array subscripts 2021-07-28 17:46:02 -04:00
runtime_safety.zig fix unused variable errors in runtime safety test cases 2021-06-23 10:44:46 -07:00
stack_traces.zig overhaul elf csu (c-runtime startup) logic 2021-05-23 15:38:57 -04:00
standalone.zig std: Fix PIE startup sequence 2021-06-19 18:02:51 +02:00
tests.zig avoid calling into stage1 backend when AstGen fails 2021-07-02 13:27:28 -07:00
translate_c.zig translate-c: fix import path in translation failure comment 2021-07-28 08:06:22 -07:00