Commit Graph

16623 Commits

Author SHA1 Message Date
Andrew Kelley
68fc26cd08 std: break up some long lines
This makes packaging Zig for Debian slightly easier since it will no
longer trigger a Lintian warning for long lines.
2022-01-28 16:23:47 -07:00
joachimschmidt557
1a324a8ad6 stage2 regalloc: Fix bug where regs were not marked as allocated 2022-01-28 18:03:03 -05:00
Andrew Kelley
d7deffee8d link: ELF, COFF, WASM: honor the "must_link" flag of positionals
Previously only the MachO linker was honoring the flag.
2022-01-28 12:18:53 -07:00
Andrew Kelley
0e6d2184ca stage2: .stub files are yet another c++ source file extension
however .cu files are a superset of c++.
2022-01-27 13:39:28 -07:00
Andrew Kelley
f589a66062 stage2: make cuda file extensions a separate enum tag than c++
follow-up to 2f41bd3be4.
2022-01-27 13:29:32 -07:00
Vesim
8c90b05add fchown: use the 32-bit uid/gid variant of the syscall on 32-bit linux targets 2022-01-27 20:27:16 +02:00
praschke
6d1b1374f7 docs: reorganize @truncate and @intCast for clarity 2022-01-27 19:51:17 +02:00
vnc5
1adb6440db fix startup procedure for async WinMain 2022-01-27 19:49:12 +02:00
David John
80ac022c46 add std.debug.todo 2022-01-27 19:42:40 +02:00
Philipp Lühmann
db1edb6535 fix precedence in langref or example 2022-01-27 19:39:35 +02:00
John Schmidt
997600ac6f Preserve alignment when cloning 2022-01-27 19:35:08 +02:00
John Schmidt
f04007028f Implement clone with initCapacity and appendSliceAssumeCapacity
`ArrayList.ensureTotalCapacityPrecise` uses `Allocator.reallocAtLeast` under
the hood, which can return more than `new_capacity` bytes if `alignment
!= @alignOf(T)`. This implementation of `clone` assures that
the case of `ensureTotalCapacityPrecise` is handled correctly.

Thanks @Vexu and @squeek502 for pointing this out.
2022-01-27 19:35:08 +02:00
John Schmidt
d86b8663fc Use expectEqualSlices instead of loop 2022-01-27 19:35:08 +02:00
John Schmidt
da8e8b89e0 Set len on copied items array
Also fix the argument order for `expectEquals`.
2022-01-27 19:35:08 +02:00
John Schmidt
554734f9f8 Add ArrayList.clone
This is a common operation and matches the API on other stdlib
collections like HashMap and MultiArrayList.
2022-01-27 19:35:08 +02:00
Exonorid
3e6952ad16 Added documentation for implicit struct pointer dereferencing 2022-01-27 19:33:07 +02:00
Daniel Saier
2f41bd3be4 zig cc: Treat cu files as C++ source files
First step towards #10634.

Treating stub files as C++ allows to use zig c++ as a host
compiler for nvcc.

Treating cu files as C++ allow using zig c++ as a host compiler in
CMake. CMake calls the host compiler with -E on a cu file to identify
the compiler.

Using zig c++ to directly compile CUDA code is untested.
2022-01-27 19:23:55 +02:00
Andrew Kelley
35423b0054 organize behavior tests
check the set of passing tests; move towards the disabling logic being
inside each test rather than which files are included.

this enables a few more passing tests.
2022-01-26 20:59:20 -07:00
Andrew Kelley
82bd0ac572 Sema: implement struct init is_ref=true
Takes advantage of the pattern already established with
array_init_anon. Also upgrades array_init (non-anon) to the pattern.

Implements comptime struct value equality and pointer value hashing.
2022-01-26 20:02:01 -07:00
Andrew Kelley
db55f469c1 std.mem.Allocator: upgrade to new function pointer semantics 2022-01-26 20:02:01 -07:00
Andrew Kelley
50accb757f stage2: fix crash on file-level struct field source locations 2022-01-26 20:02:01 -07:00
Andrew Kelley
b463924da2
Merge pull request #10699 from motiejus/arm64
[linux headers] rename arm64 to aarch64
2022-01-26 20:51:59 -05:00
Andrew Kelley
40c9ce2caf zig cc: add --hash-style linker parameter
This is only relevant for ELF files.

I also fixed a bug where passing a zig source file to `zig cc` would
incorrectly punt to clang because it thought there were no positional
arguments.
2022-01-26 15:01:59 -07:00
joachimschmidt557
35503b3d3f stage2 regalloc: Add freezeRegs/unfreezeRegs API
The freeze/unfreeze API replaces the exceptions API for hopefully
preventing bugs in codegen code using the RegisterManager. The
exceptions API is still available for backwards compatibility and will
be removed once all backends transition to the new freeze/unfreeze
API.
2022-01-26 18:23:27 +01:00
Jakub Konka
4192be8403 elf: implement slice types in debug info
Implements slice types including `[]const u8` for passing as
formal parameters in DWARF. Breaking on a function accepting
a slice in `gdb` will now yield the same behavior as stage1 and/or
LLVM backend:

```zig
fn sumArrayLens(a: []const u32, b: []const u8) usize {
  return a.len + b.len;
}
```

Both `a` and `b` can now be inspected in the debugger:

```
Breakpoint 1, sumArrayLens (a=..., b=...) at arr.zig:59
(gdb) p a
$1 = {ptr = 0x7fffffff685c, len = 5}
(gdb) p b
$2 = {ptr = 0x7fffffff683d "\252\252\252\\h\377\377\377\177", len = 3}
(gdb)
```
2022-01-26 17:28:58 +01:00
Jakub Konka
aa4eaea778 Merge branch 'mparadinha-x64-trunc' 2022-01-26 16:19:15 +01:00
Jakub Konka
9f224ebd9a stage2: add zero- and sign-extend moves to x86_64
* remove `LoweringError` error set from `Emit.zig` - it actually
  was less than helpful; it's better to either not throw an error
  since there can be instructions with mismatching operand sizes
  such as `movsx` or assert on a by instruction-basis. Currently,
  let's just pass through and see how we fare.
* when moving integers into registers, check for signedness and move
  with zero- or sign-extension if source operand is smaller than 8
  bytes. The destination operand is always assumed to be full-width,
  i.e., 8 bytes.
* clean up `airTrunc` a little to match the rest of CodeGen inst
  implementations.
2022-01-26 16:14:57 +01:00
Jakub Konka
075e2eaaaf Merge branch 'x64-trunc' of git://github.com/mparadinha/zig into mparadinha-x64-trunc 2022-01-26 11:15:57 +01:00
Andrew Kelley
2c9a5e791b organize behavior tests
Every test that is moved in this commit has been checked to see if it is
now passing.
2022-01-26 00:36:12 -07:00
Motiejus Jakštys
26e54d8a32 fix aarch64 include path 2022-01-26 09:10:12 +02:00
Motiejus Jakštys
7107a0fc40 [linux headers] rename arm64 to aarch64
Zig calls it aarch64. Linux calls it arm64. Currently lib/libc/include
has both arm64 and aarch64, which is quite confusing.

tools/update-linux-headers.zig was executed against the latest stable
linux patch version, therefore some other minor header updates. I will
update the wiki on how to do it once this PR is accepted.
2022-01-26 07:57:34 +02:00
Josh Hannaford
178cd60a5e Update the documentation for std.mem.sliceTo for readability 2022-01-26 00:49:17 -05:00
John Schmidt
9ee67b967b stage2: avoid inferred struct in os_version_check.zig
Before this commit, compiling an empty main with Stage 2 on macOS x86_64 results in

```
../stage2/bin/zig build-exe -ODebug -fLLVM empty_main.zig
error: sub-compilation of compiler_rt failed
    [...]/zig/stage2/lib/zig/std/special/compiler_rt/os_version_check.zig:26:10: error: TODO: Sema.zirStructInit for runtime-known struct values
```

By assigning the value to a variable we can sidestep the issue for now.
2022-01-26 00:48:05 -05:00
Andrew Kelley
0c1df96b17
Merge pull request #10552 from hdorio/deflate
compress: add a deflate compressor
2022-01-26 00:43:13 -05:00
Andrew Kelley
f0ddc7f7a2 translate-c: update for new function pointer semantics
After #10656, function pointers are represented with e.g.
`*const fn()void` rather than `fn()void`.

This commit adds code to translate-c to emit different code
depending on whether the output zig source code is intended
to be compiled with stage1 or stage2.

Ideally we will have stage1 and stage2 support the exact same
Zig language, but for now they diverge because I would rather
focus on finishing and shipping stage2 than implementing the
features in stage1.
2022-01-25 22:04:01 -07:00
Andrew Kelley
618055db50 c backend: use an explicit map of reserved idents
rather than unconditionally prepending double underscore to all
identifiers. Also, use the prefix `zig_e_` instead of `__`. Also, avoid
triggering this escaping when rendering an identifier and there has
already been a prefix printed.
2022-01-25 20:49:43 -07:00
mparadinha
575d430f92 stage2: x64: implement airTrunc 2022-01-25 23:53:26 +00:00
Lee Cannon
fbe5336f3b add option to force usage of GeneralPurposeAllocator 2022-01-25 18:21:58 -05:00
Jakub Konka
53c668d3a9 stage2: add naive impl of pointer type in ELF
Augment relocation tracking mechanism to de-duplicate potential
creation of base as well as composite types while unrolling
composite types in the linker - there is still potential for
further space optimisation by moving all type information into
a separate section `.debug_types` and providing references to
entries within that section whenever required (e.g., `ref4` form).
Currently, we duplicate type definitions on a per-decl basis.

Anyhow, with this patch, an example function signature of the following
type:

```zig
fn byPtrPtr(ptr_ptr_x: **u32, ptr_x: *u32) void {
    ptr_ptr_x.* = ptr_x;
}
```

will generate the following `.debug_info` for formal parameters:

```
 <1><1aa>: Abbrev Number: 3 (DW_TAG_subprogram)
    <1ab>   DW_AT_low_pc      : 0x8000197
    <1b3>   DW_AT_high_pc     : 0x2c
    <1b7>   DW_AT_name        : byPtrPtr
 <2><1c0>: Abbrev Number: 7 (DW_TAG_formal_parameter)
    <1c1>   DW_AT_location    : 1 byte block: 55        (DW_OP_reg5 (rdi))
    <1c3>   DW_AT_type        : <0x1df>
    <1c7>   DW_AT_name        : ptr_ptr_x
 <2><1d1>: Abbrev Number: 7 (DW_TAG_formal_parameter)
    <1d2>   DW_AT_location    : 1 byte block: 54        (DW_OP_reg4 (rsi))
    <1d4>   DW_AT_type        : <0x1e4>
    <1d8>   DW_AT_name        : ptr_x
 <2><1de>: Abbrev Number: 0
 <1><1df>: Abbrev Number: 5 (DW_TAG_pointer_type)
    <1e0>   DW_AT_type        : <0x1e4>
 <1><1e4>: Abbrev Number: 5 (DW_TAG_pointer_type)
    <1e5>   DW_AT_type        : <0x1e9>
 <1><1e9>: Abbrev Number: 4 (DW_TAG_base_type)
    <1ea>   DW_AT_encoding    : 7       (unsigned)
    <1eb>   DW_AT_byte_size   : 4
    <1ec>   DW_AT_name        : u32
```
2022-01-25 23:51:19 +01:00
Jakub Konka
05c5bb9edd stage2: populate debug info for args passed on stack
* implement cond_br when MCValue is a stack offset
* implement passing compare flags and immediate on stack
2022-01-25 23:51:04 +01:00
Andrew Kelley
ef7eff3939 Sema: coercion of pointers to C pointers 2022-01-25 14:53:41 -07:00
Andrew Kelley
f2835c6a28
Merge pull request #10679 from Luukdegram/wasm-unions
Stage2: wasm - Implement unions
2022-01-25 16:51:57 -05:00
Andrew Kelley
366c767444 link: Elf, Wasm: forward strip flag when linking with LLD 2022-01-25 11:52:48 -07:00
Andrew Kelley
50905d8851 zig cc: detect more linker args
* --whole-archive, -whole-archive
 * --no-whole-archive, -no-whole-archive
 * -s, --strip-all
 * -S, --strip-debug
2022-01-25 11:52:48 -07:00
Luuk de Gram
0682c9ac33
wasm: Implement genTypedValue for enums
This makes all union test cases succeed.
`rem` was also implemented as all we had to do is enable the instruction.
Loading and storing values based on ABI-size was simplified to a direct abiSize() call.

We also enabled all the newly passing test cases and disable them for all non-passing backends.
All of those test cases were verified to see if they perhaps already pass for the c-backend.
2022-01-25 19:29:40 +01:00
Luuk de Gram
e9d122f164
wasm: Implement lowering unions 2022-01-25 19:00:52 +01:00
Luuk de Gram
288b407fa9
wasm: Implement get_union_tag 2022-01-25 19:00:51 +01:00
Luuk de Gram
4b939fb34d
wasm: Implement set_union_tag 2022-01-25 19:00:48 +01:00
Meghan
f1b79c9a44 std.crypto.random: Randoms are no longer passed by reference 2022-01-25 13:00:39 -05:00
Andrew Kelley
0817d6b215
Merge pull request #10656 from ziglang/fn-ptr-type
stage2: type system treats fn ptr and body separately
2022-01-25 12:42:52 -05:00