14831 Commits

Author SHA1 Message Date
Vincent Rischmann
df4fe87163 thread: implement setName/getName 2021-07-29 12:02:12 +02:00
Vincent Rischmann
accde7fe2d windows: add wrappers for LocalFree, SetThreadDescription and GetThreadDescription 2021-07-29 10:57:08 +02:00
Vincent Rischmann
0be1e74902 windows/kernel32: add LocalFree, SetThreadDescription and GetThreadDescription 2021-07-29 10:57:08 +02:00
Vincent Rischmann
c0f40a5fe6 std/c: add pthread_setname_np and pthread_getname_np 2021-07-29 10:57:08 +02:00
Michael Dusan
ed174b7386 stage1: fix anon struct naming in certain cases
- generic "struct:L:C" naming if rloc is NodeTypeStructValueField
- generic "struct:L:C" naming if rloc is NodeTypeFnCallExpr
- move some tests from test/behavior/misc to test/behavior/typename

closes #4330
closes #9339
2021-07-28 18:17:11 -04:00
Mahdi Khanalizadeh
15bec20b00 linux: add mknod and mknodat syscalls 2021-07-28 18:15:41 -04:00
Belhorma Bendebiche
f5d9d739d7 stage1: Expand SysV C ABI support for small structs
While the SysV ABI is not that complicated, LLVM does not allow us
direct access to enforce it. By mimicking the IR generated by clang,
we can trick LLVM into doing the right thing. This involves two main
additions:

1. `AGG` ABI class
This is not part of the spec, but since we have to track class per
eightbyte and not per struct, the current enum is not enough. I
considered adding multiple classes like: `INTEGER_INTEGER`,
`INTEGER_SSE`, `SSE_INTEGER`. However, all of those cases would trigger
the same code path so it's simpler to collapse into one. This class is
only used on SysV.

2. LLVM C ABI type
Clang uses different types in C ABI function signatures than the
original structs passed in, and does conversion. For example, this
struct: `{ i8, i8, float }` would use `{ i16, float }` at ABI boundaries.
When passed as an argument, it is instead split into two arguments `i16`
and `float`. Therefore, for every struct that passes ABI boundaries we
need to keep track of its corresponding ABI type. Here are some more
examples:

```
| Struct             | ABI equivalent |
| { i8, i8, i8, i8 } | i32            |
| { float, float }   | double         |
| { float, i32, i8 } | { float, i64 } |
```

Then, we must update function calls, returns, parameter lists and inits
to properly convert back and forth as needed.
2021-07-28 18:13:17 -04:00
Matt Knight
2f9e498c6f add build dependency when linkerscript is a generated file 2021-07-28 18:10:53 -04:00
Zach Banks
9c028b2078 std/ArrayList: Allow ArrayList(u0) to be created
Enable creating ArrayList with zero-sized types.
This type still tracks length, but does not allocate
additional memory.
2021-07-28 18:05:40 -04:00
Evan Haas
8028e46f01 translate-c: handle signed array subscripts
A rather complicated workaround for handling signed array subscripts.
Once `[*]T + isize` is allowed, this can be removed.

Fixes #8556
2021-07-28 17:46:02 -04:00
Andrew Kelley
c47b46fc8d CI: enable stage2 behavior test coverage 2021-07-28 16:00:49 -04:00
Ominitay
c1285a1bbe Move fs.Walker to fs.Dir.Walker
fs.Walker has been replaced with fs.Dir.Walker. Paths of entries
returned are relative to the Dir.
2021-07-28 21:39:36 +03:00
Veikka Tuominen
f476463cd2
Merge pull request #9468 from ehaas/translate-c-inf-nan
translate-c: handle NAN and INFINITY macros
2021-07-28 21:37:46 +03:00
Evan Haas
d4d3a9dcc9
translate-c: handle floating point NAN and INFINITY macros 2021-07-28 08:06:22 -07:00
Evan Haas
c090e38340
translate-c: add support for ChooseExpr 2021-07-28 08:06:22 -07:00
Evan Haas
98eea963de
translate-c: fix import path in translation failure comment 2021-07-28 08:06:22 -07:00
Austin Clements
eb010ce65d Skip empty strings in std.fs.path.join function 2021-07-28 09:51:48 +03:00
Andrew Kelley
a8e8927c49 fix old references to verbose-ir to be verbose-air 2021-07-27 18:33:49 -07:00
Lee Cannon
c234d4790e
Add option to hide build command on compilation error to build_runner (#8513)
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2021-07-27 21:30:53 -04:00
Meghan Denny
bb2accba9b stage1: add c_longdouble mapping for s390x 2021-07-27 21:08:04 -04:00
Andrew Kelley
dc88864c97 stage2: implement @boolToInt
This is the first commit in which some behavior tests are passing for
both stage1 and stage2.
2021-07-27 17:08:37 -07:00
Andrew Kelley
66e5920dc3 llvm backend: LLVMGetNamedGlobalAlias requires a null terminated string 2021-07-27 15:47:25 -07:00
Andrew Kelley
a2eb91c422 stage2: add deinit for test_functions 2021-07-27 15:44:30 -07:00
Andrew Kelley
1eeafc3967 stage2: move call to populateTestFunctions() outside performAllTheWork()
Before calling populateTestFunctions() we want to check
totalErrorCount() but that will read from some tables that might get
populated by the thread pool for C compilation tasks. So we wait until
all those tasks are finished before proceeding.
2021-07-27 15:10:49 -07:00
Andrew Kelley
a8e964eadd stage2: zig test now works with the LLVM backend
Frontend improvements:

 * When compiling in `zig test` mode, put a task on the work queue to
   analyze the main package root file. Normally, start code does
   `_ = import("root");` to make Zig analyze the user's code, however in
   the case of `zig test`, the root source file is the test runner.
   Without this change, no tests are picked up.
 * In the main pipeline, once semantic analysis is finished, if there
   are no compile errors, populate the `test_functions` Decl with the
   set of test functions picked up from semantic analysis.
 * Value: add `array` and `slice` Tags.

LLVM backend improvements:

 * Fix incremental updates of globals. Previously the
   value of a global would not get replaced with a new value.
 * Fix LLVM type of arrays. They were incorrectly sending
   the ABI size as the element count.
 * Remove the FuncGen parameter from genTypedValue. This function is for
   generating global constants and there is no function available when
   it is being called.
   - The `ref_val` case is now commented out. I'd like to eliminate
     `ref_val` as one of the possible Value Tags. Instead it should
     always be done via `decl_ref`.
 * Implement constant value generation for slices, arrays, and structs.
 * Constant value generation for functions supports the `decl_ref` tag.
2021-07-27 14:19:53 -07:00
Jarred Sumner
ba71b96fe6 Add zld.id to list of files to skip 2021-07-27 07:54:25 +02:00
Andrew Kelley
31a59c229c stage2: improvements towards zig test
* Add AIR instruction: struct_field_val
   - This is part of an effort to eliminate the AIR instruction `ref`.
   - It's implemented for C backend and LLVM backend so far.
 * Rename `resolvePossiblyUndefinedValue` to `resolveMaybeUndefVal` just
   to save some columns on long lines.
 * Sema: add `fieldVal` alongside `fieldPtr` (renamed from
   `namedFieldPtr`). This is part of an effort to eliminate the AIR
   instruction `ref`. The idea is to avoid unnecessary loads, stores,
   stack usage, and IR instructions, by paying a DRY cost.

LLVM backend improvements:

 * internal linkage vs exported linkage is implemented, along with
   aliases. There is an issue with incremental updates due to missing
   LLVM API for deleting aliases; see the relevant comment in this commit.
   - `updateDeclExports` is hooked up to the LLVM backend now.
 * Fix usage of `Type.tag() == .noreturn` rather than calling `isNoReturn()`.
 * Properly mark global variables as mutable/constant.
 * Fix llvm type generation of function pointers
 * Fix codegen for calls of function pointers
 * Implement llvm type generation of error unions and error sets.
 * Implement AIR instructions: addwrap, subwrap, mul, mulwrap, div,
   bit_and, bool_and, bit_or, bool_or, xor, struct_field_ptr,
   struct_field_val, unwrap_errunion_err, add for floats, sub for
   floats.

After this commit, `zig test` on a file with `test "example" {}`
correctly generates and executes a test binary. However the
`test_functions` slice is undefined and just happens to be going into
the .bss section, causing the length to be 0. The next step towards
`zig test` will be replacing the `test_functions` Decl Value with the
set of test function pointers, before it is sent to linker/codegen.
2021-07-26 19:27:49 -07:00
Robin Voetter
cdeea3b094 minimum/maximum builtins 2021-07-26 20:41:00 -04:00
Robin Voetter
50a29f7c21 Add @select
@select(
    comptime T: type,
    pred: std.meta.Vector(len, bool),
    a: std.meta.Vector(len, T),
    b: std.meta.Vector(len, T)
) std.meta.Vector(len, T)

Constructs a vector from a & b, based on the values in the predicate vector. For indices where the predicate value is true, the corresponding
element from the a vector is selected, and otherwise from b.
2021-07-26 20:05:48 -04:00
Andrew Kelley
fc105f2681
Merge pull request #9458 from SuperAuguste/popcount-ctz-clz
Vector support for `@popCount`, `@ctz`, and `@clz`
2021-07-26 19:15:27 -04:00
Takeshi Yoneda
a9a4fd3200 Wasm,libc: fix wasm-ld failure in matching libc symbols.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-07-26 17:28:36 -04:00
fn ⌃ ⌥
24bfd7bddd Use -isysroot on Mojave too 2021-07-26 17:46:11 +02:00
Andrew Kelley
14d8a1c10d stage2 llvm backend improvements working towards zig test
* properly set global variables to const if they are not a global
   variable.
 * implement global variable initializations.
 * initial implementation of llvmType() for structs and functions.
 * implement genTypedValue for variable tags
 * implement more AIR instructions: varptr, slice_ptr, slice_len,
   slice_elem_val, ptr_slice_elem_val, unwrap_errunion_payload,
   unwrap_errunion_payload_ptr, unwrap_errunion_err,
   unwrap_errunion_err_ptr.
2021-07-25 22:38:50 -07:00
Auguste Rame
dd796154be Doc fixes for clz + ctz 2021-07-25 22:58:58 -04:00
Auguste Rame
c619b85f67 ctz + clz 2021-07-25 22:43:52 -04:00
Andrew Kelley
c3d10dbda1 stage2 llvm backend: implement llvmType for error union and slices 2021-07-25 19:06:48 -07:00
Andrew Kelley
5b4885fe89 stage2 llvm backend: DeclGen and DeclFn have context field
instead of a context() accessor method.
2021-07-25 18:49:25 -07:00
Andrew Kelley
66986dd248 stage2 llvm backend: rename getLLVMType to llvmType 2021-07-25 18:46:19 -07:00
Auguste Rame
ecca829bcb Add vector support for @popCount 2021-07-25 20:35:55 -04:00
Andrew Kelley
b87105c921 stage2 llvm backend: implement assembly and ptrtoint
These AIR instructions are the next blockers for `zig test` to work for
this backend.

After this commit, the "hello world" x86_64 test case passes for the
LLVM backend as well.
2021-07-24 23:54:20 -07:00
Andrew Kelley
653c851e62
Merge pull request #9446 from Luukdegram/stage2-air-wasm
stage2: wasm - Use `br_table` when possible for switch
2021-07-24 21:06:52 -04:00
Luuk de Gram
30376a82b2
Re-enable switch test cases and fix regressions 2021-07-24 20:05:41 +02:00
Luuk de Gram
5d98abd570
Support multi-value prongs 2021-07-24 19:49:25 +02:00
Luuk de Gram
72149ae7e4
Allow negative values 2021-07-24 19:49:25 +02:00
Luuk de Gram
cb41f0e58d
switchbr: When prongs are sparse values, use if/else-chain 2021-07-24 19:49:25 +02:00
Luuk de Gram
ad38fc1147
wasm: Rewrite switch_br to use br_table instead
This is an initial version, todo:
- Also make this work for u64 values, as the table must be indexed by u32.
- Add support for signed integers.
- Add support for enums.
2021-07-24 19:49:24 +02:00
Andrew Kelley
7b8cb881df stage2: improvements towards zig test
* There is now a main_pkg in addition to root_pkg. They are usually the
   same. When using `zig test`, main_pkg is the user's source file and
   root_pkg has the test runner.
 * scanDecl no longer looks for test decls outside the package being
   tested. honoring `--test-filter` is still TODO.
 * test runner main function has a void return value rather than
   `anyerror!void`
 * Sema is improved to generate better AIR for for loops on slices.
 * Sema: fix incorrect capacity calculation in zirBoolBr
 * Sema: add compile errors for trying to use slice fields as an lvalue.
 * Sema: fix type coercion for error unions
 * Sema: fix analyzeVarRef generating garbage AIR
 * C codegen: fix renderValue for error unions with 0 bit payload
 * C codegen: implement function pointer calls
 * CLI: fix usage text

 Adds 4 new AIR instructions:

  * slice_len, slice_ptr: to get the ptr and len fields of a slice.
  * slice_elem_val, ptr_slice_elem_val: to get the element value of
    a slice, and a pointer to a slice.

AstGen gains a new functionality:

 * One of the unused flags of struct decls is now used to indicate
   structs that are known to have non-zero size based on the AST alone.
2021-07-23 22:42:31 -07:00
Jakub Konka
f9798108f8
Merge pull request #9387 from ziglang/zld-incremental-2
macho+zld: bringing zld to stage2 MachO backend - simplicity is key!
2021-07-23 20:03:15 +02:00
Jakub Konka
5533f77054 Merge remote-tracking branch 'origin/master' into zld-incremental-2 2021-07-23 17:06:19 +02:00
Jakub Konka
1beda818e1 macho: re-enable parsing sections into atoms
However, make it default only when building in release modes since
it's a prelude to advanced dead code stripping not very useful in
debug.
2021-07-23 16:55:19 +02:00