aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/eval.zig
AgeCommit message (Collapse)Author
2022-09-09stage2 ARM: implement basic array_elem_valjoachimschmidt557
2022-09-09stage2 ARM: implement ptr_elem_valjoachimschmidt557
2022-09-09stage2 ARM: support larger function stacksjoachimschmidt557
This is done by introducing a new Mir pseudo-instruction
2022-09-09stage2 ARM: implement struct_field_val for registersjoachimschmidt557
2022-09-09stage2 ARM: amend implementation of various AIR instructionsjoachimschmidt557
- unwrap_errunion_err for registers - unwrap_errunion_payload for registers - ptr_slice_len_ptr for all MCValues - ptr_slice_ptr_ptr for all MCValues
2022-08-22Sema: resolve lazy values in `resolveMaybeUndefValIntable`Veikka Tuominen
Closes #12512 Closes #12513
2022-08-21Sema: ignore dbg_block instructions when checking for comptimenessVeikka Tuominen
Closes #12514
2022-08-10Sema: fix expansion of repeated valueVeikka Tuominen
Closes #12386
2022-07-22Sema: fix mutation of optional ptr represented as regular ptrVeikka Tuominen
2022-07-22Sema: fix loading and storing of optional pointers represented as pointersVeikka Tuominen
2022-07-19Sema: fix runtime instructions omittedAndrew Kelley
in the presence of comptime control flow. fixes #12171
2022-06-25stage2 ARM: implement basic intCast and error union wrappingjoachimschmidt557
2022-06-12Sema: rework beginComptimePtrMutationAndrew Kelley
This comment is now deleted because the task is completed in this commit: ``` // TODO: Update this to behave like `beginComptimePtrLoad` and properly check/use // `container_ty` and `array_ty`, instead of trusting that the parent decl type // matches the type used to derive the elem_ptr/field_ptr/etc. // // This is needed because the types will not match if the pointer we're mutating // through is reinterpreting comptime memory. ``` The main strategy is to change the ComptimePtrMutationKit struct so that instead of `val: *Value` it now returns a tagged union which can be one of three possibilities: * The pointer type matches the actual comptime Value so a direct modification is possible. Before this commit, the implementation incorrectly assumed this was always the case. * In the case of needing to write through a reinterpreted pointer, a mutable base Value pointer is provided along with a byte offset pointing to the element value in virtual memory. * Otherwise, it means a compile error must be emitted because one or both of the types (the owner of the value, or the pointer type being used to write through) do not have a well-defined memory layout. After calling beginComptimePtrMutation, the one callsite now switches on this tagged union and does the appropriate thing. The main new logic is for the second case, which involves pointer reinterpretation, which now takes this strategy: 1. write the base value to a memory buffer. 2. perform the pointer store at the proper byte offset, thereby modifying a subset of the buffer. 3. read the base value from the memory buffer, overwriting the old base value.
2022-06-09stage2: fix handling of aggregates with mixed comptime-only fieldsAndrew Kelley
2022-06-08AstGen: avoid redundant "ref" instructionsAndrew Kelley
Whenever a `ref` instruction is needed, it is created and saved in `AstGen.ref_table` instead of being immediately appended to the current block body. Then, when the referenced instruction is being added to the parent block (e.g. from setBlockBody), if it has a ref_table entry, then the ref instruction is added directly after the instruction being referenced. This makes sure two properties are upheld: 1. All pointers to the same locals return the same address. This is required to be compliant with the language specification. 2. `ref` instructions will dominate their uses. This is a required property of ZIR. A complication arises when a ref instruction refs another ref instruction. The logic in appendBodyWithFixups must take this into account, recursively handling ref refs.
2022-05-27stage2 AArch64: complete genTypedValuejoachimschmidt557
2022-05-26clean up some behavior testsAndrew Kelley
* improve names * properly categorize a couple of bug cases * mark one as already passing
2022-05-25stage2: implement runtime array multiplicationAndrew Kelley
Additionally: * Sema: fix array cat/mul not setting the sentinel value - This required an LLVM backend enhancement to the handling of the AIR instruction aggregate_init that likely needs to be propagated to the other backends. * Sema: report integer overflow of array concatenation in a proper compile error instead of crashing. * Sema: fix not using proper pointer address space for array cat/mul
2022-05-25Sema: implement array concatenation with runtime operandsAndrew Kelley
2022-05-25Sema: generic function instantiations inherit branch quotaAndrew Kelley
2022-05-24mark two behavior tests as passingAndrew Kelley
2022-05-24move bound function behavior test to compile error testAndrew Kelley
2022-05-24enable passing behavior testAndrew Kelley
This was disabled for macOS but I just tested it on my M1 and it works fine.
2022-05-24stage2: string literal interningAndrew Kelley
This is a temporary addition to stage2 in order to match stage1 behavior, however the end-game once the lang spec is settled will be to use a global InternPool for comptime memoized objects, making this behavior consistent across all types, not only string literals. Or, we might decide to not guarantee string literals to have equal comptime pointers, in which case this commit can be reverted.
2022-05-17behavior tests: correction of C pointer testAndrew Kelley
This test was also covering this behavior: ```zig test "equality of pointers to comptime const" { const a: i32 = undefined; comptime assert(&a == &a); } ``` This check belongs in its own behavior test which isolates this behavior; not bundled along with a C pointer test.
2022-05-06Sema: solve a false positive "depends on itself"Andrew Kelley
This improves the ABI alignment resolution code. This commit fully enables the MachO linker code in stage3. Note, however, that there are still miscompilations in stage3.
2022-04-02behavior tests: disable failing stage1 testAndrew Kelley
I forgot to check that the new behavior tests also pass in stage1. One of them does not. Fixes regression from 4618c41fa6ca70f06c7e65762d2f38d57b00818c.
2022-04-02Sema: mechanism for converting comptime breaks to runtimeAndrew Kelley
closes #11369
2022-03-29CBE: fix C output after PR #11302, reenable testsDaniele Cocca
Commit 052079c99455d01312d377d72fa1b8b5c0b22aad surfaced two issues with the generated C code: - renderInt128() contained a seemingly unnecessary assertion to verify that the high 64 bits of the number were nonzero, dating back to 9bf1681990fe87a6b2e5fc644a89f1aece304579. I removed it. - renderValue() didn't have any special handling for undefined structs, falling back to printing "{}" which generated invalid expressions such as "return {}" for functions returning structs, whereas "return (S){}" is the correct form. I changed it accordingly. At the same time I'm reenabling the relevant tests.
2022-03-27stage2: runtime safety check integer cast truncating bitsMitchell Hashimoto
2022-03-24Sema: fix closure capture typeof runtime-known parameterAndrew Kelley
Closures are not necessarily constant values. For example, Zig code might do something like this: fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; } ...in which case the closure_capture instruction has access to a runtime value only. In such case we preserve the type and use a dummy runtime value. closes #11292
2022-03-24AstGen: fix const locals with comptime initializationsAndrew Kelley
`const foo = comptime ...` generated invalid ZIR when the initialization expression contained an array literal because the validate_array_init_comptime instruction assumed that the corresponding alloc instruction was comptime. The solution is to look slightly ahead and notice that the initialization expression would be comptime-known and affect the alloc instruction tag accordingly.
2022-03-23Sema: introduce a type resolution queueAndrew Kelley
That happens after a function body is analyzed. This prevents circular dependency compile errors and yet a way to mark types that need to be fully resolved before a given function is sent to the codegen backend.
2022-03-23behavior tests: disable failing stage1 testAndrew Kelley
My previous commit added a new behavior test that passes for stage2 but I forgot to check whether it passes for stage1. Since it does not, it has to be disabled. Additionally, this commit organizes behavior tests; there is no longer a section of tests only passing for stage1. Instead, tests are disabled on an individual basis. There is an except for the file which has global assembly in it.
2022-03-23add behavior test to cover bug fix in previous commitAndrew Kelley
2022-03-22CBE: enable more passing tests (#11258)Daniele Cocca
2022-03-21x64: refactor fix reg aliasing in genSetRegJakub Konka
2022-03-18organize behavior testsAndrew Kelley
* Identify the ones that are passing and stop skipping them. * Flatten out the main behavior.zig file and have each individual test disable itself if it is not passing.
2022-03-15AstGen: add missing coercion for const localsAndrew Kelley
A const local which had its init expression write to the result pointer, but then gets elided to directly initialize, was missing the coercion to the type annotation.
2022-03-13stage2: add debug info for locals in the LLVM backendAndrew Kelley
Adds 2 new AIR instructions: * dbg_var_ptr * dbg_var_val Sema no longer emits dbg_stmt AIR instructions when strip=true. LLVM backend: fixed lowerPtrToVoid when calling ptrAlignment on the element type is problematic. LLVM backend: fixed alloca instructions improperly getting debug location annotated, causing chaotic debug info behavior. zig_llvm.cpp: fixed incorrect bindings for a function that should use unsigned integers for line and column. A bunch of C test cases regressed because the new dbg_var AIR instructions caused their operands to be alive, exposing latent bugs. Mostly it's just a problem that the C backend lowers mutable and const slices to the same C type, so we need to represent that in the C backend instead of printing two duplicate typedefs.
2022-02-27stage2 sema: Implement comptime result for comparison of uint to comptime valueCody Tapscott
This adds a comptime result when comparing a comptime value to an unsigned integer. For example: ( 0 <= (unsigned runtime value)) => true (-1 < (unsigned runtime value)) => true ((unsigned runtime value) < -15) => false
2022-02-26Sema: make `align(a) T` same as `align(a:0:N) T`Andrew Kelley
where `@sizeOf(T) == N`.
2022-02-24Sema: implement tupleFieldVal, fix comptime elem_ptrAndrew Kelley
2022-02-24stage2: improved handling of store_to_block_ptrAndrew Kelley
* AstGen: remove the setBlockBodyEliding function. This is no longer needed after 63788b2a511eb87974065a052e2436b0c6202544. * Sema: store_to_block_ptr instruction is handled as store_to_inferred_ptr or store, as necessary.
2022-02-20Sema: fix inline break from a non-comptime scope to outer oneAndrew Kelley
Prior to this, the compiler would hit an assertion because the break_inline would not successfully move the compile-time control flow.
2022-01-26organize behavior testsAndrew Kelley
Every test that is moved in this commit has been checked to see if it is now passing.
2021-12-29compiler_rt: move more functions to the stage2 sectionAndrew Kelley
also move more already-passing behavior tests to the passing section.
2021-12-21stage2: @shlWithOverflowRobin Voetter
2021-10-21stage2: more division supportAndrew Kelley
AIR: * div is renamed to div_trunc. * Add div_float, div_floor, div_exact. - Implemented in Sema and LLVM codegen. C backend has a stub. Improvements to std.math.big.Int: * Add `eqZero` function to `Mutable`. * Fix incorrect results for `divFloor`. Compiler-rt: * Add muloti4 to the stage2 section.
2021-10-20stage2: implement slicingAndrew Kelley
* New AIR instruction: slice, which constructs a slice out of a pointer and a length. * AstGen: use `coerced_ty` for start and end expressions, use `none` for the sentinel, and don't try to load the result of the slice operation because it returns a by-value result. * Sema: pointer arithmetic is extracted into analyzePointerArithmetic and it is used by the implementation of slice. - Also I implemented comptime pointer addition. * Sema: extract logic into analyzeSlicePtr, analyzeSliceLen and use them inside the slice semantic analysis. - The approach in stage2 is much cleaner than stage1 because it uses more granular analysis calls for obtaining the slice pointer, doing arithmetic on it, and checking if the length is comptime-known. * Sema: use the slice Value Tag for slices when doing coercion from pointer-to-array. * LLVM backend: detect when emitting a GEP instruction into a pointer-to-array and add the extra index that is required. * Type: ptrAlignment for c_void returns 0. * Implement Value.hash and Value.eql for slices. * Remove accidentally duplicated behavior test.