Andrew Kelley
aeaef8c0ff
update std lib and compiler sources to new for loop syntax
2023-02-18 19:17:21 -07:00
Andrew Kelley
321ccbdc52
Sema: implement for_len
...
This also makes another breaking change to for loops: in order to
capture a pointer of an element, one must take the address of array
values. This simplifies a lot of things, and makes more sense than how
it was before semantically.
It is still legal to use a for loop on an array value if the
corresponding element capture is byval instead of byref.
2023-02-18 19:17:21 -07:00
Andrew Kelley
5029e5364c
make zig fmt perform upgrade to new for loop syntax
...
The intent here is to revert this commit after Zig 0.10.0 is released.
2023-02-18 19:17:21 -07:00
Andrew Kelley
293d6bdc73
AstGen: back to index-based for loops
2023-02-18 19:17:20 -07:00
Andrew Kelley
841add6890
AstGen: finish multi-object for loops
...
This strategy uses pointer arithmetic to iterate through the loop. This
has a problem, however, which is tuples. AstGen does not know whether a
given indexable is a tuple or can be iterated based on contiguous
memory. Tuples unlike other indexables cannot be represented as a
many-item pointer that is incremented as the loop counter.
So, after this commit, I will modify AstGen back closer to how @vexu had
it before, using a counter and array element access.
2023-02-18 19:17:20 -07:00
Andrew Kelley
faa44e2e58
AstGen: rework multi-object for loop
...
* Allow unbounded looping.
* Lower by incrementing raw pointers for each iterable rather than
incrementing a single index variable. This elides safety checks
without any analysis required thanks to the length assertion and
lowers to decent machine code even in debug builds.
- An "end" value is selected, prioritizing a counter if possible,
falling back to a runtime calculation of ptr+len on a slice input.
* Specialize on the pattern `0..`, avoiding an unnecessary subtraction
instruction being emitted.
* Add the `for_check_lens` ZIR instruction.
2023-02-18 19:17:20 -07:00
Veikka Tuominen
6733e43d87
AstGen: work-in-progress multi-object for loops
2023-02-18 19:17:20 -07:00
Veikka Tuominen
7199d7c777
split @qualCast into @constCast and @volatileCast
2023-02-15 01:43:57 +02:00
Veikka Tuominen
8127a27eb1
zig fmt: do not consider tuples blocks
...
Closes #14056
2023-02-11 14:36:54 +02:00
Veikka Tuominen
629c3108aa
AstGen: fix orelse type coercion in call arguments
...
Closes #14506
2023-02-02 00:31:35 +02:00
Veikka Tuominen
f16c10a86b
implement @qualCast
2023-01-30 18:55:57 +02:00
Veikka Tuominen
b129350cb5
AstGen: fix crash on invalid decltest
...
Closes #14476
2023-01-30 15:20:16 +02:00
Veikka Tuominen
14f03fbd16
AstGen: reset source cursor before generating pointer attributes
...
These attributes can appear in any order but AstGen expects the source
cursor to be incremented in a monotonically increasing order.
Closes #14332
2023-01-17 20:28:43 +02:00
Veikka Tuominen
1658e4893d
AstGen: add note pointing to tuple field
...
Closes #14188
2023-01-11 21:11:21 +02:00
Veikka Tuominen
83673a8b5f
fix errdefers in functions that can't return errors
...
This was broken by 58caed1c71
Closes #14053
2023-01-10 19:17:42 +02:00
Techatrix
1f8f79cd53
std: add helper functions to std.zig.Ast for extracting data out of nodes
2023-01-09 16:59:19 +02:00
Veikka Tuominen
f2faa303a5
Sema: handle enum expressions referencing local variables
...
Closes #12272
2023-01-05 22:03:32 +02:00
Veikka Tuominen
67316e2eab
AstGen: fix dbg_block_end being inserted before last instruction in block
...
Closes #14125
2022-12-30 17:00:50 +02:00
Veikka Tuominen
8a6295fcba
AstGen: make type sentinel expressions implicitly comptime
2022-12-29 12:43:02 +02:00
Veikka Tuominen
54160e7f6a
Sema: make overflow arithmetic builtins return tuples
2022-12-27 15:13:14 +02:00
Andrew Kelley
aca9c74e80
Merge pull request #13914 from Vexu/variadic
...
implement defining C variadic functions
2022-12-18 16:24:13 -05:00
r00ster91
aac2d6b56f
std.builtin: rename Type.UnionField and Type.StructField's field_type to type
2022-12-17 14:11:33 +01:00
Veikka Tuominen
9bb1104e37
implement defining C variadic functions
2022-12-17 13:22:09 +02:00
Veikka Tuominen
58caed1c71
Sema: make is_non_{null,err} stricter about types
...
Closes #13023
2022-12-17 13:22:09 +02:00
Veikka Tuominen
7b2a936173
remove stack option from @call
2022-12-13 12:52:21 +02:00
Veikka Tuominen
5831b68341
AstGen: add check for missing builtin argument
...
Closes #13817
2022-12-09 20:37:18 -07:00
Veikka Tuominen
92f1a29c40
AstGen: make @compileError operand implicitly comptime
...
This matches the language reference.
2022-12-07 14:48:24 +02:00
Veikka Tuominen
f20e449fd6
Sema: improve error for mismatched type in implicit return
...
Closes #2653
2022-12-03 00:48:03 +02:00
Veikka Tuominen
e2509ddbe6
AstGen: add error for invalid string comparisons
...
These operations are allowed because the string literals are just
pointers but they produce unexpected results. These errors prevent
beginners from shooting themselves in the foot while still allowing
advanced users to circumvent them if they desire to do so.
Closes #8290
2022-12-03 00:09:23 +02:00
Veikka Tuominen
86e6acb37b
AstGen: improve error message for missing parameter name
...
Closes #13393
2022-12-02 15:39:40 +02:00
Veikka Tuominen
f4afeb3ffd
AstGen: fix incorrect handling of source cursor with shift builtins
...
Closes #13714
2022-11-30 17:11:06 +02:00
Andrew Kelley
ceb0a632cf
std.mem.Allocator: allow shrink to fail
...
closes #13535
2022-11-29 23:30:38 -07:00
Veikka Tuominen
6f5a438946
AstGen: unstack block scope when creating opaque type
...
Closes #13697
2022-11-29 21:44:08 +02:00
Veikka Tuominen
304e828088
Merge pull request #13637 from Vexu/stage2-fixes
...
Stage2 bug fixes
2022-11-26 22:03:49 +02:00
Veikka Tuominen
fe38898246
Sema: pass c_import_buf to child block in more places
...
Closes #13651
2022-11-26 18:05:27 +02:00
Veikka Tuominen
8eea73fb92
add tests for tuple declarations
2022-11-23 22:16:31 +02:00
Veikka Tuominen
4cea15f12b
std.zig.Ast: simplify usage of tuple_like container fields
2022-11-23 12:13:39 +02:00
Veikka Tuominen
80575face7
AstGen: implement tuple declarations
2022-11-23 12:13:39 +02:00
Cody Tapscott
3fa226a80c
AstGen: Pop error trace for continue
...
PR #12837 handled control flow for break and return, but I forgot
about `continue`. This is effectively another break, so we just
need another `.restore_err_ret_index` ZIR instruction.
Resolves #13618 .
2022-11-22 14:00:41 +02:00
Stevie Hryciw
04f3067a79
run zig fmt on everything checked by CI
2022-11-18 19:22:42 +00:00
Stevie Hryciw
e999f9f472
std: replace parseAppend with parseWrite in std.zig.string_literal
2022-11-18 19:22:42 +00:00
Stevie Hryciw
ca9e1760e8
fmt: canonicalize identifiers
2022-11-18 19:22:42 +00:00
Veikka Tuominen
e01ec96288
Autodoc: not all block_inlines contain a break_inline
2022-11-11 18:01:14 +02:00
Veikka Tuominen
25c8506421
AstGen: emit dbg_stmt before (nearly) all operations that have a safety check
...
All implicit casts can also potentially lead to a panic being emitted
but adding a dbg_stmt before every instruction is not feasible.
This adds 24k new instructions to the ZIR for Sema.zig increasing its
size from 3.8MiB to 4.0MiB.
Closes #13488
2022-11-11 17:59:53 +02:00
Veikka Tuominen
0a188190b3
AstGen: make pointless discard error more strict
...
The error should only happen as a result of `_ = <expr>` not
for an operand of a break expression that is discarded.
Closes #13212
2022-11-11 17:59:53 +02:00
Veikka Tuominen
89e8bb409a
AstGen: use condbr_inline if force_comptime is set
...
The `finishThenElseBlock` would correctly use `break_inline`
which would cause Sema to use `addRuntimeBreak` instead of
doing the branch at comptime.
2022-11-11 17:59:53 +02:00
Veikka Tuominen
8c4faa5f3f
Merge pull request #13338 from Vexu/stage2-compile-errors
...
Improve some error messages
2022-11-04 16:04:31 +02:00
Jacob Young
5c3a486639
AstGen: avoid accessing value from inner scope
...
While continue expressions can access the capture, so ensure that it is
unwrapped in an outer scope.
2022-10-30 15:25:58 -04:00
Veikka Tuominen
5321afcf9c
stage2: make switch on corrupt value panic point to switch condition
...
Closes #13295
2022-10-29 14:55:43 +03:00
Veikka Tuominen
4ac8ec4c5c
AstGen: fix refing inferred allocs
...
Closes #13285
2022-10-27 01:31:18 +03:00