Commit Graph

4135 Commits

Author SHA1 Message Date
Veikka Tuominen
d139e44cfa
Merge pull request #5495 from xackus/fix_5314
stage1: fix non-exhaustive enums with one field
2020-08-18 23:55:44 +03:00
Andrew Kelley
56c81c713f stage1: let \r\n slide 2020-08-18 01:29:34 -07:00
Soren
60ea87340e Fix opaque structs and C++ mangling 2020-08-18 00:31:29 -04:00
Ashish Shekar
27cb23cbc5
Handle singular param count word in error messages (#6073) 2020-08-17 22:18:29 -04:00
Andrew Kelley
502d413621 simplify zig info and rename it to zig env
also add version to it
2020-08-17 17:06:43 -07:00
Sergey Poznyak
80e70735fb add zig info command 2020-08-17 16:35:32 -07:00
Vexu
2948f2d262
fix cast from invalid non-exhaustive enum to union 2020-08-17 20:48:22 +03:00
Vexu
1e835e0fcc
disallow '_' prong when switching on non-exhaustive tagged union
A tagged union cannot legally be initiated to an invalid enumeration
2020-08-17 20:47:31 +03:00
xackus
65185016f1
stage1: fix non-exhaustive enums with one field 2020-08-17 20:45:34 +03:00
Andrew Kelley
2cd19c05d0 stage1: remove buggy "unable to inline function" compile error
We still want this compile error but I'm giving up on implementing it
correctly in stage1. It's been buggy and has false positives sometimes.

I left the test cases there, but commented out, so that when we go
through the stage1 compile error cases and get coverage for them in
stage2 we can reactivate the test cases.

closes #2154
2020-08-15 09:53:39 -07:00
Andrew Kelley
576581bd7b stage1: fix enums having wrong debug info
It wasn't wrong info, but e.g. GDB couldn't handle non-power-of-two
enum tags. Now we tell debug info that enum tags are always power of two
size.

closes #4526
closes #5432
2020-08-13 20:32:32 -07:00
Vexu
3734881577
add error for unused/duplicate block labels 2020-08-13 01:13:17 +03:00
Vexu
cf5932b236
translate-c: convert int to bool if bool is expected 2020-08-11 12:24:45 +03:00
Andrew Kelley
1b1921f0e2 stage1: deal with WebAssembly not supporting @returnAddress()
This makes `@returnAddress()` return 0 for WebAssembly (when not using
the Emscripten OS) and avoids trying to capture stack traces for the
general purpose allocator on that target.
2020-08-08 01:00:29 -07:00
Andrew Kelley
cc17f84ccc std: introduce GeneralPurposeAllocator
`std.GeneralPurposeAllocator` is now available. It is a function that
takes a configuration struct (with default field values) and returns an
allocator. There is a detailed description of this allocator in the
doc comments at the top of the new file.

The main feature of this allocator is that it is *safe*. It
prevents double-free, use-after-free, and detects leaks.

Some deprecation compile errors are removed.

The Allocator interface gains `old_align` as a new parameter to
`resizeFn`. This is useful to quickly look up allocations.

`std.heap.page_allocator` is improved to use mmap address hints to avoid
obtaining the same virtual address pages when unmapping and mapping
pages. The new general purpose allocator uses the page allocator as its
backing allocator by default.

`std.testing.allocator` is replaced with usage of this new allocator,
which does leak checking, and so the LeakCheckAllocator is retired.

stage1 is improved so that the `@typeInfo` of a pointer has a lazy value
for the alignment of the child type, to avoid false dependency loops
when dealing with pointers to async function frames.

The `std.mem.Allocator` interface is refactored to be in its own file.

`std.Mutex` now exposes the dummy mutex with `std.Mutex.Dummy`.

This allocator is great for debug mode, however it needs some work to
have better performance in release modes. The next step will be setting
up a series of tests in ziglang/gotta-go-fast and then making
improvements to the implementation.
2020-08-07 22:45:45 -07:00
Andrew Kelley
ab483281d3 stage1: elide @intToPtr alignment safety check for 1-byte alignment 2020-08-07 23:36:36 -04:00
Vexu
4ab2f947f9
translate-c: recognize other type trait expressions
Closes #5979
2020-08-04 00:48:29 +03:00
Vexu
6bba7c702b add compile error for alignCasting zero sized types 2020-08-02 17:49:16 +00:00
Andrew Kelley
c37f273cb0 stage1: hot path for resolving types of primitives
This is an attempt to save memory when building self-hosted.

before:
Total bytes allocated: 5.941 GiB, deallocated: 2.259 GiB, remaining: 3.681 GiB

after:
Total bytes allocated: 5.933 GiB, deallocated: 2.253 GiB, remaining: 3.680 GiB
2020-07-28 00:00:35 -07:00
Vexu
5f0bde6358 add helpful error note for when function cannot return an error
This has caused frequent confusion since it looks like you are handling
errors correctly with a try but you forgot to change your return type.
2020-07-28 04:24:52 +00:00
zigazeljko
bf273b7aec Add comment explaining --stack-first option 2020-07-27 19:51:58 +00:00
Andrew Kelley
a36772ee64
Merge pull request #5693 from antlilja/switch-unreachable-else
Add error message for unreachable else prong in switch
2020-07-26 05:46:18 +00:00
Andrew Kelley
995fd7314c Revert "Support taking extern pointers at comptime"
This reverts commit d3ebd42865.

This caused a build failure on multiple targets.
2020-07-24 14:06:44 -07:00
yvt
d3ebd42865 Support taking extern pointers at comptime
This commit makes it possible to obtain pointers to `extern` variables
at comptime.

 - `ir_get_var_ptr` employs several checks to determine if the given
   variable is eligible for obtaining its pointer at comptime. This
   commit alters these checks to consider `extern` variables, which have
   runtime values, as eligible.

 - After this change, it's now possible for `render_const_val` to be
   called for `extern` variables. This commit modifies
   `render_const_val` to suppress the value generation for `extern`
   variables.

 - `do_code_gen` now creates `ZigValue::llvm_global` of `extern`
   variables before iterating through module-level variables so that
   other module-level variables can refer to them.

This solution is incomplete since there are several cases still
failing:

 - `global_var.array[n..m]`
 - `&global_var.array[i]`
 - `&global_var.inner_struct.value`
 - `&global_array[i]`

Closes #5349
2020-07-24 13:33:17 -07:00
Michael Dusan
3b26e50863 macOS: macho ld64.lld fixes
* bring `construct_linker_job_macho` to parity with
   `construct_linker_job_elf`
 * macho now sets `-error-limit`
 * macho on macOS now sets `-macosx_version_min` and `-sdk_version`
   to `10.13` when running `zig0`
 * macho now detects when `-l` prefix is not needed
 * macho on macOS detects system libraries in a case-insensitive manner
 * macho now ads user-specified libraries to linker command-line args
   when condition `is_native_os != true`
 * re-ordered some macho args positions to match elf positions

closes #5059
closes #5067
2020-07-24 20:01:18 +00:00
Andrew Kelley
25a01a16e0
Merge pull request #5905 from Vexu/stage2-float
Stage2: floats
2020-07-21 22:35:05 +00:00
Hiroki Noda
68e0632aa5 Use function attribute "frame-pointer" 2020-07-21 21:03:02 +00:00
Vexu
fd2f034e31
fix comptime comparisons of different sized floats 2020-07-21 22:29:15 +03:00
Vexu
596ca6cf70 allow non-pointer extern opaque variables 2020-07-18 16:45:07 +03:00
Vexu
78962eeeda
fix floatCast type check regression
Closes #5900
2020-07-18 10:22:15 +03:00
Vexu
a1e78d0b06
add is_tuple field to struct typeinfo
part of #4335
2020-07-17 00:15:34 +03:00
haze
82562b205f
On darwin, only add the self exe to the cache hash for compiler id (#5880)
Now that Big Sur does not have system libraries on the filesystem, zig can no longer read them and add them to the cache hash for the compiler id.
This changes it so that only the first library path returned by os_self_exe_shared_libs is added to the cache hash under Darwin. I looked into methods on getting the system version to keep parity with older versions, but @fengb reported that this works on Catalina (a version behind Big Sur)

Signed-off-by: Haze Booth <isnt@haze.cool>
2020-07-15 22:37:04 -04:00
Andrew Kelley
a7c3cec65f follow up from previous commit for generic methods 2020-07-14 15:29:07 -07:00
Andrew Kelley
4696cd3e09 fix ability to call methods on enums with pointer-to-self
closes #3218
2020-07-14 14:38:40 -07:00
Vexu
dff1ac1089 check for invalid sentinel when creating pointer with @Type 2020-07-13 00:29:53 +00:00
Vexu
bfe9d4184f fix alignment parsing in stage1 2020-07-12 07:35:34 +00:00
Vexu
be1507a7af
update compile error tests and some doc comments 2020-07-12 00:54:07 +03:00
Vexu
8110639c79
add 'anytype' to stage1 and langref 2020-07-11 17:41:33 +03:00
Vexu
2e037fd827 use correct cast function when doing @floatCast at comptime 2020-07-11 11:36:28 +03:00
Andrew Kelley
02619edf41 Revert "use correct cast function when doing @floatCast at comptime"
This reverts commit 2e1bdd0d14.

Test failures
2020-07-09 23:24:21 -07:00
Vexu
2e1bdd0d14
use correct cast function when doing @floatCast at comptime
Closes #5832
2020-07-09 21:25:55 +03:00
Vexu
5667a21b1e fix missing check on extern variables with no type 2020-07-08 03:09:41 +00:00
xackus
51f8c306d9 stage1: add missing runtime safety for @intCast unsigned -> signed of same bit count 2020-07-05 17:58:21 +02:00
Andrew Kelley
22f0a103c3 stage1 HashMap: linear scan for < 16 entries 2020-07-03 03:50:35 +00:00
Andrew Kelley
df2c27eb48 stage1 HashMap: store hash & do robin hood hashing
This adds these two fields to a HashMap Entry:

uint32_t hash
uint32_t distance_from_start_index

Compared to master branch, standard library tests compiled 8.4% faster
and took negligible (0.001%) more memory to complete. The amount of
memory used is still down from before 8b82c40104 which moved indexes
to be stored separately from entries.

So, it turns out, keeping robin hood hashing plus separating indexes
did result in a performance improvement. What happened previously is
that the gains from separating indexes balanced out the losses from
removing robin hood hashing, resulting in a wash.

This also serves as an inspiration for adding a benchmark to
std.AutoHashMap and improving the implementation.
2020-07-02 22:38:55 +00:00
Andrew Kelley
8b82c40104 stage1: reimplement HashMap
The indexes are stored separately using an array of
uint8_t, uint16_t, uint32_t, or size_t, depending on the number of
entries in the map.

Entries only contain a key and a value, no longer have
distance_from_start_index or is_used.

In theory this should be both faster and use less memory.

In practice it seems to have little to no effect. For the standard
library tests, vs master branch, the time had no discernable
difference, and it shaved off only 13 MiB of peak rss usage.
2020-07-02 04:53:26 +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
2fde8249b7 Fixed crash when resolving peer types of *[N:s]const T and [*:s]const T 2020-06-24 23:58:02 -04:00