Commit Graph

93 Commits

Author SHA1 Message Date
Andrew Kelley b9a099e83c stage2: type declarations ZIR encode AnonNameStrategy
which can be either parent, func, or anon. Here's the enum reproduced in
the commit message for convenience:

```zig
pub const NameStrategy = enum(u2) {
    /// Use the same name as the parent declaration name.
    /// e.g. `const Foo = struct {...};`.
    parent,
    /// Use the name of the currently executing comptime function call,
    /// with the current parameters. e.g. `ArrayList(i32)`.
    func,
    /// Create an anonymous name for this declaration.
    /// Like this: "ParentDeclName_struct_69"
    anon,
};
```

With this information in the ZIR, a future commit can improve the
names of structs, unions, enums, and opaques.

In order to accomplish this, the following ZIR instruction forms were
removed and replaced with Extended op codes:

 * struct_decl
 * struct_decl_packed
 * struct_decl_extern
 * union_decl
 * union_decl_packed
 * union_decl_extern
 * enum_decl
 * enum_decl_nonexhaustive

By being extended opcodes, one more u32 is needed, however we more than
make up for it by repurposing the 16 "small" bits to provide shorter
encodings for when decls_len == 0, fields_len == 0, a source node is not
provided, etc. There tends to be no downside, and in fact sometimes
upsides, to using an extended op code when there is a need for flag
bits, which is the case for all three of these. Likewise, the container
layout can be encoded in these bits rather than into the opcode.

The following 4 ZIR instructions were added, netting a total of 4 freed
up ZIR enum tags for future use:

 * opaque_decl_anon
 * opaque_decl_func
 * error_set_decl_anon
 * error_set_decl_func

This is so that opaques and error sets can have the same name hint as
structs, enums, and unions.

`std.builtin.ContainerLayout` gets an explicit integer tag type so that
it can be used inside packed structs.

This commit also makes `Module.Namespace` use a separate set for
anonymous decls, thus allowing anonymous decls to share the same
`Decl.name` as their owner `Decl` objects.
2021-05-10 21:34:43 -07:00
Andrew Kelley 5619ce2406 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * doc/langref.html.in
 * lib/std/enums.zig
 * lib/std/fmt.zig
 * lib/std/hash/auto_hash.zig
 * lib/std/math.zig
 * lib/std/mem.zig
 * lib/std/meta.zig
 * test/behavior/alignof.zig
 * test/behavior/bitcast.zig
 * test/behavior/bugs/1421.zig
 * test/behavior/cast.zig
 * test/behavior/ptrcast.zig
 * test/behavior/type_info.zig
 * test/behavior/vector.zig

Master branch added `try` to a bunch of testing function calls, and some
lines also had changed how to refer to the native architecture and other
`@import("builtin")` stuff.
2021-05-08 14:45:21 -07:00
Veikka Tuominen fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
Andrew Kelley fc40d23723 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * build.zig
 * lib/std/array_list.zig
 * lib/std/c/ast.zig
 * lib/std/c/parse.zig
 * lib/std/os/bits/linux.zig
2021-05-05 10:48:22 -07:00
lithdew 76304a36af std/builtin: add missing comma to CallingConvention 2021-05-03 14:49:10 +09:00
lithdew 13068da43e x/os, x/net: re-approach Address, rename namespace TCP -> tcp
Address comments from @ifreund and @MasterQ32 to address unsafeness and
ergonomics of the `Address` API.

Rename the `TCP` namespace to `tcp` as it does not contain any
top-level fields.

Fix missing reference to `sockaddr` which was identified by @kprotty in
os/bits/linux/arm64.zig.
2021-05-03 14:49:10 +09:00
Andrew Kelley df24ce52b1 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted to take advantage of the new hex float parsing
code.
2021-04-28 14:57:38 -07:00
Andrew Kelley 429cd2b5dd std: change @import("builtin") to std.builtin 2021-04-15 19:06:39 -07:00
Sreehari S 9ebdbca379 callconv: add SysV 2021-04-08 21:00:53 -07:00
Tadeo Kondrak 1c15091bc8 stage1: switch from inline fn to callconv(.Inline) 2021-02-10 20:06:13 -07:00
Tadeo Kondrak 0b5f3c2ef9 Replace @TagType uses, mostly with std.meta.Tag 2021-01-30 22:26:44 +02:00
LemonBoy dd973fb365 std: Use {s} instead of {} when printing strings 2021-01-02 17:12:57 -07:00
Frank Denis 6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
LemonBoy 9b7d9c72b0 stage1: Initial implementation of @extern 2020-11-20 22:32:43 +01:00
Tadeo Kondrak 25ec2dbc1e Add builtin.Signedness, use it instead of is_signed 2020-11-19 18:59:21 +02:00
Veikka Tuominen ee1d21bbef Merge pull request #6649 from Rocknest/verparse
make Version.parse less strict
2020-11-18 16:06:52 +02:00
LemonBoy 0d6a7088dc stage1: Implement Add/Mul reduction operators 2020-11-01 14:30:31 -07:00
Rocknest 39841d5e2c remove workaround 2020-10-12 15:18:50 +03:00
Rocknest 47d7bf1a0e add a test for Version.parse 2020-10-11 16:30:51 +03:00
Rocknest cd4200ccef make Version.parse less strict 2020-10-11 16:29:19 +03:00
Andrew Kelley 95a37373e9 Merge pull request #6421 from tadeokondrak/opaque-syntax
Add opaque syntax that allows declarations
2020-10-07 16:58:50 -04:00
Tadeo Kondrak 0a6863a267 Remove .Cold calling convention.
This isn't a stable, defined calling convention, so it shouldn't be
grouped in with the others.

Closes https://github.com/ziglang/zig/issues/6556
2020-10-07 04:31:20 -04:00
Tadeo Kondrak 069fbb3c01 Add opaque type syntax 2020-10-06 22:08:24 -06:00
LemonBoy 22b5e47839 stage1: Implement @reduce builtin for vector types
The builtin folds a Vector(N,T) into a scalar T using a specified
operator.

Closes #2698
2020-10-05 04:51:45 -04:00
Tadeo Kondrak 183d1d4ba1 Switch TypeInfo.Fn.alignment to comptime_int from u29
All integers in TypeInfo are intentionally comptime_int:
https://github.com/ziglang/zig/issues/1683
2020-10-01 18:01:41 -06:00
Tadeo Kondrak 97ab720d84 stage1: Add alignment to TypeInfo.Fn 2020-10-01 17:59:42 -06:00
Tadeo Kondrak a12203d2be Switch TypeInfo alignment fields from u29 to comptime_int 2020-10-01 15:01:28 -06:00
Tadeo Kondrak d81648ce8c Add alignment field to TypeInfo.UnionField and TypeInfo.StructField
Closes https://github.com/ziglang/zig/issues/6122
2020-10-01 15:01:25 -06:00
Tadeo Kondrak 77df5dae7f Make builtin.TypeInfo.Pointer.alignment u29 instead of comptime_int 2020-10-01 15:01:24 -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
Tadeo Kondrak 1b2154dfe2 builtin: Add TypeInfo.StructField.is_comptime 2020-09-02 00:17:59 -04:00
Tadeo Kondrak a049c31f21 Remove TypeInfo.Error.value 2020-08-22 03:20:12 -04:00
Andrew Kelley 776bfb0ee6 Merge pull request #6099 from tadeokondrak/@Type(.Struct)
Implement @Type for structs
2020-08-20 16:57:10 -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
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
Maciej Walczak 6febe7e977 copy_file_range linux syscall (#6010) 2020-08-11 15:49:43 -04:00
Andrew Kelley 20510d209b GeneralPurposeAllocator: use std.log instead of std.debug.print
`std.builtin.StackTrace` gains a `format` function.

GeneralPurposeAllocator uses `std.log.err` instead of directly printing
to stderr. Some errors are recoverable.

The test runner is modified to fail the test run if any log messages of
"err" or worse severity are encountered.

self-hosted is modified to always print log messages of "err" severity
or worse even if they have not been explicitly enabled.

This makes GeneralPurposeAllocator available on the freestanding target.
2020-08-11 02:01:32 -04:00
Vexu a1e78d0b06 add is_tuple field to struct typeinfo
part of #4335
2020-07-17 00:15:34 +03:00
Vexu e85fe13e44 run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03: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
Andrew Kelley 4a38799631 make file and fn_name fields of SourceLocation also null-terminated
One of the main motivating use cases for this language feature is
tracing/profiling tools, which expect null-terminated strings for these
values. Since the data is statically allocated, making them
additionally null-terminated comes at no cost.

This prevents the requirement of compile-time code to convert to
null-termination, which could increase the compilation time of
code with tracing enabled.

See #2029
2020-06-18 17:09:10 -04:00
Vexu a5379aa3ee implement @src 2020-06-18 21:11:09 +03:00
Tadeo Kondrak a62e9bc8e5 Implement @Type for ErrorSet 2020-05-02 14:39:32 -06:00
Tadeo Kondrak 647901b4a8 Constify TypeInfo 2020-05-02 14:39:31 -06:00
Tadeo Kondrak ca6db2d008 Implement @Type() for EnumLiteral and FnFrame 2020-05-02 14:39:28 -06:00
xackus cd20e0cc67 rename mem.separate to mem.split 2020-04-04 17:37:51 -04:00
Andrew Kelley 656ba530d8 Merge remote-tracking branch 'origin/master' into llvm10 2020-03-13 15:17:53 -04:00
Benjamin Feng 4aae55b4cc Replace fmt with new fmtstream 2020-03-12 10:41:09 -05:00
Benjamin Feng 0fbccec000 Convert builtin to fmtstream 2020-03-12 10:41:04 -05:00
Andrew Kelley 96c07674fc Merge remote-tracking branch 'origin/master' into llvm10 2020-03-07 12:18:41 -05:00