Commit Graph

451 Commits

Author SHA1 Message Date
Veikka Tuominen 5e37da6ade Sema: check_comptime_control_flow needs to check runtime_index 2022-09-15 00:50:18 +03:00
Veikka Tuominen 349d78a443 validate number literals in AstGen 2022-09-13 20:26:04 -04:00
Andrew Kelley f16855b9d7 remove pointless discards 2022-09-12 18:13:24 -07:00
Veikka Tuominen e323cf1264 stage2: change how defers are stored in Zir
Storing defers this way has the benefits that the defer doesn't get
analyzed multiple times in AstGen, it takes up less space, and it
makes Sema aware of defers allowing for 'unreachable else prong'
error on error sets in generic code.

The disadvantage is that it is a bit more complex and errdefers with
payloads now emit a placeholder instruction (but those are rare).

Sema.zig before:
  Total ZIR bytes:    3.7794370651245117MiB
  Instructions:       238996 (2.051319122314453MiB)
  String Table Bytes: 89.2802734375KiB
  Extra Data Items:   430144 (1.640869140625MiB)
Sema.zig after:
  Total ZIR bytes:    3.3344192504882812MiB
  Instructions:       211829 (1.8181428909301758MiB)
  String Table Bytes: 89.2802734375KiB
  Extra Data Items:   374611 (1.4290275573730469MiB)
2022-09-12 01:52:44 -04:00
Veikka Tuominen 1c4c68e6ba AstGen: use reachableExpr for try operand
Closes #12248
2022-09-02 17:57:10 +03:00
Veikka Tuominen d3b4b2edf1 Sema: shift of comptime int with runtime value
Closes #12290
2022-08-30 12:22:07 -07:00
Veikka Tuominen fc213e2d61 AstGen: add error for named function type
Closes #12660
2022-08-28 15:41:21 +03:00
Andrew Kelley 7a881435ed Merge pull request #12623 from Vexu/stage2-fixes
Stage2 fixes
2022-08-24 15:59:46 -04:00
Veikka Tuominen d515d37934 AstGen: make root decls relative to beginning of file
Closes #12610
2022-08-24 15:26:49 +03:00
Veikka Tuominen 62ff8871ed stage2+stage1: remove type parameter from bit builtins
Closes #12529
Closes #12511
Closes #6835
2022-08-22 11:19:20 +03:00
zooster 4055e6055b AstGen: disallow leading zeroes in int literals and int types
This makes `0123` and `u0123` etc. illegal.

I'm now confident that this is a good change because
I actually caught two C header translation mistakes in `haiku.zig` with this.
Clearly, `0123` being octal in C (TIL) can cause confusion, and we make this easier to read by
requiring `0o` as the prefix and now also disallowing leading zeroes in integers.

For consistency and because it looks weird, we disallow it for integer types too (e.g. `u0123`).

Fixes #11963
Fixes #12417
2022-08-18 19:54:51 +03:00
Veikka Tuominen 233049503a Sema: allow empty enums and unions 2022-08-17 23:03:04 +03:00
Veikka Tuominen 9d4561ef00 AstGen: detect declarations shadowing locals
Closes #9355
2022-08-16 20:35:03 +03:00
Cody Tapscott 7e07f3d4f9 stage2 astgen: Use rl semantics for @Type
Resolves #12430.
2022-08-13 09:22:25 +03:00
Isaac Freund 0d32b73078 stage2: Implement explicit backing integers for packed structs
Now the backing integer of a packed struct type may be explicitly
specified with e.g. `packed struct(u32) { ... }`.
2022-08-10 19:54:45 +02:00
Veikka Tuominen 0fd90749d1 stage2: generate call arguments in separate blocks 2022-08-09 16:19:55 +03:00
Andrew Kelley 85a3f9b054 Merge pull request #12383 from ziglang/stage2-stack-traces
several improvements to error return tracing in the self-hosted compiler
2022-08-09 02:11:58 -07:00
Veikka Tuominen c76b5c1a31 stage2: correct node offset of nested declarations 2022-08-09 11:59:10 +03:00
Andrew Kelley feb90f6ed4 AstGen: emit debug stmt for try
This improves the following test case:

```zig
pub fn main() !void {
    try foo();
}

fn foo() !void {
    return error.Bad;
}
```

The error return trace now points to the `try` token instead of pointing
to the foo() function call, matching stage1.

Closes #12308.
2022-08-08 21:12:04 -07:00
Andrew Kelley 0648177ed7 AstGen: avoid multiple dbg_stmt instructions in a row
This is purely an optimization to emit fewer ZIR instructions.
2022-08-08 20:43:05 -07:00
Andrew Kelley 3389890709 stage2: error return tracing handles ret better
Sema: insert an error return trace frame when appropriate when analyzing
ret_load. Also optimize the instructions to avoid an unnecessary block
sent to the backends.

AstGen: always emit a dbg_stmt for return expressions, in between the
defer instructions and the return instruction.

This improves the following test case:

```zig
pub fn main() !void {
    return foo();
}

fn foo() !void {
    return error.Bad;
}
```

The error return trace now points to the return token instead of
pointing to the foo() function call, matching stage1.
2022-08-08 20:43:05 -07:00
Veikka Tuominen d769fd0102 stage2: pass anon name strategy to reify 2022-08-08 18:28:39 -07:00
Veikka Tuominen 3e2defd36c stage2: add a helpful error for when async is used 2022-08-06 14:51:20 -07:00
Veikka Tuominen b79929b2ea AstGen: better source location for if/while condition unwrapping 2022-08-03 16:45:33 +03:00
Veikka Tuominen d1d24b426d AstGen: check loop bodies and else branches for unused result 2022-08-03 16:45:33 +03:00
Veikka Tuominen 02112f8836 AstGen: add error for break/continue out of defer expression 2022-08-03 16:45:33 +03:00
Veikka Tuominen f1768b40b2 stage2: better source location for var decls 2022-08-01 23:37:01 +03:00
Veikka Tuominen fdaf9c40d6 stage2: handle tuple init edge cases 2022-07-29 10:12:36 +03:00
Veikka Tuominen 9e0a930ce3 stage2: add error for comptime control flow in runtime block 2022-07-29 10:08:35 +03:00
Andrew Kelley 6a4df2778e AstGen: fix ref instruction injection for functions
For the expressions regarding return type, alignment,
parameter type, etc.
2022-07-27 16:19:23 -07:00
Veikka Tuominen e4a36a4cec AstGen: add dbg_stmts for unreachable and @panic
Closes #12249
2022-07-27 17:11:46 +03:00
Veikka Tuominen a463dc7d6c AstGen: disable null bytes and empty stings in some places
Namely:
 * test names
 * identifiers
 * library names
 * import strings
2022-07-26 12:14:59 +03:00
Meghan dea437edfb stage2: implement noinline fn 2022-07-24 11:56:33 +03:00
Veikka Tuominen 2436dd2c1b Sema: validate duplicate fields in anon structs 2022-07-23 15:40:12 +03:00
Veikka Tuominen 15dddfd84d AstGen: make comptime fields in packed and extern structs compile errors 2022-07-23 15:40:12 +03:00
Veikka Tuominen ff7ec4efb5 Sema: bad union field access safety 2022-07-23 15:40:11 +03:00
Veikka Tuominen 4d20d6874c move passing safety tests to stage2 2022-07-23 15:40:11 +03:00
Veikka Tuominen 9fb8d21a01 AstGen: add error for fields in opaque types 2022-07-21 12:21:30 -07:00
Veikka Tuominen 1705a21f80 Sema: more union and enum tag type validation 2022-07-21 12:21:30 -07:00
Veikka Tuominen d729173204 stage2: better pointer source location 2022-07-21 12:21:30 -07:00
Andrew Kelley fad95741db AstGen: fix loop control flow applying to wrong loop
In the case of 'continue' or 'break' inside the 'else' block of a
'while' or 'for' loop.

Closes #12109
2022-07-13 16:10:41 -07:00
Andrew Kelley 4a28c1d5c3 stage2: lower each struct field type, align, init separately
Previously, struct types, alignment values, and initialization
expressions were all lowered into the same ZIR body, which caused false
positive "depends on itself" errors when the initialization expression
depended on the size of the struct.

This also uses ResultLoc.coerced_ty for struct field alignment and
initialization values. The resulting ZIR encoding ends up being roughly
the same, neither smaller nor larger than previously.

Closes #12029
2022-07-13 02:38:13 -04:00
Andrew Kelley 0c78ece1c9 Merge pull request #12016 from Vexu/stage2-compile-errors
Stage2 compile error improvements
2022-07-07 14:52:28 -04:00
emma 81bbefe9b8 AstGen: fix catch payoad not checking for shadowing 2022-07-07 21:38:32 +03:00
Veikka Tuominen 5007f727e5 stage2: move C pointer allowzero error to AstGen 2022-07-07 10:50:06 +03:00
Veikka Tuominen b5ac2b4330 Sema: improve array source location 2022-07-07 10:50:06 +03:00
Veikka Tuominen 2ca752ea1a Module: add .node_offset_un_op 2022-07-07 10:50:06 +03:00
Veikka Tuominen 299836dbd9 Sema: panic at comptime + misc error message improvements 2022-07-07 10:50:05 +03:00
Veikka Tuominen 252388eb28 AstGen: move error_to_int, int_to_error and select to extended 2022-07-07 10:45:45 +03:00
Veikka Tuominen 2029601cb2 AstGen: use elem_{ptr,val}_node for array access syntax 2022-07-01 10:22:26 +03:00