Commit Graph

918 Commits

Author SHA1 Message Date
Andrew Kelley
ccce3d8526 no-copy semantics for function forwarding
```zig
fn foo() Foo {
    return bar();
}
```

```llvm
define internal fastcc void @foo(%Foo* nonnull sret) unnamed_addr #2 !dbg !48 {
Entry:
  call fastcc void @bar(%Foo* sret %0), !dbg !52
  ret void, !dbg !54
}
```
2019-05-31 01:36:57 -04:00
Andrew Kelley
78f32259da default struct field initialization expressions
closes #485
2019-05-30 15:46:11 -04:00
Andrew Kelley
1ab0ac3ea2 cleanups for windows subsystem in builtin.zig 2019-05-29 16:55:02 -04:00
Andrew Kelley
1ccbd1fb67 use works on unions and enums in addition to structs 2019-05-29 16:31:49 -04:00
Andrew Kelley
9891c4f30d Merge branch 'use-struct-pt2' of https://github.com/LemonBoy/zig into LemonBoy-use-struct-pt2 2019-05-29 15:48:49 -04:00
LemonBoy
528c151a55 Reject undefined as type
Make analyze_type_expr behave like ir_resolve_type when the user tries
to use `undefined` as a type.

Closes #2436
2019-05-28 18:02:57 -04:00
LemonBoy
048169cbea Avoid a crash when there are no namespace components
Fixes #2500
2019-05-28 17:49:37 -04:00
emekoi
3f302594b8 respect subsystem flag in all cases 2019-05-27 22:15:33 -04:00
LemonBoy
86b3007b94 Reject slices in use expressions
Co-Authored-By: emekoi <emekankurumeh@outlook.com>
2019-05-24 13:20:44 +02:00
LemonBoy
f67ca20655 Make use work with arbitrary structs 2019-05-21 17:07:40 +02:00
LemonBoy
b660134a18 Use the correct scope for use
use expressions outside the top-level scope now work as intended.
2019-05-19 00:32:49 -04:00
LemonBoy
d210628c91 Amend the error messages 2019-05-11 21:29:55 +02:00
LemonBoy
b05e8d46ec Change the enum value allocation strategy 2019-05-11 21:29:53 +02:00
LemonBoy
655794f44f amend type_is_valid_extern_enum_tag 2019-05-11 21:29:00 +02:00
LemonBoy
c766f3f9ca Support signed types as enum tags 2019-05-11 21:28:58 +02:00
LemonBoy
917bd4192d Validate enum tag for extern enum
The C specification mandates the enum to be compatible with signed char,
signed int or unsigned int.
2019-05-11 21:27:58 +02:00
Andrew Kelley
010963ce43 stage1: make some asserts print source location 2019-05-09 14:52:06 -04:00
Andrew Kelley
c82acdbb9e clean up test output
After 4df2f3d74f test names have the word "test" in them so the
redundant word is removed from test runner. Also move the prefix/suffix
to where it logically belongs in the fully qualified symbol name.
2019-04-26 15:10:13 -04:00
rylmovuk
4df2f3d74f Change symbol name of tests in codegen
Tests now have the symbol name of the format `test "<name>"` in order
to be more easily distinguished from functions with similar names.
See issue #2267.
2019-04-26 14:23:56 -04:00
Andrew Kelley
976080462c translate-c: a little closer to self-hosted implementation 2019-04-25 00:06:54 -04:00
Shawn Landden
8ef7f6febb remove Shebang (#!) support
Closes:  #2165
2019-04-24 23:34:19 -04:00
Michael Dusan
611d4bc6a1 stage1: const_values_equal support tagged union 2019-04-16 13:55:23 -04:00
Andrew Kelley
68d7e4a1b6 better handle quota of setEvalBranchQuota
Now that c58b802034 has removed
the "top of the comptime stack" requirement, the branch quota
can be modified somewhere other than the top of the comptime stack.

This means that the quota of a parent IrExecutable has to be
modifiable by an instruction in the child.

Closes #2261
2019-04-13 16:55:59 -04:00
Andrew Kelley
025a1475c4 emit better debug info for enums
fixes llvm assertion when building for windows
2019-04-02 19:40:33 -04:00
Andrew Kelley
6a7b75b73c fix LLVM assertion failures 2019-04-02 19:09:25 -04:00
Andrew Kelley
15bd4aa54f fix setting union body twice 2019-04-02 18:43:25 -04:00
Andrew Kelley
e9dc504141 avoid tripping assertion for setting struct body twice 2019-04-02 18:31:19 -04:00
Andrew Kelley
d577dde636 passing all tests 2019-04-02 18:31:19 -04:00
Andrew Kelley
9780fd59f0 put the alignment hack in for unions too. fixes std tests 2019-04-02 18:31:19 -04:00
Andrew Kelley
cb0241fe44 behavior tests passing again 2019-04-02 18:31:19 -04:00
Andrew Kelley
4c38a8cce1 more regression fixes. empty test passes again 2019-04-02 18:31:19 -04:00
Andrew Kelley
5aee17e888 regression fixes and fix packed struct abi size 2019-04-02 18:31:19 -04:00
Andrew Kelley
ddb8aa73f5 more regression fixes 2019-04-02 18:31:18 -04:00
Andrew Kelley
30b2fb2fb5 bug fixes 2019-04-02 18:31:18 -04:00
Andrew Kelley
d7bc7635c0 put the hack from master branch back in 2019-04-02 18:31:18 -04:00
Andrew Kelley
d3f2fe2cef remove the lazy value stuff
let's try to keep this branch to solving one problem at a time
2019-04-02 18:31:18 -04:00
Andrew Kelley
3dc8448680 introduce lazy values
but I think it's a bad idea, so I'm going to back out the change
2019-04-02 18:31:18 -04:00
Andrew Kelley
ee5064c053 decouple llvm types from zig types
Not tested yet, but it builds.

This closes #761, and lays the groundwork for fixing the remaining
false positive "foo depends on itself" bugs, such as #624.

It also lays the groundwork for implementing ability to specify
alignment of fields (#1512).
2019-04-02 18:31:17 -04:00
Andrew Kelley
5eaead6a56 implement allowzero pointer attribute
closes #1953

only needed for freestanding targets.

also adds safety for `@intToPtr` when the address is zero.
2019-03-25 12:55:45 -04:00
Andrew Kelley
d0551db5cd introduce the enum literal type
see #683
2019-03-24 00:44:18 -04:00
Sahnvour
c17b1635ca c_abi: when compiling for x86_64, differenciate between system V and windows ABI 2019-03-19 22:08:19 +01:00
Andrew Kelley
c40448eb9a add compile error for wrong type with use
closes #1557
2019-03-16 00:18:10 -04:00
Andrew Kelley
9c13e9b7ed breaking changes to std.mem.Allocator interface API
Before, allocator implementations had to provide `allocFn`,
`reallocFn`, and `freeFn`.

Now, they must provide only `reallocFn` and `shrinkFn`.
Reallocating from a zero length slice is allocation, and
shrinking to a zero length slice is freeing.

When the new memory size is less than or equal to the
previous allocation size, `reallocFn` now has the option
to return `error.OutOfMemory` to indicate that the allocator
would not be able to take advantage of the new size.

For more details see #1306. This commit closes #1306.

This commit paves the way to solving #2009.

This commit also introduces a memory leak to all coroutines.
There is an issue where a coroutine calls the function and it
frees its own stack frame, but then the return value of `shrinkFn`
is a slice, which is implemented as an sret struct. Writing to
the return pointer causes invalid memory write. We could work
around it by having a global helper function which has a void
return type and calling that instead. But instead this hack will
suffice until I rework coroutines to be non-allocating. Basically
coroutines are not supported right now until they are reworked as
in #1194.
2019-03-15 17:57:21 -04:00
Andrew Kelley
fec4555476 fix inconsistent type information of optional C pointers
solves an assertion failure in LLVM
2019-03-10 18:02:59 -04:00
Andrew Kelley
91955dee58 breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
   to call, unless setOutputDir() was used, or within a custom make()
   function. Instead there is more convenient API to use which takes
   advantage of the caching system. Search this commit diff for
   `exe.run()` for an example.
 * Zig build by default enables caching. All build artifacts will go
   into zig-cache. If you want to access build artifacts in a convenient
   location, it is recommended to add an `install` step. Otherwise
   you can use the `run()` API mentioned above to execute programs
   directly from their location in the cache. Closes #330.
   `addSystemCommand` is available for programs not built with Zig
   build.
 * Please note that Zig does no cache evicting yet. You may have to
   manually delete zig-cache directories periodically to keep disk
   usage down. It's planned for this to be a simple Least Recently
   Used eviction system eventually.
 * `--output`, `--output-lib`, and `--output-h` are removed. Instead,
   use `--output-dir` which defaults to the current working directory.
   Or take advantage of `--cache on`, which will print the main output
   path to stdout, and the other artifacts will be in the same directory
   with predictable file names. `--disable-gen-h` is available when
   one wants to prevent .h file generation.
 * `@cImport` is always independently cached now. Closes #2015.
   It always writes the generated Zig code to disk which makes debug
   info and compile errors better. No more "TODO: remember C source
   location to display here"
 * Fix .d file parsing. (Fixes the MacOS CI failure)
 * Zig no longer creates "temporary files" other than inside a
   zig-cache directory.

This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 23:23:11 -05:00
Andrew Kelley
d0d615d819 fix const initialization of optional C pointer to null 2019-03-03 10:47:06 -05:00
Andrew Kelley
ea5cedced1 fix @typeName on slices
closes #2026
2019-03-02 14:31:27 -05:00
Andrew Kelley
67b4de33d2 compile error for import outside package path
closes #2024

there's a new cli option `--main-pkg-path` which you can use to choose
a different root package directory besides the one inferred from the
root source file

and a corresponding build.zig API:
foo.setMainPkgPath(path)
2019-03-02 10:38:27 -05:00
Andrew Kelley
26128396f3 gen-h: use the bare type names for now 2019-03-01 17:36:08 -05:00
Andrew Kelley
5f7d9c5845 @typeInfo for structs and opaque types is the bare name 2019-03-01 17:15:58 -05:00