aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
AgeCommit message (Collapse)Author
2021-03-23stage2: fix comptimeExpr and comptime function callsAndrew Kelley
2021-03-23stage2: add helper functions to clean up astgen Ref/IndexAndrew Kelley
2021-03-23stage2: fix two return types to be Ref not IndexIsaac Freund
We currently have no type safety between zir.Inst.Ref, zir.Inst.Index, and plain u32s.
2021-03-22stage2: fix `if` expressionsAndrew Kelley
2021-03-22astgen: improve the ensure_unused_result elisionAndrew Kelley
2021-03-22stage2: Sema improvements and boolean logic astgenAndrew Kelley
* add `Module.setBlockBody` and related functions * redo astgen for `and` and `or` to use fewer ZIR instructions and require less processing for comptime known values * Sema: rework `analyzeBody` function. See the new doc comments in this commit. Divides ZIR instructions up into 3 categories: - always noreturn - never noreturn - sometimes noreturn
2021-03-23stage2: remove all async related codeIsaac Freund
The current plan is to avoid using async and related features in the stage2 compiler so that we can bootstrap before implementing them. Having this untested and incomplete code in the codebase increases friction while working on stage2, in particular when preforming larger refactors such as the current zir memory layout rework. Therefore remove all async related code, leaving only error messages in astgen.
2021-03-22fix calculation in ensureCapacityDimenus
2021-03-22astgen: implement array typesIsaac Freund
2021-03-21Sema: implement arithmeticAndrew Kelley
2021-03-22astgen: implement bool_and/bool_orIsaac Freund
2021-03-21zir: add negate/negate_wrap, implement astgenIsaac Freund
These were previously implemented as a sub/sub_wrap instruction with a lhs of 0. Making this separate instructions however allows us to save some memory as there is no need to store a lhs.
2021-03-20stage2: fix memory management of ZIR codeAndrew Kelley
* free Module.Fn ZIR code when destroying the owner Decl * unreachable_safe and unreachable_unsafe are collapsed into one ZIR instruction with a safety flag. * astgen: emit an unreachable instruction for unreachable literals * don't forget to call deinit on ZIR code * astgen: implement some builtin functions
2021-03-20astgen: implement inline assemblyAndrew Kelley
2021-03-20astgen: implement function callsAndrew Kelley
2021-03-19astgen: support blocksAndrew Kelley
We are now passing this test: ```zig export fn _start() noreturn {} ``` ``` test.zig:1:30: error: expected noreturn, found void ``` I ran into an issue where we get an integer overflow trying to compute node index offsets from the containing Decl. The problem is that the parser adds the Decl node after adding the child nodes. For some things, it is easy to reserve the node index and then set it later, however, for this case, it is not a trivial code change, because depending on tokens after parsing the decl determines whether we want to add a new node or not. Possible strategies here: 1. Rework the parser code to make sure that Decl nodes are before children nodes in the AST node array. 2. Use signed integers for Decl node offsets. 3. Just flip the order of subtraction and addition. Expect Decl Node index to be greater than children Node indexes. I opted for (3) because it seems like the simplest thing to do. We'll want to unify the logic for computing the offsets though because if the logic gets repeated, it will probably get repeated wrong.
2021-03-19stage2: first pass at repairing ZIR printingAndrew Kelley
2021-03-19Sema: allocate inst_map with arena where appropriateAndrew Kelley
2021-03-19stage2: fix some math oopsies and typosAndrew Kelley
2021-03-19stage2: fix export source locations not being relative to DeclAndrew Kelley
2021-03-19llvm backend: use new srclocjacob gw
this allows to compile with ninja
2021-03-19zir-memory-layout: astgen: fill in identifierjacob gw
2021-03-18stage2: the code is compiling againAndrew Kelley
(with a lot of things commented out)
2021-03-18stage2: get Module and Sema compiling againAndrew Kelley
There are some `@panic("TODO")` in there but I'm trying to get the branch to the point where collaborators can jump in. Next is to repair the seam between LazySrcLoc and codegen's expected absolute file offsets.
2021-03-17stage2: Module and Sema are compiling againAndrew Kelley
Next up is reworking the seam between the LazySrcLoc emitted by Sema and the byte offsets currently expected by codegen. And then the big one: updating astgen.zig to use the new memory layout.
2021-03-17stage2: work through some compile errors in Module and SemaAndrew Kelley
2021-03-16stage2: rename zir_sema.zig to Sema.zigAndrew Kelley
2021-03-16stage2: *WIP*: rework ZIR memory layout; overhaul source locationsAndrew Kelley
The memory layout for ZIR instructions is completely reworked. See zir.zig for those changes. Some new types: * `zir.Code`: a "finished" set of ZIR instructions. Instead of allocating each instruction independently, there is now a Tag and 8 bytes of data available for all ZIR instructions. Small instructions fit within these 8 bytes; larger ones use 4 bytes for an index into `extra`. There is also `string_bytes` so that we can have 4 byte references to strings. `zir.Inst.Tag` describes how to interpret those 8 bytes of data. - This is shared by all `Block` scopes. * `Module.WipZirCode`: represents an in-progress `zir.Code`. In this structure, the arrays are mutable, and get resized as we add/delete things. There is extra state to keep track of things. This struct is stored on the stack. Once it is finished, it produces an immutable `zir.Code`, which will remain on the heap for the duration of a function's existence. - This is shared by all `GenZir` scopes. * `Sema`: represents in-progress semantic analysis of a `zir.Code`. This data is stored on the stack and is shared among all `Block` scopes. It is now the main "self" argument to everything in the file that was previously named `zir_sema.zig`. Additionally, I moved some logic that was in `Module` into here. `Module.Fn` now stores its parameter names inside the `zir.Code`, instead of inside ZIR instructions. When the TZIR memory layout reworking time comes, codegen will be able to reference this data directly instead of duplicating it. astgen.zig is (so far) almost entirely untouched, but nearly all of it will need to be reworked to adhere to this new memory layout structure. I have no benchmarks to report yet, as I am still working through compile errors and fixing various things that I broke in this branch. Overhaul of Source Locations: Previously we used `usize` everywhere to mean byte offset, but sometimes also mean other stuff. This was error prone and also made us do unnecessary work, and store unnecessary bytes in memory. Now there are more types involved into source locations, and more ways to describe a source location. * AllErrors.Message: embrace the assumption that files always have less than 2 << 32 bytes. * SrcLoc gets more complicated, to model more complicated source locations. * Introduce LazySrcLoc, which can model interesting source locations with very little stored state. Useful for avoiding doing unnecessary work when no compile errors occur. Also, previously, we had `src: usize` on every ZIR instruction. This is no longer the case. Each instruction now determines whether it even cares about source location, and if so, how that source location is stored. This requires more careful work inside `Sema`, but it results in fewer bytes stored on the heap, without compromising accuracy and power of compile error messages. Miscellaneous: * std.zig: string literals have more helpful result values for reporting errors. There is now a lower level API and a higher level API. - side note: I noticed that the string literal logic needs some love. There is some unnecessarily hacky code there. * cut & pasted some TZIR logic that was in zir.zig to ir.zig. This probably broke stuff and needs to get fixed. * Removed type/Enum.zig, type/Union.zig, and type/Struct.zig. I don't think this quite how this code will be organized. Need some more careful planning about how to implement structs, unions, enums. They need to be independent Decls, just like a top level function.
2021-03-06stage2: implement var argsVeikka Tuominen
2021-03-06stage2: astgen asyncVeikka Tuominen
2021-03-03stage2: remove error number from error set mapjacob gw
This saves memory since it is already stored in module as well as allowing for better threading. Part 2 of what is outlined in #8079.
2021-02-28stage2: remove value field from errorjacob gw
This saves memory and from what I have heard allows threading to be easier.
2021-02-25improve stage2 to allow catch at comptime:g-w1
* add error_union value tag. * add analyzeIsErr * add Value.isError * add TZIR wrap_errunion_payload and wrap_errunion_err for wrapping from T -> E!T and E -> E!T * add anlyzeInstUnwrapErrCode and analyzeInstUnwrapErr * add analyzeInstEnsureErrPayloadVoid: * add wrapErrorUnion * add comptime error comparison for tests * tests!
2021-02-24zig fmt src/Andrew Kelley
2021-02-19stage2: fix not setting up ZIR arg instruction correctlyAndrew Kelley
This is a regression from when I briefly flirted with changing how arg ZIR instructions work in this branch, and then failed to revert it correctly.
2021-02-19stage2: remove incorrect newlines from log statementsAndrew Kelley
2021-02-19stage2: AST: clean up parse errorsAndrew Kelley
* struct instead of tagged union * delete dead code * simplify parser code * remove unnecessary metaprogramming
2021-02-18stage2: astgen: fix most of the remaining compile errorsAndrew Kelley
more progress on converting astgen to the new AST memory layout. only a few code paths left to update.
2021-02-17stage2: fix a couple more compilation errorsAndrew Kelley
2021-02-17stage2: fix some of the compilation errors in this branchAndrew Kelley
2021-02-17astgen: finish updating expressions to new mem layoutAndrew Kelley
Now all that is left is compile errors and whatever regressions this branch introduced.
2021-02-12stage2: more progress towards Module/astgen building with new mem layoutAndrew Kelley
2021-02-11Merge remote-tracking branch 'origin/master' into ast-memory-layoutAndrew Kelley
Conflicts: * lib/std/zig/ast.zig * lib/std/zig/parse.zig * lib/std/zig/parser_test.zig * lib/std/zig/render.zig * src/Module.zig * src/zir.zig I resolved some of the conflicts by reverting a small portion of @tadeokondrak's stage2 logic here regarding `callconv(.Inline)`. It will need to get reworked as part of this branch.
2021-02-11stage2: start reworking Module/astgen for memory layout changesAndrew Kelley
This commit does not reach any particular milestone, it is work-in-progress towards getting things to build. There's a `@panic("TODO")` in translate-c that should be removed when working on translate-c stuff.
2021-02-10stage2: switch from inline fn to callconv(.Inline)Tadeo Kondrak
2021-02-09require specifier for arrayish typesJonathan Marler
2021-02-01Merge pull request #7827 from Snektron/spirv-setupAndrew Kelley
Stage 2: SPIR-V setup
2021-02-01stage2 cbe: implement switchbrVeikka Tuominen
2021-01-31stage2: delete astgen for switch expressionsAndrew Kelley
The astgen for switch expressions did not respect the ZIR rules of only referencing instructions that are in scope: %14 = block_comptime_flat({ %15 = block_comptime_flat({ %16 = const(TypedValue{ .ty = comptime_int, .val = 1}) }) %17 = block_comptime_flat({ %18 = const(TypedValue{ .ty = comptime_int, .val = 2}) }) }) %19 = block({ %20 = ref(%5) %21 = deref(%20) %22 = switchbr(%20, [%15, %17], { %15 => { %23 = const(TypedValue{ .ty = comptime_int, .val = 1}) %24 = store(%10, %23) %25 = const(TypedValue{ .ty = void, .val = {}}) %26 = break("label_19", %25) }, %17 => { %27 = const(TypedValue{ .ty = comptime_int, .val = 2}) %28 = store(%10, %27) %29 = const(TypedValue{ .ty = void, .val = {}}) %30 = break("label_19", %29) } }, { %31 = unreachable_safe() }, special_prong=else) }) In this snippet you can see that the comptime expr referenced %15 and %17 which are not in scope. There also was no test coverage for runtime switch expressions. Switch expressions will have to be re-introduced to follow these rules and with some test coverage. There is some usable code being deleted in this commit; it will be useful to reference when re-implementing switch later. A few more improvements to do while we're at it: * only use .ref result loc on switch target if any prongs obtain the payload with |*syntax| - this improvement should be done to if, while, and for as well. - this will remove the needless ref/deref instructions above * remove switchbr and add switch_block, which is both a block and a switch branch. - similarly we should remove loop and add loop_block. This commit introduces a "force_comptime" flag into the GenZIR scope. The main purpose of this will be to choose the "comptime" variants of certain key zir instructions, such as function calls and branches. We will be moving away from using the block_comptime_flat ZIR instruction, and eventually deleting it. This commit also contains miscellaneous fixes to this branch that bring it to the state of passing all the tests.
2021-01-31astgen: rework labeled blocksAndrew Kelley