Commit Graph
1440 Commits
Author SHA1 Message Date
Andrew Kelley 40c4c25e2b Sema: add missing coercion when checking for loop len 2023-02-18 19:20:19 -07:00
Andrew Kelley 12a7a0d76f omit safety check when incrementing for loop counter
Since for loops are statically analyzed to have an upper bound, and the
loop counter is a usize, it is impossible for it to overflow.
2023-02-18 19:20:19 -07:00
Andrew Kelley 8b05205bb7 implement error for unbounded for loops 2023-02-18 19:20:19 -07:00
Andrew Kelley 74db8c2e83 omit safety checks for element access in for loops
One of the main points of for loops is that you can safety check the
length once, before entering the loop, and then safely assume that every
element inside the loop is in bounds.

In master branch, the safety checks are incorrectly intact even inside
for loops. This commit fixes it. It's especially nice with multi-object
loops because the number of elided checks is N * M where N is how many
iterations and M is how many objects.
2023-02-18 19:20:19 -07:00
Andrew Kelley 4dd958d585 improve error message for byref capture of byval array 2023-02-18 19:20:19 -07:00
Andrew Kelley 601db3981c fix source location for not-indexable for loop errors 2023-02-18 19:20:19 -07:00
Andrew Kelley 22965e6fcb Sema: improve error message for mismatched for loop lengths 2023-02-18 19:17:21 -07:00
Andrew Kelley f2a6a1756b Sema: fix for loops with comptime-known int ranges 2023-02-18 19:17:21 -07:00
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 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 7199d7c777 split @qualCast into @constCast and @volatileCast 2023-02-15 01:43:57 +02:00
Veikka Tuominen 28413ffcba Sema: fix typo in zirCUndef
Closes #14617
2023-02-11 14:36:54 +02:00
Veikka Tuominen 31ed8d293d Sema: add missing peer type resolution for error unions
Closes #14077
2023-02-11 14:36:54 +02:00
Veikka Tuominen b9c2837c1c Sema: validate inferred error set payload type
This was missed in b0a55e1b3b
2023-02-11 14:36:54 +02:00
Andrew Kelley 6b7ad22981 Merge pull request #14477 from Vexu/fixes
Improve `@ptrCast` errors, fix some bugs
2023-02-01 23:31:52 -05:00
Jakub Konka 304420b99c Merge pull request #14502 from ziglang/link-owned-atoms
link: move ownership of linker atom from frontend to the linkers
2023-02-02 01:39:01 +01:00
Veikka Tuominen 490addde27 Sema: fix error location on comptime arg to typed generic param
Closes #14505
2023-02-01 20:50:43 +02:00
Jakub Konka beb20d29db link: remove union types which are now internal to backends 2023-02-01 19:32:54 +01:00
Luuk de Gram 46f54b23ae link: make Wasm atoms fully owned by the linker 2023-02-01 19:10:56 +01:00
Jakub Konka b3277c8936 link: make Plan9 atoms fully owned by the linker 2023-02-01 11:12:53 +01:00
Andrew Kelley 2f5892671e move compiler's CType logic to std.Target
This API only depends on std.Target and is extremely useful in build
scripts when populating configure files.
2023-01-31 15:09:35 -07:00
Jakub Konka c430e9afa7 link: make Coff atoms fully owned by the linker 2023-01-31 20:27:17 +01:00
Jakub Konka 4404c4d200 link: make Elf atoms fully owned by the linker 2023-01-31 17:54:12 +01:00
r00ster91 17404f8e6e Sema: emit compile error for comptime or inline call of function pointer 2023-01-31 17:15:34 +02:00
Jakub Konka d42a931051 link: make MachO atoms fully owned by the linker 2023-01-31 00:43:25 +01:00
Veikka Tuominen f16c10a86b implement @qualCast 2023-01-30 18:55:57 +02:00
Veikka Tuominen fe4ea31f7e Sema: replace backticks with single quotes
Most error messages already use single quotes for everything
so this makes the remaining ones consistent.
2023-01-30 15:20:16 +02:00
Veikka Tuominen a9785fe8ee Sema: add helpful notes to invalid @ptrCast operations
Closes #14474
2023-01-30 15:20:16 +02:00
Veikka Tuominen 720d82721f Sema: ensure args to inline comptime args are comptime-known
Closes #14413
2023-01-30 15:20:16 +02:00
Jakub Konka a898729139 self-hosted: remove allocateDeclIndexes from the public link.File API 2023-01-27 19:51:06 +01:00
mlugg 6d71d79dc2 Package: store package name directly
By @Vexu's suggestion, since fetching the name from the parent package
is error-prone and complex, and optimising Package for size isn't really
a priority.
2023-01-22 19:00:03 +00:00
Veikka Tuominen a28fbf3132 Sema: fix error message for bad pointer arithmetic
Closes #14388
2023-01-22 01:04:20 +02:00
Veikka Tuominen 1f475de852 Sema: fix unwrapping null when reporting error on member access
Closes #14399
2023-01-22 01:04:20 +02:00
Veikka Tuominen 5259d11e3b Sema: resolve fields before checking tuple len
Closes #14400
2023-01-22 00:12:37 +02:00
Veikka Tuominen 5f5ab49168 Value: implement compareAllWithZero for bytes and str_lit
Closes #10692
2023-01-22 00:12:37 +02:00
Veikka Tuominen d284c00fda Sema: handle lazy values in more places
* resolve lazy values in anon structs being passed to anytype params
* use `resolveMaybeUndefValIntable` where appropriate

Closes #14356
2023-01-22 00:12:36 +02:00
Veikka Tuominen fc066992d9 Sema: do not create slices with undefined pointers
The undef pointer ended up being zero on wasm32.
2023-01-17 20:28:43 +02:00
Veikka Tuominen 3b2c421102 Sema: fix bad boolean logic for cast to null panic
Closes #14349
2023-01-17 20:28:43 +02:00
Veikka Tuominen e04547642a Sema: promote smaller float types passed to variadic functions
Closes #6854
2023-01-17 20:28:43 +02:00
Veikka Tuominen 8b35f09f4a Sema: resolve lazy values in switch prong items
Closes #14330
2023-01-17 20:28:43 +02:00
Veikka Tuominen 6b037bad59 Sema: ignore dependency loops in typeinfo decls
This matches stage1 behavior.

Closes #14322
2023-01-17 20:28:43 +02:00
Veikka Tuominen 342bae02d8 Sema: automatically optimize order of struct fields
This is a simple starting version of the optimization described in #168
where the fields are just sorted by order of descending alignment.
2023-01-16 19:46:41 +02:00
Veikka Tuominen d8128c272a Sema: fix typeInfo decls with usingnamespace
Closes #12403
2023-01-11 21:11:21 +02:00
Veikka Tuominen 8b1780d939 Sema: fix condition for omitting comptime arg from function type
Closes #14164
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
Veikka Tuominen fd6b79e67f Sema: restore status on layout resolution failure
`resolveTypeFields` and `resolveTypeFully` already do this.

Closes #14059
2023-01-10 18:38:44 +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