aboutsummaryrefslogtreecommitdiff
path: root/src/Zir.zig
AgeCommit message (Collapse)Author
2022-09-12stage2: change how defers are stored in ZirVeikka Tuominen
Storing defers this way has the benefits that the defer doesn't get analyzed multiple times in AstGen, it takes up less space, and it makes Sema aware of defers allowing for 'unreachable else prong' error on error sets in generic code. The disadvantage is that it is a bit more complex and errdefers with payloads now emit a placeholder instruction (but those are rare). Sema.zig before: Total ZIR bytes: 3.7794370651245117MiB Instructions: 238996 (2.051319122314453MiB) String Table Bytes: 89.2802734375KiB Extra Data Items: 430144 (1.640869140625MiB) Sema.zig after: Total ZIR bytes: 3.3344192504882812MiB Instructions: 211829 (1.8181428909301758MiB) String Table Bytes: 89.2802734375KiB Extra Data Items: 374611 (1.4290275573730469MiB)
2022-08-30Sema: shift of comptime int with runtime valueVeikka Tuominen
Closes #12290
2022-08-28stage2: add an explicit padding field to avoid Valgrind warningAndrew Kelley
Adds a `unused: u32 = 0` field to `Zir.Header`. We could leave this as padding, however it triggers a Valgrind warning because we read and write undefined bytes to the file system. This is harmless, but it's essentially free to have a zero field here and makes the warning go away, making it more likely that following Valgrind warnings will be taken seriously.
2022-08-15Zir: add missing support for packed ints in declIteratorLoris Cro
2022-08-10stage2: Implement explicit backing integers for packed structsIsaac Freund
Now the backing integer of a packed struct type may be explicitly specified with e.g. `packed struct(u32) { ... }`.
2022-08-09stage2: generate call arguments in separate blocksVeikka Tuominen
2022-08-08stage2: pass anon name strategy to reifyVeikka Tuominen
2022-08-05Merge pull request #12300 from antlilja/getParamNameVeikka Tuominen
Replace param_names and anytype_args fields inside of Fn with functions
2022-08-01stage2: better source location for var declsVeikka Tuominen
2022-08-01Removed param_names from Fn inside Module.zigantlilja
Removed the copy of param_names inside of Fn and changed to implementation of getParamName to fetch to parameter name from the ZIR. The signature of getParamName was also changed to take an additional *Module argument.
2022-07-29stage2: handle tuple init edge casesVeikka Tuominen
2022-07-29stage2: add error for comptime control flow in runtime blockVeikka Tuominen
2022-07-24stage2: implement `noinline fn`Meghan
2022-07-23Sema: bad union field access safetyVeikka Tuominen
2022-07-21stage2: better pointer source locationVeikka Tuominen
2022-07-13stage2: lower each struct field type, align, init separatelyAndrew Kelley
Previously, struct types, alignment values, and initialization expressions were all lowered into the same ZIR body, which caused false positive "depends on itself" errors when the initialization expression depended on the size of the struct. This also uses ResultLoc.coerced_ty for struct field alignment and initialization values. The resulting ZIR encoding ends up being roughly the same, neither smaller nor larger than previously. Closes #12029
2022-07-07Sema: improve array source locationVeikka Tuominen
2022-07-07Module: add `.node_offset_un_op`Veikka Tuominen
2022-07-07Sema: panic at comptime + misc error message improvementsVeikka Tuominen
2022-07-07AstGen: move error_to_int, int_to_error and select to extendedVeikka Tuominen
2022-07-01AstGen: use elem_{ptr,val}_node for array access syntaxVeikka Tuominen
2022-07-01Sema: validate deref operator type and valueVeikka Tuominen
2022-06-30Sema: add source location to coerce result ptr, fix negation errorVeikka Tuominen
2022-06-11stage2: improve anon name strategy for local variablesVeikka Tuominen
2022-06-09introduce std.debug.TraceAndrew Kelley
And use it to debug a LazySrcLoc in stage2 that is set to a bogus value. The actual fix in this commit is: ```diff - try sema.emitBackwardBranch(&child_block, call_src); + try sema.emitBackwardBranch(block, call_src); ```
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-06-06Merge pull request #11783 from ziglang/stage2-tryAndrew Kelley
introduce a "try" ZIR and AIR instruction
2022-06-06stage2: use correct type (u29) for alignmentVeikka Tuominen
2022-06-05explicit "_ptr" variants of ZIR try instructionAndrew Kelley
* Introduce "_ptr" variants of ZIR try instruction to disallow constructs such as `try` on a pointer value instead of an error union value. * Disable the "_inline" variants of the ZIR try instruction for now because we are out of ZIR tags. I will free up some space in an independent commit. * AstGen: fix tryExpr calling rvalue() on ResultLoc.ref
2022-06-05AstGen: introduce `try` instructionAndrew Kelley
This introduces two ZIR instructions: * `try` * `try_inline` This is part of an effort to implement #11772.
2022-05-31stage2: introduce support for noaliasAndrew Kelley
Not implemented yet is enhancements to coerceInMemory to account for noalias parameters. Related to #11498.
2022-05-30Merge pull request #11752 from ziglang/zir-fancy-fnsAndrew Kelley
stage2: add missing data to ZIR encoding of functions
2022-05-30stage2: add missing data to ZIR encoding of functionsAndrew Kelley
The main purpose of this commit is to prepare to implement support for callconv(), align(), linksection(), and addrspace() annotations on generic functions where the provided expression depends on comptime parameters (making the function generic). It's a rather involved change, so this commit only makes the necessary changes to AstGen without regressing any behavior, and a follow-up commit can finish the task by making the enhancements to Sema. By my quick estimation, the new encoding for functions is a negligible improvement - along the lines of 0.005% fewer total ZIR bytes on average. Still, it's nice that this commit, while adding more data into ZIR, actually ends up reducing the storage size thanks to a slightly more sophisticated encoding. Zir.Inst.ExtendedFunc is renamed to Zir.Inst.FuncFancy to eliminate confusion about it being an extended instruction (it used to be but is no longer). The encoding for this instruction is completely reworked. The encoding for Zir.Inst.Func is also changed slightly - when the return type body length is 1, then only a Zir.Inst.Ref is provided; not a full body. linksection() and addrspace() are now communicated via func_fancy ZIR instruction rather than as part of the corresponding decl. This allows their expressions to observe comptime parameters.
2022-05-29AstGen: add tuple aware elem_type_indexVeikka Tuominen
2022-05-29AstGen: improve generated Zir for array init exprsVeikka Tuominen
2022-05-20stage2: fix `@call` when used in a comptime or nosuspend blockAndrew Kelley
`@call` allows specifying the modifier explicitly, however it can still appear in a context that overrides the modifier. This commit adds flags to the BuiltinCall ZIR encoding. Since we have unused bits I also threw in the ensure_result_used mechanism. I also deleted a behavior test that was checking for bound function behavior where I think stage2 behavior is correct and stage1 behavior is incorrect.
2022-05-04stage2: improve semantics of atomic operationsAndrew Kelley
ZIR instructions updated: atomic_load, atomic_rmw, atomic_store, cmpxchg These no longer construct a pointer type as the result location. This solves a TODO that was preventing the pointer from possibly being volatile, as well as properly handling allowzero and addrspace. It also allows the pointer to be over-aligned, which may be needed depending on the target. As a consequence, the element type needs to be communicated in the ZIR. This is done by strategically making one of the operands be ResultLoc.ty instead of ResultLoc.coerced_ty if possible, or otherwise explicitly adding elem_type into the ZIR encoding, such as in the case of atomic_load. The pointer type of atomic operations is now checked in Sema by coercing it to an expected pointer type, that maybe over-aligned according to target requirements. Together with the previous commit, Zig now has smaller alignment for large integers, depending on the target, and yet still has type safety for atomic operations that specially require higher alignment.
2022-04-30Zir: turn extended func into func_extendedVeikka Tuominen
2022-04-30Zir: move more common instructions out of extendedVeikka Tuominen
2022-04-30stage2: fix comptime unreachableVeikka Tuominen
2022-04-27add new builtin function `@tan`Andrew Kelley
The reason for having `@tan` is that we already have `@sin` and `@cos` because some targets have machine code instructions for them, but in the case that the implementation needs to go into compiler-rt, sin, cos, and tan all share a common dependency which includes a table of data. To avoid duplicating this table of data, we promote tan to become a builtin alongside sin and cos. ZIR: The tag enum is at capacity so this commit moves `field_call_bind_named` to be `extended`. I measured this as one of the least used tags in the zig codebase. Fix libc math suffix for `f32` being wrong in both stage1 and stage2. stage1: add missing libc prefix for float functions.
2022-03-31AstGen: fix treating noreturn instructions as voidAndrew Kelley
Fixes regression introduced in cf4aad4858ac61b4814d8f021c8eae22ee7f63e6.
2022-03-30AstGen: fix referencing unreferencable instructionsAndrew Kelley
Sema avoids adding map entries for certain instructions such as `set_eval_branch_quota` and `atomic_store`. This means that result location semantics in AstGen must not emit any instructions that attempt to use the result of any of these instructions. This commit makes AstGen replace such instructions with `Zir.Inst.Ref.void_value` if their result value ends up being referenced. This fixes a compiler crash when running std lib atomic tests.
2022-03-31stage2: fix print_zir for .builtin_srcMeghan Denny
2022-03-29Sema: fix generic instantiations of return types with nested capturesAndrew Kelley
* In semaStructFields and semaUnionFields we return error.GenericPoison if one of the field types ends up being generic poison. - This requires handling function calls and function types taking this into account when calling `typeRequiresComptime` on the return type. * Unrelated: I noticed using Valgrind that struct reification did not populate the `known_opv` field. After fixing it, the behavior tests run Valgrind-clean. * ZIR: use `@ptrCast` to cast between slices instead of exploiting the fact that stage1 incorrectly allows `@bitCast` between slices. - A future enhancement will make Zig support `@ptrCast` to directly cast between slices.
2022-03-26stage2: result location types for function call argumentsAndrew Kelley
* AstGen: restore the param_type ZIR instruction and pass it to the expression for function call arguments. This does not solve the problem for generic function parameters, but it catches stage2 up to stage1 which also does not solve the problem for generic function parameters. - Most of the enhancements in this commit will still be needed for a more sophisticated further improvement to handle generic function types. - In Sema, handling of `as` coercion recognizes the `var_args_param` Type Tag and passes the operand through doing no coercion. - That was the last ZIR tag and we are now using all 256 ZIR tags. * AstGen: array init and struct init expressions use the anon form even when the result location has a type. Prevents the type system incorrectly believing, for example, that a tuple is actually an array when the result location is a param_type of a function with `anytype` parameter. * Sema: add missing coercion in `unionInit` to coerce the init to the corresponding union field type. * `Value.fieldValue` now takes a type and does not take an allocator. closes #11293 After this commit, stage2 passes all the parser tests.
2022-03-25Sema: implement zirSwitchCapture for error setsVeikka Tuominen
2022-03-19stage2: add dbg_block_{begin,end} instructionVeikka Tuominen
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-03-10AstGen: structInitExpr and arrayInitExpr avoid crashAndrew Kelley
when an inferred alloc is passed as the result pointer of a block.