0
Fork 0
mirror of https://codeberg.org/ziglang/zig synced 2026-11-18 07:05:05 +00:00
zig/src
Andrew Kelley ede76f4fe3 stage2: fix generics with non-comptime anytype parameters
The `comptime_args` field of Fn has a clarified purpose:
For generic function instantiations, there is a `TypedValue` here
for each parameter of the function:
 * Non-comptime parameters are marked with a `generic_poison` for the value.
 * Non-anytype parameters are marked with a `generic_poison` for the type.

Sema now has a `fn_ret_ty` field. Doc comments reproduced here:
> When semantic analysis needs to know the return type of the function whose body
> is being analyzed, this `Type` should be used instead of going through `func`.
> This will correctly handle the case of a comptime/inline function call of a
> generic function which uses a type expression for the return type.
> The type will be `void` in the case that `func` is `null`.
Various places in Sema are modified in accordance with this guidance.

Fixed `resolveMaybeUndefVal` not returning `error.GenericPoison` when
Value Tag of `generic_poison` is encountered.

Fixed generic function memoization incorrect equality checking. The
logic now clearly deals properly with any combination of anytype and
comptime parameters.

Fixed not removing generic function instantiation from the table in case
a compile errors in the rest of `call` semantic analysis. This required
introduction of yet another adapter which I have called
`GenericRemoveAdapter`. This one is nice and simple - it's the same hash
function (the same precomputed hash is passed in) but the equality
function checks pointers rather than doing any logic.

Inline/comptime function calls coerce each argument in accordance with
the function parameter type expressions. Likewise the return type
expression is evaluated and provided (see `fn_ret_ty` above).

There's a new compile error "unable to monomorphize function". It's
pretty unhelpful and will need to get improved in the future. It happens
when a type expression in a generic function did not end up getting
resolved at a callsite. This can happen, for example, if a runtime
parameter is attempted to be used where it needed to be comptime known:

```zig
fn foo(x: anytype) [x]u8 { _ = x; }
```

In this example, even if we pass a number such as `10` for `x`, it is
not marked `comptime`, so `x` will have a runtime known value, making
the return type unable to resolve.

In the LLVM backend I implement cmp instructions for float types to pass
some behavior tests that used floats.
History 2021-08-06 16:24:39 -07:00
..
codegen stage2: fix generics with non-comptime anytype parameters 2021-08-06 16:24:39 -07:00
link macho: remove obsolete pack/unpack dylib ordinal fns 2021-08-02 19:49:32 +02:00
stage1 stage1: fix anon struct naming in certain cases 2021-07-28 18:17:11 -04:00
translate_c translate-c: add framework for special-casing macros 2021-07-22 08:09:46 -07:00
Air.zig stage2: implement @truncate 2021-08-01 16:13:58 -07:00
AstGen.zig AstGen: fix function declarations 2021-08-05 23:20:10 -07:00
BuiltinFn.zig minimum/maximum builtins 2021-07-26 20:41:00 -04:00
Cache.zig std: implement a cross platform file locking abstraction 2021-06-29 14:25:04 -07:00
clang.zig translate-c: better codegen for pointer index by int literal 2021-08-03 08:38:15 +03:00
clang_options.zig rename src-self-hosted/ to src/ 2020-09-21 18:38:55 -07:00
clang_options_data.zig zig cc: recognize more pie flags 2021-06-11 15:57:52 -07:00
codegen.zig stage2: implement @truncate 2021-08-01 16:13:58 -07:00
Compilation.zig Merge pull request #9517 from ziglang/generic-functions 2021-08-05 23:32:42 -07:00
config.zig.in add ast-check flag to zig fmt, fix found bugs 2021-06-14 00:16:40 +03:00
DepTokenizer.zig std, src, doc, test: remove unused variables 2021-06-21 17:03:03 -07:00
empty.zig fix wrong entrypoint, undefined package, and wrong build option 2020-12-07 17:27:09 -07:00
glibc.zig stage2: improvements towards zig test 2021-07-23 22:42:31 -07:00
introspect.zig zig build: use ZIG_GLOBAL_CACHE_DIR 2021-03-25 22:05:21 -04:00
libc_installation.zig native libc detection: respect spaces in CC env var 2021-06-09 17:26:58 -04:00
libcxx.zig stage2: improvements towards zig test 2021-07-23 22:42:31 -07:00
libtsan.zig stage2: improvements towards zig test 2021-07-23 22:42:31 -07:00
libunwind.zig stage2: improvements towards zig test 2021-07-23 22:42:31 -07:00
link.zig Merge remote-tracking branch 'origin/master' into zld-incremental-2 2021-07-23 17:06:19 +02:00
Liveness.zig stage2: implement @truncate 2021-08-01 16:13:58 -07:00
main.zig fix help for ast-check command 2021-08-01 03:57:34 -04:00
mingw.zig std, src, doc, test: remove unused variables 2021-06-21 17:03:03 -07:00
Module.zig stage2: fix generics with non-comptime anytype parameters 2021-08-06 16:24:39 -07:00
musl.zig stage2: improvements towards zig test 2021-07-23 22:42:31 -07:00
Package.zig Breaking hash map changes for 0.8.0 2021-06-03 17:02:16 -05:00
print_air.zig stage2: return type expressions of generic functions 2021-08-05 19:19:19 -07:00
print_env.zig fix code broken from previous commit 2021-06-21 17:03:03 -07:00
print_targets.zig fix code broken from previous commit 2021-06-21 17:03:03 -07:00
RangeSet.zig stage2: fix hashing and comparison design flaw with Value 2021-07-30 16:17:59 -07:00
register_manager.zig Get register_manager.zig tests to compile - use value '1' as mock Air.Inst.Index 2021-07-20 12:19:16 -07:00
Sema.zig stage2: fix generics with non-comptime anytype parameters 2021-08-06 16:24:39 -07:00
stage1.zig stage2: improvements towards zig test 2021-07-23 22:42:31 -07:00
target.zig initial plan9 boilerplate 2021-07-08 14:10:49 -07:00
test.zig stage2: improvements towards zig test 2021-07-23 22:42:31 -07:00
ThreadPool.zig std.Thread: fixup ThreadPool.zig 2021-06-30 21:49:00 -05:00
tracy.zig fix code broken from previous commit 2021-06-21 17:03:03 -07:00
translate_c.zig translate-c: handle macros that cast to cv void 2021-08-06 09:10:50 +03:00
type.zig Sema: respect requiresComptime of function return types 2021-08-05 23:26:11 -07:00
TypedValue.zig rename src-self-hosted/ to src/ 2020-09-21 18:38:55 -07:00
value.zig stage2: implement generic function memoization 2021-08-05 16:37:21 -07:00
WaitGroup.zig organize std lib concurrency primitives and add RwLock 2021-01-14 20:41:37 -07:00
wasi_libc.zig wasi-libc: remove crt1.o as it's not WASI ABI compatible 2021-07-11 00:06:47 +02:00
windows_com.hpp compiling on mingw is now supported (#1542) 2018-09-18 00:13:17 -04:00
windows_sdk.cpp fixed mingw compilation 2018-10-27 11:35:01 -04:00
windows_sdk.h fix regressed stage2 test harness 2020-09-21 21:14:01 -07:00
windows_sdk.zig add ast-check flag to zig fmt, fix found bugs 2021-06-14 00:16:40 +03:00
zig_clang.cpp translate-c: better codegen for pointer index by int literal 2021-08-03 08:38:15 +03:00
zig_clang.h translate-c: better codegen for pointer index by int literal 2021-08-03 08:38:15 +03:00
zig_clang_cc1_main.cpp fix to compile against 12.0.0-rc2 2021-02-25 19:41:30 -08:00
zig_clang_cc1as_main.cpp Update clang drivers 2020-12-16 12:18:14 +01:00
zig_clang_driver.cpp Fix argument forwarding to LLVM on Windows 2021-07-10 15:58:38 -04:00
zig_llvm-ar.cpp Fix argument forwarding to LLVM on Windows 2021-07-10 15:58:38 -04:00
zig_llvm.cpp minimum/maximum builtins 2021-07-26 20:41:00 -04:00
zig_llvm.h minimum/maximum builtins 2021-07-26 20:41:00 -04:00
Zir.zig Sema: respect requiresComptime of function return types 2021-08-05 23:26:11 -07:00