Commit Graph

2187 Commits

Author SHA1 Message Date
Andrew Kelley
09304aab77 fix cancel and await semantics 2018-07-29 23:25:40 -04:00
Andrew Kelley
0d79e03816 canceling an await also cancels things awaiting it 2018-07-28 13:52:48 -04:00
Andrew Kelley
dd272d1316 await cancels the await target when it is canceled 2018-07-28 12:36:02 -04:00
Andrew Kelley
0ba2bc38d7 await checks the cancel bit 2018-07-28 12:23:47 -04:00
Andrew Kelley
60cda3713f suspend cancels awaiter when it gets canceled 2018-07-28 12:11:39 -04:00
Andrew Kelley
c6f9a4c044 cancel detects suspend bit 2018-07-28 01:26:11 -04:00
Andrew Kelley
6fed777637 cancel detects if the target handle has already returned 2018-07-28 01:22:51 -04:00
Andrew Kelley
f0c049d02b detect double await 2018-07-27 18:37:30 -04:00
Andrew Kelley
e5beca886d suspend checks the cancel bit 2018-07-27 18:07:30 -04:00
Andrew Kelley
e491c38189 resume detects resuming when not suspended 2018-07-27 18:01:39 -04:00
Andrew Kelley
341bd0dfa4 await sets the await bit 2018-07-27 17:47:27 -04:00
Andrew Kelley
0b7a9c0722 cancel sets the cancel bit 2018-07-27 17:42:09 -04:00
Andrew Kelley
02c5bda704 remove ability to break from suspend blocks
closes #803
2018-07-27 17:27:03 -04:00
Andrew Kelley
442e244b4d suspend sets suspend bit 2018-07-27 17:16:00 -04:00
Andrew Kelley
10764ee0e6 resume clears suspend bit 2018-07-27 17:00:41 -04:00
Andrew Kelley
7113f109a4 update coroutine return codegen with new status bits 2018-07-27 15:50:26 -04:00
Andrew Kelley
b3f4182ca1 coroutines have 3 more bits of atomic state 2018-07-26 22:26:00 -04:00
Andrew Kelley
2cbad364c1 add compile error for ignoring return value of while loop bodies
closes #1049
2018-07-26 18:29:07 -04:00
Andrew Kelley
fd575fe1f3 add compile error for missing parameter name of generic function 2018-07-25 18:15:55 -04:00
Andrew Kelley
84195467ad add compile error for non-inline for loop on comptime type 2018-07-25 17:08:55 -04:00
Andrew Kelley
2257660916 fix assertion failure when some compile errors happen
I don't actually know of a test case to trigger this

self-hosted won't have this problem because get_pointer_to_type
will return error.SemanticAnalysisFailed
2018-07-25 13:12:03 -04:00
Andrew Kelley
2ea08561cf self-hosted: function types use table lookup 2018-07-24 14:20:49 -04:00
Andrew Kelley
29e19ace36 fix logic for determining whether param requires comptime
closes #778
closes #1213
2018-07-24 10:21:33 -04:00
Andrew Kelley
dd9728c5a0 Merge remote-tracking branch 'origin/master' into llvm7 2018-07-24 00:43:12 -04:00
Andrew Kelley
72599d420b self-hosted: find all libc paths; windows linker code 2018-07-24 00:06:34 -04:00
Andrew Kelley
2614ef056a self-hosted: basic linker code for macos 2018-07-23 17:38:03 -04:00
Andrew Kelley
5a919dd82d Merge remote-tracking branch 'origin/master' into self-hosted-libc-hello-world 2018-07-23 14:32:13 -04:00
Andrew Kelley
d767fae47e self-hosted: add first compare-output test 2018-07-23 00:35:53 -04:00
Andrew Kelley
58c5f94a99 self-hosted: share C++ code for finding libc on windows 2018-07-20 23:38:13 -04:00
Andrew Kelley
0a880d5e60 fix generation of error defers for fns inside fns
closes #878
2018-07-19 18:06:41 -04:00
Andrew Kelley
a9f0681f85 prevent non-export symbols from clobbering builtins
closes #1263
2018-07-19 10:47:17 -04:00
Jimmi Holst Christensen
fd3a41dadc Allow pointers to anything in extern/exported declarations (#1258)
* type_allowed_in_extern accepts all ptr not size 0

* Generate correct headers for none extern structs/unions/enums
2018-07-18 11:00:42 -04:00
Andrew Kelley
c393a399fb fix invalid character test on windows 2018-07-18 10:51:42 -04:00
Andrew Kelley
cbfe9a4077 fix @setEvalBranchQuota not respected in generic fn calls
closes #1257
2018-07-17 23:37:17 -04:00
Andrew Kelley
ecf8da00c5 self-hosted: linking 2018-07-17 13:18:13 -04:00
kristopher tate
69e3b4e7dc revert commit 860d3da915 ; please see #1249 for more information; (#1255) 2018-07-17 10:27:18 -04:00
Andrew Kelley
97bfeac13f self-hosted: create tmp dir for .o files and emit .o file for fn 2018-07-16 20:52:50 -04:00
Andrew Kelley
0fa24b6b75 allow implicit cast of undefined to optional 2018-07-16 19:26:15 -04:00
Andrew Kelley
558b0b8791 Merge remote-tracking branch 'origin/master' into llvm7 2018-07-16 13:37:16 -04:00
Andrew Kelley
d3ce9d0643 codegen: remove unused variable 2018-07-16 11:59:37 -04:00
Andrew Kelley
e9a03cccf3 all integer sizes are available as primitives
* fix wrong implicit cast for `@IntType` bit_count parameter.
 * fix incorrect docs for `@IntType` bit_count parameter.

closes #1242
closes #745
closes #1240
2018-07-16 10:53:15 -04:00
Andrew Kelley
2255f275a0 update for latest clang API 2018-07-15 00:03:33 -04:00
Andrew Kelley
4d920cee6e Merge remote-tracking branch 'origin/master' into llvm7 2018-07-14 18:27:51 -04:00
Eduardo Sánchez Muñoz
722b9b9e59 codegen: Store returned value if type is 'handle_is_ptr' and function is not 'first_arg_ret'.
Seems to fix #1230, includes test.
2018-07-14 11:33:01 -04:00
Andrew Kelley
c87102c304 ir_get_ref: delete unnecessary and probably buggy code 2018-07-13 14:53:54 -04:00
Andrew Kelley
171f33b961 ir: remove unnecessary and probably buggy code 2018-07-13 14:18:37 -04:00
Andrew Kelley
860d3da915 ir: remove dead code 2018-07-13 13:37:01 -04:00
Andrew Kelley
5354d1f5fc allow == for comparing optional pointers
closes #658
2018-07-13 12:34:42 -04:00
Andrew Kelley
ce11d6d16c ir: refactor lvalues 2018-07-11 21:37:47 -04:00
Andrew Kelley
3f30897fdc add compile error for disallowed types in extern structs
closes #1218
2018-07-11 14:08:56 -04:00
Andrew Kelley
da3acacc14 update vendor list for newest llvm version 2018-07-11 00:46:48 -04:00
Andrew Kelley
574e31f0a0 self-hosted: first passing test
* introduce std.atomic.Int
 * add src-self-hosted/test.zig which is tested by the main test suite
   - it fully utilizes the multithreaded async/await event loop so the
     tests should Go Fast
 * `stage2/bin/zig build-obj test.zig` is able to spit out an error if 2 exported
   functions collide
 * ability for `zig test` to accept `--object` and `--assembly`
   arguments
 * std.build: TestStep supports addLibPath and addObjectFile
2018-07-10 20:18:43 -04:00
Andrew Kelley
cfaebb20d8 Merge remote-tracking branch 'origin/master' into llvm7 2018-07-10 14:03:03 -04:00
Andrew Kelley
0ce6934e26 allow var args calls to async functions 2018-07-10 11:44:47 -04:00
Andrew Kelley
28f9230b40 fix crash when calling comptime-known undefined function ptr
closes #880
closes #1212
2018-07-10 10:12:08 -04:00
Andrew Kelley
3f4d0ecd7e Merge remote-tracking branch 'origin/master' into m-n-threading 2018-07-09 17:14:42 -04:00
Andrew Kelley
0ac1b83885 fix non-portable format specifier 2018-07-09 17:13:31 -04:00
Andrew Kelley
2ee67b7642 langref: docs for invalid error set cast and incorrect pointer alignment
also add detection of incorrect pointer alignment at compile-time
of pointers that were constructed with `@intToPtr`.
2018-07-09 11:13:29 -04:00
Andrew Kelley
9eb51e20ed fix crash on @ptrToInt of a *void
closes #1192
2018-07-09 10:44:06 -04:00
Andrew Kelley
eb326e1553 M:N threading
* add std.atomic.QueueMpsc.isEmpty
 * make std.debug.global_allocator thread-safe
 * std.event.Loop: now you have to choose between
   - initSingleThreaded
   - initMultiThreaded
 * std.event.Loop multiplexes coroutines onto kernel threads
 * Remove std.event.Loop.stop. Instead the event loop run() function
   returns once there are no pending coroutines.
 * fix crash in ir.cpp for calling methods under some conditions
 * small progress self-hosted compiler, analyzing top level declarations
 * Introduce std.event.Lock for synchronizing coroutines
 * introduce std.event.Locked(T) for data that only 1 coroutine should
   modify at once.
 * make the self hosted compiler use multi threaded event loop
 * make std.heap.DirectAllocator thread-safe

See #174

TODO:
 * call sched_getaffinity instead of hard coding thread pool size 4
 * support for Windows and MacOS
 * #1194
 * #1197
2018-07-07 00:32:19 -04:00
Andrew Kelley
d8295c1889 add @popCount intrinsic 2018-07-07 00:25:32 -04:00
Andrew Kelley
4ad4cd2654 fix iterating over a void slice
closes #1203
2018-07-06 17:27:44 -04:00
Andrew Kelley
1cf7511dc9 add compile error notes for where struct definitions are
closes #1202
2018-07-06 16:20:46 -04:00
Andrew Kelley
1a5bd88881 alternate implementation of previous commit
This strategy adds another field to the SwitchBr instruction,
which is the result of the CheckSwitchProngs instruction. The
type of the result is void, and is unused, except that the SwitchBr
instruction will not perform analysis if the CheckSwitchProngs
instruction did not pass analysis. This allows the CheckSwitchProngs
instruction to do implicit casting for its type checking, while
preventing duplicate compile error messages.
2018-07-06 12:03:07 -04:00
Andrew Kelley
b5d07297de Merge remote-tracking branch 'origin/master' into llvm7 2018-07-04 20:43:49 -04:00
Isaac Hier
9cff23dbf9 Fix assertion crash on enum switch values 2018-07-04 13:27:10 -04:00
Isaac Hier
9395162a7c Debug enum issue 2018-07-04 12:47:35 -04:00
Andrew Kelley
8c39cdc89f fix await on early return when return type is struct
previously, await on an early return would try to access the
destroyed coroutine frame; now it copies the result into a
temporary variable before destroying the coroutine frame
2018-07-04 11:51:02 -04:00
Andrew Kelley
291afcf75a fix runtime libc detection depending on locale
closes #1165
2018-07-03 14:20:26 -04:00
Andrew Kelley
9665cfe027 update for latest llvm 2018-07-03 03:48:47 -04:00
Andrew Kelley
6e1425e312 Merge remote-tracking branch 'origin/master' into llvm7 2018-07-02 20:00:13 -04:00
Andrew Kelley
35463526cc add runtime safety for @intToEnum; add docs for runtime safety
See #367
2018-07-02 15:50:28 -04:00
Andrew Kelley
2759c7951d always link against compiler_rt.o even when linking libc
sometimes libgcc is missing things we need, so we always link
compiler_rt and rely on weak linkage to allow libgcc to override.
2018-07-02 14:10:27 -04:00
Andrew Kelley
4c0e280d6d
Merge pull request #1185 from ziglang/undefined-at-comptime-improvements
Operators now throw a compiler error when operating on undefined values
2018-07-01 01:33:23 -04:00
Jimmi Holst Christensen
055e0fef4e Avoid resolve_const in cmp when instr are not comptime 2018-06-30 21:22:26 +02:00
Jimmi Holst Christensen
ecd5e60be9 Expanded the list of operators that catch undefined values at comptime 2018-06-30 20:50:09 +02:00
Jimmi Holst Christensen
42033ea3ca
Merge pull request #1167 from ziglang/comptime-array-by-value
Implement const_values_equal for arrays
2018-06-30 18:58:31 +02:00
Jimmi Holst Christensen
01bd5c46e1 Revert "ir_resolve_const now checks recursivly for undef values"
This reverts commit 4c3f27ce1e.
2018-06-30 17:35:06 +02:00
Jimmi Holst Christensen
616fe798c8 Revert "contains_comptime_undefined_value should not follow pointers"
This reverts commit 58b1692182.
2018-06-30 17:35:05 +02:00
Ben Noordhuis
03f66825d6 support --emit in 'test' command
Support the `--emit` switch in `zig --emit asm test file.zig`.

The command fails because no tests run (no executable is created) but
it emits the requested file.  That seems like a good tradeoff.
2018-06-29 23:32:10 +02:00
isaachier
f1c56f7f22 Clarify reason implicit cast does not work for large RHS (#1168)
* Clarify reason implicit cast does not work for large RHS
2018-06-29 14:52:25 -04:00
Jimmi HC
58b1692182 contains_comptime_undefined_value should not follow pointers 2018-06-29 11:34:38 +02:00
Jimmi HC
4c3f27ce1e ir_resolve_const now checks recursivly for undef values 2018-06-29 10:21:43 +02:00
Jimmi HC
b1128b18d5 Assert that array is not ConstArraySpecialUndef in const_values_equal 2018-06-29 08:41:16 +02:00
Jimmi HC
3ec38b2494 Implement const_values_equal for array type
* This allows arrays to be passed by value at comptime
2018-06-28 10:34:37 +02:00
Marc Tiehuis
4a35d7eeeb Correct hex-float parsing
Unblocks #495.
2018-06-28 20:12:03 +12:00
Andrew Kelley
2fa588e81d fix coroutine accessing freed memory
closes #1164
2018-06-27 18:45:21 -04:00
Andrew Kelley
19961c50e4 fix comptime @tagName crashing sometimes
closes #1118
2018-06-27 13:15:55 -04:00
Ben Noordhuis
440c1d52b4 simplify comptime floating-point @divTrunc
Replace a conditional ceil/floor call with an unconditional trunc call.
2018-06-27 16:20:04 +02:00
Ben Noordhuis
fd75e73ee9 add f16 type
Add support for half-precision floating point operations.

Introduce `__extendhfsf2` and `__truncsfhf2` in std/special/compiler_rt.

Add `__gnu_h2f_ieee` and `__gnu_f2h_ieee` as aliases that are used in
Windows builds.

The logic in std/special/compiler_rt/extendXfYf2.zig has been reworked
and can now operate on 16 bits floating point types.

`extendXfYf2()` and `truncXfYf2()` are marked `inline` to work around
a not entirely understood stack alignment issue on Windows when calling
the f16 versions of the builtins.

closes #1122
2018-06-27 16:20:04 +02:00
Ben Noordhuis
1f45075a0e dry floating-point type definitions 2018-06-27 16:20:04 +02:00
Andrew Kelley
11ca38a4e9 fix crash for optional pointer to empty struct
closes #1153
2018-06-26 15:27:41 -04:00
Andrew Kelley
af95e15572 rename get_maybe_type to get_optional_type 2018-06-26 15:11:05 -04:00
Isaac Hier
8e714289ca Fix os_path_join for case where dirname is empty 2018-06-26 13:31:32 -04:00
Andrew Kelley
459d72f873 fix compiler crash for invalid enum
closes #1079
closes #1147
2018-06-21 17:41:49 -04:00
Andrew Kelley
5f38d6e2e9 add casting docs, __extenddftf2, and __extendsftf2 2018-06-21 14:44:35 -04:00
Isaac Hier
eeda1a1396 Fix logic 2018-06-21 08:17:08 -04:00
Isaac Hier
0ab4afbf42 Fix increment operation for bigint -1 2018-06-21 08:14:26 -04:00
Ben Noordhuis
eb6a8e6a3b fix f128 remainder division bug
The modulo operation computed rem(b+rem(a,b), b) which produces -1
for a=1 and b=2.

Switch to a - b * trunc(a/b) which produces the expected result, 1.

closes #1137
2018-06-20 17:37:38 -04:00
Andrew Kelley
55193cb13b fix runtime fn ptr equality codegen
closes #1140
2018-06-20 06:46:53 -04:00
Andrew Kelley
7c99c30bf4 fix calling method with comptime pass-by-non-copyign-value self arg
closes #1124
2018-06-19 19:35:59 -04:00
Andrew Kelley
42db807f37 remove redundant implicit casting code
and introduce better type mismatch errors

closes #1061
2018-06-19 18:51:46 -04:00
Andrew Kelley
c7804277bf @floatToInt now has safety-checked undefined behavior
when the integer part does not fit in the destination integer type

 * Also fix incorrect safety triggered for integer casting an
   `i32` to a `u7`. closes #1138
 * adds compiler-rt function: `__floatuntidf`
2018-06-19 16:06:10 -04:00
Andrew Kelley
85422d7aea
Merge pull request #1136 from alexnask/typeinfo_improvements
@typeInfo now uses optional types instead of @typeOf(undefined)
2018-06-19 11:46:32 -04:00
Alexandros Naskos
1392313236 @typeInfo now uses optional types instead of @typeOf(undefined) 2018-06-19 17:45:19 +03:00
Andrew Kelley
a3ddd0826b remove enum to/from int casting syntax; add @enumToInt/@intToEnum
see #1061
2018-06-19 03:50:38 -04:00
Andrew Kelley
dd62737266 translate-c: add new libclang c types 2018-06-19 03:43:40 -04:00
Andrew Kelley
626b73e8be remove error to/from int casting syntax; add @errorToInt/@intToError
See #1061
2018-06-18 18:48:29 -04:00
Andrew Kelley
a430853a48 standard library fixes 2018-06-18 17:43:01 -04:00
Andrew Kelley
1aafbae5be remove []u8 casting syntax. add @bytesToSlice and @sliceToBytes
See #1061
2018-06-18 17:25:29 -04:00
Andrew Kelley
5d705fc6e3 remove error set casting syntax. add @errSetCast
See #1061
2018-06-18 15:01:42 -04:00
Andrew Kelley
c757984879 Merge remote-tracking branch 'origin/master' into llvm7 2018-06-18 14:51:23 -04:00
Andrew Kelley
cd4676a233 stage1: update darwin code to workaround old libc bug
See #1128
2018-06-18 12:54:31 -04:00
Andrew Kelley
4ce36a6475 adjust logic for finding the path to zig executable on darwin 2018-06-18 12:18:39 -04:00
Andrew Kelley
c09c3902c4 Merge branch 'fix-1117-macos-realpath' of https://github.com/binary132/zig into binary132-fix-1117-macos-realpath 2018-06-18 12:16:47 -04:00
Andrew Kelley
8fd7cc11e1 disallow opaque as a return type of fn type syntax
closes #1115
2018-06-18 11:12:15 -04:00
Andrew Kelley
d49d6f0cde fix compiler crash when using @intToFloat with float literal
closes #1132
2018-06-18 11:04:18 -04:00
Bodie Solomon
c7057bd25b
Fix 1117: Revise realpath scratch logic 2018-06-18 07:40:31 -04:00
Bodie Solomon
0456822892
Fix 1117: Tweak realpath logic to use out_path as scratch space 2018-06-18 07:40:31 -04:00
Bodie Solomon
e6b69151c0
Fix 1117: Use realpath in stage1 Darwin os_self_exe_path
Issue: https://github.com/ziglang/zig/issues/1117

The macOS stage1 Zig compiler should look in Zig's real absolute path
for the Zig stdlib, but os_self_exe_path looks in its path as returned
by _NSGetExecutablePath, which may be a symlink.  This means that a
symlinked Zig cannot find the Zig stdlib.

This patch fixes the issue by resolving the _NSGetExecutablePath result
to the real path using realpath() before copying the result to the
output path.
2018-06-18 07:40:31 -04:00
Andrew Kelley
4210f1f6a0 remove bool to int syntax. add @boolToInt
add missing docs

See #1061
2018-06-18 03:07:16 -04:00
Andrew Kelley
92a36040b1 msp430 target: c_long is always 32 bits
closes #1125
2018-06-18 01:03:45 -04:00
Andrew Kelley
431fda4141
Merge pull request #1123 from ziglang/remove-number-casting-syntax
Remove number casting syntax
2018-06-17 14:40:07 -04:00
Andrew Kelley
e5956f23ca add target C int type information for msp430 target
closes #1125
2018-06-17 12:47:27 -04:00
Andrew Kelley
7912061226 remove integer and float casting syntax
* add `@intCast`
 * add `@floatCast`
 * add `@floatToInt`
 * add `@intToFloat`

See #1061
2018-06-17 02:57:07 -04:00
Andrew Kelley
472b7ef7e6 disable byval 2018-06-16 19:37:00 -04:00
Andrew Kelley
e311cd562b don't automatically take pointer when passing by non-copying value
this commit does not have all tests passing
2018-06-16 19:37:00 -04:00
Andrew Kelley
59b3dc8907 allow passing by non-copying value
closes #733
2018-06-16 19:36:33 -04:00
Andrew Kelley
48de57d824 add basic std lib code for loading dynamic libraries
this is going to only work for very basic libraries;
I plan to slowly add more features over time to support more
complicated libraries
2018-06-16 17:01:23 -04:00
Andrew Kelley
84a700f972 llvm7: find external liblldWasm and update for newest lld macho API 2018-06-14 18:28:42 -04:00
Andrew Kelley
32dd98b19f Merge remote-tracking branch 'origin/master' into llvm7 2018-06-14 18:27:59 -04:00
Alexandros Naskos
4ec09ac243 Enabled optional types of zero bit types with no LLVM DI type. (#1110)
* Zero bit optional types do not need a LLVM DI type
2018-06-14 10:57:28 -04:00
Andrew Kelley
8dd24796c4 disallow implicit casts that break rules for optionals
closes #1102
2018-06-13 11:04:09 -04:00
Andrew Kelley
259413251d fix ability to call mutating methods on zero size structs
closes #838
2018-06-12 15:06:02 -04:00
Andrew Kelley
03c16c6c54 implement @tagName as a switch instead of table lookup
closes #976
closes #1080
2018-06-11 14:58:42 -04:00
Andrew Kelley
0a95b0f1ff std.zig: update syntax for orelse keyword 2018-06-10 01:18:31 -04:00
Andrew Kelley
77678b2cbc
breaking syntax change: orelse keyword instead of ?? (#1096)
use the `zig-fmt-optional-default` branch to have zig fmt
automatically do the changes.

closes #1023
2018-06-10 01:13:51 -04:00
Andrew Kelley
ec1b6f6673
breaking syntax change: ??x to x.? (#1095)
See #1023

This also renames Nullable/Maybe to Optional
2018-06-09 23:42:14 -04:00
Ben Noordhuis
d464b25322 support --target-arch wasm32 (#1094)
Add wasm32 support to the build-obj, build-exe and build-lib commands
of the stage 1 compiler.  Wasm64 should work transparently once it's
supported in upstream LLVM.

To export a function:

    // lib.zig - for exposition, not necessary for this example
    pub use @import("add.zig");

    // add.zig
    export fn add(a: i32, b: i32) i32 {
        return a + b;
    }

To import a function:

    // cube.zig
    extern fn square(x: i32) i32;

    export fn cube(x: i32) i32 {
        return x * square(x);
    }
2018-06-09 22:39:22 -04:00
Andrew Kelley
9046b5eac0 fix assertion failure when debug printing comptime values 2018-06-09 11:41:59 -04:00
Andrew Kelley
6edd81109d nullable pointers follow const-casting rules
any *T -> ?*T cast is allowed implicitly, even
when it occurs deep inside the type, and the cast
is a no-op at runtime.

in order to add this I had to make the comptime value
representation of nullable pointers the same as the
comptime value representation of normal pointers,
so that we don't have to do any recursive transformation
of values when doing this kind of cast.
2018-06-09 00:26:26 -04:00
Andrew Kelley
39fa313ad8 disable some implicit casts for unknown length pointers
closes #770
2018-06-08 14:57:16 -04:00
Jimmi HC
bf3d1c1aab Allow access of array.len through a pointer 2018-06-08 09:21:31 +02:00
Andrew Kelley
f0b6dac1f2 add implicit casts from *[N]T
* to `[]T`
 * to `[*]T`

See #770
2018-06-07 22:41:58 -04:00
Andrew Kelley
b65203f573 remove @canImplicitCast builtin
nobody will miss it
2018-06-07 19:50:25 -04:00
Andrew Kelley
688ff2830d langref: automatic update of builtin.zig
now the docs can't get out of date for this

See #367
2018-06-07 19:10:45 -04:00
Andrew Kelley
31aefa6a21 fix structs that contain types which require comptime
Now, if a struct has any fields which require comptime,
such as `type`, then the struct is marked as requiring
comptime as well. Same goes for unions.

This means that a function will implicitly be called
at comptime if the return type is a struct which contains
a field of type `type`.

closes #586
2018-06-07 18:07:30 -04:00
Andrew Kelley
d3693dca73 Pointer Reform: update @typeInfo
* add assertion for trying to do @typeInfo on global error set
 * remove TypeInfo.Slice
 * add TypeInfo.Pointer.Size with possible values
   - One
   - Many
   - Slice

See #770
2018-06-06 00:39:39 -04:00
Andrew Kelley
bd13e757e7 disable deref syntax for unknown length pointers
See #770
2018-06-05 23:26:43 -04:00
Andrew Kelley
0ccc186869 disable field access for unknown length pointers
See #770
2018-06-05 23:26:43 -04:00
Andrew Kelley
652f4bdf62 disallow unknown-length pointer to opaque
This also means that translate-c has to detect when a pointer to
opaque is happening, and use `*` instead of `[*]`.

See #1059
2018-06-05 18:03:21 -04:00
Andrew Kelley
ef7f69d14a update to latest libclang 2018-06-05 15:02:48 -04:00
Andrew Kelley
ba5eeea1e5 Merge remote-tracking branch 'origin/master' into llvm7 2018-06-05 11:28:30 -04:00
Andrew Kelley
7a09482536 fix crash when evaluating return type has compile error
closes #1058
2018-06-05 10:48:53 -04:00
Andrew Kelley
7dd18294b7 Merge remote-tracking branch 'origin/master' into llvm7 2018-06-05 10:29:54 -04:00
Jimmi HC
a8146ade2a Renamed UndefinedLiteral to Undefined 2018-06-05 11:54:11 +02:00
Jimmi HC
236c680f6b Removed NullLiteral to Null 2018-06-05 11:30:01 +02:00
Jimmi HC
02cb220faf Renamed "(int/float literal)" to "comptime_int/float" 2018-06-05 11:14:43 +02:00
Andrew Kelley
e53b683bd3
Pointer Reform: proper slicing and indexing (#1053)
* enable slicing for single-item ptr to arrays
 * disable slicing for other single-item pointers
 * enable indexing for single-item ptr to arrays
 * disable indexing for other single-item pointers

see #770
closes #386
2018-06-04 22:11:14 -04:00
Andrew Kelley
32e0dfd4f0 never call malloc with size 0
instead we return nullptr. this makes the behavior consistent
across all platforms.

closes #1044
closes #1045
2018-06-04 14:09:31 -04:00
Andrew Kelley
58ce79f935 Merge remote-tracking branch 'origin/master' into llvm7 2018-06-04 02:58:55 -04:00
Andrew Kelley
96164ce613 disallow single-item pointer indexing
add pointer arithmetic for unknown length pointer
2018-06-04 01:39:57 -04:00
Marc Tiehuis
4c273126df Add context to zig_unreachable calls (#1039)
This greatly aids debugging on platforms with no stack-traces.
2018-06-03 02:30:43 -04:00
Andrew Kelley
b85b68a7fd better compile error for error sets behind nullable 2018-06-02 15:20:51 -04:00
Andrew Kelley
f06bce5dda introduce [*] for unknown length pointers
See #770

Currently it does not have any different behavior than `*`
but it is now recommended to use `[*]` for unknown length
pointers to be future-proof.

Instead of [ * ] being separate tokens as the proposal
suggested, this commit implements `[*]` as a single token.
2018-06-02 04:04:23 -04:00
Andrew Kelley
019217d7a2 fix regressions 2018-06-01 00:17:31 -04:00
Andrew Kelley
2f614c42fe ir: rip out special logic for using addr-of instruction for types
See #588
2018-05-31 18:23:39 -04:00
Andrew Kelley
fcbb7426fa use * for pointer type instead of &
See #770

To help automatically translate code, see the
zig-fmt-pointer-reform-2 branch.

This will convert all & into *. Due to the syntax
ambiguity (which is why we are making this change),
even address-of & will turn into *, so you'll have
to manually fix thes instances. You will be guaranteed
to get compile errors for them - expected 'type', found 'foo'
2018-05-31 17:28:07 -04:00
Jimmi HC
15302e84a4 Adding workaround for when the user tries to unwrap 'type'
closes #1011
2018-05-30 11:51:46 +02:00
Jimmi HC
1b3aaacba2 Removed copy-pasted resolve_inferred_error_set
both ir.cpp and analyze.cpp have a function resolve_inferred_error_set,
which is a nearly exact copy-paste. This commit removes the one in ir.cpp
and exposes then one in analyze.cpp. This also allows us to make
analyze_fn_body local to analyze.cpp, as it is not used anywhere in
ir.cpp after this change
2018-05-30 10:34:20 +02:00
Jimmi HC
2b3af4ef6b fixed #1009
ir_make_type_info_defs already calls resolve_top_level_decl on all Tld
when building the def array. This means, that there is no reason that
analyze_fn_body is nessesary, as the fn type should have already been
resolved completly. The only thing analyze_fn_body does here, is cause
problems with generic functions.
2018-05-30 10:30:09 +02:00
Andrew Kelley
8efb3f5e19 update to latest LLVM API 2018-05-26 12:18:13 -04:00
Andrew Kelley
1f96a86676 Merge remote-tracking branch 'origin/master' into llvm7 2018-05-26 12:06:08 -04:00
Andrew Kelley
43085417be update github.com/zig-lang to github.com/ziglang 2018-05-24 21:27:44 -04:00
Andrew Kelley
99fc2bd4dd Merge remote-tracking branch 'origin/master' into pointer-reform 2018-05-17 00:56:35 -04:00
Andrew Kelley
967bad43a0 OpenBSD has the same C integer sizes as Linux
Thanks Jan S <jan.schreib@gmail.com> for this information

closes #1016
2018-05-16 20:18:38 -04:00
Andrew Kelley
5cfabdd493 Merge remote-tracking branch 'origin/master' into pointer-reform 2018-05-16 00:02:26 -04:00
Andrew Kelley
74b10c08d1 fix @typeInfo not setting a field to comptime 2018-05-15 14:11:41 -04:00
Andrew Kelley
86a352c45b Merge branch 'master' into pointer-reform 2018-05-13 13:38:03 -04:00
Andrew Kelley
548ddd1f0c fix AST dumping code in self hosted compiler 2018-05-12 23:57:15 -04:00
Andrew Kelley
a6ae45145f add @newStackCall builtin function
See #1006
2018-05-12 17:35:15 -04:00
Andrew Kelley
277b9cf878 fix comptime code modification of global const
closes #1008
2018-05-11 22:41:44 -04:00
Andrew Kelley
284ab109c4 Merge remote-tracking branch 'origin/master' into llvm7 2018-05-10 11:37:25 -04:00
Marc Tiehuis
efa39c5343 Fix bigint shift-right partial shift 2018-05-10 22:26:26 +12:00
Andrew Kelley
6928badd85 Merge branch 'master' into pointer-reform 2018-05-09 23:43:07 -04:00
Andrew Kelley
4438c5e09b Merge branch 'rework-parser' 2018-05-09 22:17:47 -04:00
Andrew Kelley
bf21747a42 translate-c: fix typedef duplicate definition of variable
closes #998
2018-05-09 20:23:36 -04:00
Jimmi HC
2a74aa2067 Freeing ptr_field_name after use 2018-05-09 09:40:57 +02:00
Jimmi HC
9b29c872ce Added Slice as it's own type info in userland 2018-05-09 09:34:04 +02:00
Andrew Kelley
69ef6ae0f9 rework std.zig.parser 2018-05-07 21:57:44 -04:00
Andrew Kelley
77a1a216d2 tagged union field access prioritizes members over enum tags
closes #959
2018-05-07 16:43:20 -04:00
Marc Tiehuis
d7b029995c Fix bigint multi-limb shift and masks 2018-05-05 22:40:29 +12:00
Andrew Kelley
7e37d268c8 Merge remote-tracking branch 'origin/master' into llvm7 2018-05-04 13:39:27 -04:00
Andrew Kelley
b9e320dd52
Merge pull request #951 from alexnask/reflect_reify
Metaprogramming - @typeInfo [DONE]
2018-05-03 23:02:33 -04:00
Jimmi Holst Christensen
aa2586de18 Fixed extern enums having the wrong size (#970)
Fixed extern enums having the wrong size

See #977
2018-05-03 22:27:04 -04:00
Alexandros Naskos
131c133bb7 Fixed inlining determination test (#972)
When deciding wether we should inline a scope, look up the parents until we get to a function definition scope
2018-05-02 21:43:07 -04:00
Jimmi Holst Christensen
1a9403f38a Added better support for none pure enums in tranlate C 2018-05-02 21:50:41 +02:00
Andrew Kelley
6309121f70 translate-c: update to llvm7 2018-05-02 09:46:29 -04:00
Andrew Kelley
1090b289ec Merge remote-tracking branch 'origin/master' into llvm7 2018-05-01 14:29:50 -04:00
Alexandros Naskos
849ea61fa1 Small fix. 2018-05-01 17:10:50 +03:00
Alexandros Naskos
255c0ef406 Resolved merge conflict. 2018-05-01 13:09:34 +03:00
Alexandros Naskos
ff1c4e1f13 Added tests. 2018-05-01 13:00:39 +03:00
Andrew Kelley
a35b366eb6 [breaking] delete ptr deref prefix op
start using zig-fmt-pointer-reform branch build of zig fmt
to fix code to use the new syntax

all of test/cases/* are processed, but there are more left
to be done - all the std lib used by the behavior tests
2018-04-30 20:35:54 -04:00
Andrew Kelley
76ab1d2b6c support foo.* for ptr deref
See #770
2018-04-30 14:20:56 -04:00
Alexandros Naskos
013f548202 Finished FnDef TypeInfo generation (warning: may be buggy). 2018-04-29 15:40:26 +03:00
Alexandros Naskos
66aa760f83 More FnDef TypeInfo generation. 2018-04-29 14:03:55 +03:00
Andrew Kelley
bf8e419d2b linux uses pthreads when linking against libc 2018-04-29 00:40:04 -04:00
Andrew Kelley
998e25a01e pthread support working 2018-04-28 23:47:39 -04:00
Andrew Kelley
96ecb40259 add fuzz tests for std.atomic.Stack 2018-04-28 17:53:06 -04:00
Jimmi Holst Christensen
73bf897b5c Using allocate instead of allocate_nonzero so we don't have to memset 2018-04-28 19:21:23 +02:00
Jimmi Holst Christensen
d6f033b42d Fixed build error 2018-04-28 19:09:25 +02:00
Jimmi Holst Christensen
837166319d Trying to fix osx build failing by setting param_info.type to nullptr 2018-04-28 19:02:46 +02:00
Alexandros Naskos
af73462da4 Started work on function definition TypeInfo generation. 2018-04-28 19:57:59 +03:00
Jimmi Holst Christensen
341f8c1e86 Fixed wrong formatting for arg_index when reporting @ArgType error 2018-04-28 17:57:47 +02:00
Alexandros Naskos
9ba400673d Generating TypeInfo's now forces definitions to be resolved. 2018-04-28 18:38:38 +03:00
Jimmi Holst Christensen
fba0347ec4 .ReturnType and @ArgType now emits errors on unresolved types
related: #846
2018-04-28 17:17:48 +02:00
Jimmi Holst Christensen
2fc34eaa58 Functions with infered error set can now return literals
fixes #852
2018-04-28 16:27:31 +02:00
Alexandros Naskos
61b0180596 Added definition TypeInfo generation, except for function definitions. 2018-04-28 17:01:19 +03:00
Jimmi Holst Christensen
3178528335 Removed zero sized error set optimization
fixes #762
fixes #818
2018-04-28 14:05:08 +02:00
Alexandros Naskos
ea2596280f Added BoundFn TypeInfo generation. 2018-04-27 05:10:20 +03:00
Alexandros Naskos
8f703f919f Added Fn TypeInfo generation. 2018-04-27 04:29:50 +03:00
Alexandros Naskos
a2dadbc206 Added struct TypeInfo generation. 2018-04-27 02:52:09 +03:00
Alexandros Naskos
9041d0d37e Fixed enum tag type detection in TypeInfo generation. 2018-04-27 02:05:24 +03:00
Alexandros Naskos
884e32d5c3 Added ErrorUnion, Union TypeInfo generation 2018-04-26 19:56:34 +03:00
Andrew Kelley
4d0b660f4b translate-c: add missing decl type from LLVM 7 2018-04-26 11:43:18 -04:00
Alexandros Naskos
fbbbee6b72 Switched to shallow TypeInfo. 2018-04-26 18:18:47 +03:00
Andrew Kelley
bbfff46146 Merge remote-tracking branch 'origin/master' into llvm7 2018-04-26 10:55:29 -04:00
Alexandros Naskos
4aa5d87ada Added ErrorSet TypeInfo generation. 2018-04-26 17:14:38 +03:00
Alexandros Naskos
f5977f68eb Added Enum TypeInfo except for methods 2018-04-26 16:41:59 +03:00
Alexandros Naskos
7a91e4736a Reset parent on cached TypeInfo values if we need to. 2018-04-26 14:29:27 +03:00
Alexandros Naskos
bb56360bfa Added TypeInfo cache 2018-04-26 14:03:19 +03:00
Alexandros Naskos
dd88d7deda Cleanup 2018-04-26 13:27:16 +03:00
Alexandros Naskos
bc160821d3 Changed TypeInfo layout. 2018-04-25 17:50:11 +03:00
Alexandros Naskos
2606993cb4 Fixed ir_type_info_struct_set_parent for struct parents. 2018-04-25 11:59:35 +03:00
Alexandros Naskos
d68aea4f35 Added checks for field name/index mapping in TypeInfo generation. Abstracted the parent setting out. 2018-04-25 11:35:46 +03:00
Alexandros Naskos
778b931bf3 Fixed comptime union void field access 2018-04-25 02:50:18 +03:00
Alexandros Naskos
182a9fad2d Added ArrayInfo, NullableInfo, PromiseInfo generation 2018-04-24 17:38:30 +03:00
Alexandros Naskos
09d7033d1d PointerInfo child is known at comptime 2018-04-24 17:08:45 +03:00
Alexandros Naskos
2d8553c853 Fixed PointerInfo generation 2018-04-24 17:01:20 +03:00
Alexandros Naskos
189e8e97bd PointerInfo child is a pointer to a TypeInfo union, still not working correctly 2018-04-24 16:50:36 +03:00
Alexandros Naskos
0e5fb035e3 Added (broken) pointer info, float info 2018-04-24 16:23:22 +03:00
Alexandros Naskos
e9309d3b13 Fixed IntInfo generation. 2018-04-24 15:17:34 +03:00
Alexandros Naskos
ec2a3ed500 Attempt at adding comptime union field access 2018-04-24 15:03:46 +03:00
Alexandros Naskos
fb88f5a0d2 @typeInfo with void payloads now works! 2018-04-24 11:20:33 +03:00
Alexandros Naskos
7eab62325b One step towards @typeInfo 2018-04-24 01:49:22 +03:00
Andrew Kelley
15bf0c1541 fix interaction between defer and labeled break
closes #830
2018-04-23 18:06:33 -04:00
Andrew Kelley
89a4c373d3 fix bigint twos complement implementation
closes #948
2018-04-23 12:06:18 -04:00
Andrew Kelley
8503eff8c1 add compile error for invalid deref on switch target
closes #945
2018-04-22 23:46:55 -04:00
Andrew Kelley
75328e3204 exit(1) instead of abort() for file not found 2018-04-22 21:47:25 -04:00
Andrew Kelley
25dff91fa0 fix windows build broken by previous commit
fixes build failure from 1c41f1ca62
2018-04-22 21:08:52 -04:00
Andrew Kelley
1c41f1ca62 better error reporting for missing libc on windows
closes #931
2018-04-22 20:54:52 -04:00
Andrew Kelley
21767144fc linux: support VDSO for clock_gettime
also fix a compiler crash when using cmpxchg with nullable pointer
2018-04-22 18:11:50 -04:00
Andrew Kelley
6e57243a79 zig fmt: preserve comments in front of test blocks
* refactor std.zig.parser
 * fix compiler crashing for some compile errors
 * take advantage of @field in std.zig.ast
 * move ast.NodeFoo to ast.Node.Foo
 * comment preservation is more explicit

See #911
2018-04-20 02:15:09 -04:00
Jimmi Holst Christensen
1b91478bff Optimized field ptr ir for hot path and fix assignment bug 2018-04-19 21:34:18 +02:00
Jimmi Holst Christensen
6b4f6ebd89 Added field builtin function 2018-04-19 20:11:16 +02:00
Andrew Kelley
06909ceaab support break in suspend blocks
* you can label suspend blocks
 * labeled break supports suspend blocks

See #803
2018-04-18 22:21:54 -04:00
Andrew Kelley
ca4341f7ba add --no-rosegment cli option
this provides a workaround for #896
until valgrind adds support for clang/LLD
(equivalent to gcc/gold -rosegment)
2018-04-18 17:14:09 -04:00
Andrew Kelley
f1f998e071 improve cmpxchg
* remove @cmpxchg, add @cmpxchgWeak and @cmpxchgStrong
   - See explanations in the langref.
 * add operand type as first parameter
 * return type is ?T where T is the operand type

closes #461
2018-04-18 12:16:42 -04:00
Andrew Kelley
96ebd8b23b fix windows not respecting --msvc-lib-dir, --kernel32-lib-dir
I believe this was a regression caused by
51a6ff18d4

closes #927
2018-04-16 22:33:34 -04:00
Alexandros Naskos
1c85050dad Set SizeLevel to 2 in ReleaseSmall mode 2018-04-16 03:54:40 +03:00
Alexandros Naskos
253ecd5c11 Added ReleaseSmall mode 2018-04-16 03:26:10 +03:00
Andrew Kelley
b9360640ce add @atomicLoad builtin
See #174
2018-04-15 18:12:00 -04:00
Andrew Kelley
a8d794215e exit with error code instead of panic for file not found 2018-04-15 15:22:07 -04:00
Andrew Kelley
b5459eb987 add @sqrt built-in function
See #767
2018-04-15 13:26:58 -04:00
Andrew Kelley
4a2bfec150 fix linux implementation of self exe path
closes #894
2018-04-15 12:57:45 -04:00
Andrew Kelley
b7af9edb8a add std.os.createThread
this adds kernel thread support to the standard library for
linux.

See #174
2018-04-14 02:24:05 -04:00
Andrew Kelley
0509414dfe fix regression with zig install dir
introduced in 1999f0daad
2018-04-13 11:31:38 -04:00
Andrew Kelley
30c5f3c441
Merge pull request #915 from zig-lang/self-hosted-cli
Revise self-hosted command line interface
2018-04-13 11:16:06 -04:00
Andrew Kelley
1999f0daad fix undefined behavior triggered by fn inline test
LLVM destroys the string that we use to test if LLVM deleted the
inlined function.

Also fixed forgetting to initialize a buffer in std lib path detection.
2018-04-13 11:10:17 -04:00
Andrew Kelley
373b3586a1 inline functions must be stored in const or comptime var
closes #913
2018-04-12 16:26:23 -04:00
Andrew Kelley
29e0e4088e Merge remote-tracking branch 'origin/master' into self-hosted-cli 2018-04-12 11:20:38 -04:00
Andrew Kelley
7b2cb7e679 remove --zig-install-prefix arg now that we find std at runtime 2018-04-12 11:00:11 -04:00
Andrew Kelley
ce68dda4b6 Merge remote-tracking branch 'origin/master' into llvm7 2018-04-11 18:27:06 -04:00
Andrew Kelley
e48e707c32 allow integer and float literals to be passed to var params
closes #623
2018-04-11 14:47:37 -04:00
Andrew Kelley
e85a10e9f5 async tcp server proof of concept 2018-04-09 00:52:45 -04:00
Andrew Kelley
acd8f6ef18 fixups from rebase 2018-04-08 18:49:20 -04:00
Andrew Kelley
b85ef656ca running into the llvm corosplit error again 2018-04-08 18:30:54 -04:00
Andrew Kelley
0d22a00f6f *WIP* async/await TCP server 2018-04-08 18:26:24 -04:00
Andrew Kelley
ee1a4f4c1d error return traces work with async return case 2018-04-08 17:44:29 -04:00
Andrew Kelley
9e98ea552d fix calling convention at callsite of zig-generated fns 2018-04-08 16:40:59 -04:00
Andrew Kelley
ada441157f put the error return addresses in the coro frame 2018-04-08 16:04:48 -04:00
Andrew Kelley
e4083b7391 codegen: fix not putting llvm allocas together 2018-04-08 16:04:48 -04:00
Andrew Kelley
d26905c102 error return traces for the early return case
it would work but LLVM is not correctly spilling the addresses.

See #821
2018-04-08 16:04:48 -04:00
Ben Noordhuis
8980281184 fix llvm assert on version string with git sha
LLVM's CodeViewDebug pass misparses the version string when it contains
a git revision so stop doing that.  This only affected Windows builds.

closes #898
2018-04-06 00:31:55 +02:00
Andrew Kelley
5800faa318 update to latest llvm API 2018-04-04 18:27:52 -04:00
Andrew Kelley
cca93908e6 Merge remote-tracking branch 'origin/master' into llvm7 2018-04-04 17:22:26 -04:00
Marc Tiehuis
2e5115b068 Add run compiler command
'zig run file.zig' builds a file and stores the artifacts in the global
cache. On successful compilation the binary is executed.

'zig run file.zig -- a b c' does the same, but passes the arguments a,
b and c as runtime arguments to the program. Everything after an '--' are
treated as runtime arguments.

On a posix system, a shebang can be used to run a zig file directly. An
example shebang would be '#!/usr/bin/zig run'. You may not be able pass
extra compile arguments currently as part of the shebang. Linux for example
treats all arguments after the first as a single argument which will result
in an 'invalid command'.

Currently there is no customisability for the cache path as a compile
argument. For a posix system you can use `TMPDIR=. zig run file.zig` to
override, in this case using the current directory for the run cache.

The input file is always recompiled, even if it has changed. This is
intended to be cached but further discussion/thought needs to go into
this.

Closes #466.
2018-04-01 17:03:06 +12:00
Andrew Kelley
67f11190d1 musl-friendly dynamic linking 2018-03-31 16:34:55 -04:00
Andrew Kelley
8f962a957a fix regressions on windows 2018-03-31 11:26:02 -04:00
Andrew Kelley
c3724ec506 implement os_self_exe_path in the c++ compiler for darwin
ported from the zig std lib

this fixes looking for zig std lib at runtime on darwin
2018-03-31 02:12:44 -04:00
Andrew Kelley
b01c50d6fa find libc and zig std lib at runtime
this removes the following configure options:
 * ZIG_LIBC_LIB_DIR
 * ZIG_LIBC_STATIC_LIB_DIR
 * ZIG_LIBC_INCLUDE_DIR
 * ZIG_DYNAMIC_LINKER
 * ZIG_EACH_LIB_RPATH
 * zig's reliance on CMAKE_INSTALL_PREFIX

these options are still available as command line options, however,
the default will attempt to execute the system's C compiler to
collect system defaults for these values.

closes #870
2018-03-30 17:10:54 -04:00
Andrew Kelley
ccadcbc715 fix examples and rename std.rand.Rand to std.rand.Random 2018-03-29 12:33:29 -04:00
Andrew Kelley
032fccf615 fix compile time array concatenation for slices
closes #866
2018-03-28 23:25:12 -04:00
Andrew Kelley
5627347bab
Merge pull request #865 from bnoordhuis/zig-build-stage2
skeleton stage 2 support for 'zig build'
2018-03-28 21:02:09 -04:00
Jimmi Holst Christensen
72ce146293 Fixed looking for windows sdk when targeting linux 2018-03-29 00:53:06 +02:00
Ben Noordhuis
db70b909a0 non-zero exit when build.zig cannot be created
Make the stage 1 compiler exit with a non-zero status code
when `zig build --init` cannot create a new build.zig file.
2018-03-28 18:30:41 +02:00
Andrew Kelley
6cb99fdac3 fix crash when compile error in analyzing @panic call 2018-03-27 15:07:45 -04:00
Andrew Kelley
aa2995ee39 fix invalid codegen for error return traces across suspend points
See #821

Now the code works correctly, but error return traces are missing
the frames from coroutines.
2018-03-24 22:07:12 -04:00
Andrew Kelley
897e783763 add promise->T syntax parsing
closes #857
2018-03-24 19:25:53 -04:00
Andrew Kelley
18af2f9a27 fix async fns with inferred error sets
closes #856
2018-03-24 18:28:32 -04:00