Commit graph

72 commits

Author SHA1 Message Date
Daniele Cocca
00ed8d9c50 CBE: enable more tests that are currently passing 2022-03-17 11:39:56 -07:00
Andrew Kelley
0bc9635490 stage2: add debug info for locals in the LLVM backend
Adds 2 new AIR instructions:
 * dbg_var_ptr
 * dbg_var_val

Sema no longer emits dbg_stmt AIR instructions when strip=true.

LLVM backend: fixed lowerPtrToVoid when calling ptrAlignment on
the element type is problematic.

LLVM backend: fixed alloca instructions improperly getting debug
location annotated, causing chaotic debug info behavior.

zig_llvm.cpp: fixed incorrect bindings for a function that should use
unsigned integers for line and column.

A bunch of C test cases regressed because the new dbg_var AIR
instructions caused their operands to be alive, exposing latent bugs.
Mostly it's just a problem that the C backend lowers mutable
and const slices to the same C type, so we need to represent that in the
C backend instead of printing two duplicate typedefs.
2022-03-13 03:41:31 -04:00
Veikka Tuominen
98a5998d83 Sema: improve detection of generic parameters 2022-03-11 11:25:45 +02:00
joachimschmidt557
95fc41b2b4 stage2 ARM: implement ret_load 2022-03-08 21:10:04 +01:00
joachimschmidt557
a06e9eca45
stage2 AArch64: add more slice support
* airSlice
* airArrayToSlice
* and initial support for airSlicePtr and co
2022-03-05 11:31:51 +01:00
joachimschmidt557
91fbcf7093
stage2 ARM: enable more behavior tests 2022-02-27 21:38:56 +01:00
Jakub Konka
25e4b16e25 Port more behavior tests 2022-02-22 21:57:42 +01:00
joachimschmidt557
4468abfc42 stage2 ARM: enable a handful of passing behavior tests 2022-02-06 02:23:31 -05:00
Andrew Kelley
35423b0054 organize behavior tests
check the set of passing tests; move towards the disabling logic being
inside each test rather than which files are included.

this enables a few more passing tests.
2022-01-26 20:59:20 -07:00
Andrew Kelley
4d05f2ae5f remove zig_is_stage2 from @import("builtin")
Instead use the standarized option for communicating the
zig compiler backend at comptime, which is `zig_backend`. This was
introduced in commit 1c24ef0d0b.
2022-01-17 21:55:49 -07:00
Robin Voetter
2b589d71fb stage2: move some tests which are now passing 2021-11-22 04:36:57 +01:00
Martin Wickham
1cc5d4e758
Stage 2: Support inst.func() syntax (#9827)
* Merge call zir instructions to make space for field_call
* Fix bug with comptime known anytype args
* Delete the param_type zir instruction
* Move some passing tests to stage 2
* Implement a.b() function calls
* Add field_call_bind support for call and field builtins
2021-09-28 12:00:35 -05:00
Andrew Kelley
4bb5d17edc AstGen: pre-scan all decls in a namespace
Also:
 * improve the "ambiguous reference" error by swapping the order of
   "declared here" and "also declared here" notes.
 * improve the "not accessible from inner function" error:
   - point out that it has to do with the thing being mutable
   - eliminate the incorrect association with it being a function
   - note where it crosses a namespace boundary
 * struct field types are evaluated in a context that has the struct
   namespace visible. Likewise with align expressions, linksection
   expressions, enum tag values, and union/enum tag argument
   expressions.

Closes #9194
Closes #9622
2021-08-28 16:04:38 -07:00
Andrew Kelley
2b40815a22 stage2: fix wrong value for Decl owns_tv
In the case of a comptime function call of a function that returns a
type, resulting in a compiler crash on deinit().
2021-08-21 20:47:42 -07:00
Andrew Kelley
f0176eec4a stage2: support comptime fn call returning type
...when the field type expressions reference locals as well as
comptime function parameters.
2021-08-20 17:44:03 -07:00
Andrew Kelley
7d0de54ad4 stage2: fix return pointer result locations
* Introduce `ret_load` ZIR instruction which does return semantics
   based on a corresponding `ret_ptr` instruction. If the return type of
   the function has storage for the return type, it simply returns.
   However if the return type of the function is by-value, it loads the
   return value from the `ret_ptr` allocation and returns that.

 * AstGen: improve `finishThenElseBlock` to not emit break instructions
   after a return instruction in the same block.

 * Sema: `ret_ptr` instruction works correctly in comptime contexts.
   Same with `alloc_mut`.

The test case with a recursive inline function having an implicitly
comptime return value now has a runtime return value because of the fact
that it calls a function in a non-comptime context.
2021-08-06 19:53:04 -07:00
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.
2021-08-06 16:24:39 -07:00
Andrew Kelley
c03a04a589 stage2: return type expressions of generic functions
* ZIR encoding for function instructions have a body for the return
   type. This lets Sema for generic functions do the same thing it does
   for parameters, handling `error.GenericPoison` in the evaluation of
   the return type by marking the function as generic.

 * Sema: fix missing block around the new Decl arena finalization. This
   led to a memory corruption.

 * Added some floating point support to the LLVM backend but didn't get
   far enough to pass any new tests.
2021-08-05 19:19:19 -07:00
Andrew Kelley
e9e3a29946 stage2: implement generic function memoization
Module has a new field `monomorphed_funcs` which stores the set of
`*Module.Fn` objects which are generic function instantiations.
The hash is based on hashes of comptime values of parameters known to be
comptime based on an explicit comptime keyword or must-be-comptime
type expressions that can be evaluated without performing monomorphization.
This allows function calls to be semantically analyzed cheaply for
generic functions which are already instantiated.

The table is updated with a single `getOrPutAdapted` in the semantic
analysis of `call` instructions, by pre-allocating the `Fn` object and
passing it to the child `Sema`.
2021-08-05 16:37:21 -07:00
Veikka Tuominen
e63ff4f1c1 add ast-check flag to zig fmt, fix found bugs 2021-06-14 00:16:40 +03: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
Andrew Kelley
4307436b99 move behavior tests from test/stage1/ to test/
And fix test cases to make them pass. This is in preparation for
starting to pass behavior tests with self-hosted.
2021-04-29 15:54:04 -07:00
Renamed from test/stage1/behavior/generics.zig (Browse further)