Commit graph

176 commits

Author SHA1 Message Date
Andrew Kelley
507a8096d2 std: fix compile errors caught by stage2 AstGen
* `comptime const` is redundant
 * don't use `extern enum`; specify a tag type.
   `extern enum` is only when you need tags to alias. But aliasing tags
   is a smell. I will be making a proposal shortly to remove `extern enum`
   from the language.
 * there is no such thing as `packed enum`.
 * instead of `catch |_|`, omit the capture entirely.
 * unused function definition with missing parameter name
 * using `try` outside of a function or test
2021-04-22 18:07:46 -07:00
Evan Haas
d4d21dd46d translate-c: better handling of int -> enum casts
In std.meta.cast when casting to an enum type from an integer type, first
do a C-style cast from the source value to the tag type of the enum.
This ensures that we don't get an error due to the source value not being
representable by the enum.

In transCCast() use std.meta.cast instead of directly emitting the cast
operation since the enum's underlying type may not be known at translation
time due to an MSVC bug, see https://github.com/ziglang/zig/issues/8003

Fixes #6011
2021-04-15 22:46:22 -04:00
Andrew Kelley
429cd2b5dd std: change @import("builtin") to std.builtin 2021-04-15 19:06:39 -07:00
xackus
89c41f30c3 zig fmt 2021-04-11 20:16:17 +02:00
xackus
a5007d819a std.meta: add isError 2021-04-11 16:26:29 +02:00
xackus
2d2316f5c0 translate-c: fix meta.cast to ?*c_void 2021-04-08 08:33:26 +03:00
Evan Haas
8de14a98a6 translate-c: Add support for vector expressions
Includes vector types, __builtin_shufflevector, and __builtin_convertvector
2021-04-06 11:22:27 -07:00
xackus
9a94415680 translate-c: improve std.meta.cast 2021-03-17 00:05:42 +02:00
xackus
eee43a65ae add tests 2021-03-05 21:21:23 +01:00
Maciej Walczak
5f53b77c2b remove redundant cast
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2021-03-05 21:04:27 +01:00
xackus
679910ecec translate-c: promote int literals to bigger types 2021-03-05 21:04:27 +01:00
Andrew Kelley
5f35dc0c0d zig fmt the std lib 2021-02-24 21:29:23 -07:00
Tadeo Kondrak
0b5f3c2ef9
Replace @TagType uses, mostly with std.meta.Tag 2021-01-30 22:26:44 +02:00
Tadeo Kondrak
b7767eb834
std.meta: rename TagPayloadType to TagPayload 2021-01-30 13:19:52 +02:00
Tadeo Kondrak
68ec54f386
std.meta: rename TagType to Tag 2021-01-30 13:19:52 +02:00
Martin Wickham
3d4eeafb47 Fill out more cases for std.meta.sizeof 2021-01-30 11:13:20 +02:00
daurnimator
9c97a07f18 std: have std.meta.fieldInfo take an enum rather than a string 2021-01-01 15:48:46 -07:00
daurnimator
73bf2e1525 std: add std.meta.FieldEnum 2021-01-01 15:48:04 -07:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
Andrew Kelley
53987c932c std.crypto.random: introduce fork safety
Everybody gets what they want!

 * AT_RANDOM is completely ignored.
 * On Linux, MADV_WIPEONFORK is used to provide fork safety.
 * On pthread systems, `pthread_atfork` is used to provide fork safety.
 * For systems that do not have the capability to provide fork safety,
   the implementation falls back to calling getrandom() every time.
 * If madvise is unavailable or returns an error, or pthread_atfork
   fails for whatever reason, it falls back to calling getrandom() every
   time.
 * Applications may choose to opt-out of fork safety.
 * Applications may choose to opt-in to unconditionally calling
   getrandom() for every call to std.crypto.random.fillFn.
 * Added `std.meta.globalOption`.
 * Added `std.os.madvise` and related bits.
 * Bumped up the size of the main thread TLS buffer. See the comment
   there for justification.
 * Simpler hot path in TLS initialization.
2020-12-18 15:54:01 -07:00
Vexu
7e30e83900
small fixes and zig fmt 2020-12-09 13:54:26 +02:00
Jonathan Marler
48660371a2 std.meta: add assumeSentinel 2020-11-29 10:36:02 -08:00
LemonBoy
a2e9554699 std: Add test for meta.declarations on opaque{} 2020-11-21 14:03:49 -08:00
Isaac Freund
a5691ee363 std.meta.declarations: support opaque {} 2020-11-19 15:04:38 -08:00
Tadeo Kondrak
25ec2dbc1e Add builtin.Signedness, use it instead of is_signed 2020-11-19 18:59:21 +02:00
Alexandros Naskos
252924ae33 Added std.meta.fieldNames 2020-11-18 13:16:56 +02:00
xackus
27b73cc395 std: make meta.IntType a compile error
the function signature changed
also update langref
2020-11-18 12:57:49 +02:00
Frank Denis
37bc6ee54a std.meta: test that const and mut variables have different addresses
We are checking that two identical, constant values, are stored at
different addresses.

But sharing a unique location doesn't look like something the compiler
wouldn't do.

It may make more sense to check that a const variable and a mutable
variable set to the same value have different addresses.
2020-11-03 16:52:51 -05:00
Felix (xq) Queißner
b014bc77c8 Fixes std.meta.Tuple and std.meta.ArgsTuple for zero-sized types (like void). 2020-10-17 21:10:01 -04:00
Jan Prudil
aadccc4206 Make std.meta.Int accept a signedness parameter 2020-10-17 14:09:59 +02:00
Tadeo Kondrak
e892ee17e6 std: move std.meta.refAllDecls to std.testing 2020-10-15 20:34:22 -04:00
Tadeo Kondrak
362c87f1aa
Update std.meta.ArgsTuple for alignment in StructField/UnionField 2020-10-01 15:06:24 -06:00
Tadeo Kondrak
ec8f0777f2
Update std.meta.Tuple for alignment in StructField/UnionField 2020-10-01 15:06:23 -06:00
Alexandros Naskos
d27a34f05c
Merge branch 'master' into args-tuple 2020-09-29 16:19:44 +03:00
Felix (xq) Queißner
c2d60bc5b5 Follows @tadeokondrak remark about taking []const type. 2020-09-28 12:24:22 +02:00
Felix (xq) Queißner
55dfe729b4 Changes comptime block to test. 2020-09-28 11:44:55 +02:00
Felix (xq) Queißner
9331466998 Changes comptime block to test. 2020-09-28 11:42:39 +02:00
Felix (xq) Queißner
7f68b14377 Implements std.meta.Tuple(), implements #4607 in userland. 2020-09-25 09:27:00 +02:00
Felix (xq) Queißner
93291cc472 Implements std.meta.ArgsTuple. 2020-09-25 09:16:43 +02:00
Vexu
a3624e94f8
translate-c: determine sizeof using std.meta.sizeof 2020-09-14 23:53:38 +03:00
Vexu
29fd0c6d61
fix meta.cast behavior; add exhaustive tests 2020-09-14 23:21:26 +03:00
Tadeo Kondrak
771f35c593
Use less inefficient method of replacing TypeInfo.UnionField.enum_field 2020-09-07 06:23:27 -06:00
Tadeo Kondrak
ac19ccf595
Update standard library for removal of TypeInfo.UnionField.enum_field 2020-09-07 06:23:26 -06:00
Lachlan Easton
2a58e30bd5 std meta: fix use of alignOf in meta.cast 2020-09-03 14:11:04 -04:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Andrew Kelley
eac6280241 add std.meta.TrailerFlags API
This is useful for saving memory when allocating an object that has many
optional components. The optional objects are allocated sequentially in
memory, and a single integer is used to represent each optional object
and whether it is present based on each corresponding bit.
2020-07-14 17:19:17 -07:00
Vexu
e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
Charlie Stanton
8c15cfe3da Compacts switch statements and string literal 2020-06-21 21:48:12 +01:00
Charlie Stanton
6f47513009 Adds std.meta.cast and uses it to simplify translate-c 2020-06-21 18:24:59 +01:00
Andrew Kelley
c70633eacd
Merge pull request #5203 from tadeokondrak/@type-for-even-more-types
implement @typeInfo for Frame and implement @Type for Frame, EnumLiteral, and ErrorSet
2020-06-18 21:25:03 -04:00