1220 Commits

Author SHA1 Message Date
Andrew Kelley
c432811d96 fix regression in compile errors 2020-05-23 20:27:09 -04:00
Andrew Kelley
140dc2f43e stage1: fix false positive redeclared variable compile error 2020-05-20 23:13:02 -04:00
Andrew Kelley
9a22c8b6ca
Merge pull request #5057 from xackus/opaque-param
stage1: fix assert fail on opaque fn ptr param
2020-05-17 12:48:56 -04:00
Tadeo Kondrak
7ada59f873
remove nakedcc/stdcallcc/async fn/extern fn fnproto 2020-05-05 09:37:28 -06:00
Tadeo Kondrak
b957dc29a4
Rename noasync to nosuspend in C++ compiler 2020-05-05 05:17:34 -06:00
xackus
887bf8ba93 stage1: remove unneeded switch 2020-05-04 06:51:51 +02:00
xackus
0db9e90e8f stage1: fix assert fail on opaque fn ptr param 2020-05-04 06:51:37 +02:00
Timon Kruiper
c829f2f7b7 Add mips support to standard library 2020-04-24 15:28:55 -04:00
LemonBoy
b5e72c0148 stage1: Prevent the creation of illegal pointer types
Changing the pointer length from Unknown to Single/C now resets the
sentinel value too.

Closes #5134
2020-04-22 14:40:57 -04:00
LemonBoy
395b530387 stage1: Another hack for the C ABI compatibility
Applying the wrong ABI is slightly better than using the Zig ABI, the
whole thing is so wrong it should be burned to the ground.
2020-04-22 12:52:24 +02:00
LemonBoy
aca6b70184 stage1: Handle errors when generating block IR
Closes #5005
2020-04-20 22:39:34 -04:00
Vexu
1afaf42525
add error for non-exter variadic functions 2020-04-17 22:02:49 +03:00
LemonBoy
8e96922f31 stage1: Fix several bugs in constant generation
The codegen would sometimes change the LLVM type for some constants to
an unnamed structure in order to accomodate extra padding. This is fine
as long as the alignment of each field is still respected and it was not
the case for structure types, leading to ill-formed constants being
generated.

Optional types suffer from this to a lower extent as their layout is
quite lucky, the only missing piece was the tail padding.

Closes #4530
Closes #4594
Closes #4295
Closes my will to live
2020-04-17 13:42:23 -04:00
LemonBoy
cc0fca9d83 stage1: Respect the specified name for extern var
Extend the logic used for function definitions to variables.

Closes #4947
2020-04-07 14:48:37 -04:00
Andrew Kelley
e2dc63644a
type_has_one_possible_value takes comptime struct fields into account
Before, type_has_one_possible_value would return false for the value
`.{1}`. But actually, that type is a tuple with a single comptime field.
Such a type, in fact, has one possible value.

This plus the corresponding adjustment to get_the_one_possible_value
solves #3878.
2020-04-05 17:09:01 -04:00
Timon Kruiper
b5526d0b3b Fix multiplication overflow in hash_const_val
In some cases the compiler was actually emitting an 64 bit signed
multiplication, instead of a 32 bit unsigned one.
2020-04-02 17:51:04 -04:00
Michael Dusan
212e2354b8 stage1: make C++ switch fallthrough an error
Make fallthrough an error when compiler supports it. This requires a new
macro that is defined with such compilers to be used as a statement, at
all fallthrough sites:

    switch (...) {
        case 0:
            ...
            ZIG_FALLTHROUGH;
        case 1:
            ...
            break;
        default:
            ...
            break;
    }

If we ever move to C++17 as minimal requirement, then the macro can be
replaced with `[[fallthrough]];` at statement sites.
2020-04-01 15:56:00 -04:00
Timon Kruiper
d33766e6c7 Make sure that ZigTypeVector and ZigTypeArray have the same memory layout
Throughout the stage1 code it is assumed that these have the same layout,
but that was not the case. This caused an issue on 32-bit hardware.
2020-04-01 20:50:13 +02:00
Andrew Kelley
db17c0d88c
ability to compile c++ hello world with zig c++
closes #4786
2020-03-26 22:48:37 -04:00
Andrew Kelley
e947f0c740
0-bit array type does not resolve child type 2020-03-19 09:53:55 -04:00
Andrew Kelley
8d0ac6dc4d
@ptrCast supports casting a slice to pointer 2020-03-19 09:53:54 -04:00
Andrew Kelley
0707be8de8
fixes in semantic analysis needed to support this feature 2020-03-19 09:53:54 -04:00
Andrew Kelley
2182d28cb0
slicing with comptime start and end results in array
implements #863
2020-03-19 09:53:51 -04:00
LemonBoy
e3c92d0532 ir: More changes to sentinel-terminated const arrays
* Don't add an extra slot for the sentinel. Most of the code keeps using
  the constant value from the type descriptor, let's harmonize all the
  code dealing with sentinels.

* Properly write out sentinel values when reinterpreting pointers at
  comptime.

* Allow the reading of the 0th element in a `[0:S]T` type.
2020-03-19 09:53:30 -04:00
Andrew Kelley
63a4dbc30d
array sentinel does not count towards type_has_one_possible_value 2020-03-18 11:11:41 -04:00
LemonBoy
1479c28b49
ir: Correct ABI size calculation for arrays
Zero-length array with a sentinel may not have zero size.

Closes #4749
2020-03-18 11:10:45 -04:00
Andrew Kelley
675f01f176
Merge pull request #4590 from xackus/fix-4587
fix failed assert on generic fn opaque return type
2020-03-09 22:10:57 -04:00
LemonBoy
1f44b29724 ir: Fix codegen of ?*T types where T is zero-sized
* Fix codegen for optional types that decay to a pointer, the type
  behaves as a boolean
* Fix comptime evaluation of zero-sized arrays, always initialize the
  internal array elements

Closes #4673
2020-03-09 22:08:56 -04:00
xackus
e7cc456421 better error messages and more tests 2020-03-09 22:33:18 +01:00
Vexu
3618256c97
implement noasync scopes 2020-03-09 12:33:24 +02:00
LemonBoy
06d0dac0fb ir: Prevent crash in compiler error
Anonymous containers have no struct_field->type AstNode set, let's
always use the field node itself to make the error messages consistent.

Closes #4691
2020-03-08 18:12:50 -04:00
xackus
7782c76bee fix failed assert on generic fn opaque return type 2020-03-08 18:05:45 +01:00
Andrew Kelley
fa46bcb368
stage1: make get_optional_type more robust
Now it will emit a compile error rather than crashing when the child
type has not been resolved properly.

Introduces `get_optional_type2` which should be used generally inside
ir.cpp.

Fix some std lib compile errors noticed by the provided test case.

Thanks @LemonBoy for the test case. Closes #4377.

Fixes #4374.
2020-03-06 18:30:30 -05:00
Michael Dusan
428677ea36 stage1: fix regression
- regression was introduced by 371c21aa70fc61ef703e34079ce6de6c52ec91df
2020-03-05 20:45:01 -05:00
Michael Dusan
371c21aa70
stage1: housekeeping
- use consistent allocator in `realloc_const_vals_ptrs()`
- unexport `create_fn_raw()`
2020-03-05 12:17:47 -05:00
Andrew Kelley
f247a90541
get_codegen_ptr_type returns possible error
And fix most of the fallout. This also makes optional pointers not
require resolving zero bits, because the comptime value struct layout no
longer depends on whether the type has zero bits.

Thanks to @LemonBoy for the behavior test case

Closes #4357
Closes #4359
2020-03-04 17:04:59 -05:00
Andrew Kelley
7617610400
Merge pull request #4550 from ziglang/os-version-ranges
introduce operating system version ranges as part of the target; self-host native dynamic linker detection and native glibc version detection
2020-02-29 01:57:06 -05:00
Andrew Kelley
3cba603eae
fix crash when building docgen 2020-02-29 01:05:11 -05:00
Andrew Kelley
a5a53a182a
fix typo from other commit
d2535c003c6188fcc362028e01ef9f7fb3356727
2020-02-28 16:06:06 -05:00
Andrew Kelley
bee4007ec9
fix crash with multiple comptime fn calls and...
...default initialized array to undefined

closes #4578
2020-02-28 15:49:19 -05:00
Andrew Kelley
578dc16910
fix compiler crash when comptime parsing targets 2020-02-28 15:41:30 -05:00
Andrew Kelley
c8669a4cf8
improve debug info for optionals 2020-02-28 14:51:54 -05:00
Andrew Kelley
fba39ff331
restructuring std.Target for OS version ranges, pass 1 2020-02-28 14:51:50 -05:00
LemonBoy
fd1eade4ca ir: Allow empty inferred error sets
Closes #4564
2020-02-26 21:02:22 -05:00
LemonBoy
d2535c003c ir: Fix regression with self-referencing containers 2020-02-26 10:05:04 +01:00
LemonBoy
b46efcde82 ir: Fix sizeOf comparison with ptr to zst
Closes #4536
2020-02-25 12:48:08 +01:00
Timon Kruiper
7560fc716d
Makes the declaration slice resolve lazely when using @typeInfo
This way all the declarations in a container won't be resolved untill
the user actually uses the decls slice in the builtin TypeInfo union.
2020-02-18 15:26:37 -05:00
Andrew Kelley
7f7d1fbe5a
Implement noasync awaits
Note that there is not yet runtime safety for this.

See #3157
2020-02-16 01:44:52 -05:00
LemonBoy
55304128c0 Fix rendering of empty arrays 2020-02-12 23:10:53 +01:00
Michael Dusan
edb210905d
stage1: memory/report overhaul
- split util_base.hpp from util.hpp
- new namespaces: `mem` and `heap`
- new `mem::Allocator` interface
- new `heap::CAllocator` impl with global `heap::c_allocator`
- new `heap::ArenaAllocator` impl
- new `mem::TypeInfo` extracts names without RTTI
- name extraction is enabled w/ ZIG_ENABLE_MEM_PROFILE=1
- new `mem::List` takes explicit `Allocator&` parameter
- new `mem::HashMap` takes explicit `Allocator&` parameter
- add Codegen.pass1_arena and use for all `ZigValue` allocs
- deinit Codegen.pass1_arena early in `zig_llvm_emit_output()`
2020-02-10 21:08:08 -05:00