Commit graph

1686 commits

Author SHA1 Message Date
Tadeo Kondrak
acdf1f0bde
@Type for union fixes 2020-09-07 06:23:50 -06:00
Tadeo Kondrak
ff2ed966bb
Implement @Type for Union
This removes TypeInfo.UnionField.enum_field, which is redundant with
TypeInfo.Union.tag_type.
2020-09-07 06:23:24 -06:00
Veikka Tuominen
41bbadbb9a
Merge pull request #6246 from Vexu/field
Remove deprecated fields on `type`
2020-09-05 13:58:02 +03:00
Vexu
6b2f4fd20d
langref: atomic ops are allowed on pointers
Closes #6217
2020-09-04 22:02:39 +03:00
Vexu
4eeeda0f52
remove deprecated fields from types 2020-09-03 16:49:20 +03:00
Andrew Kelley
c86108dd63
Merge pull request #6229 from LemonBoy/fix-6054
ir: Typecheck the sentinel value in *[N:S1]T to [S2]T casts
2020-09-02 19:13:21 -04:00
Tadeo Kondrak
1b2154dfe2 builtin: Add TypeInfo.StructField.is_comptime 2020-09-02 00:17:59 -04:00
LemonBoy
c51b871c45 ir: Typecheck the sentinel value in *[N:S1]T to [S2]T casts
Closes #6054
2020-09-01 17:29:10 +02:00
Tadeo Kondrak
a2c47d2b0b
Remove @OpaqueType 2020-08-30 19:02:23 -06:00
Vexu
c1ee9efb7c
fix error note using invalid source node
Closes #6153
2020-08-24 15:24:00 +03:00
Vexu
9589dc4c95 add error checks to @Type 2020-08-24 11:13:43 +03:00
Andrew Kelley
55d7c399c1
Merge pull request #6119 from tadeokondrak/@Type(.Enum)
Implement @Type for Enum
2020-08-22 03:21:46 -04:00
Tadeo Kondrak
a049c31f21 Remove TypeInfo.Error.value 2020-08-22 03:20:12 -04:00
Tadeo Kondrak
351701bcad
@Type for Enum fix: use correct decls_scope 2020-08-21 17:45:30 -06:00
Tadeo Kondrak
5a5956bd20
Implement @Type for Enum 2020-08-21 14:31:24 -06:00
Tadeo Kondrak
8126421d07
Small fixes for @Type(.Struct) 2020-08-19 16:36:22 -06:00
Tadeo Kondrak
b46d764fd9
Implement @Type for structs without decls support 2020-08-19 14:55:42 -06:00
Tadeo Kondrak
0f677810ea
Remove offset field from TypeInfo.StructField
This isn't needed with @bitOffsetOf/@byteoffsetOf and complicates
@Type handling.
2020-08-19 14:55:40 -06:00
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
Ashish Shekar
27cb23cbc5
Handle singular param count word in error messages (#6073) 2020-08-17 22:18:29 -04: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
Vexu
3734881577
add error for unused/duplicate block labels 2020-08-13 01:13:17 +03: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
Vexu
6bba7c702b add compile error for alignCasting zero sized types 2020-08-02 17:49:16 +00: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
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
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
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
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
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
antlilja
fd50696359 Store else node in IrInstSrcCheckSwitchProngs
* Remove have_else_prong (bool)
* Add else_prong (AstNode*)
2020-06-24 17:36:24 +02:00
Alexandros Naskos
eefcd04462 Small fixes, fixed tests, added test for argument tuple type 2020-06-24 16:56:24 +03:00
Alexandros Naskos
50b70bd77f @asyncCall now requires an argument tuple 2020-06-24 14:07:39 +03:00
antlilja
0de35af98b Add duplicate checking for switch on types
* Add compile error tests
2020-06-23 15:17:04 -04:00
xackus
d907f574e0 stage1: fix concat of sliced str literals 2020-06-21 14:57:12 -04:00