Commit graph

117 commits

Author SHA1 Message Date
Veikka Tuominen
b511231f95 Merge pull request #13338 from Vexu/stage2-compile-errors
Improve some error messages
2023-01-09 13:48:34 -07:00
Yujiri
d8970de510 Add docstrings to some functions in std.meta 2023-01-09 13:46:58 -07:00
Evin Yulo
b346d48572 Simplify code in std.meta.isTag 2022-10-16 11:35:27 -04:00
Isaac Yonemoto
99c3578f69
adds isTag function to std.meta (#11895) 2022-10-15 14:32:05 -04:00
Silver
f3a1b5c481 std/meta: make FieldEnum(T) == Tag(T) for tagged unions when values match field indices 2022-09-27 18:42:20 +03:00
Veikka Tuominen
541b3e3a31 Sema: check pointer qualifiers before implicit cast
Closes #12881
2022-09-20 00:50:13 +03:00
antlilja
ae8d26a6a0 Sema: add error for non-comptime param in comptime func
Adds error for taking a non comptime parameter in a function returning a
comptime-only type but not when that type is dependent on a parameter.

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-08-27 11:17:48 +03:00
Felix "xq" Queißner
5696cc8ab6 Adds std.meta.FnPtr for easier stage1/stage2 compatibility 2022-08-24 03:13:44 -04:00
Felix "xq" Queißner
263b5933d2 Makes std.meta.Tuple and std.meta.ArgsTuple generate a unique type instead of generating one per invocation. 2022-08-05 15:39:53 +03:00
Veikka Tuominen
6d44c0a16c std: update tests to stage2 semantics 2022-06-03 20:21:20 +03:00
Erik Arvstedt
8b8e57c670 std.meta.TrailerFlags: include in std tests
Previously, TrailerFlags was unreferenced in std,
so its tests were never run.

Also, fix the use of `default_value` whose type was changed in
f4a249325e (#10766).
2022-05-04 20:01:48 +02:00
Isaac Freund
6c0719fd5f std.meta: deprecate bitCount() for @bitSizeOf() 2022-04-27 11:10:52 +02:00
Jimmi Holst Christensen
cea310c908 Remove usage of inline for from print_targets.cmdTargets
This function was one of the biggest zig functions in a debug build of
the compiler.

  $ bloaty stage3-debug/bin/zig -d symbols --tsv -n 10000000 |
      rg -v '(llvm|clang|std|lld|\(anonymous namespace\))::|\[section ' |
      sort -h -k 3

  ...
  translate_c.ast.renderNode                    86168   86219
  main.buildOutputType                         177959  178004
  InfoTable                                    184832  184870
  AArch64SVEIntrinsicMap                       188544  188596
  print_targets.cmdTargets__anon_4735          319156  319216
  __static_initialization_and_destruction_0()  486666  489582
  MatchTable1                                  621884  621997
  OperandMatchTable                           1139622 1139861
  MatchTable0                                 1899764 1900141
2022-04-26 17:52:21 -04:00
Andrew Kelley
f5f5b9373d std.meta: fix unit tests depending on unstable behavior
The unit tests of std.meta depended on `@typeInfo` for the same type
returning a slice of declarations and fields with the same pointer
address. This is not something guaranteed by the language specification.
2022-03-24 17:47:39 -07:00
Andrew Kelley
2af69710a7 stage2: fix some generics issues
* std.meta: correct use of `default_value` in reification. stage1
   accepted a wrong type for `null`.
 * Sema: after instantiating a generic function, if the return type ends
   up being a comptime-known type, then we return an error, undoing the
   generic function instantiation, and making a comptime function call
   instead.
   - We also needed to clean up the dependency graph in this case.
 * Sema: reified enums set tag_ty_inferred to false since an integer tag
   type is provided. This is a limitation of the `@Type` builtin which
   will be addressed with #10710.
 * Sema: fix resolveInferredErrorSet incorrectly calling
   ensureFuncBodyAnalyzed on generic functions.
2022-03-23 23:28:05 -07:00
Andrew Kelley
d42d31f72f basic language features do not belong in std.meta 2022-03-14 00:11:46 -07:00
Jonathan Marler
d805adddd6 deprecated TypeInfo in favor of Type
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-03-08 20:38:12 +02:00
Andrew Kelley
f4a249325e stage1: avoid anytype fields for type info
prerequisite for #10705
2022-02-01 18:10:19 -07:00
Andrew Kelley
75bbc74d56 a small crusade against std.meta.declarations 2022-01-31 22:25:49 -07:00
Meghan Denny
b7ba728929 std: add meta.DeclEnum 2022-01-20 10:54:45 +02:00
Andrew Kelley
902df103c6 std lib API deprecations for the upcoming 0.9.0 release
See #3811
2021-11-30 00:13:07 -07:00
Lewis Gaul
bc3e86c4b7 Add std.meta.Float, alongside std.meta.Int 2021-11-22 21:30:20 -05:00
InKryption
eeb8629bea Use debug.assert instead of testing.expect.
`testing.expect` and friends are intended to be used only in tests; this change reflects that intention.
2021-10-29 20:01:59 +00:00
Andrew Kelley
6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Robin Voetter
c5945467ac Address Spaces: Pointer and function info in @Type 2021-09-20 02:29:04 +02:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Jacob G-W
9fffffb07b fix code broken from previous commit 2021-06-21 17:03:03 -07:00
Jacob G-W
641ecc260f std, src, doc, test: remove unused variables 2021-06-21 17:03:03 -07:00
Veikka Tuominen
699b6cdf01 translate-c: move utility functions to a separate namespace 2021-06-14 20:13:34 +03:00
Veikka Tuominen
029fe6c9ab meta.cast: handle casts from negative ints to ptrs 2021-06-13 16:53:01 +03:00
Evan Haas
45212e3b33 translate-c: Implement flexible arrays
Fixes #8759
2021-06-11 21:31:39 +03:00
Andrew Kelley
c9cc09a3bf Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * lib/std/os/linux.zig
 * lib/std/os/windows/bits.zig
 * src/Module.zig
 * src/Sema.zig
 * test/stage2/test.zig

Mainly I wanted Jakub's new macOS code for respecting stack size, since
we now depend on it for debug builds able to pass one of the test cases
for recursive comptime function calls with `@setEvalBranchQuota`.

The conflicts were all trivial.
2021-05-12 16:41:20 -07:00
Isaac Freund
c036957521
std.meta.Elem: support all optional types 2021-05-11 22:22:21 +02: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
474ade88b5 std: fix compile errors found by stage2 AstGen 2021-04-29 20:33:29 -07: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
2fc6b347ec
Merge pull request #8616 from LemonBoy/fn-align
Function pointer alignment
2021-04-25 19:12:06 -04:00
Andrew Kelley
6f61594692
Merge pull request #8496 from xackus/isError
std.meta: add isError
2021-04-25 13:27:44 -04:00
LemonBoy
19cec0db1e std: Make met.alignment work on more types
Make it return the correct value for function types and optional
pointers.
2021-04-25 16:49:21 +02:00
Andrew Kelley
e86cee258c Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted the change that makes `suspend;` illegal in the
parser.
2021-04-24 10:44:41 -07:00
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