Commit Graph

9653 Commits

Author SHA1 Message Date
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 b975f7a56f.
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 c5ba941b77.
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
Loris Cro 7f7d58ee89 Merge branch 'master' into autodoc-links 2022-08-16 16:52:26 +02:00
Veikka Tuominen c17793b487 Sema: ignore current declaration in ambiguous reference error
Closes #12429
2022-08-16 16:37:27 +03:00
Loris Cro b3922289be Zir: add missing support for packed ints in declIterator 2022-08-15 21:57:33 +02:00
sin-ack a9c4dc84f4 Sema: Revert sema.err to null if the Decl already has an error
Previously we would assign the error message to Sema and then never
clear it even when destroying the error message, which caused memory
corruption.

Closes #12437
2022-08-15 11:34:12 +03:00
Veikka Tuominen 40eac90280 Merge pull request #12416 from Vexu/stage2-safety
Stage2 error set safety improvements
2022-08-15 11:32:26 +03:00
LeRoyce Pearson cb901e578c stage2: add compile errors for comptime @shrExact and @divExact failures 2022-08-15 11:28:42 +03:00
joachimschmidt557 c9d9fd53a6 stage2 ARM: add inline memcpy to genSetStack 2022-08-13 17:00:03 +02:00
joachimschmidt557 91969ad908 stage2 ARM: Fix tracking of function return values 2022-08-13 17:00:03 +02:00
joachimschmidt557 4c5156544b stage2 ARM: pass stack arguments in opposite order
Earlier arguments have a smaller address (i.e. towards the bottom of
the stack)
2022-08-13 17:00:00 +02:00
Cody Tapscott 7e07f3d4f9 stage2 astgen: Use rl semantics for @Type
Resolves #12430.
2022-08-13 09:22:25 +03:00
Jakub Konka aeaffd42f6 x86: fix generating debug info for variables
Add handling for these additional `MCValue`s:
* `.immediate` - lower to `DW.OP.consts` or `DW.OP.constu` depending
  on signedness followed by popping off the DWARF stack with
  `DW.OP.stack_value`
* `.undef` - lower to `DW.OP.implicit_value`
* `.none` - lower to `DW.OP.lit0` followed by popping off the DWARF
  stack with `DW.OP.stack_value`

For any remaining unhandled case, we generate `DW.OP.nop` in order
not to mess up remaining DWARF info.
2022-08-12 12:05:34 +02:00
Jakub Konka f2f1bb7cb6 macho: update __DWARF sections before and after writing out __LINKEDIT 2022-08-12 11:50:39 +02:00
martinhath 92568a0097 Sema: add error for signed integer division
stage1 error reads

error: division with 'i32' and 'comptime_int': signed integers must use @divTrunc, @divFloor, or @divExact

Fixes: #12339
2022-08-12 11:45:11 +03:00
Veikka Tuominen 09f273136c stage2: check for zero in @intToError safety 2022-08-12 11:41:09 +03:00
Veikka Tuominen 7c9979a02e stage2: generate a switch for @errSetCast safety 2022-08-12 11:40:37 +03:00