Commit Graph

1505 Commits

Author SHA1 Message Date
Andrew Kelley
ea3d9d5c53
add test for 74bdc1d1f8 2019-02-18 18:11:30 -05:00
Andrew Kelley
28bf768883 export _mh_execute_header with weak linkage
* also fix extern variables with initialiaztion values to generate runtime code
 * remove the workaround in example/shared_library/mathtest.zig
 * introduce the ability for global variables to have Weak and LinkOnce
   linkage
 * fix `@export` to work for non-functions. this code needs to be
   audited though.
 * fix comptime ptrcast not keeping bigger alignment
 * fix linker warnings when targeting darwin

closes #1903
2019-02-18 16:47:30 -05:00
Andrew Kelley
7a84fe79b9
pull request fixups 2019-02-18 13:05:26 -05:00
emekoi
9b3013d2f6
make @enumToInt work on union(enum)
closes #1711
2019-02-18 11:43:45 -05:00
LemonBoy
e280dce30f Translate parameterless C functions (#1978)
Both FunctionNoProto and FunctionProto are subclasses of FunctionType,
the only difference is that the former is parameterless.
2019-02-18 10:26:45 -05:00
Matthew McAllister
c70ee9177e Check for duped error messages in compile tests 2019-02-17 15:33:28 -08:00
Matthew McAllister
51783510b9 Deduplicate compile log statement warnings 2019-02-17 14:02:37 -08:00
Matthew McAllister
91989e70ba Fix lvalue dereference type checking
Previously, if a dereference instruction was an lvalue, it would fail to
typecheck that the value being dereferenced was indeed a pointer.
Although a little clunky, this change obviates the need for redundant
type checks scattered about the analysis.
2019-02-16 17:37:47 -08:00
Andrew Kelley
f57182456d
Merge pull request #1898 from Sahnvour/translate-c-arrays
Translate c arrays
2019-02-16 14:07:41 -05:00
Andrew Kelley
a05e224150
typecheck the panic function
this adds the prototype of panic to @import("builtin")
and then uses it to do an implicit cast of the panic
function to this prototype, rather than redoing all the
implicit cast logic.

closes #1894
closes #1895
2019-02-15 19:19:28 -05:00
Andrew Kelley
7293e012d7
breaking: fix @sizeOf to be alloc size rather than store size
* Fixes breaches of the guarantee that `@sizeOf(T) >= @alignOf(T)`
 * Fixes std.mem.secureZero for integers where this guarantee previously
   was breached
 * Fixes std.mem.Allocator for integers where this guarantee previously
   was breached

Closes #1851
Closes #1864
2019-02-15 18:05:50 -05:00
Andrew Kelley
567c9b688e
Merge pull request #1965 from ziglang/c-pointer-type
implement C pointers
2019-02-15 02:20:42 -05:00
Andrew Kelley
ee5e196f88
add test for truncate on comptime integers
closes #703
2019-02-15 02:02:19 -05:00
Andrew Kelley
d6e0d82c32
translate-c: back to *c_void for opaque types
See #1059
2019-02-14 23:09:31 -05:00
Andrew Kelley
d5bbd74871
allow C pointers to have alignment
clang/gcc support pointer alignment attribute:
https://clang.llvm.org/docs/AttributeReference.html#align-value
2019-02-14 20:04:13 -05:00
Andrew Kelley
cc7060d0d9
compile error for C pointer with align attribute
See #1059
2019-02-14 20:02:29 -05:00
Andrew Kelley
6769183a9d
fix implicit cast error unions with non-optional to optional pointer
and update self hosted compiler for C pointers

See #1059
2019-02-14 15:48:28 -05:00
Andrew Kelley
52c03de5c2
add missing compile error for OpaqueType inside structs/unions
closes #1862
2019-02-14 13:07:51 -05:00
Andrew Kelley
e03c770145
compile error tests for implicit C pointer casting
See #1059
2019-02-14 12:28:50 -05:00
Andrew Kelley
c58b802034
remove the "top of the comptime stack" compile error
It's still best practice to put `@setEvalBranchQuota` at the top of
the comptime stack, but as Jimmi notes in #1949, when a function
can be called at comptime and also can be the top of the comptime stack,
this compile error is fundamentally unsound.

So now it's gone.

closes #1949
2019-02-14 10:51:59 -05:00
Andrew Kelley
59de24817e
runtime safety check for casting null to pointer
see #1059
2019-02-14 01:09:33 -05:00
Andrew Kelley
d4d2718bca
comptime detection of casting null to pointer
See #1059
2019-02-14 00:40:39 -05:00
Jimmi Holst Christensen
2911eb34de Added error for nesting vectors 2019-02-13 12:19:08 +01:00
Jimmi Holst Christensen
53297a1bd0 We already support vector bit operators, so let's test it 2019-02-13 11:40:32 +01:00
Jimmi Holst Christensen
c221b29c9d We already support vector on floats, so let's test it 2019-02-13 11:31:13 +01:00
Andrew Kelley
5699ab5e77
C pointers: errors for nested pointer casting regarding null
See #1059
2019-02-12 18:20:00 -05:00
Andrew Kelley
270933b1e9
compile error test for casting integer to c pointer
when the int has more bits than pointers

See #1059
2019-02-12 10:25:21 -05:00
Andrew Kelley
6f05e8d1be
implicit casting between C pointer and optional non-C pointer
See #1059
2019-02-12 01:38:11 -05:00
Andrew Kelley
285e2f62ba
disallow C pointers to non-C-ABI-compatible element types
See #1059
2019-02-12 00:51:06 -05:00
Andrew Kelley
069fc1a269
peer type resolution with C pointers
See #1059
2019-02-11 19:21:59 -05:00
Andrew Kelley
57a7ab0d33
comptime support for pointer arithmetic with hard coded addresses 2019-02-11 19:12:01 -05:00
Andrew Kelley
90b8cd4a45
add C pointer type to @typeInfo
See #1059
2019-02-11 16:07:40 -05:00
Andrew Kelley
342bca7f46
C pointer comparison and arithmetic
See #1059
2019-02-11 15:31:09 -05:00
Andrew Kelley
d9e01be973
translate-c: use C pointer type everywhere
See #1059
2019-02-11 14:56:59 -05:00
Andrew Kelley
bcbcb2e9ff
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-10 11:03:17 -05:00
Andrew Kelley
73e8e46257
casting between C pointers and normal pointers
See #1059
2019-02-10 01:11:40 -05:00
Andrew Kelley
b8cbe3872e
added C pointer type and implicit int-to-ptr for this type
See #1059
2019-02-10 00:14:30 -05:00
Andrew Kelley
caf672c495
@truncate: comptime 0 when target type is 0 bits
also if the dest type is a comptime_int, then treat it
as an implicit cast.

also compile error for attempting to truncate undefined

closes #1568
2019-02-09 21:38:34 -05:00
Andrew Kelley
34eb9f18ac
fix not updating debug info type of optional error sets
There's an unfortunate footgun in the current design of error sets.
The debug info type for every error set is the same as the debug info
type of the global error set, which is essentially an enum forward
declaration. The problem is that when we "replace" the forward
declaration with the final value, once we know all the possible errors,
we have to update the pointers of every error set.

So the footgun is that if you ever copy the debug info type of the
global error set, you have to add the address of the pointer to a list
of pointers that need to be updated once we "replace" the forward
declaration. I activated the footgun when I introduced the optimization
that `?anyerror` types are the same size as `anyerror` types (using 0 as
the null value), because I introduced a pointer copy of the global error
set debug info type, but forgot to add it to the list.

I'm sure that there is a better way to code this, which does not have
the footgun, but this commit contains only a fix, not a reworking of the
logic.

closes #1937
2019-02-09 20:41:26 -05:00
Andrew Kelley
1864acd326
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-09 18:57:39 -05:00
Andrew Kelley
373e21bb56
implement vector math safety with ext and trunc 2019-02-09 16:24:29 -05:00
Andrew Kelley
46ddd5f5f4
fix compiler assertion failure when returning value from test
closes #1935
2019-02-08 19:23:46 -05:00
Andrew Kelley
c2db077574
std.debug.assert: remove special case for test builds
Previously, std.debug.assert would `@panic` in test builds,
if the assertion failed. Now, it's always `unreachable`.

This makes release mode test builds more accurately test
the actual code that will be run.

However this requires tests to call `std.testing.expect`
rather than `std.debug.assert` to make sure output is correct.

Here is the explanation of when to use either one, copied from
the assert doc comments:

Inside a test block, it is best to use the `std.testing` module
rather than assert, because assert may not detect a test failure
in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert
is the correct function to use.

closes #1304
2019-02-08 18:23:38 -05:00
Andrew Kelley
f330eebe4b fix using the result of @intCast to u0
closes #1817
2019-02-07 16:02:45 -05:00
Andrew Kelley
a94304d3e4
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-07 12:21:20 -05:00
Andrew Kelley
36bade5c56
fixups, and modify std.mem.join and std.os.path.resolve API
* zig fmt
 * std.mem.join takes a slice of slices instead of var args
 * std.mem.join takes a separator slice rather than byte,
   and always inserts it. Previously it would not insert the separator
   if there already was one, violating the documented behavior.
 * std.mem.join calculates exactly the correct amount to allocate
   and has no call to allocator.shrink()
 * bring back joinWindows and joinPosix and the corresponding tests.
   it is intended to be able to call these functions from any OS.
 * rename std.os.path.resolveSlice to resolve (now resolve takes
   a slice of slices instead of var args)
2019-02-07 00:42:41 -05:00
Andrew Kelley
c804ae2d6b
Merge branch 'zig-backport-std.os.path' of https://github.com/kristate/zig into kristate-zig-backport-std.os.path 2019-02-06 22:53:34 -05:00
Andrew Kelley
8a5d3e2eaf
Merge pull request #1924 from ziglang/tls
Implement Thread Local Variables
2019-02-06 20:21:13 -05:00
Andrew Kelley
d2602b442e
require running std lib tests coherently
this should actually improve CI times a bit too

See the description at the top of std/os/startup.zig (deleted in this
commit) for a more detailed understanding of what this commit does.
2019-02-06 14:32:20 -05:00
Andrew Kelley
b1775ca168
thread local storage working for linux x86_64 2019-02-06 13:48:04 -05:00
Sahnvour
075fda3c73 translate-c: add tests. Commented for now as the output is currently empty until #646 is fixed. 2019-02-05 20:36:57 +01:00
Jimmi Holst Christensen
4010f6a11d Added support for vector wrapping mult and sub
* I also merged the code that generates ir for add, sub, and mult
2019-02-05 09:57:11 -05:00
Andrew Kelley
f32f7a937f
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-04 21:26:50 -05:00
Andrew Kelley
8c6fa982cd
SIMD: array to vector, vector to array, wrapping int add
also vectors and arrays now use the same ConstExprVal representation

See #903
2019-02-04 20:30:00 -05:00
Andrew Kelley
dfbc063f79
std.mem.Allocator.create replaced with better API
`std.mem.Allocator.createOne` is renamed to `std.mem.Allocator.create`.

The problem with the previous API is that even after copy elision,
the initalization value passed as a parameter would always be a copy.
With the new API, once copy elision is done, initialization
functions can directly initialize allocated memory in place.

Related:
 * #1872
 * #1873
2019-02-03 16:13:28 -05:00
Matthew McAllister
c90c256868 Fix slice concatenation
This was causing an underflow error
2019-02-02 22:22:00 -05:00
Andrew Kelley
9b8e23934b
introduce --single-threaded build option
closes #1764

This adds another boolean to the test matrix; hopefully it does not
inflate the time too much.

std.event.Loop does not work with this option yet. See #1908
2019-02-01 18:05:54 -05:00
Matthew McAllister
8bedb10939 Fix runtime assignment to comptime aggregate field
This was causing a segfault
2019-02-01 17:14:12 -05:00
Andrew Kelley
ae1ebe09b7
add compile errror for @bitCast when bit counts mismatch
fixes invalid LLVM IR from previous commit
2019-02-01 14:06:51 -05:00
Andrew Kelley
545064c1d9
introduce vector type for SIMD
See #903

 * create with `@Vector(len, ElemType)`
 * only wrapping addition is implemented

This feature is far from complete; this is only the beginning.
2019-01-30 23:39:25 -05:00
Andrew Kelley
169a789b34
fix test after merging ad8381e0d2
this test slipped through due to branching
2019-01-30 16:12:30 -05:00
Matthew McAllister
ad8381e0d2 Move tokenizer error location to offending char
Previously, it pointed to the start of the current token, but this made
it difficult to tell where the error occurred when it was, say, in the
middle of a string.
2019-01-30 14:02:01 -05:00
Andrew Kelley
581edd643f
backport copy elision changes
This commit contains everything from the copy-elision-2
branch that does not have to do with copy elision directly,
but is generally useful for master branch.

 * All const values know their parents, when applicable, not
   just structs and unions.
 * Null pointers in const values are represented explicitly,
   rather than as a HardCodedAddr value of 0.
 * Rename "maybe" to "optional" in various code locations.
 * Separate DeclVarSrc and DeclVarGen
 * Separate PtrCastSrc and PtrCastGen
 * Separate CmpxchgSrc and CmpxchgGen
 * Represent optional error set as an integer, using the 0 value.
   In a const value, it uses nullptr.
 * Introduce type_has_one_possible_value and use it where applicable.
 * Fix debug builds not setting memory to 0xaa when storing
   undefined.
 * Separate the type of a variable from the const value of a variable.
 * Use copy_const_val where appropriate.
 * Rearrange structs to pack data more efficiently.
 * Move test/cases/* to test/behavior/*
 * Use `std.debug.assertOrPanic` in behavior tests instead of
   `std.debug.assert`.
 * Fix outdated slice syntax in docs.
2019-01-29 22:30:30 -05:00
Andrew Kelley
9c328b4291
simpler implementation of && and || hints
This accomplishes the same goal, but with less changes, so that
I can backport copy elision stuff easier.
2019-01-29 22:29:56 -05:00
kristopher tate
5bf9ffdc5b Hint at use of and/or when &&/|| is improperly used (#1886) 2019-01-25 21:10:40 +01:00
Andrew Kelley
87f5bed11f Merge remote-tracking branch 'origin/master' into llvm8 2019-01-22 20:10:34 -05:00
Andrew Kelley
1357bc7430
add test case for previous commit 2019-01-20 14:09:17 -05:00
Andrew Kelley
027a0c46ae Merge remote-tracking branch 'origin/master' into llvm8 2019-01-08 16:50:16 -05:00
Jimmi HC
97702988d1 Added test case 2019-01-06 17:58:00 +01:00
vegecode
1f08be4d7f Mark comptime int hardcoded address pointee as a run time variable #1171 (#1868)
* Mark comptime int hardcoded address as a run time variable #1171

* test case for dereferencing hardcoded address intToPtr
2019-01-04 17:34:21 -05:00
vegecode
f6cd68386d @bitreverse intrinsic, part of #767 (#1865)
* bitreverse - give bswap behavior

* bitreverse, comptime_ints, negative values still not working?

* bitreverse working for negative comptime ints

* Finished bitreverse test cases

* Undo exporting a bigint function. @bitreverse test name includes ampersand

* added docs entry for @bitreverse
2019-01-02 16:47:47 -05:00
Andrew Kelley
036a49e97d Merge remote-tracking branch 'origin/master' into llvm8 2019-01-01 18:36:12 -05:00
alexander
64061cc1bf Test cases for compiler error and working behavior for switching on booleans 2018-12-27 13:46:32 -06:00
Andrew Kelley
280187031a
tests: make type info tests not depend on builtin.Os enum 2018-12-23 18:03:22 -05:00
Andrew Kelley
94424e3fa6 test: remove type info test dependency on builtin.Os enum 2018-12-23 17:40:38 -05:00
Andrew Kelley
c00216701c Merge remote-tracking branch 'origin/master' into llvm8 2018-12-23 17:04:26 -05:00
Andrew Kelley
218a4d4b30
comptime: ability to @ptrCast to an extern struct and read fields 2018-12-22 23:06:30 -05:00
kristopher tate
fb81b1978b
tests: re: 79db394;
ref: ziglang/zig#1832
2018-12-20 22:53:54 +09:00
Jimmi Holst Christensen
45e72c0b39 Fixed intToPtr to fn type when the address is hardcoded (#1842)
* Fixed intToPtr to fn type

* Added test

* Import inttoptr.zig in behavior.zig
2018-12-19 09:39:18 -05:00
Andrew Kelley
f75262b79f
fix comptime pointer reinterpretation array index offset
closes #1835
2018-12-17 11:05:50 -05:00
Andrew Kelley
b883bc873d
breaking API changes to all readInt/writeInt functions & more
* add `@bswap` builtin function. See #767
 * comptime evaluation facilities are improved to be able to
   handle a `@ptrCast` with a backing array.
 * `@truncate` allows "truncating" a u0 value to any integer
   type, and the result is always comptime known to be `0`.
 * when specifying pointer alignment in a type expression,
   the alignment value of pointers which do not have addresses
   at runtime is ignored, and always has the default/ABI alignment
 * threw in a fix to freebsd/x86_64.zig to update syntax from
   language changes
 * some improvements are pending #863

closes #638
closes #1733

std lib API changes
 * io.InStream().readIntNe renamed to readIntNative
 * io.InStream().readIntLe renamed to readIntLittle
 * io.InStream().readIntBe renamed to readIntBig
 * introduced io.InStream().readIntForeign
 * io.InStream().readInt has parameter order changed
 * io.InStream().readVarInt has parameter order changed
 * io.InStream().writeIntNe renamed to writeIntNative
 * introduced io.InStream().writeIntForeign
 * io.InStream().writeIntLe renamed to writeIntLittle
 * io.InStream().writeIntBe renamed to writeIntBig
 * io.InStream().writeInt has parameter order changed
 * mem.readInt has different parameters and semantics
 * introduced mem.readIntNative
 * introduced mem.readIntForeign
 * mem.readIntBE renamed to mem.readIntBig and different API
 * mem.readIntLE renamed to mem.readIntLittle and different API
 * introduced mem.readIntSliceNative
 * introduced mem.readIntSliceForeign
 * introduced mem.readIntSliceLittle
 * introduced mem.readIntSliceBig
 * introduced mem.readIntSlice
 * mem.writeInt has different parameters and semantics
 * introduced mem.writeIntNative
 * introduced mem.writeIntForeign
 * mem.writeIntBE renamed to mem.readIntBig and different semantics
 * mem.writeIntLE renamed to mem.readIntLittle and different semantics
 * introduced mem.writeIntSliceForeign
 * introduced mem.writeIntSliceNative
 * introduced mem.writeIntSliceBig
 * introduced mem.writeIntSliceLittle
 * introduced mem.writeIntSlice
 * removed mem.endianSwapIfLe
 * removed mem.endianSwapIfBe
 * removed mem.endianSwapIf
 * added mem.littleToNative
 * added mem.bigToNative
 * added mem.toNative
 * added mem.nativeTo
 * added mem.nativeToLittle
 * added mem.nativeToBig
2018-12-12 20:35:04 -05:00
Andrew Kelley
1b0f4d5976
implement compile error note for function parameter type mismatch 2018-12-05 15:32:25 -05:00
kristopher tate
2b78a90424
std.os.path: remove dependance on std.mem.join;
std/os/child_process.zig: windows

test/cli.zig: godbolt;

doc/docgen.zig
2018-11-30 03:52:27 +09:00
Andrew Kelley
56a8f2b018
fix @intCast not catching negative numbers to unsigned 2018-11-24 14:36:16 -05:00
Sahnvour
703c6684d1 Crash fixes and small improvements to inline asm. (#1756)
* codegen: LLVMConstInlineAsm is deprecated.

* codegen: replace commas in asm constraint strings by pipes as required by LLVM.

* ir: enforce usage of '=' constraint modifier for inline assembly outputs.

Others are not currently supported and this was just asserted alter in `ir_render_asm`.

* asm: forbid comptime_int/floats as inputs in favor of explicitely sized constants.

Fixes a crash due to comptime_int/floats having no type_ref.

* asm: handle inputs with integers of <8 or non power of 2 bitsize.

We widen them to the next highest power of two.
2018-11-19 16:22:21 -05:00
Andrew Kelley
2f5d1ec500
improve error message when wrong type returned
closes #1650
2018-11-19 11:22:57 -05:00
Andrew Kelley
3829e200ec
fix assertion failure related to @intToEnum 2018-11-18 20:04:16 -05:00
Andrew Kelley
f8a782fb2e
all numbers with comptime known values implicitly cast
to all number types. If the value does not fit,
a compile error is emitted.

closes #422
closes #1712
2018-11-18 19:37:59 -05:00
Andrew Kelley
c21884e1d6 Merge remote-tracking branch 'origin/master' into llvm8 2018-11-17 02:18:56 -05:00
Andrew Kelley
704374e512
rename section keyword to linksection
add zig fmt support for this syntax

closes #1152
2018-11-17 01:38:35 -05:00
Jimmi Holst Christensen
be9bb0a857 Fixed #1663 and removed IrInstructionArrayLen 2018-11-16 10:15:13 -05:00
Andrew Kelley
3666fbd9f9
** and ++ operators force comptime on operands
closes #1707
2018-11-14 12:23:40 -05:00
Jimmi Holst Christensen
8139c5a516
New Zig formal grammar (#1685)
Reverted #1628 and changed the grammar+parser of the language to not allow certain expr where types are expected
2018-11-13 05:08:37 -08:00
Andrew Kelley
ef5d7ce463
array type syntax implies comptime 2018-11-09 19:26:54 -05:00
Andrew Kelley
63f636e7b7
limit integer types to maximum bit width of 65535
closes #1541
2018-11-06 11:09:14 -05:00
Andrew Kelley
2928b01afc fix broken cli test and translate-c: support no-op cast 2018-11-05 20:03:16 -05:00
Andrew Kelley
0a495aa563 update type info behavior test
it depends on the OS struct, which is probably not necessary
to accomplish the test's goal.
2018-11-05 11:37:48 -05:00
Andrew Kelley
2b395d4ede
remove @minValue,@maxValue; add std.math.minInt,maxInt
closes #1466
closes #1476
2018-10-26 15:01:51 -04:00
Andrew Kelley
d5648d2640
remove implicit cast from T to *const T
closes #1465
2018-10-15 18:23:47 -04:00
Jimmi Holst Christensen
378d3e4403
Solve the return type ambiguity (#1628)
Changed container and initializer syntax
* <container> { ... } -> <container> . { ... }
* <exrp> { ... } -> <expr> . { ...}
2018-10-15 09:51:15 -04:00
Andrew Kelley
b7dda772a8
disable C ABI tests on macos due to LLD deficiency
See #1535

we'll have a better macos linker someday
2018-10-06 00:06:36 -04:00
Jimmi Holst Christensen
bc3e99c5e5
Fixed StackTrace not being resolved when panic is invalid (#1615) 2018-10-01 20:30:34 +02:00
Andrew Kelley
9d4eaf1e07
update std lib API for I/O
std.io.FileInStream -> std.os.File.InStream
std.io.FileInStream.init(file) -> file.inStream()
std.io.FileOutStream -> std.os.File.OutStream
std.io.FileOutStream.init(file) -> file.outStream()

remove a lot of error code possibilities from os functions

std.event.net.socketRead -> std.event.net.read
std.event.net.socketWrite -> std.event.net.write
add std.event.net.readv
add std.event.net.writev
add std.event.net.readvPosix
add std.event.net.writevPosix
add std.event.net.OutStream
add std.event.net.InStream

add std.event.io.InStream
add std.event.io.OutStream
2018-09-30 17:28:35 -04:00
Andrew Kelley
1c26c2f4d5
fix crash when compile error evaluating return...
...type of inferred error set. closes #1591
2018-09-26 16:59:08 -04:00
Andrew Kelley
589201b104
fix variables which are pointers to packed struct fields
closes #1121
2018-09-26 14:54:53 -04:00
Andrew Kelley
dcfd15a7f0
the last number in a packed ptr is host int bytes
See #1121
2018-09-26 14:54:52 -04:00
Andrew Kelley
9485043b3c
fix implicit casting to *c_void
closes #1588

also some small std lib changes regarding posix sockets
and one doc typo fix
2018-09-26 11:06:09 -04:00
Andrew Kelley
2e562a5f36
fix crash on runtime index into slice of comptime type
closes #1435
2018-09-25 12:03:39 -04:00
Andrew Kelley
eafb8e8572
fix self reference through fn ptr field crash
closes #1208
2018-09-25 10:45:11 -04:00
Andrew Kelley
4241cd666d
fix more bigint code paths and add tests 2018-09-24 16:31:22 -04:00
Andrew Kelley
877036e7ef fix translate-c test expecting incorrect C ABI on windows 2018-09-24 15:14:20 -04:00
Andrew Kelley
32c91ad892
fix comptime bitwise operations with negative values
closes #1387
closes #1529
2018-09-24 14:38:51 -04:00
Andrew Kelley
004c383292
fix translate-c incorrectly translating negative enum init values
closes #1360
2018-09-24 12:19:16 -04:00
Andrew Kelley
8a7737eef4
fix godbolt cli test on non-linux-x86_64 hosts 2018-09-24 12:01:51 -04:00
Andrew Kelley
6d048aa3bf
add panic function to godbolt CLI API test 2018-09-24 11:14:39 -04:00
Andrew Kelley
a155f2973b
add test to cover the CLI API that godbolt is using
closes #1399
2018-09-24 11:12:21 -04:00
Andrew Kelley
c84548e71d
fix @compileLog having unintended side effects
closes #1459
2018-09-22 10:46:22 -04:00
Andrew Kelley
5c15c5fc48
add compile error for slice of undefined slice
closes #1293
2018-09-22 10:04:47 -04:00
Andrew Kelley
2e27407161
stage1: unify 2 implementations of pointer deref
I found out there were accidentally two code paths
in zig ir for pointer dereference. So this should
fix a few bugs.

closes #1486
2018-09-21 18:47:12 -04:00
Andrew Kelley
9e5cd43e6d
fix comptime string concatenation ignoring slice bounds
closes #1362
2018-09-21 15:45:13 -04:00
Andrew Kelley
7c5e3e1f8e
fixups 2018-09-21 14:15:58 -04:00
Andrew Kelley
5a21d3dce0
Merge branch 'BitByteOffsetOfs' of https://github.com/raulgrell/zig into raulgrell-BitByteOffsetOfs 2018-09-21 13:10:21 -04:00
Andrew Kelley
44f2ee101f
fix comptime slice of pointer to array
closes #1565
2018-09-21 10:31:11 -04:00
Andrew Kelley
9c8dfadbb1
add compile error for casting const array to mutable slice
See #1565
2018-09-20 12:24:51 -04:00
Andrew Kelley
f8fe517d12
better string literal caching implementation
We were caching the ConstExprValue of string literals,
which works if you can never modify ConstExprValues.
This premise is broken with `comptime var ...`.

So I implemented an optimization in ConstExprValue
arrays, where it stores a `Buf *` directly rather
than an array of ConstExprValues for the elements,
and then similar to array of undefined, it is
expanded into the canonical form when necessary.
However many operations can happen directly on the
`Buf *`, which is faster.

Furthermore, before a ConstExprValue array is expanded
into canonical form, it removes itself from the string
literal cache. This fixes the issue, because before an
array element is modified it would have to be expanded.

closes #1076
2018-09-20 11:04:31 -04:00
Andrew Kelley
345f8db1c4
fix optional pointer to empty struct incorrectly being non-null
closes #1178
2018-09-18 17:51:50 -04:00
Andrew Kelley
c1af360532
add compile error for slice.*.len
closes #1372
2018-09-18 16:32:40 -04:00
Andrew Kelley
8c77c5705f
implementation for bitcasting extern enum type to c_int
closes #1036
2018-09-18 15:00:14 -04:00
Andrew Kelley
5fd3af9dc6
fix implicit cast of packed struct field to const ptr
closes #966
2018-09-18 14:34:30 -04:00
Andrew Kelley
d353d5aef8
fix @bytesToSlice on a packed struct
closes #1551
2018-09-18 09:49:57 -04:00
Josh Wolfe
13645585fe link to #1544 2018-09-17 21:25:37 -04:00
Josh Wolfe
d7492b2c22 somewhat realistic usecase test for shifting strange integer sizes 2018-09-17 20:49:23 -04:00
Andrew Kelley
bfcfaaf5bd
fix codegen for @intCast to u0 2018-09-17 20:33:42 -04:00
Andrew Kelley
b16229da1d
add compile error for @ptrCast 0 bit type to non-0 bit type 2018-09-17 19:41:11 -04:00
Andrew Kelley
78a9a465a3
add compile error for non-optional types compared against null
closes #1539
2018-09-17 18:58:50 -04:00
Andrew Kelley
6c71e9a54d
fix crash when bit shifting a u1 2018-09-17 18:44:45 -04:00
Andrew Kelley
cf9200b815
dereferencing a *u0 is comptime-known to be 0 2018-09-17 18:13:38 -04:00
Andrew Kelley
4c6f1e614a
remove zig build --init. add zig init-lib and zig init-exe
init-lib creates a working static library with tests, and
init-exe creates a working hello world with a `run` target.

both now have test coverage with the new "cli tests" file.

closes #1035
2018-09-17 17:11:18 -04:00
Andrew Kelley
9c9eefc841
allow extern structs to have stdcallcc function pointers
closes #1536
2018-09-17 11:22:30 -04:00
Andrew Kelley
dd5b2d1b04
fix crash when pointer casting a runtime extern function 2018-09-16 11:23:38 -04:00
Andrew Kelley
3f776af3fa
fix alignment of structs
closes #1248
closes #1052
closes #1154
2018-09-14 19:08:59 -04:00
Wink Saville
82af31ce36 Fix additional regressions calling FileOutStream/FileInStream init()
This is caused by change 686663239a and not
fixed in 832caefc2a.
2018-09-14 12:07:21 -04:00
Andrew Kelley
3d38feded9
fix tagged union with all void payloads but meaningful tag
closes #1322
2018-09-14 00:38:22 -04:00
Andrew Kelley
1e03cf1739
fix assertion failure on compile-time @intToPtr of function 2018-09-13 19:12:25 -04:00
Andrew Kelley
c06a61e9bf
remove this. add @This().
closes #1283
2018-09-13 16:34:33 -04:00
Andrew Kelley
7c3636aaa3
remove the scope parameter of setFloatMode
also document that scopes inherit this value. See #367
See #1283
2018-09-13 15:46:34 -04:00
Andrew Kelley
ac0cda8df8
add compile error for merging non- error sets
closes #1509
2018-09-13 13:48:41 -04:00
Andrew Kelley
22e39e1e5a
fix tagged union with only 1 field tripping assertion
closes #1495

now the tag type of an enum with only 1 item is comptime_int.
2018-09-13 13:33:11 -04:00
Andrew Kelley
7dd3c3814d
fix incorrect error union const value generation
closes #1442

zig needed to insert explicit padding into this structure before
it got bitcasted.
2018-09-11 15:16:50 -04:00
Andrew Kelley
dd1338b0e6
fix incorrect union const value generation
closes #1381

The union was generated as a 3 byte struct when it needed to be
4 bytes so that the packed struct bitcast could work correctly.

Now it recognizes this situation and adds padding bytes to become
the correct size so that it can fit into an array.
2018-09-11 12:59:39 -04:00
Andrew Kelley
52f4e934a9
fix llvm assertion and missing compile error 2018-09-10 22:44:27 -04:00
Andrew Kelley
9c169f3cf7
C ABI: support returning large structs on x86_64
also panic instead of emitting bad code for returning small structs

See #1481
2018-09-07 20:09:33 -04:00
Andrew Kelley
9017efee22
C ABI: support medium size structs & unions for x86_64 params
See #1481
2018-09-07 18:51:34 -04:00
raulgrell
09a1162af5 builtin functions: @byteOffsetOf and @bitOffsetOf 2018-09-07 22:49:19 +01:00
Andrew Kelley
b18af37c57
fix crash when var init has compile error
and then the var is referenced

closes #1483
2018-09-07 15:17:24 -04:00
Andrew Kelley
743b2e4afc
add C ABI test for big unions 2018-09-07 13:51:11 -04:00
Andrew Kelley
be6cccb3a5
stage1: c abi for big struct works 2018-09-07 11:52:57 -04:00
Andrew Kelley
a9a925e500
add C ABI tests 2018-09-06 16:29:35 -04:00
Andrew Kelley
6632d85e5f
stage1: improve handling of generic fn proto type expr
closes #902
2018-09-05 21:21:59 -04:00
Andrew Kelley
1d8b8ad687
add compile error for using outer scoped runtime variables
from a fn defined inside it. closes #876
2018-09-05 20:32:06 -04:00
Andrew Kelley
a3d384e593
add test case for #726 2018-09-05 18:20:04 -04:00
Andrew Kelley
b517bea734
allow comptime_int to @floatToInt 2018-09-05 18:01:48 -04:00
hfcc
768d1fc539 Added compilation error when a non-float is given to @floatToInt() 2018-09-05 23:31:25 +02:00
Andrew Kelley
ffb3b1576b
stage1: fix tagged union with no payloads
closes #1478
2018-09-05 16:19:58 -04:00
Andrew Kelley
c87a576cb5
stage1 compile error instead of crashing for unsupported comptime ptr cast
See #955
2018-09-05 15:53:36 -04:00
Andrew Kelley
a76a72469b
stage1: fix crash when invalid type used in array type
closes #1186
2018-09-05 10:43:35 -04:00
Andrew Kelley
869167fc6d
compile error for @noInlineCall on an inline fn
closes #1133
2018-09-04 17:38:48 -04:00
Andrew Kelley
68db9d5074
add compile error for comptime control flow inside runtime block
closes #834
2018-09-04 15:28:35 -04:00
Andrew Kelley
e82cd53df4
fix incorrect value for inline loop
09cc1dc660 failed to handle mem_slot_index correctly

closes #1436
2018-09-03 21:24:20 -04:00
Andrew Kelley
95636c7e5f
ability to @ptrCast to *void
fixes #960
2018-09-03 00:04:12 -04:00
Andrew Kelley
832caefc2a fix regressions 2018-09-02 18:35:32 -04:00
Andrew Kelley
b65cca37ce
add test coverage for invalid switch expression parameter
closes #604
2018-08-28 15:48:39 -04:00
Andrew Kelley
901b5c1566
add compile error for function prototype with no body
closes #1231
2018-08-28 15:39:32 -04:00
Andrew Kelley
09cc1dc660
fix crash when var in inline loop has different types
closes #917
closes #845
closes #741
closes #740
2018-08-28 15:24:28 -04:00
Andrew Kelley
45d9d9f953
minor fixups 2018-08-27 18:31:28 -04:00
raulgrell
e2a9f2ef98 Allow implicit cast from *T and [*]T to ?*c_void 2018-08-27 23:13:57 +01:00
Andrew Kelley
009e90f446
fix @typeInfo unable to distinguish compile error vs no-payload
closes #1421
closes #1426
2018-08-27 17:13:34 -04:00
Andrew Kelley
526d8425ab
fix false negative determining if function is generic
This solves the smaller test case of #1421 but the
other test case is still an assertion failure.
2018-08-27 16:14:48 -04:00
Andrew Kelley
4b68ef45af fix incorrectly generating an unused const fn global
closes #1277
2018-08-22 14:31:30 -04:00
Raul Leal
87b10400c2 allow implicit cast from *[N]T to ?[*]T (#1398)
* allow implicit cast from *[N]T to ?[*]T
2018-08-22 13:12:08 -04:00
Andrew Kelley
02ba4b1678 Merge branch 'master' into shawnl-path_max 2018-08-21 20:56:28 -04:00
Andrew Kelley
b2917e6be0 Revert "Merge branch 'mtn-translate-c-enum-vals'"
This reverts commit 937b822fa9, reversing
changes made to dd4b13ac03.

Tests failing on Windows.

Re-opens #1360
2018-08-21 20:50:03 -04:00
Andrew Kelley
ea1b21dbdb fix linux
* error.BadFd is not a valid error code. it would always be a bug to
   get this error code.
 * merge error.Io with existing error.InputOutput
 * merge error.PathNotFound with existing error.FileNotFound.
   Not all OS's support both.
 * add os.File.openReadC
 * add error.BadPathName for windows file operations with invalid
   characters
 * add os.toPosixPath to help stack allocate a null terminating byte
 * add some TODOs for other functions to investigate removing the
   allocator requirement
 * optimize some implementations to use the alternate functions when
   a null byte is already available
 * add a missing error.SkipZigTest
 * os.selfExePath uses a non-allocating API
 * os.selfExeDirPath uses a non-allocating API
 * os.path.real uses a non-allocating API
 * add os.path.realAlloc and os.path.realC
 * convert many windows syscalls to use the W versions (See #534)
2018-08-21 20:31:50 -04:00
kristopher tate
b023db2e82 src/translate_c.cpp: correctly bridge llvm::APSInt with Zig BigInt;
ACHTUNG: llvm::APSInt stores an int's sign inside of its getRawData; Internally to Zig we store an integer's sign outside of getRawData! (~aps_int) calls .flip() internally on the raw data to match Zig.

test/translate_c.zig: enum: add wider range of values (u64) to try;
2018-08-20 22:46:11 -04:00
Michael Noronha
7e7e59d881 translate-c: Correctly translate enum init values, addressing #1360 2018-08-20 22:45:19 -04:00
Andrew Kelley
dd4b13ac03 Revert "translate-c: Correctly translate enum init values, addressing #1360 (#1377)"
This reverts commit b8ce8f219c.

Squashing the commits from the pull request resulted in kristopher tate
from being omitted from the authors. A future commit will merge
the code correctly.
2018-08-20 22:39:39 -04:00
Michael Noronha
b8ce8f219c translate-c: Correctly translate enum init values, addressing #1360 (#1377)
* translate-c: Correctly translate enum init values

* translate-c: Test enum initialization

* translate-c: Flip to positive using APSInt builtins

* src/translate_c.cpp: correctly bridge llvm::APSInt with Zig BigInt;

ACHTUNG: llvm::APSInt stores an int's sign inside of its getRawData; Internally to Zig we store an integer's sign outside of getRawData! (~aps_int) calls .flip() internally on the raw data to match Zig.

* test/translate_c.zig: enum: add wider range of values (u64) to try;

closes #1360
2018-08-20 14:29:26 -04:00
Andrew Kelley
63a23e848a translate-c: fix for loops with var init and empty body 2018-08-05 18:40:14 -04:00
Andrew Kelley
387fab60a6 translate-c: fix do while with empty body 2018-08-05 18:32:38 -04:00
Andrew Kelley
c420b234cc translate-c: handle for loop with empty body 2018-08-05 18:18:24 -04:00
Andrew Kelley
aa232089f2 translate-c: fix while loop with no body 2018-08-05 18:06:39 -04:00
Andrew Kelley
9bd8b01650 fix tagged union initialization with a runtime void
closes #1328
2018-08-03 15:21:08 -04:00
kristopher tate
298abbcff8 better support for _ identifier
* disallow variable declaration of `_`
 * prevent `_` from shadowing itself
 * prevent read access of `_`

closes #1204
closes #1320
2018-08-03 02:57:17 -04:00
Andrew Kelley
895f262a55 pull request fixups
* clean up parser code
 * fix stage2 parse and render code
 * remove redundant test
 * make stage1 compile tests leaner
2018-08-02 14:15:31 -04:00
kristopher tate
9b890d7067 test/cases/cancel.zig: update suspend to use @handle();
Tracking Issue #1296 ;
2018-08-02 17:47:03 +09:00
kristopher tate
9bed23f8b7 test/cases/coroutines.zig: update suspend to use @handle();
Tracking Issue #1296 ;
2018-08-02 17:46:41 +09:00
kristopher tate
51955a5ca2 test/compile_errors.zig: update test to reflect that the promise symbol is no in scope with suspend;
Tracking Issue #1296 ;
2018-08-02 17:02:14 +09:00
kristopher tate
9b3cebcdb9 test/cases/coroutines.zig: test for immediate resume inside of suspend with @handle();
Tracking Issue #1296 ;
2018-08-02 17:02:14 +09:00
kristopher tate
3241ada468 test/cases/coroutines.zig: update test to reflect that the promise symbol is no in scope with suspend;
Tracking Issue #1296 ;
2018-08-02 17:02:14 +09:00
kristopher tate
79792a32e1 test/cases/coroutine_await_struct.zig: update test to reflect that the promise symbol is no in scope with suspend;
Tracking Issue #1296 ;
2018-08-02 16:59:11 +09:00
kristopher tate
13ec5db234 test/compile_errors.zig: @handle() in non-async function
Tracking Issue #1296 ;
2018-08-02 16:50:08 +09:00
kristopher tate
c546f750f1 test/compile_errors.zig: @handle() called outside of function definition;
Tracking Issue #1296 ;
2018-08-02 16:50:08 +09:00
kristopher tate
1f0040dd92 test/cases/coroutines.zig: remove dummy assert used for testing; 2018-08-02 16:50:08 +09:00
kristopher tate
0ee6502562 src/codegen.cpp: remove add_node_error from ir_render_handle;
Tracking Issue #1296 ;
Thanks @andrewrk ;
2018-08-02 16:50:08 +09:00
kristopher tate
9366a58bdd test/cases/couroutines.zig: test @handle();
Tracking Issue #1296 ;
2018-08-02 16:50:08 +09:00
Andrew Kelley
c91c781952 add behavior tests for cancel semantics 2018-07-30 12:49:53 -04:00
Andrew Kelley
442e244b4d suspend sets suspend bit 2018-07-27 17:16: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
02713e8d8a fix race conditions in self-hosted compiler; add test
* fix race condition in std.event.Channel deinit
 * add support to zig build for --no-rosegment
 * add passing self-hosted compare-output test for calling a function
 * put a global lock on LLD linking because it's not thread safe
2018-07-24 21:28:54 -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
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
f5a67dba08 self-hosted: implicit cast comptime ints to other ints
we now have successful exit codes from main linking
against libc
2018-07-20 01:46:49 -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
bd1c55d2c2 self-hosted: compile errors for return in wrong place
* outside fn definition
 * inside defer expression
2018-07-18 17:43:36 -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
Jimmi HC
b7be082bd9 -Dskip-release now also skips build example tests 2018-07-18 10:28:14 +02:00
Andrew Kelley
cbfe9a4077 fix @setEvalBranchQuota not respected in generic fn calls
closes #1257
2018-07-17 23:37:17 -04:00
Andrew Kelley
0fa24b6b75 allow implicit cast of undefined to optional 2018-07-16 19:26:15 -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
f78d4ed30c add an assertion to the test 2018-07-14 11:33:01 -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
5354d1f5fc allow == for comparing optional pointers
closes #658
2018-07-13 12:34:42 -04:00
Andrew Kelley
9751a0ae04 std.atomic: use spinlocks
the lock-free data structures all had ABA problems and
std.atomic.Stack had a possibility to load an unmapped memory address.
2018-07-11 19:38:01 -04:00
Andrew Kelley
9bdcd2a495 add std.event.Future
This is like a promise, but it's for multiple getters, and
uses an event loop.
2018-07-11 16:00:06 -04:00
Andrew Kelley
5954c94d20 build system: add -Dskip-release option to test faster 2018-07-11 14:09:05 -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
28f9230b40 fix crash when calling comptime-known undefined function ptr
closes #880
closes #1212
2018-07-10 10:12:08 -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
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
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
35463526cc add runtime safety for @intToEnum; add docs for runtime safety
See #367
2018-07-02 15:50:28 -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
b182151de5 Fixed line numbers for tests 2018-06-30 21:59:14 +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
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
4c3f27ce1e ir_resolve_const now checks recursivly for undef values 2018-06-29 10:21:43 +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