13439 Commits

Author SHA1 Message Date
Andrew Kelley
fbfae832ea AstGen: emit nosuspend function calls
Inside a nosuspend block, emit function calls as nosuspend calls.
Also inside a comptime block, emit function calls as comptime calls.
Also emit `async foo()` calls as async calls.

Remove compile error for `nosuspend` block inside `suspend` block.
Instead of implicitly treating every `suspend` block also as a
`nosuspend` block (which would make sense), we leave suspension points
as compile errors, to hint to the programmer about accidents. Of course
they may then assert `nosuspend` by introducing a block within their
suspend block.

To make room in `Zir.Inst.Tag` I moved `typeof_peer` and `compile_log`
to `Extended`.
2021-04-23 21:12:29 -07:00
Andrew Kelley
49be88859d AstGen: implement nosuspend expressions
Also implement ZIR error notes
2021-04-23 20:31:12 -07:00
Andrew Kelley
9a271347fe AstGen: implement suspend blocks 2021-04-23 20:09:56 -07:00
Andrew Kelley
b40a8efb9a stage2: implement anyframe, anyframe->T and fix assembly
* AstGen: implement `anyframe_literal` and `anyframe_type`.
 * Introduce `makeSubBlock` to avoid redundant AstGen code for GenZir
   scopes. Allows adding/removing a field without possibility of
   accidentally introducing a bug of forgetting to set the new field.
 * Add to GenZir `nosuspend_node` and `suspend_node` in preparation for
   implementing `suspend` blocks and `nosuspend` blocks.
 * AstGen: fix assembly to support clobbers, multiple outputs, and
   outputs without `->` syntax.
   - `asm` and `asm_volatile` move to `Extended` enum with `small` being
     repurposed for a few things. This frees up 2 ZIR tags, 1 of which
     is used in this commit and 1 is leftover.
 * AstGen: fix `simple_types` incorrectly having multiple conflicting
   values for "undefined" and "null".
   - Also add "anyframe" to `simple_types`.
 * Add `anyframe_type` to type.zig, value.zig and `Zir.Inst.Ref`.
   - Also add i128 and u128 types to `Zir.Inst.Ref` and `simple_types`.
 * Sema/Zir: Fix incorrect math causing the function body to be messed
   up for Extended-encoded functions.
 * Zir: support `i32` fields for "extra" payloads.
2021-04-23 18:35:21 -07:00
Andrew Kelley
183ee0965f AstGen: compile error for unable to infer array size 2021-04-23 11:14:11 -07:00
Andrew Kelley
0262dda9b8 std: remove comptime const 2021-04-22 23:52:52 -07:00
Andrew Kelley
715abe8ebe AstGen: implement integers bigger than u64
also get rid of the `optional_type_from_ptr_elem` instruction.
2021-04-22 23:47:31 -07:00
Andrew Kelley
2d290d6f82 stage2: write out builtin.zig before spawning AstGen tasks
Otherwise it's possible for AstGen to get FileNotFound when trying to
eager-load `import("builtin")`.
2021-04-22 22:35:18 -07:00
Andrew Kelley
a830ebe718 ZIR: fix text printing of field_ptr_type
Thanks @g-w1
2021-04-22 22:18:53 -07:00
Andrew Kelley
8df4bb7c96 stage2: fix builtin.zig for zig test 2021-04-22 19:48:12 -07:00
jacob gw
ce41ddcd23 std: fix potential bug in parseInt 2021-04-22 22:42:46 -04:00
Andrew Kelley
93d1c2d6d4 std: fix compile errors caught by stage2 AstGen
Follow-up from 507a8096d2f9624bafaf963c3e189a477ef6b7bf
2021-04-22 19:32:57 -07:00
Andrew Kelley
8dd7378013 delete packed enums from the language
No need for any such thing. Instead, provide an integer tag type for the
enum.
2021-04-22 19:21:50 -07:00
Andrew Kelley
329a359974 AstGen: implement align and linksection on globals 2021-04-22 19:21:33 -07:00
Andrew Kelley
507a8096d2 std: fix compile errors caught by stage2 AstGen
* `comptime const` is redundant
 * don't use `extern enum`; specify a tag type.
   `extern enum` is only when you need tags to alias. But aliasing tags
   is a smell. I will be making a proposal shortly to remove `extern enum`
   from the language.
 * there is no such thing as `packed enum`.
 * instead of `catch |_|`, omit the capture entirely.
 * unused function definition with missing parameter name
 * using `try` outside of a function or test
2021-04-22 18:07:46 -07:00
Andrew Kelley
7c453b91b8 AstGen: implement @extern builtin 2021-04-22 16:31:51 -07:00
Andrew Kelley
3d637e6dd2 AstGen: fix @export
Make it properly use `std.builtin.ExportOptions`.
2021-04-22 16:07:58 -07:00
Andrew Kelley
130ad08001 AstGen: implement function prototypes 2021-04-22 14:24:22 -07:00
Andrew Kelley
389020009a AstGen: implement alignment on locals 2021-04-21 22:43:57 -07:00
Andrew Kelley
ea00ddfe37 AstGen: implement comptime locals 2021-04-21 20:42:49 -07:00
Andrew Kelley
8ee0cbe50a AstGen: fix switch result location elision
It was eliding wrong instructions for nested break from labeled block
2021-04-21 19:49:58 -07:00
Andrew Kelley
570ed7b3bf AstGen: implement @bitCast for other result location types 2021-04-21 19:11:36 -07:00
Andrew Kelley
4cfea2fbd5 AstGen: fix @floatCast having wrong arity
It's not time for #5909 yet.
2021-04-21 19:10:54 -07:00
Andrew Kelley
d10ec6e70d AstGen: slightly better eager-allocating heuristic
Some early ensureCapacity calls to avoid needless reallocations.
2021-04-20 22:16:45 -07:00
Andrew Kelley
a1ac2b95bb AstGen: implement union decls 2021-04-20 21:48:18 -07:00
Andrew Kelley
971f3d95f9 AstGen: implement size zero inferred length arrays 2021-04-20 18:32:43 -07:00
Andrew Kelley
c69a95f64b AstGen: fix store_to_block_ptr elision for switch statements
to make sure it matches the expected block
2021-04-20 17:58:04 -07:00
Andrew Kelley
a008fb0a71 std.fs: delete unused label
stage2 starting to catch problems with the standard library :)
2021-04-20 17:57:35 -07:00
Andrew Kelley
e9477048e5 AstGen: implement for loop payload 2021-04-20 17:52:35 -07:00
Andrew Kelley
30c9808391 AstGen: implement anytype parameters 2021-04-20 17:38:06 -07:00
Andrew Kelley
a62db38d90 AstGen: implement defer for break 2021-04-20 17:04:11 -07:00
Andrew Kelley
458c4b6fc6 AstGen: implement defer for continue 2021-04-20 17:04:11 -07:00
Andrew Kelley
a59bcae59f AstGen: basic defer implementation 2021-04-20 17:04:11 -07:00
jacob gw
b4aec0e31d stage2: make std.fmt.parseInt ignore _ 2021-04-20 17:08:05 -04:00
jacob gw
6b944492b5 stage2: fix compile error in codegen 2021-04-20 17:08:05 -04:00
Andrew Kelley
b4baa9eda2 AstGen: try fixups
Primarily this required fixing `setCondBrPayloadElideBlockStorePtr` to
not assume there would always be two `store_to_block_ptr` instructions
in each of the condbr prongs.
2021-04-20 11:16:50 -07:00
jacob gw
ee3c1c763c stage2: astgen try 2021-04-20 13:16:08 -04:00
Andrew Kelley
e315120b79 AstGen: implement array initialization expressions 2021-04-19 23:23:24 -07:00
Andrew Kelley
693dbeeef2 stage2: make @alignCast accept 2 parameters
It is not yet time to implement #5909.
2021-04-19 18:46:45 -07:00
Andrew Kelley
4630e3891c AstGen: implement inline asm output 2021-04-19 18:44:59 -07:00
Andrew Kelley
a136c093bf zig astgen: print instruction counts and byte sizes 2021-04-19 16:23:05 -07:00
Andrew Kelley
7f931a7522 AstGen: implement error set decls 2021-04-19 16:03:46 -07:00
Andrew Kelley
2083208f19 AstGen: implement functions with inferred error sets
This commit also reclaims +2 ZIR instruction tags by moving the
following to `extended`:
 * func_var_args
 * func_extra
 * func_extra_var_args
The following ZIR instruction tag is added:
 * func_inferred
2021-04-19 15:03:41 -07:00
Andrew Kelley
22015c1b3b std.MultiArrayList: ensureUnusedCapacity/ensureTotalCapacity
Same as c8ae581fef6506a8234cdba1355ba7f0f449031a, but for
MultiArrayList.
2021-04-19 15:02:37 -07:00
Andrew Kelley
27d4bea9a4 AstGen: implement if optional, if error union 2021-04-19 12:25:16 -07:00
Andrew Kelley
3dadccec45 AstGen: implement while optional and while error union 2021-04-19 12:02:11 -07:00
Andrew Kelley
3f60481be4 AstGen: implement the remaining struct init ResultLoc forms 2021-04-19 11:09:00 -07:00
Andrew Kelley
ae495de54d AstGen: implement all the builtin functions 2021-04-18 22:38:41 -07:00
Andrew Kelley
5a3045b5de AstGen: implement overflow arithmetic builtins 2021-04-17 13:00:10 -07:00
Andrew Kelley
8cf0ef2779 AstGen: implement simple enums and decls for enums 2021-04-16 22:21:26 -07:00