494 Commits

Author SHA1 Message Date
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
Meghan
02acde99a1 stage2: ensure 'std', 'builtin', and 'root' is always available to @import 2022-07-28 15:19:17 -07:00
Andrew Kelley
dfc7493dcb
Merge pull request #12256 from Vexu/stage2
stage2 typeInfo UAF fix + more
2022-07-27 16:11:07 -07:00
Veikka Tuominen
793db63746 Sema: copy fn param ty in zirTypeInfo
Closes #12247
2022-07-27 18:27:17 +03:00
LordMZTE
c6f5832bb6 Module: fix inverted condition 2022-07-27 18:17:07 +03:00
LordMZTE
8c4896fb3a Module: use path.isSep
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-07-27 18:17:07 +03:00
LordMZTE
1110eafe9b Module: fix error message importing file starting with root path 2022-07-27 18:17:07 +03:00
Veikka Tuominen
825fc654b6 Sema: better source location for builtin options 2022-07-26 12:14:59 +03:00
Veikka Tuominen
28478a4bac Module: improve handling of errors in @call arguments 2022-07-26 12:14:59 +03:00
Veikka Tuominen
2f34d06d01 Sema: analyzeInlineCallArg needs a block for the arg and the param 2022-07-25 22:04:08 +03:00
Andrew Kelley
93ae386f56 stage2: don't skip liveness or codegen if -femit-asm is supplied
Fixes Godbolt's CLI usage of Zig.
2022-07-24 15:02:05 -07: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
881c0cb20b Sema: add default value here note to invalid comptime field store error 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
821e4063f9 Sema: better source location for function call args 2022-07-21 12:21:30 -07:00
Veikka Tuominen
79ef0cdf30 Sema: better function parameter source location 2022-07-21 12:21:30 -07:00
Veikka Tuominen
83b2d2cd3e Sema: better source location for incompatible capture group 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
8feb398760 Sema: validate function parameter types and return type 2022-07-21 12:21:30 -07:00
Veikka Tuominen
d851b24180 Sema: validate function pointer alignment 2022-07-21 12:21:30 -07:00
Veikka Tuominen
76e7959a90 Sema: explain why comptime is needed 2022-07-21 12:21:30 -07:00
Veikka Tuominen
d729173204 stage2: better pointer source location 2022-07-21 12:21:30 -07:00
Veikka Tuominen
cf207df592 Module: improve source spans for initializers and var types
```zig
const U = union { foo: u32, bar: u32 };
test {
    var a = U{ .foo = 1213, .bar = 1123 };
    _ = a;
}
test {
    var a: (123 + 5238094) = 0;
    _ = a;
}
```

before:
```
:30: note: additional initializer here
    var a = U{ .foo = 1213, .bar = 1123 };
                             ^~~
:12: error: expected type 'type', found 'comptime_int'
    var a: (123 + 5238094) = 0;
           ^
```
after:
```
:30: note: additional initializer here
    var a = U{ .foo = 1213, .bar = 1123 };
                            ~^~~~~~~~~~
:12: error: expected type 'type', found 'comptime_int'
    var a: (123 + 5238094) = 0;
           ^~~~~~~~~~~~~~~
```
2022-07-15 16:06:16 +03:00
Veikka Tuominen
1463144fc8 Compilation: point caret in error message at the main token 2022-07-15 15:11:43 +03:00
Veikka Tuominen
b5a838247b stage2: point to error location using spans 2022-07-14 22:18:58 +03: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
Veikka Tuominen
2a3f3766a4 stage2: handle parser notes in a more general way 2022-07-12 12:50:59 +03:00
Veikka Tuominen
5d22204d2d parser: add helpful error for C style container declarations
```zig
// a.zig
struct Foo {
    a: u32,
};
```

before:
```
a.zig:1:1: error: expected test, comptime, var decl, or container field, found 'struct'
struct Foo {
^
```
after:
```
a.zig:1:8: error: 'struct Foo' is invalid
struct Foo {
       ^
a.zig:1:8: note: to declare a container do 'const Foo = struct'
struct Foo {
       ^
```
2022-07-12 12:50:59 +03:00
Veikka Tuominen
27ee414159 Sema: improve slice source locations 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
6cadac18b8 Sema: improve auto generated union enum name 2022-06-30 09:57:38 +02:00
Andrew Kelley
3b19869853 Sema: honor the --test-filter flag 2022-06-27 14:31:54 -07:00
Veikka Tuominen
0f820d0bdf stage2: improve debugging tools
llvm: dump failed module when -femit-llvm-ir set
print_air:
 * print fully qualified name
 * use Type.fmt and Value.fmtValue, fmtDebug is useless

TypedValue
 * handle anon structs and tuples
 * fix bugs
2022-06-11 11:02:56 +03:00
Andrew Kelley
2bf532fc23 stage2: use std.debug.Trace only when explicitly enabled
Because it bumps up the stack space requirements, which is making a test
case fail on aarch64 drone CI.
2022-06-09 20:00:59 -07:00
Andrew Kelley
af909f6c93 std.debug.Trace: improve API
Now `std.debug.Trace` is a concrete type with pre-chosen defaults.
`std.debug.ConfigurableTrace` can be used for more advanced cases.
2022-06-09 15:37:16 -07:00
Andrew Kelley
bac132bc8f introduce std.debug.Trace
And use it to debug a LazySrcLoc in stage2 that is set to a bogus value.

The actual fix in this commit is:

```diff
-        try sema.emitBackwardBranch(&child_block, call_src);
+        try sema.emitBackwardBranch(block, call_src);
```
2022-06-09 15:37:16 -07:00
Veikka Tuominen
14685e59b2 stage2: use correct type (u29) for alignment 2022-06-06 13:11:54 -07:00
Andrew Kelley
9da3a058d8 stage2: add missing data to ZIR encoding of functions
The main purpose of this commit is to prepare to implement support for
callconv(), align(), linksection(), and addrspace() annotations on
generic functions where the provided expression depends on comptime
parameters (making the function generic).

It's a rather involved change, so this commit only makes the necessary
changes to AstGen without regressing any behavior, and a follow-up
commit can finish the task by making the enhancements to Sema.

By my quick estimation, the new encoding for functions is a negligible
improvement - along the lines of 0.005% fewer total ZIR bytes on
average. Still, it's nice that this commit, while adding more
data into ZIR, actually ends up reducing the storage size thanks to a
slightly more sophisticated encoding.

Zir.Inst.ExtendedFunc is renamed to Zir.Inst.FuncFancy to eliminate
confusion about it being an extended instruction (it used to be but is
no longer). The encoding for this instruction is completely reworked.

The encoding for Zir.Inst.Func is also changed slightly - when the
return type body length is 1, then only a Zir.Inst.Ref is provided; not
a full body.

linksection() and addrspace() are now communicated via func_fancy ZIR
instruction rather than as part of the corresponding decl. This allows
their expressions to observe comptime parameters.
2022-05-30 12:03:53 -07:00
Ali Chraghi
0e6285c8fc math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
Andrew Kelley
ab88165326 Sema: generic function instantiations inherit branch quota 2022-05-25 23:32:52 -04:00
Andrew Kelley
818fbd9c56 stage2: string literal interning
This is a temporary addition to stage2 in order to match stage1 behavior,
however the end-game once the lang spec is settled will be to use a global
InternPool for comptime memoized objects, making this behavior consistent
across all types, not only string literals. Or, we might decide to not
guarantee string literals to have equal comptime pointers, in which case
this commit can be reverted.
2022-05-24 01:01:24 -07:00
Veikka Tuominen
e369752430 Sema: do not call returnError when returning payload of error union 2022-05-16 17:42:51 -07:00
Veikka Tuominen
eee8fffec7 stage2: implement error return traces 2022-05-16 17:42:51 -07:00
Andrew Kelley
ec95e00e28 flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.

 * stage2: fix cleanup bug when creating Module
 * flatten lib/std/special/* to lib/*
   - this was motivated by making main_pkg_is_inside_std false for
     compiler_rt & friends.
 * rename "mini libc" to "universal libc"
2022-05-06 22:41:00 -07:00
Andrew Kelley
3b60ab4872 stage2: fix std lib tests always filtering out all tests 2022-05-06 22:41:00 -07:00
Andrew Kelley
1b432b5576 stage2: implement global assembly
So far it's supported by the LLVM backend only. I recommend for the
other backends to wait for the resolution of #10761 before adding
support for this feature.
2022-05-04 20:38:53 -07:00
Veikka Tuominen
596f7df02e Zir: turn extended func into func_extended 2022-04-30 01:06:01 +03:00
Andrew Kelley
06310e3d4e Revert "Fix C include files not being in whole cache (#11365)"
This reverts commit a430630002bf02162ccbf8d3eb10fd73e490cefd.

Wait a minute, I'm sorry, I need to revert this. The whole premise
of this change is broken because the point of the hash is that it tells
whether the same compilation has been done before. This requires items
to be added to the hash in the same sequence every time. This means that
introducing a lock is fundamentally broken because the order needs to be
the same in future runs of the compiler, and not decided by threads
racing against each other.

The proper solution to this is to, in whole cache mode, append the hash
inputs to some data structure, and then after the compilation is
complete, do some kind of sorting on the hash inputs so that they will
be the same order every time, then apply them in sequence. No lock on
the Cache object is needed for this scheme.
2022-04-22 08:19:51 -07:00