9668 Commits

Author SHA1 Message Date
Veikka Tuominen
5404dcdfd8 Sema: fix fieldCallBind on tuples and anon structs
Closes #12573
2022-08-22 14:31:58 +03:00
Veikka Tuominen
560baf67ce Sema: fix implicit cast from extern fn to fn ptr
Closes #12570
2022-08-22 11:16:36 +03:00
Veikka Tuominen
b0bcd4add2 Sema: allow optional pointers in packed structs
Closes #12572
2022-08-22 11:16:36 +03:00
Veikka Tuominen
74c7782c60 Sema: make orelse with C pointers behave like stage1 for now
Closes #12537
2022-08-22 11:16:36 +03:00
Veikka Tuominen
c1afe57d70 Sema: resolve lazy values in resolveMaybeUndefValIntable
Closes #12512
Closes #12513
2022-08-22 11:16:36 +03:00
Veikka Tuominen
b55a5007fa Sema: fix parameter of type 'T' must be comptime error
Closes #12519
Closes #12505
2022-08-22 11:16:36 +03:00
Veikka Tuominen
b2f02a820f Sema: check for astgen failures in semaStructFields
The struct might be a top level struct in which case it might not have Zir.

Closes #12548
2022-08-22 11:16:36 +03:00
Jakub Konka
6c020cdb76
Merge pull request #12557 from Luukdegram/wasm-archive
wasm-linker: Improve archive linking
2022-08-22 08:38:41 +02:00
Veikka Tuominen
20d0018d79 Sema: ignore dbg_block instructions when checking for comptimeness
Closes #12514
2022-08-21 12:53:19 +03:00
Veikka Tuominen
d48af541c7 Sema: handle union and enum field order being different
Closes #12543
2022-08-21 12:51:40 +03:00
Veikka Tuominen
e8102d8738 Sema: add note about function call being comptime because of comptime only return type 2022-08-21 12:24:48 +03:00
Jakub Konka
4a98385b0a macho: do not leave file descriptors open if unused
This manifested in different `AccessDenied` errors on Windows when
trying to do an atomic file copying in the compiler/linker.
2022-08-20 19:41:23 +02:00
Luuk de Gram
1544625df3
wasm/Object: parse using the correct file size
When an object file is being parsed from within an archive
file, we provide the object file size to ensure we do not
read past the object file. This is because follow up object
files can exist there, as well as an LF character to notate
the end of the file was reached. Such a character is invalid
within the object file.

This also fixes a bug in getting the function/global type
for defined globals/functions from object files as it was missing
the substraction with the import count of the respective type.
2022-08-20 14:50:11 +02:00
Luuk de Gram
aca911ca18
wasm/archive: correctly parse long file names
Wasm archive files are encoded the same way as GNU.
This means that the header notates the character index within
the long file name list rather than the length of the name.
The entire name is then delimited by an LF character (0x0a).

This also makes a cosmetic update to remove the `self` name,
and rather label it as `archive` instead.
2022-08-20 14:50:08 +02:00
Andrew Kelley
437311756d LLVM: add DLL export attribute
This was present in stage1 but missing from self-hosted.
2022-08-19 16:45:16 -07:00
Andrew Kelley
507aae4a1a make self-hosted the default compiler
stage1 is available behind the -fstage1 flag.

closes #89
2022-08-19 16:45:15 -07:00
Andrew Kelley
73bbd1069a build: remove the option to omit stage2 2022-08-19 16:45:15 -07:00
r00ster91
39f43fea8d fix: fix off-by-one for leading zeroes 2022-08-20 01:45:34 +03:00
Andrew Kelley
fdb934a157 stage2: disable stack-protector on wasm, matching stage1
The CI gave me: unknown import: `env::__stack_chk_fail` has not been
defined
2022-08-19 03:41:13 -07:00
Andrew Kelley
d6ba66e50d Sema: avoid false positive error for linking libc
when extern c functions are called.
2022-08-19 03:41:13 -07:00
Andrew Kelley
c0b7f20893 stage2: implement stack protectors
This is one of the final remaining TODOs for the LLVM backend.
2022-08-19 03:41:13 -07:00
Andrew Kelley
150786e83c test harness: fix handling of object format
Follow-up to b975f7a56fec9e0e7aca9832282bc772c743d731.
2022-08-18 22:02:55 -07:00
Andrew Kelley
5e989fcb67 stage2: pointers to comptime-only types are comptime-only
This is a partial revert of c5ba941b77fbdb06841f28142420c6786f2a4d0c.
2022-08-18 22:02:10 -07:00
Andrew Kelley
cee82c7ce4 improved ABI alignment/size for >= 128-bit integers
* riscv64: adjust alignment and size of 128-bit integers.
 * take ofmt=c into account for ABI alignment of 128-bit integers and
   structs.
 * Type: make packed struct support intInfo
 * fix f80 alignment for i386-windows-msvc
2022-08-18 20:34:36 -07:00
Andrew Kelley
b975f7a56f std.Target gains ObjectFormat field 2022-08-18 18:58:28 -07:00
Andrew Kelley
517eb73b23 LLVM: disable the ABI size safety check
There still more instances of this check being tripped during behavior
tests that we need to fix before we can enable this.
2022-08-18 17:11:34 -07:00
Andrew Kelley
4552ccb685 stage2: make @Vector ABI size agree with LLVM 2022-08-18 17:11:34 -07:00
Andrew Kelley
6e313eb110 stage2: agree with LLVM that @alignOf(u128) is 8
on x86_64 and similar targets.
2022-08-18 17:11:32 -07:00
Andrew Kelley
c5ba941b77 stage2: all pointers have runtime bits 2022-08-18 16:02:29 -07:00
Jakub Konka
b12992cb01 macho: do not open file handle when building static archive
Firstly, opening a file handle is not really needed since we won't even
use it, and secondly, this can cause AccessDenied errors on Windows
when trying to move a directory from zig-cache/tmp/ to zig-cache/o/
since, without POSIX semantics, it is illegal to move directories
with open handles to any of its resources.
2022-08-18 15:54:09 -04: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
Loris Cro
2523b443a4
Merge pull request #12477 from der-teufel-programming/master
Autodoc: HTML files generation
2022-08-18 18:05:11 +02:00
Loris Cro
53e971226d autodoc: minor pr cleanup 2022-08-18 18:02:19 +02:00
Veikka Tuominen
b038dba06b
Merge pull request #12462 from Vexu/stage2-noreturn
Stage2: improve behavior of noreturn
2022-08-18 17:18:57 +03:00
Der Teufel
51a4861a08 Fixed Docgen.zig formatting 2022-08-18 15:44:42 +02:00
Der Teufel
f0bfdf9766 Fixed stage1 compilation error 2022-08-18 15:33:56 +02:00
Luuk de Gram
4f2143becc link/Wasm: improve symbol resolution
This adds additional checks during symbol resolution:
- Ensures function signatures match when a symbol will be replaced.
- Ensures global types match when the symbol is being replaced.
- When both symbols are undefined, ensures they have a matching module name.

Those changes ensure the result will pass the validator when
the runtime compiles the Wasm module.

Additionally, this also slightly changes the behavior when both
the existing symbol and new symbol are both defined. Rather than
always resulting in a collision, it only results in a collision
when both are also weak. Else, the non-weak symbol will be picked.
2022-08-18 14:17:01 +02:00
Luuk de Gram
63c25cc1cc wasm: fix callInstrinsic return value
Rather than storing it in a local and returning that,
we now keep this on the stack as all internal functions
expect it to be on the stack already and therefore were
generating extra `local.set` instructions.
2022-08-18 14:17:01 +02:00
der-teufel-programming
3ed9cdc1cc
Merge branch 'ziglang:master' into master 2022-08-18 14:10:47 +02:00
Der Teufel
656b9429d0 autodoc: An attempt at generating HTML files from all imported source
files. Files generated from the standard library could be considered
for placing with main.js and index.html in lib/docs. Paths should
reflect packages in the future.
2022-08-18 14:03:42 +02:00
Andrew Kelley
2cccd14491 fix typo in compile error message 2022-08-17 14:09:42 -07:00
Veikka Tuominen
59b6483d63 add test 2022-08-17 14:09:42 -07:00
Martin Hafskjold Thoresen
07f64a2e13 Sema: error on ambiguous coercion of comptime float and ints
The following, from the documentation as of the time of writing, illustrates
the problem:

```zig
// Compile time coercion of float to int
test "implicit cast to comptime_int" {
    var f: f32 = 54.0 / 5;
    _ = f;
}
```

It is not clear how to unify the types of 54.0 and 5 to perform the
division. We can either

 - cast 54.0 to comptime_int resulting in @as(comptime_int, 10), which is
   casted to @as(f32, 10), or
 - cast 5 to comptime_float resulting in @as(comptime_float, 10.8), which
   is casted to @as(f32, 10.8)

Since the two resulting values are different, a compiler error is appropriate.

If we know that casting to either type will result in the same value we
don't need to error.  For instance, 10.0 / 2 is okay, as is 10 / 2.0.

Fixes: #12364
2022-08-17 14:09:09 -07:00
Veikka Tuominen
233049503a Sema: allow empty enums and unions 2022-08-17 23:03:04 +03:00
Andrew Kelley
c764640e92 Sema: fix generics with struct literal coerced to tagged union
The `Value.eql` function has to test for value equality *as-if* the lhs
value parameter is coerced into the type of the rhs. For tagged unions,
there was a problematic case when the lhs was an anonymous struct,
because in such case the value is empty_struct_value and the type
contains all the value information. But the only type available in the
function was the rhs type.

So the fix involved making `Value.eqlAdvanced` also accept the lhs type,
and then enhancing the logic to handle the case of the `.anon_struct` tag.

closes #12418

Tests run locally:
 * test-behavior
 * test-cases
2022-08-17 13:02:57 -07:00
Veikka Tuominen
c3d5428cba Sema: properly handle noreturn fields in unions 2022-08-17 22:07:48 +03:00
Veikka Tuominen
b0a55e1b3b Sema: make noreturn error union behave correctly 2022-08-17 20:10:18 +03:00
Veikka Tuominen
db0f372da8 Sema: make optional noreturn behave correctly 2022-08-17 20:10:18 +03:00
Andrew Kelley
a12abc6d6c
Merge pull request #12456 from Vexu/stage2
Stage2 namespacing fixes
2022-08-16 19:57:22 -04:00
Veikka Tuominen
9d4561ef00 AstGen: detect declarations shadowing locals
Closes #9355
2022-08-16 20:35:03 +03:00