Commit Graph

690 Commits

Author SHA1 Message Date
Vexu
78962eeeda
fix floatCast type check regression
Closes #5900
2020-07-18 10:22:15 +03:00
Vexu
dff1ac1089 check for invalid sentinel when creating pointer with @Type 2020-07-13 00:29:53 +00:00
Vexu
be1507a7af
update compile error tests and some doc comments 2020-07-12 00:54:07 +03:00
Vexu
2e037fd827 use correct cast function when doing @floatCast at comptime 2020-07-11 11:36:28 +03:00
Vexu
5667a21b1e fix missing check on extern variables with no type 2020-07-08 03:09:41 +00:00
antlilja
dcc406deff Add new error message for unreachable else prongs
* Adds error message for types: enum, int and bool
* Adds compile error tests
2020-07-01 16:09:36 +02:00
Andrew Kelley
581d16154b
Merge pull request #5696 from alexnask/async_call_tuple
@asyncCall now takes arguments as a tuple instead of varargs
2020-06-28 01:00:58 -04:00
arbrk1
78d8931647
Fix issue #5618 (#5685)
* fix issue #5618

* A test for the issue #5618 added.
Also inserted a comma in the neighboring test to make it more zigfmt-friendly.
2020-06-24 23:58:50 -04:00
Alexandros Naskos
eefcd04462 Small fixes, fixed tests, added test for argument tuple type 2020-06-24 16:56:24 +03:00
antlilja
0de35af98b Add duplicate checking for switch on types
* Add compile error tests
2020-06-23 15:17:04 -04:00
Robin Voetter
8696e52a3d
Make unary minus for unsigned types a compile error (#5654)
* Make unary minus for unsigned types a compile error

* Add unreachable when generating unsigned negate
2020-06-21 14:55:44 -04:00
Vexu
14acc65675
add tests for @src 2020-06-18 21:11:34 +03:00
Jakub Konka
8ffa8ed9a8 Expose full llvm intrinsic 2020-06-09 00:22:34 -04:00
Jakub Konka
73a3bfd1dd Add basic tests for the new builtins 2020-06-09 00:22:34 -04:00
xackus
0d40cb6255 stage1: fix crash on slice byte reinterpretation 2020-06-08 17:19:06 -04:00
foobles
51682717d7 Support equality comparison for optional to non-optional (?T ==/!= T)
extracted function ir_try_evaluate_bin_op_const
extracted type_is_self_comparable function
renamed ir_try_evaluate_bin_op_const to ir_try_evaluate_bin_op_cmp_const
implemented analysis of ?T == T
added ir_set_cursor_at_end_and_append_basic_block_gen
use build_br_gen and ir_set_cursor_at_end_and_append_block_gen
added ir_append_basic_block_gen
removed include of all_types in ir.cpp
extracted compile-time and runtime evaluation of cmp_optional_non_optional to separate functions

closes #5390
closes #1332
2020-05-29 18:46:09 -04:00
Jakub Konka
08b0cae777 Add matching compile error test 2020-05-26 18:00:08 +02:00
Andrew Kelley
9a22c8b6ca
Merge pull request #5057 from xackus/opaque-param
stage1: fix assert fail on opaque fn ptr param
2020-05-17 12:48:56 -04:00
xackus
204f8daeed stage1: detect underflow in bigint_fits_in_bits 2020-05-11 14:06:37 +02:00
Vexu
f2d3266075
Merge pull request #4932 from Qix-/fix-private-access
Fix private access
2020-05-08 18:21:15 +03:00
Josh Junon
fbf081a306
add failing test for #4909 2020-05-08 14:26:13 +03:00
xackus
2c9effc101 stage1: handle all cases of invalid struct field default value 2020-05-07 16:39:16 -04:00
Tadeo Kondrak
84a0a9688c
update docs/tests for async/extern fn removal 2020-05-05 10:31:32 -06:00
Andrew Kelley
e6955688ac
Merge pull request #5272 from tadeokondrak/noasync-to-nosuspend
Noasync to nosuspend
2020-05-05 11:21:02 -04:00
Tadeo Kondrak
2c9204032d
update tests for nosuspend 2020-05-05 05:55:26 -06:00
Vexu
adc444ceeb
fix missing compile error on call assigned to const 2020-05-04 14:28:58 +03:00
xackus
0db9e90e8f stage1: fix assert fail on opaque fn ptr param 2020-05-04 06:51:37 +02:00
Andrew Kelley
5929e5ca0e
Merge pull request #5196 from tadeokondrak/@vector-to-@type-vector
`@Vector` -> `@Type(.Vector)`
2020-04-28 16:25:40 -04:00
Tadeo Kondrak
f977155fdb
@Vector -> std.meta.Vector 2020-04-28 00:47:13 -06:00
Tadeo Kondrak
17e41f6cd3
@OpaqueType -> @Type(.Opaque) 2020-04-28 00:02:13 -06:00
LemonBoy
a7a8c433d0 stage1: Prevent the creation of illegal ptr types
Closes #5140
2020-04-24 15:55:32 -04:00
xackus
a9eb4a6740 stage1: fix crash on accessing an array of size zero with runtime index 2020-04-23 12:45:32 -04:00
Vexu
b6fe839248
update std lib to decls being disallowed between fields 2020-04-18 23:56:05 +03:00
Vexu
fff00c3bbb
disallow declarations between container fields 2020-04-18 23:56:03 +03:00
Vexu
4f02cf32b4
fix typeInfo tests 2020-04-18 11:39:52 +03:00
Vexu
1afaf42525
add error for non-exter variadic functions 2020-04-17 22:02:49 +03:00
Vexu
c026a9f6d2 fix missing compile errors on builtin cast functions 2020-04-17 14:22:20 -04:00
foobles
022a71ca7d
Shift error message now says "fixed-width integer type" instead of just "integer type" (#5028)
* error message of ir_analyze_bit_shift now more accurate/specific

* fixed compile error test to match bit shift error message
2020-04-14 16:19:45 -04:00
Vexu
f60e7348d5
add error message for invalid assignment 2020-04-09 11:50:32 +03:00
Vexu
b1e44adcba
move array and struct const checks to more appropriate places 2020-04-08 14:32:02 +03:00
Vexu
ff0f97a1bc
fix missing compile error on assign to slice and array parameters 2020-04-08 00:27:14 +03:00
Vexu
95fefcd4c9
fix broken tests 2020-04-07 16:56:48 +03:00
Vexu
e62671f643
fix missing const on address of literal 2020-04-07 15:25:44 +03:00
Michael Dusan
8b6a06eefe
add compiler-error test: coerce
Issue fixed by an unknown commit.

closes #4207
2020-04-03 19:11:51 -04:00
Michael Dusan
db4c06ce60 stage1: add compile errors for sentinel slicing
closes #3963
2020-04-03 19:05:30 -04:00
Michael Dusan
f6d384450f add compile-error test: bitcast
Issue fixed by an unknown commit.

closes #3818
2020-04-01 18:07:45 -04:00
LemonBoy
6695fa4f32 ir: Fix comparison of ?T values
The code assumed that every ?T had a pointer child type T, add some more
checks to make sure the type is effectively a pointer.

Closes #4789
2020-04-01 15:56:38 -04:00
Timon Kruiper
d9cf779b47 Fix some nullptr dereferences on arm-linux-musleabhif 2020-04-01 20:38:32 +02:00
Michael Dusan
e3d12471a2 add compile-error test for #2687
Issue fixed by an unknown commit.

closes #2687
2020-03-31 20:08:00 -04:00
Andrew Kelley
ab20b351ce
update compile error tests 2020-03-26 14:07:19 -04:00
Andrew Kelley
13d04f9963
Merge pull request #4741 from momumi/master
allow `_` separators in number literals (stage 1)
2020-03-23 00:54:54 -04:00
LemonBoy
dc79f181a5
ir: Disallow comparison between enum literal and untagged enum
Closes #4770
2020-03-21 20:54:05 -04:00
LemonBoy
28dbc58837 Address review comments 2020-03-21 09:54:49 +01:00
Andrew Kelley
160367e0dd
fix compile error for reading past end of pointer casted array 2020-03-19 17:23:53 -04:00
Andrew Kelley
61266d2621
test & docs fixups to work with new semantics 2020-03-19 09:53:55 -04:00
momumi
47f7e66580 add more test cases for invalid number literals 2020-03-15 23:42:29 +10:00
momumi
925f710852 make parsing 0.0_e1 an error 2020-03-15 13:05:24 +10:00
momumi
7aac21c6f5 allow _ separators in number literals (stage 1)
* Underscores `_` may be placed between two digits in a int/float literal
* Consecutive underscores are not allowed
* Fixed parsing bug in exponents of hexadecimal float literals.
  Exponents should always be base 10, but hex characters would be parsed
  inside the exponent and everything after them would be ignored. eg:
  `0x1.0p1ab1` would be parsed as `0x1.0p1`.
2020-03-15 12:38:35 +10:00
Andrew Kelley
f51bec321b
Merge pull request #4707 from Vexu/small-atomics
Support atomic operations with bools and non power of two integers
2020-03-12 18:55:16 -04:00
Vexu
710b05b153
support @atomicRmw at comptime 2020-03-12 16:46:16 +02:00
Vexu
ee5b00a8b9
use atomic bools in std lib 2020-03-10 22:54:47 +02:00
LemonBoy
300fceac6e ir: Implement more safety checks for shl/shr
The checks are now valid on types whose size is not a power of two.

Closes #2096
2020-03-10 20:54:05 +01:00
Andrew Kelley
675f01f176
Merge pull request #4590 from xackus/fix-4587
fix failed assert on generic fn opaque return type
2020-03-09 22:10:57 -04:00
xackus
e7cc456421 better error messages and more tests 2020-03-09 22:33:18 +01:00
Vexu
3fd2cd4367
add LemonBoy's test 2020-03-09 18:43:09 +02:00
Vexu
3618256c97
implement noasync scopes 2020-03-09 12:33:24 +02:00
LemonBoy
e2fd289a33 ir: Create usize result_loc for array subscript expr
Allow the subscript expression to infer the resulting type.

Closes #4169
2020-03-08 18:52:44 -04:00
LemonBoy
06d0dac0fb ir: Prevent crash in compiler error
Anonymous containers have no struct_field->type AstNode set, let's
always use the field node itself to make the error messages consistent.

Closes #4691
2020-03-08 18:12:50 -04:00
xackus
7782c76bee fix failed assert on generic fn opaque return type 2020-03-08 18:05:45 +01:00
daurnimator
b85bb152bf
Fix grammar in error message 2020-03-08 19:18:06 +11:00
LemonBoy
0c310f0fbf
ir: Implement @TypeOf with multiple arguments
Closes #439
2020-03-04 17:21:10 -05:00
Andrew Kelley
dbe4d72bcf
separate std.Target and std.zig.CrossTarget
Zig now supports a more fine-grained sense of what is native and what is
not. Some examples:

This is now allowed:
-target native

Different OS but native CPU, default Windows C ABI:
-target native-windows
This could be useful for example when running in Wine.

Different CPU but native OS, native C ABI.
-target x86_64-native -mcpu=skylake

Different C ABI but otherwise native target:
-target native-native-musl
-target native-native-gnu

Lots of breaking changes to related std lib APIs.
Calls to getOs() will need to be changed to getOsTag().
Calls to getArch() will need to be changed to getCpuArch().

Usage of Target.Cross and Target.Native need to be updated to use
CrossTarget API.

`std.build.Builder.standardTargetOptions` is changed to accept its
parameters as a struct with default values. It now has the ability to
specify a whitelist of targets allowed, as well as the default target.
Rather than two different ways of collecting the target, it's now always
a string that is validated, and prints helpful diagnostics for invalid
targets. This feature should now be actually useful, and contributions
welcome to further improve the user experience.

`std.build.LibExeObjStep.setTheTarget` is removed.
`std.build.LibExeObjStep.setTarget` is updated to take a CrossTarget
parameter.

`std.build.LibExeObjStep.setTargetGLibC` is removed. glibc versions are
handled in the CrossTarget API and can be specified with the `-target`
triple.

`std.builtin.Version` gains a `format` method.
2020-02-28 14:51:54 -05:00
Andrew Kelley
87b9e744dd
update std lib to new Target API 2020-02-28 14:51:54 -05:00
LemonBoy
2696c8b42d ir: Robust checking for init expr type
Closes #3979
2020-02-27 10:40:22 -05:00
LemonBoy
fd1eade4ca ir: Allow empty inferred error sets
Closes #4564
2020-02-26 21:02:22 -05:00
Vexu
d505ea6caf
fix @tagName on extern and non-exhaustive enums 2020-02-26 11:19:39 -05:00
LemonBoy
55ea855e2c ir: Various fixes for comptime ptr handling
* Correctly fold ptrToInt on optional types
* Generate null as ConstPtrSpecialNull in intToPtr
* Correctly stop ptrToInt on ?*T where T is zero-sized

Closes #4535
2020-02-25 17:38:56 -05:00
Vexu
d56115ef41
remove @IntType and @ArgType (mostly) from the compiler 2020-02-25 01:27:34 +02:00
Vexu
538d9a5dd8
remove uses of @ArgType and @IntType 2020-02-24 23:39:03 +02:00
Vexu
45da72c5b6
remove usages of @typeId, @memberCount, @memberName and @memberType 2020-02-24 23:09:01 +02:00
Andrew Kelley
1d06c82c3b
Merge pull request #4516 from xackus/remove-bytes-to-slice
remove @bytesToSlice, @sliceToBytes from the language
2020-02-24 13:51:47 -05:00
xackus
7664c3bc11 remove @bytesToSlice, @sliceToBytes from tests, docs 2020-02-23 18:03:50 +01:00
Andrew Kelley
2de7d0b10c
fix zig build, ABI ABI, and update tests to new Target layout 2020-02-20 18:50:20 -05:00
Andrew Kelley
903127f36c
Merge remote-tracking branch 'origin/master' into sub-architecture-annihilation 2020-02-20 18:36:04 -05:00
Andrew Kelley
0f016b368d
support -mcpu=baseline, both in stage1 and stage2
See e381a42de9 for more details.
This is set up so that if we wish to make "baseline" depend on the
OS in the future, it is possible to do that.
2020-02-20 18:31:17 -05:00
LemonBoy
a385547786 ir: Compile error on result_loc type mismatch w/ slicing
Closes #4508
2020-02-20 13:14:19 +01:00
Andrew Kelley
63383a8af8
consistent capitalization of error message 2020-02-19 01:24:19 -05:00
Andrew Kelley
30194f27fb
update new test case to take into account lazy @typeInfo 2020-02-18 18:27:18 -05:00
LemonBoy
a6b74cdd38
stage1: Make the parser reject extern fn with body 2020-02-18 18:18:29 -05:00
Andrew Kelley
ccca4b5a5e
Merge pull request #4474 from LemonBoy/saukerkraut
Patches
2020-02-18 18:15:11 -05:00
Timon Kruiper
7560fc716d
Makes the declaration slice resolve lazely when using @typeInfo
This way all the declarations in a container won't be resolved untill
the user actually uses the decls slice in the builtin TypeInfo union.
2020-02-18 15:26:37 -05:00
LemonBoy
6b74fd2e12 ir: Avoid invalidating the decl_table iterator
Collect the declarations to resolve first and run resolve_top_level_decl
on them later.

Closes #4310
2020-02-16 21:14:30 +01:00
LemonBoy
096f79260b ir: Prevent crash when indexing undefined ptr to array
Closes #4471
2020-02-16 19:53:53 +01:00
Andrew Kelley
70a4794c57
fix compiler assertion when duplicating fields...
...in nested anonymous struct literals

closes #4391
2020-02-10 10:57:40 -05:00
Andrew Kelley
014f66e6de Merge pull request #4404 from ziglang/async-std
a big step towards std lib integration with async I/O
2020-02-10 00:22:59 -05:00
Andrew Kelley
27575d19c8
avoid conflict with master branch 2020-02-09 22:44:23 -05:00
Andrew Kelley
acdf4048b4
allow local variable address detection to regress
See #3180 for a more comprehensive plan to catch this problem. More
sophisticated control flow analysis is needed to provide compile errors
for returning local variable addresses from a function.
2020-02-09 22:40:36 -05:00
Andrew Kelley
5ea79bfc4a
fix not checking type of return pointer
Thanks to Vexu for the test cases.

Closes #3422
Closes #3646
Closes #3224
Closes #3327
Closes #3269
2020-02-09 22:34:34 -05:00
LemonBoy
21932a0ef2 Fix edge case in cast between fn with varargs
* Prevent the next_param_index to become greater than the param_count
  one as it's expected by every other function.
* Fix a typo in a error message.

Closes #4381
2020-02-05 20:31:18 +01:00
Benjamin Feng
b077f3ab7d Promoted "leak_count_allocator" to the main testing.allocator 2020-01-29 22:22:00 -06:00
Benjamin Feng
aa9caf5064 Create leak_count_allocator 2020-01-29 14:37:01 -06:00
Benjamin Feng
4d134a01f5 Move debug.global_allocator to testing.allocator 2020-01-29 12:21:29 -06:00
Andrew Kelley
504ce86ac9
fix more compile error test regressions 2020-01-28 14:17:25 -05:00
Andrew Kelley
f41e50dc08
Merge branch 'fx-4274' of https://github.com/LemonBoy/zig into LemonBoy-fix-4274 2020-01-27 09:52:31 -05:00
LemonBoy
8d9b8ab930 More error checking for unresolved TLDs
Closes #4274
2020-01-23 22:40:12 +01:00
Andrew Kelley
48c7e6c48b
std.Target.CpuFeatures is now a struct with both CPU and feature set
Previously it was a tagged union which was one of:
 * baseline
 * a specific CPU
 * a set of features

Now, it's possible to have a CPU but also modify the CPU's feature set
on top of that. This is closer to what LLVM does.

This is more correct because Zig's notion of CPUs (and LLVM's) is not
exact CPU models. For example "skylake" is not one very specific model;
there are several different pieces of hardware that match "skylake" that
have different feature sets enabled.
2020-01-22 17:13:31 -05:00
Vexu
6c8f01dcde
correct field count 2020-01-16 22:52:10 +02:00
Vexu
02e5cb1cd4
add non-exhaustive enum to langref 2020-01-15 23:05:52 +02:00
Vexu
f3d174aa61
require size for non-exhaustive enums 2020-01-15 21:38:11 +02:00
Vexu
b971c7d0ff
update tests and translate-c 2020-01-15 20:58:42 +02:00
LemonBoy
49771f356f Make sure @export symbol name is not empty 2020-01-14 21:23:11 +01:00
LemonBoy
84930fec27 Validate switch range endpoints 2020-01-13 21:45:16 +01:00
LemonBoy
54b11f66a9 Fix compiler-error regression 2020-01-13 08:49:32 +01:00
LemonBoy
34cdcb13c0 Fix @call being too eager to resolve the fn argument
Closes #4020
2020-01-12 23:51:18 +01:00
LemonBoy
c96131f30c Propagate errors in for loop bodies
Closes #3819
2020-01-12 12:49:12 -05:00
LemonBoy
5ab5de89c0 New @export() handling
Use a struct as second parameter to be future proof (and also allows to
specify default values for the parameters)

Closes #2679 as it was just a matter of a few lines of code.
2020-01-09 13:43:06 -05:00
LemonBoy
3607d9ee68 Fix crash in struct initializer evaluation
Closes #4100
2020-01-07 15:06:22 -05:00
Andrew Kelley
8492c46ade
add test case for already fixed bug
closes #2655
2020-01-06 23:03:07 -05:00
LemonBoy
8c640b3e60 Prevent bitCast to enum types
Stop the user from creating invalid enum values.
2020-01-06 19:36:17 -05:00
Andrew Kelley
be2483c576
fix test suite regressions 2020-01-06 18:20:31 -05:00
Andrew Kelley
53913acaf7
zig fmt and update extern fn to callconv(.C) 2020-01-06 15:34:50 -05:00
LemonBoy
563d9ebfe5 Implement the callconv() annotation 2020-01-02 18:53:16 +01:00
Andrew Kelley
73e535e112
Merge pull request #3683 from Vexu/atomic-float
Support floats with some atomic operations
2019-12-30 19:19:05 -05:00
Andrew Kelley
a05150e92d
fix comparing comptime_int against undefined literal
closes #4004
2019-12-30 19:08:57 -05:00
LemonBoy
c1ee846c22 Fix ptrCast of zero-sized type
Closes #2431
2019-12-30 17:43:58 -05:00
Vexu
ab7fc33c83
add zig llvm wrapper for atomicrmw 2019-12-23 11:55:00 +02:00
Vexu
8bb1e04449
support some atomic operations with floats 2019-12-23 11:54:47 +02:00
Andrew Kelley
26f3c2d061
fix std.mem.addNullByte and implement sentinel slicing
see #3770
2019-12-20 18:28:56 -05:00
Andrew Kelley
9468d63819
allow comparison of any numeric types 2019-12-16 11:09:10 -05:00
Vexu
0f38410ea6
improve extern enum 2019-12-15 19:28:53 -05:00
LemonBoy
19ddbd9e9e Make sure the address is aligned for intToPtr ops
Closes #773
2019-12-15 14:41:05 -05:00
Vexu
c759a77aa0 fix dot init parsing 2019-12-12 13:06:48 -05:00
Robin Voetter
4b4fbe3887
Replace @typeOf with @TypeOf in all zig source
This change was mostly made with `zig fmt` and this also modified some whitespace. Note that in some files, `zig fmt` produced incorrect code, so the change was made manually.
2019-12-10 11:09:41 -05:00
Andrew Kelley
a3f6a58c77
remove var args from the language
closes #208
2019-12-09 15:27:27 -05:00
Andrew Kelley
8b2622cdd5
std.fmt.format: tuple parameter instead of var args 2019-12-08 22:53:51 -05:00
Andrew Kelley
fe8d65556d
add syntax for comptime struct fields 2019-12-08 12:26:20 -05:00
Andrew Kelley
656cc33f8d
allow calling with a new stack to regress a bit
Calling with a new stack, with a runtime-known stack pointer (e.g.
not a global variable) is regressed with this branch. It is now a
compile-error, due to the Runtime Hint system not being smart enough
to mix a compile-time modifier field with a runtime stack field.
I'm OK with this regression because this feature is flawed (see #3268)
and may be deleted from the language.
2019-12-06 15:25:00 -05:00
Andrew Kelley
71b7f4b47f
remove @newStackCall from zig 2019-12-06 14:52:09 -05:00
Andrew Kelley
ef83358eb6
remove @noInlineCall from zig 2019-12-05 17:37:29 -05:00
Andrew Kelley
1f602fe8c5
implement @call
closes #3732
2019-12-05 17:07:15 -05:00
Andrew Kelley
6a046c1bcd
activate start code when pub main exists
and rename LinkType->LinkMode, OutType->OutputMode
2019-12-03 12:50:42 -05:00
Vexu
ffd21c586d
fix tests 2019-12-03 12:50:42 -05:00
Vexu
20bcdab462
correct caching and add test for missing fn name 2019-12-03 12:50:41 -05:00
LemonBoy
fd7c7be33c Pick up WinMain with proper CC 2019-12-03 12:49:08 -05:00
Andrew Kelley
c32e50f505
fix regressions in compile error tests 2019-12-01 20:53:24 -05:00
Andrew Kelley
b36c07a95a
Merge remote-tracking branch 'origin/master' into remove-array-type-coercion 2019-12-01 09:56:01 -05:00
Andrew Kelley
f980c29306
fix typo in error note for integer casting 2019-11-29 22:33:55 -05:00
Andrew Kelley
8ecd6c4d8c
add compiler note for bad int coercion
closes #3724
2019-11-26 19:50:52 -05:00
Vexu
379d547603
add missing cast to generic function call result 2019-11-26 14:32:37 -05:00
Vexu
0e405c5fc5
add missing cast to call result type 2019-11-26 14:32:34 -05:00
Andrew Kelley
4261fa3c49
move logic to the appropriate layers; add new compile error 2019-11-25 18:46:17 -05:00
Andrew Kelley
34b1ebefaa
Merge remote-tracking branch 'origin/master' into null-terminated-pointers 2019-11-24 20:28:46 -05:00
Andrew Kelley
b9f88c3552
fix compile errors for array sentinels mismatching 2019-11-24 20:25:14 -05:00
Andrew Kelley
217a5090ff
fix compile error regressions 2019-11-24 18:10:31 -05:00
Andrew Kelley
c96d565166
add compile error for incompatible pointer sentinels 2019-11-24 17:02:56 -05:00
Andrew Kelley
4c7b52503b
all tests passing 2019-11-24 02:14:21 -05:00
Vexu
4d9318cee0
fix missing implicit cast in return instruction 2019-11-21 23:21:51 -05:00
Timon Kruiper
94299d16d1 Stage1: Add compile error for an empty switch on a integer 2019-11-22 04:00:47 +00:00
Andrew Kelley
fd6020c4e2
update tests, better error messages, update self-hosted tokenizer 2019-11-21 20:43:41 -05:00
Andrew Kelley
47f06be369
string literals are now null terminated
this also deletes C string literals from the language, and then makes
the std lib changes and compiler changes necessary to get the behavior
tests and std lib tests passing again.
2019-11-21 20:43:41 -05:00
Andrew Kelley
1aa978f32e
implement null terminated pointers 2019-11-21 20:43:41 -05:00
Andrew Kelley
0c33ebb38e
add regression test case. closes #2980 2019-11-18 19:59:03 -05:00
Andrew Kelley
21aed86a4a
add regression test case
closes #3097
2019-11-18 17:31:35 -05:00
LemonBoy
924dd674e2 Catch invalid type from peer resolution
Fixes #3703
2019-11-17 22:25:14 +00:00
Vexu
b83ce08a3b add compile error for @atomicRmw on enum not being an .Xchg 2019-11-13 18:48:31 +00:00
Andrew Kelley
8bae70454d
Merge pull request #3675 from Vexu/atomic-store
Add @atomicStore builtin
2019-11-13 03:06:55 +00:00
Andrew Kelley
37318bf151
fn parameters participate in result location semantics
See #3665
2019-11-12 18:55:17 -05:00
Vexu
41914321b4
fix comptime atomicStore and add tests 2019-11-13 01:32:16 +02:00
Andrew Kelley
a33b9aec72
add test for missing const in slice with nested array type 2019-11-11 18:01:27 -05:00
Andrew Kelley
5b27943498
implement anon struct literal syntax
This implements stage1 parser support for anonymous struct literal
syntax (see #685), as well as semantic analysis support for anonymous
struct literals and anonymous list literals (see #208). The semantic
analysis works when there is a type coercion in the result location;
inferring the struct type based on the values in the literal is not
implemented yet. Also remaining to do is zig fmt support for this new
syntax and documentation updates.
2019-11-11 13:11:58 -05:00
Andrew Kelley
3cf5c2c62b
fix regressed tests and update docs to use "type coercion" 2019-11-08 15:57:25 -05:00
Andrew Kelley
aa0daea541
update more of the std lib to use @as 2019-11-08 15:57:25 -05:00
Andrew Kelley
e0db54e89d
update the codebase to use @as 2019-11-08 15:57:24 -05:00
Andrew Kelley
9a08de93b6
fix incorrect type name on bit field pointers 2019-11-05 13:37:43 -05:00
Andrew Kelley
cbaa10fc3b
implement storing vector elements via runtime index 2019-11-05 12:11:57 -05:00
Andrew Kelley
70be308c43
implement loading vector elements via runtime index 2019-11-05 12:11:40 -05:00
LemonBoy
c47211cc60 Prevent crash when slicing undefined ptr to slice
Fixes #3534
2019-11-04 20:33:41 +01:00
LemonBoy
61825062aa Correctly process errors for invalid types in fn call
Fixes #3544
2019-11-04 20:33:40 +01:00
Andrew Kelley
0de862e8ba
make std.net more portable
* Delete `std.net.TmpWinAddr`. I don't think that was ever meant to
   be a real thing.
 * Delete `std.net.OsAddress`. This abstraction was not helpful.
 * Rename `std.net.Address` to `std.net.IpAddress`. It is now an extern
   union of IPv4 and IPv6 addresses.
 * Move `std.net.parseIp4` and `std.net.parseIp6` to the
   `std.net.IpAddress` namespace. They now return `IpAddress` instead of
   `u32` and `std.net.Ip6Addr`, which is deleted.
 * Add `std.net.IpAddress.parse` which accepts a port and parses either
   an IPv4 or IPv6 address.
 * Add `std.net.IpAddress.parseExpectingFamily` which additionally
   accepts a `family` parameter.
 * `std.net.IpAddress.initIp4` and `std.net.IpAddress.initIp6` are
   improved to directly take the address fields instead of a weird
   in-between type.
 * `std.net.IpAddress.port` is renamed to `std.net.IpAddress.getPort`.
 * Added `std.net.IpAddress.setPort`.
 * `os.sockaddr` struct on all targets is improved to match the
   corresponding system struct. Previously I had made it a union of
   sockaddr_in, sockaddr_in6, and sockaddr_un. The new abstraction for
   this is now `std.net.IpAddress`.
 * `os.sockaddr` and related bits are added for Windows.
 * `os.sockaddr` and related bits now have the `zero` fields default
   to zero initialization, and `len` fields default to the correct size.
   This is enough to abstract the differences across targets, and so
   no more switch on the target OS is needed in `std.net.IpAddress`.
 * Add the missing `os.sockaddr_un` on FreeBSD and NetBSD.
 * `std.net.IpAddress.initPosix` now takes a pointer to `os.sockaddr`.
2019-10-30 20:22:05 -04:00
Andrew Kelley
32c89531b1
Add missing compile error when ptr used instead of array
in array literals.

Fixes #3524
2019-10-24 16:23:33 -04:00
Andrew Kelley
17eb24a7e4
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
  `@import("std").builtin`. The target-related types are moved
  to `std.Target`. This allows the data types to have methods, such as
  `std.Target.current.isDarwin()`.
 * `std.os.windows.subsystem` is moved to
   `std.Target.current.subsystem`.
 * Remove the concept of the panic package from the compiler
   implementation. Instead, `std.builtin.panic` is always the panic
   function. It checks for `@hasDecl(@import("root"), "panic")`,
   or else provides a default implementation.

This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 19:09:49 -04:00
LemonBoy
ddb87237de Fix crash with peer type resolution & error unions
Fixes #3353
2019-10-20 22:03:39 -04:00
Michael Dusan
42f2814d9a stage1: fix root top-level-struct typename
- during diagnostics the string representation for root was empty
  and now is `(root)`
- retrofitted all other namespace-qualified type naming to elide
  prefixing with root

closes #2032
2019-10-09 17:36:13 -04:00
LemonBoy
663e665843
Prevent crash with invalid extern type
Fixes #3240
2019-09-23 17:30:28 -04:00
LemonBoy
db988f42a7 Fix computation of switch coverage
Closes #3258
2019-09-23 16:13:28 -04:00
Sahnvour
74d0b5bf7c reject types of automatic container layout in packed unions 2019-09-20 13:25:32 -04:00
Timon Kruiper
3b4a6679a6 Fix comptime bitcast inside an expression 2019-09-20 13:13:26 -04:00
Andrew Kelley
005a54a853
fixups for @splat
* Fix codegen for splat - instead of giving vectors of length N
   to shufflevector for both of the operands, it gives vectors of length
   1. The mask vector is the only one that needs N elements.
 * Separate Splat into SplatSrc and SplatGen; the `len` is not needed
   once it gets to codegen since it is redundant with the result type.
 * Refactor compile error for wrong vector element type so that the
   compile error message is not duplicated in zig source code
 * Improve implementation to correctly handle comptime values such as
   undefined and lazy values.
 * Improve compile error for bad vector element type to point to the
   correct place.
 * Delete dead code.
 * Modify behavior test to use an array cast instead of vector element
   indexing since I'm merging this splat commit out-of-order from
   Shawn's patch set.
2019-09-19 10:58:12 -04:00
Shawn Landden
01577a3af4
@splat 2019-09-19 10:11:06 -04:00
Andrew Kelley
2038f4d45a
rework the implementation
* update documentation
   - move `@shuffle` to be sorted alphabetically
   - remove mention of LLVM
   - minor clarifications & rewording
 * introduce ir_resolve_vector_elem_type to avoid duplicate compile
   error message and duplicate vector element checking logic
 * rework ir_analyze_shuffle_vector to solve various issues
 * improve `@shuffle` to allow implicit cast of arrays
 * the shuffle tests weren't being run
2019-09-18 16:15:19 -04:00
Shawn Landden
193604c837
stage1: add @shuffle() shufflevector support
I change the semantics of the mask operand, to make it a little more
flexible. There is no real danger in this because it is a compile-error
if you do it the LLVM way (and there is an appropiate error to tell you
this).

v2: avoid problems with double-free
2019-09-18 11:26:45 -04:00
Shawn Landden
0e3ca4c63e
Fix array->vector and vector->array for many types. Allow vector of bool.
Vectors do not have the same packing as arrays, and just bitcasting
is not the correct way to convert them.
2019-09-18 09:52:58 -04:00
Sahnvour
a06f84fcc6 forbid opaque types in function return types 2019-09-10 10:11:49 -04:00
Timon Kruiper
ca70ca7e26 Add compiler error when negating invalid type 2019-09-05 15:27:50 -04:00
Timon Kruiper
866c253e0e
Add compile error when shifting amount is not an int type 2019-09-05 13:10:39 -04:00
Andrew Kelley
ac7703f65f
fixups and add documentation for @Type 2019-09-04 11:12:14 -04:00
Jonathan Marler
b728cb6d4e Add @Type builtin 2019-09-03 22:50:29 -06:00
Sahnvour
ce14c543d1 error message and test for alignment of variables of zero-bit types 2019-09-03 21:14:40 -04:00
Andrew Kelley
5c3a9a1a3e
improvements to @asyncCall
* `await @asyncCall` generates better code. See #3065
 * `@asyncCall` works with a real `@Frame(func)` in addition to
   a byte slice. Closes #3072
 * `@asyncCall` allows passing `{}` (a void value) as the result
   pointer, which uses the result location inside the frame.
   Closes #3068
 * support `await @asyncCall` on a non-async function. This is in
   preparation for safe recursion (#1006).
2019-08-31 18:50:16 -04:00
Andrew Kelley
6ab8b2aab4
support recursive async and non-async functions
which heap allocate their own frames

related: #1006
2019-08-30 20:06:02 -04:00