zig/test/behavior
mlugg 9c3670fc93
compiler: implement analysis-local comptime-mutable memory
This commit changes how we represent comptime-mutable memory
(`comptime var`) in the compiler in order to implement the intended
behavior that references to such memory can only exist at comptime.

It does *not* clean up the representation of mutable values, improve the
representation of comptime-known pointers, or fix the many bugs in the
comptime pointer access code. These will be future enhancements.

Comptime memory lives for the duration of a single Sema, and is not
permitted to escape that one analysis, either by becoming runtime-known
or by becoming comptime-known to other analyses. These restrictions mean
that we can represent comptime allocations not via Decl, but with state
local to Sema - specifically, the new `Sema.comptime_allocs` field. All
comptime-mutable allocations, as well as any comptime-known const allocs
containing references to such memory, live in here. This allows for
relatively fast checking of whether a value references any
comptime-mtuable memory, since we need only traverse values up to
pointers: pointers to Decls can never reference comptime-mutable memory,
and pointers into `Sema.comptime_allocs` always do.

This change exposed some faulty pointer access logic in `Value.zig`.
I've fixed the important cases, but there are some TODOs I've put in
which are definitely possible to hit with sufficiently esoteric code. I
plan to resolve these by auditing all direct accesses to pointers (most
of them ought to use Sema to perform the pointer access!), but for now
this is sufficient for all realistic code and to get tests passing.

This change eliminates `Zcu.tmp_hack_arena`, instead using the Sema
arena for comptime memory mutations, which is possible since comptime
memory is now local to the current Sema.

This change should allow `Decl` to store only an `InternPool.Index`
rather than a full-blown `ty: Type, val: Value`. This commit does not
perform this refactor.
2024-03-25 14:49:41 +00:00
..
conflicting_externs categorize behavior/bugs/<issueno>.zig tests 2024-01-06 16:49:41 -08:00
hasdecl
import
namespace_depends_on_compile_var
pub_enum
usingnamespace compiler_rt: fix arm hard-float f16 abi 2023-09-19 09:37:53 -07:00
abs.zig x86_64+macho: pass more behavior tests 2024-02-06 19:01:17 +01:00
align.zig compiler: implement analysis-local comptime-mutable memory 2024-03-25 14:49:41 +00:00
alignof.zig test/behavior: replace all 'comptime expect' with 'comptime assert' 2024-01-15 20:55:01 +11:00
array.zig spirv: update tests 2024-02-04 19:09:33 +01:00
asm.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
async_fn.zig test/behavior: replace all 'comptime expect' with 'comptime assert' 2024-01-15 20:55:01 +11:00
atomics.zig std.builtin: make atomic order fields lowercase 2024-03-11 07:09:10 -07:00
await_struct.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
basic.zig spirv: make generic globals invocation-local 2024-03-18 19:13:50 +01:00
bit_shifting.zig categorize behavior/bugs/<issueno>.zig tests 2024-01-06 16:49:41 -08:00
bitcast.zig disable failing behavior test: "comptime bitcast with fields following f80" 2024-03-21 19:07:08 -07:00
bitreverse.zig x86_64+macho: pass more behavior tests 2024-02-06 19:01:17 +01:00
bool.zig spirv: air int_from_bool 2024-02-04 19:09:29 +01:00
builtin_functions_returning_void_or_noreturn.zig std.builtin: make atomic order fields lowercase 2024-03-11 07:09:10 -07:00
byteswap.zig Add 64bit byteswap case, use fewer locals 2024-03-18 12:40:41 +01:00
byval_arg_var.zig spirv: enable passing tests 2024-03-18 19:13:51 +01:00
call.zig test/behavior: replace all 'comptime expect' with 'comptime assert' 2024-01-15 20:55:01 +11:00
call_tail.zig spirv: disable failing tests 2023-09-23 12:36:44 -07:00
cast.zig spirv: enable passing tests 2024-03-18 19:13:51 +01:00
cast_int.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
comptime_memory.zig compiler: implement analysis-local comptime-mutable memory 2024-03-25 14:49:41 +00:00
const_slice_child.zig spirv: update failing / passing tests 2023-10-15 20:08:18 +02:00
decltest.zig spirv: more passing tests 2023-05-20 17:30:22 +02:00
defer.zig spirv: update failing / passing tests 2023-10-15 20:08:18 +02:00
destructure.zig Ast: fix comptime destructure 2024-03-17 15:23:16 -07:00
duplicated_test_names.zig spirv: update tests 2024-02-04 19:09:33 +01:00
empty_file_level_struct.zig fix overflow found while fuzzing 2022-12-23 23:10:04 +02:00
empty_file_level_union.zig fix overflow found while fuzzing 2022-12-23 23:10:04 +02:00
empty_tuple_fields.zig setup spirv backend in behavior tests 2023-05-11 20:31:52 +02:00
empty_union.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
enum.zig behavior: add tests for #18816 2024-03-06 21:26:38 +00:00
error.zig spirv: enable passing tests 2024-03-18 19:13:51 +01:00
eval.zig compiler: implement analysis-local comptime-mutable memory 2024-03-25 14:49:41 +00:00
export_builtin.zig std.builtin: make link mode fields lowercase 2024-03-11 07:09:10 -07:00
export_c_keywords.zig cbe: fix non-msvc externs and exports 2024-01-03 02:52:25 -05:00
export_keyword.zig spirv: update tests 2024-02-04 19:09:33 +01:00
export_self_referential_type_info.zig all: zig fmt and rename "@XToY" to "@YFromX" 2023-06-19 12:34:42 -07:00
extern.zig Sema: perform codegen for anon decl created by @extern 2024-03-09 04:52:06 +00:00
extern_struct_zero_size_fields.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
field_parent_ptr.zig spirv: fieldParentPtr 2023-10-16 20:27:28 -04:00
file_to_embed.txt rename behavior test to better describe what it does 2023-10-23 17:28:10 -07:00
floatop.zig Merge pull request #19337 from Snektron/spirv-globals 2024-03-19 09:34:59 +01:00
fn.zig x86_64+macho: pass more behavior tests 2024-02-06 19:01:17 +01:00
fn_delegation.zig spirv: more passing tests 2023-05-20 17:30:22 +02:00
fn_in_struct_in_comptime.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
for.zig spirv: update tests 2024-02-04 19:09:33 +01:00
generics.zig Sema: allow param instructions to clobber inst_map 2024-03-17 14:42:12 +02:00
globals.zig spirv: make rusticl the primary testing implementation 2024-02-09 09:27:08 +03:30
hasdecl.zig spirv: update tests 2024-02-04 19:09:33 +01:00
hasfield.zig
if.zig categorize behavior/bugs/<issueno>.zig tests 2024-01-06 16:49:41 -08:00
import.zig spirv: update tests 2024-02-04 19:09:33 +01:00
import_c_keywords.zig x86_64+macho: pass more behavior tests 2024-02-06 19:01:17 +01:00
incomplete_struct_param_tld.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
inline_switch.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
int128.zig x86_64: implement some todos 2023-12-03 10:24:03 -05:00
int_comparison_elision.zig categorize behavior/bugs/<issueno>.zig tests 2024-01-06 16:49:41 -08:00
int_div.zig spirv: update tests 2024-02-04 19:09:33 +01:00
ir_block_deps.zig spirv: update failing / passing tests 2023-10-15 20:08:18 +02:00
lower_strlit_to_vector.zig spirv: update failing / passing tests 2023-10-15 20:08:18 +02:00
math.zig test: skip new failing tests for spirv 2024-02-15 18:44:24 +03:30
maximum_minimum.zig spirv: vectorize max, min 2024-02-04 19:09:31 +01:00
member_func.zig Zir: eliminate field_call_bind and field_call_bind_named 2023-05-20 12:27:48 -07:00
memcpy.zig Sema: ensure slice_ptr produces the correct type 2023-12-23 02:08:58 -05:00
memset.zig categorize behavior/bugs/<issueno>.zig tests 2024-01-06 16:49:41 -08:00
merge_error_sets.zig spirv: update failing / passing tests 2023-10-15 20:08:18 +02:00
muladd.zig x86_64+macho: pass more behavior tests 2024-02-06 19:01:17 +01:00
multiple_externs_with_conflicting_types.zig x86_64+macho: pass more behavior tests 2024-02-06 19:01:17 +01:00
namespace_depends_on_compile_var.zig spirv: update tests 2024-02-04 19:09:33 +01:00
nan.zig x86_64: fix compiler rt test failures 2023-10-29 07:20:36 -04:00
null.zig spirv: air is_(non_)null_ptr, optional_payload_ptr 2024-02-04 19:09:30 +01:00
optional.zig spirv: enable passing tests 2024-03-18 19:13:51 +01:00
packed-struct.zig x86_64: fix packed load 2024-02-12 05:25:07 +01:00
packed-union.zig Fix some comptime packed struct issues 2024-01-29 13:09:17 -08:00
packed_struct_explicit_backing_int.zig std.builtin.Endian: make the tags lower case 2023-10-31 21:37:35 -04:00
pointers.zig spirv: enable passing tests 2024-03-18 19:13:51 +01:00
popcount.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
prefetch.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
ptrcast.zig Remove all usages of std.mem.copy and remove std.mem.set (#18143) 2023-11-29 16:03:02 -05:00
ptrfromint.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
pub_enum.zig spirv: update tests 2024-02-04 19:09:33 +01:00
ref_var_in_if_after_if_2nd_switch_prong.zig spirv: more passing tests 2023-05-20 17:30:22 +02:00
reflection.zig spirv: more passing tests 2023-05-20 17:30:22 +02:00
return_address.zig enable passing behavior tests 2023-05-31 18:04:33 +02:00
saturating_arithmetic.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
select.zig x86_64: implement @select 2024-02-25 11:22:10 +01:00
shuffle.zig x86_64: implement @shuffle 2024-02-25 11:22:10 +01:00
sizeof_and_typeof.zig Sema: replace uses of toUnsignedInt with toUnsignedIntAdvanced 2024-01-20 12:21:05 -08:00
slice.zig test/behavior: fix test type check for multi-ptr slice 2024-01-15 20:55:01 +11:00
slice_sentinel_comptime.zig spirv: update tests 2024-02-04 19:09:33 +01:00
src.zig behavior: correct tests after #18816 2024-03-06 21:26:38 +00:00
stage2_wasm_div.zig Replace @panic with unreachable, add test 2023-08-23 20:34:59 +01:00
string_literals.zig categorize behavior/bugs/<issueno>.zig tests 2024-01-06 16:49:41 -08:00
struct.zig behavior: add tests for #18816 2024-03-06 21:26:38 +00:00
struct_contains_null_ptr_itself.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
struct_contains_slice_of_itself.zig Revert "Revert "Merge pull request #17657 from Snektron/spirv-recursive-ptrs"" 2023-10-23 06:27:12 -04:00
switch.zig Sema: reset block error return trace index between cases 2024-03-08 07:30:32 -08:00
switch_on_captured_error.zig spirv: update tests 2024-02-04 19:09:33 +01:00
switch_prong_err_enum.zig spirv: update failing / passing tests 2023-10-15 20:08:18 +02:00
switch_prong_implicit_cast.zig spirv: update failing / passing tests 2023-10-15 20:08:18 +02:00
this.zig categorize behavior/bugs/<issueno>.zig tests 2024-01-06 16:49:41 -08:00
threadlocal.zig Remove all usages of std.mem.copy and remove std.mem.set (#18143) 2023-11-29 16:03:02 -05:00
truncate.zig spirv: vectorize int_cast, trunc 2024-02-04 19:09:31 +01:00
try.zig categorize behavior/bugs/<issueno>.zig tests 2024-01-06 16:49:41 -08:00
tuple.zig std.builtin: make container layout fields lowercase 2024-03-11 07:09:07 -07:00
tuple_declarations.zig std.builtin: make container layout fields lowercase 2024-03-11 07:09:07 -07:00
type.zig AstGen: disallow alignment on function types 2024-03-17 03:06:17 +01:00
type_info.zig AstGen: disallow alignment on function types 2024-03-17 03:06:17 +01:00
type_info_mul_linksection_addrspace_decls.zig Zir: add missing extra index for linksection_or_addspace 2023-11-25 11:39:37 +00:00
type_info_only_pub_decls.zig spirv: update failing / passing tests 2023-10-15 20:08:18 +02:00
typename.zig AstGen: disallow alignment on function types 2024-03-17 03:06:17 +01:00
undefined.zig x86_64: implement ret_safe 2024-02-12 05:25:07 +01:00
underscore.zig spirv: enable passing tests 2023-09-23 12:36:56 -07:00
union.zig disable failing behavior test: "reinterpret extern union" 2024-03-21 20:09:20 -07:00
union_with_members.zig enable passing behavior tests 2023-05-31 18:04:33 +02:00
usingnamespace.zig Sema: fix spurious type has no namespace error 2024-03-17 14:42:12 +02:00
var_args.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
vector.zig spirv: enable passing tests 2024-03-18 19:13:51 +01:00
void.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
wasm.zig test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
while.zig spirv: enable passing tests 2024-03-18 19:13:51 +01:00
widening.zig x86_64+macho: pass more behavior tests 2024-02-06 19:01:17 +01:00
wrapping_arithmetic.zig spirv: update tests 2024-02-04 19:09:33 +01:00
zero.bin Module: fix @embedFile of files containing zero bytes 2024-02-22 12:33:53 -08:00