aboutsummaryrefslogtreecommitdiff
path: root/src/zir.zig
AgeCommit message (Collapse)Author
2020-12-31stage2: inferred local variablesAndrew Kelley
This patch introduces the following new things: Types: - inferred_alloc - This is a special value that tracks a set of types that have been stored to an inferred allocation. It does not support most of the normal type queries. However it does respond to `isConstPtr`, `ptrSize`, `zigTypeTag`, etc. - The payload for this type simply points to the corresponding Value payload. Values: - inferred_alloc - This is a special value that tracks a set of types that have been stored to an inferred allocation. It does not support any of the normal value queries. ZIR instructions: - store_to_inferred_ptr, - Same as `store` but the type of the value being stored will be used to infer the pointer type. - resolve_inferred_alloc - Each `store_to_inferred_ptr` puts the type of the stored value into a set, and then `resolve_inferred_alloc` triggers peer type resolution on the set. The operand is a `alloc_inferred` or `alloc_inferred_mut` instruction, which is the allocation that needs to have its type inferred. Changes to the C backend: * Implements the bitcast instruction. If the source and dest types are both pointers, uses a cast, otherwise uses memcpy. * Tests are run with -Wno-declaration-after-statement. Someday we can conform to this but not today. In ZIR form it looks like this: ```zir fn_body main { // unanalyzed %0 = dbg_stmt() =>%1 = alloc_inferred() %2 = declval_in_module(Decl(add)) %3 = deref(%2) %4 = param_type(%3, 0) %5 = const(TypedValue{ .ty = comptime_int, .val = 1}) %6 = as(%4, %5) %7 = param_type(%3, 1) %8 = const(TypedValue{ .ty = comptime_int, .val = 2}) %9 = as(%7, %8) %10 = call(%3, [%6, %9], modifier=auto) =>%11 = store_to_inferred_ptr(%1, %10) =>%12 = resolve_inferred_alloc(%1) %13 = dbg_stmt() %14 = ret_type() %15 = const(TypedValue{ .ty = comptime_int, .val = 3}) %16 = sub(%10, %15) %17 = as(%14, %16) %18 = return(%17) } // fn_body main ``` I have not played around with very many test cases yet. Some interesting ones that I want to look at before merging: ```zig var x = blk: { var y = foo(); y.a = 1; break :blk y; }; ``` In the above test case, x and y are supposed to alias. ```zig var x = if (bar()) blk: { var y = foo(); y.a = 1; break :blk y; } else blk: { var z = baz(); z.b = 1; break :blk z; }; ``` In the above test case, x, y, and z are supposed to alias. I also haven't tested with `var` instead of `const` yet.
2020-12-30stage2: rework Value Payload layoutAndrew Kelley
This is the same as the previous commit but for Value instead of Type. Add `Value.castTag` and note that it is preferable to call than `Value.cast`. This matches other abstractions in the codebase. Added a convenience function `Value.Tag.create` which really cleans up the callsites of creating `Value` objects. `Value` tags can now share payload types. This is in preparation for another improvement that I want to do.
2020-12-30stage2: rework Type Payload layoutAndrew Kelley
Add `Type.castTag` and note that it is preferable to call than `Type.cast`. This matches other abstractions in the codebase. Added a convenience function `Type.Tag.create` which really cleans up the callsites of creating `Type` objects. `Type` payloads can now share types. This is in preparation for another improvement that I want to do.
2020-12-28Revert "stage2: add compile log statement (#7191)"Andrew Kelley
The addition of `addDeclErr` introduced a memory leak at every call site, and I also would like to push back on having more than 1 compilation error per `Decl`. This reverts commit 1634d45f1d53c8d7bfefa56ab4d2fa4cc8218b6d.
2020-12-28stage2: make Alloc(Inferred) have mutabality info (#7570)g-w1
2020-12-26make compileError use an UnOp since its operand is just a *Instg-w1
2020-12-26add test for @compileError in zig code, not only zirg-w1
2020-12-26change zir definition to use *Inst instead of []const u8g-w1
2020-12-26stage2: add compile log statement (#7191)g-w1
2020-12-23Merge pull request #7507 from joachimschmidt557/stage2-armVeikka Tuominen
stage2 ARM: implement basic binary bitwise operations
2020-12-23stage2: @TypeOf (#7475)g-w1
* stage2: add @TypeOf * stage2: discriminate on what type of @builtinCall in nodeMayNeedMemoryLocation * merge upstream into my stash * add type equality to make easier to test and defer free the types * remove addDeclErr, I dont know why I added it, its from a different branch that im working on * add tests * update error message to match stage1 * use ComptimeStringMap and update which nodes don't need memory from vexu's suggestions * fix typo Co-authored-by: Veikka Tuominen <git@vexu.eu> * make @TypeOf(single_arg) go to .typeof zir inst and add test for that * unioninit, as, reduce change mayneedmemorylocation Co-authored-by: Veikka Tuominen <git@vexu.eu>
2020-12-21stage2 ARM: implement basic binary bitwise operationsjoachimschmidt557
2020-12-03stage2: make sure to emit the ZIR instructions of exported functionsTimon Kruiper
Previously the emitted ZIR code would not have the ZIR instructions of the exported functions.
2020-11-19Add builtin.Signedness, use it instead of is_signedTadeo Kondrak
2020-11-17stage2: initial container astgenVexu
2020-11-13stage2: add zir instructions for creating container typesVexu
2020-10-30stage2: switch liveness analysisVexu
2020-10-30stage2: switch comptime executionVexu
2020-10-30stage2: switch ranges and multi item prongsVexu
2020-10-30stage2: disallow switching on floatsVexu
2020-10-30stage2: redesign switchbrVexu
Switchbr now only handles single item prongs. Ranges and multi item prongs are checked with condbrs after the switchbr.
2020-10-30stage2: dump generated zir with --verbose-irVexu
2020-10-30stage2: switch emit zirVexu
2020-10-30stage2: basic switch analysisVexu
2020-10-30stage2: basic switch validationVexu
2020-10-30stage2: switch astgenVexu
2020-10-17std: remove renderStringLiteral in favor of std.fmt specifierVexu
2020-09-30stage2: add import builtin stubVexu
2020-09-21rename src-self-hosted/ to src/Andrew Kelley