9858 Commits

Author SHA1 Message Date
Andrew Kelley
d726c2a2d3 self-hosted: beginnings of stack allocation
Comment out non-x86_64 architectures for now in codegen.zig, because
they all have compile errors for their codepaths anyway, and it was
bloating the compilation speed and memory usage when stage1 tried to
build self-hosted. Here's the panic message:

"Backend architectures that don't have good support yet are commented
out, to improve compilation performance. If you are interested in one
of these other backends feel free to uncomment them. Eventually these
will be completed, but stage1 is slow and a memory hog."

This is a workaround to lower the time it takes to build self-hosted
with stage1 as well as use less memory. It should fix the CI.

Additionally:
 * Add `single_mut_pointer` support to `Type`
 * Trivial implementation of stack allocation in codegen.zig. It does
   not deal with freeing yet, and it's missing the stack pointer
   adjustment prologue.
 * Add the `alloc` IR instruction and semantic analysis for `alloc` ZIR
   instruction.
2020-07-28 01:43:04 -07:00
Andrew Kelley
c37f273cb0 stage1: hot path for resolving types of primitives
This is an attempt to save memory when building self-hosted.

before:
Total bytes allocated: 5.941 GiB, deallocated: 2.259 GiB, remaining: 3.681 GiB

after:
Total bytes allocated: 5.933 GiB, deallocated: 2.253 GiB, remaining: 3.680 GiB
2020-07-28 00:00:35 -07:00
Andrew Kelley
0965724e31 self-hosted: refactor some code out of Module.zig into zir_sema.zig
This makes sense from an organizational point of view, as explained by
this new doc comment at the top of the new file:

//! Semantic analysis of ZIR instructions.
//! This file operates on a `Module` instance, transforming untyped ZIR
//! instructions into semantically-analyzed IR instructions. It does type
//! checking, comptime control flow, and safety-check generation. This is the
//! the heart of the Zig compiler.
//! When deciding if something goes into this file or into Module, here is a
//! guiding principle: if it has to do with (untyped) ZIR instructions, it goes
//! here. If the analysis operates on typed IR instructions, it goes in Module.

Before:
   4009 src-self-hosted/Module.zig

After:
   2776 src-self-hosted/Module.zig
   1128 src-self-hosted/zir_sema.zig

This should be sufficient to avoid the situation we have in stage1 where
ir.cpp is 32,516 lines.
2020-07-27 22:44:18 -07:00
Vexu
5f0bde6358 add helpful error note for when function cannot return an error
This has caused frequent confusion since it looks like you are handling
errors correctly with a try but you forgot to change your return type.
2020-07-28 04:24:52 +00:00
Andrew Kelley
b8e22d2002 stage2: implement integer return values 2020-07-27 18:59:13 -07:00
Andrew Kelley
3e0a46281c stage2: fix function calls always having void return type 2020-07-27 18:59:13 -07:00
Jay Petacat
1c2e65fe1d std.elf: Fix read functions for 32-bit targets
The buffer index was declared as `u64`, which overflows `usize` on a
32-bit target.

The following example program failed to compile for 32-bit targets:

```zig
const std = @import("std");

pub fn main() !void {
    const alloc = std.testing.allocator;
    const file = std.io.getStdIn();
    _ = try std.elf.readAllHeaders(alloc, file);
}
```

```
lib/zig/std/elf.zig:543:36: error: expected type 'usize', found 'u64'
        const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
                                   ^
lib/zig/std/elf.zig:543:36: note: unsigned 32-bit int cannot represent all possible unsigned 64-bit values
        const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
                                   ^
lib/zig/std/elf.zig:543:35: note: referenced here
        const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
                                  ^
lib/zig/std/elf.zig:348:5: note: referenced here
    try preadNoEof(file, &hdr_buf, 0);
    ^
lib/zig/std/elf.zig:392:19: note: referenced here
        .header = try readHeader(file),
```
2020-07-28 01:36:26 +00:00
Andrew Kelley
488df7f1d1 stage2: astgen for all arithmetic and assignments 2020-07-27 17:09:47 -07:00
Andrew Kelley
bd9b3fe1e6
Merge pull request #5511 from jessrud/arraylist-replaceRange
add replaceRange() function to ArrayList
2020-07-27 20:04:19 +00:00
zigazeljko
bf273b7aec Add comment explaining --stack-first option 2020-07-27 19:51:58 +00:00
Felix (xq) Queißner
fb9d5529da Adds support for RunStep to use the result of a WriteFileStep. 2020-07-27 19:46:15 +00:00
Jakub Konka
f0ed2ed67f Replace DeviceIoControl with FsControlFile
This commit replaces `windows.DeviceIoControl` with
`windows.FsControlFile` which is a wrapper around the NT-based
syscall `ntdll.NtFsControlFile`.
2020-07-27 19:45:23 +00:00
Ashok Gautham
d1755e7f16
Add meta viewport to fix mobile rendering, add missing <code> block
Co-authored-by: Vexu <git@vexu.eu>
2020-07-27 17:10:55 +03:00
frmdstryr
fa4a9ab51f Use writer for LinearFifo instead of deprecated outStream 2020-07-27 17:05:39 +03:00
Vexu
e7007fa7bd
translate-c: use ArrayList for macro tokens 2020-07-27 15:38:56 +03:00
Henrik Laxhuber
9f6401c692 Fix a use of appendToken to appendIdentifier in translate-c 2020-07-27 13:43:49 +03:00
Henrik Laxhuber
442025481c Fix parsing of unsigned in translate-c.
Previously, `unsigned` was parsed as the shorthand for `unsigned int`.
This commit introduces code to parse `unsigned short`, `unsigned int`,
`unsigned long`, and `unsigned long long`.

There is a comment in the code about std.c.parse` - Im not
familiar with zig internals, but it seems like this is a separate
C parsing implementation. In the long run, it probably makes
sense to merge both implementations, so this commit should be
regarded as a quick fix that doesn't address an apparently
underlying issue.
2020-07-27 13:43:49 +03:00
joachimschmidt557
616355807f Fix bug in big.int.Mutable.toManaged() and add tests
Fixes #5918
2020-07-27 07:16:44 +00:00
Andrew Kelley
5139aa7ba4
Merge pull request #5932 from Sahnvour/hash
new trait `hasUniqueRepresentation` and hashmap speedup
2020-07-27 07:12:54 +00:00
Jonathan Marler
6cc72af03d Provide Ip4Address and Ip6Address in addition to Address 2020-07-27 07:11:07 +00:00
Sahnvour
f67ce1e35f make use of hasUniqueRepresentation to speed up hashing facilities, fastpath in getAutoHashFn is particularly important for hashmap performance
gives a 1.18x speedup on gotta-go-fast hashmap bench
2020-07-26 23:04:33 +02:00
Sahnvour
345cb3200c improve autoHash type switch
floats shouldn't be autoHash'd as they have multiple representations for some values, preventing it by default is safer
2020-07-26 22:04:10 +02:00
Sahnvour
7ae1b3a6b3 add trait hasUniqueRepresentation 2020-07-26 22:01:33 +02:00
Andrew Kelley
c95091e5a5 run zig fmt on std.testing 2020-07-25 23:33:15 -07:00
Andrew Kelley
09b0ad494b stage2: remove superfluous else => unreachable 2020-07-25 23:32:30 -07:00
Andrew Kelley
40d81a8364
Merge pull request #5678 from antlilja/float-testing
Add functions for testing floats with margins and epsilons to standard library
2020-07-26 05:54:30 +00:00
Andrew Kelley
a36772ee64
Merge pull request #5693 from antlilja/switch-unreachable-else
Add error message for unreachable else prong in switch
2020-07-26 05:46:18 +00:00
meme
f050150ffa Add memory replacement routines
* Added `replace` for simple pre-allocated search-and-replace
* Added `replacementSize` for calculating ahead-of-time buffer sizes for
performing a safe search-and-replace
* Added `replaceOwned` for automatically allocating and performing
replacement
2020-07-26 05:42:38 +00:00
Andrew Kelley
9b75091fd4 ci: update msys2 installer 2020-07-25 22:21:52 -07:00
Andrew Kelley
995fd7314c Revert "Support taking extern pointers at comptime"
This reverts commit d3ebd428650748e60db70dd2171cc044855814b1.

This caused a build failure on multiple targets.
2020-07-24 14:06:44 -07:00
daurnimator
978a38ee40 std: fix json parsing into unions 2020-07-24 20:35:47 +00:00
yvt
d3ebd42865 Support taking extern pointers at comptime
This commit makes it possible to obtain pointers to `extern` variables
at comptime.

 - `ir_get_var_ptr` employs several checks to determine if the given
   variable is eligible for obtaining its pointer at comptime. This
   commit alters these checks to consider `extern` variables, which have
   runtime values, as eligible.

 - After this change, it's now possible for `render_const_val` to be
   called for `extern` variables. This commit modifies
   `render_const_val` to suppress the value generation for `extern`
   variables.

 - `do_code_gen` now creates `ZigValue::llvm_global` of `extern`
   variables before iterating through module-level variables so that
   other module-level variables can refer to them.

This solution is incomplete since there are several cases still
failing:

 - `global_var.array[n..m]`
 - `&global_var.array[i]`
 - `&global_var.inner_struct.value`
 - `&global_array[i]`

Closes #5349
2020-07-24 13:33:17 -07:00
Michael Dusan
3b26e50863 macOS: macho ld64.lld fixes
* bring `construct_linker_job_macho` to parity with
   `construct_linker_job_elf`
 * macho now sets `-error-limit`
 * macho on macOS now sets `-macosx_version_min` and `-sdk_version`
   to `10.13` when running `zig0`
 * macho now detects when `-l` prefix is not needed
 * macho on macOS detects system libraries in a case-insensitive manner
 * macho now ads user-specified libraries to linker command-line args
   when condition `is_native_os != true`
 * re-ordered some macho args positions to match elf positions

closes #5059
closes #5067
2020-07-24 20:01:18 +00:00
Andrew Kelley
df1a2ecd3b
Merge pull request #5891 from Luukdegram/stage2-substraction
Stage2: Substraction support
2020-07-24 18:29:52 +00:00
Luuk de Gram
3019ab9391
Fix resolvepeertype() int signess and feedback improvements 2020-07-24 17:51:24 +02:00
Luuk de Gram
470264a4f5
Restructuring and f32/f64 support 2020-07-24 17:16:48 +02:00
Luuk de Gram
97e92d868e
Rebase and skeleton for float support 2020-07-24 17:16:48 +02:00
Luuk de Gram
ee7fbb9548
Restructured arithmetic operations 2020-07-24 17:16:48 +02:00
Luuk de Gram
198c09197b
Fixed test case 2020-07-24 17:16:48 +02:00
Luuk de Gram
9d79741fd0
Stage2: Add support for substraction 2020-07-24 17:16:48 +02:00
Jakub Konka
a1d72fad81 Use -c flag in all s3cmd occurrences on Win 2020-07-24 14:35:48 +02:00
Jakub Konka
937c02f185 Re-apply temp msys2 python fix
Tweak `windows_upload` script to manually specify the config path
to `s3cmd`.
2020-07-24 09:19:51 +02:00
Jakub Konka
b7353240c7 Refactor macOS build script in Azure
We don't really want to rebuild the cache in Azure...
2020-07-24 06:29:50 +00:00
Andrew Kelley
56a21b7ec3 ci: undo the recent changes. maybe upstream fixed it 2020-07-23 23:26:24 -07:00
Andrew Kelley
aac6e8c418 self-hosted: AST flattening, astgen improvements, result locations, and more
* AST: flatten ControlFlowExpression into Continue, Break, and Return.
 * AST: unify identifiers and literals into the same AST type: OneToken
 * AST: ControlFlowExpression uses TrailerFlags to optimize storage
   space.
 * astgen: support `var` as well as `const` locals, and support
   explicitly typed locals. Corresponding Module and codegen code is not
   implemented yet.
 * astgen: support result locations.
 * ZIR: add the following instructions (see the corresponding doc
   comments for explanations of semantics):
   - alloc
   - alloc_inferred
   - bitcast_result_ptr
   - coerce_result_block_ptr
   - coerce_result_ptr
   - coerce_to_ptr_elem
   - ensure_result_used
   - ensure_result_non_error
   - ret_ptr
   - ret_type
   - store
   - param_type
 * the skeleton structure for result locations is set up. It's looking
   pretty clean so far.
 * add compile error for unused result and compile error for discarding
   errors.
 * astgen: split builtin calls up to implemented manually, and implement
   `@as`, `@bitCast` (and others) with respect to result locations.
 * add CLI support for hex and raw object formats. They are not
   supported by the self-hosted compiler yet, and emit errors.
 * rename `--c` CLI to `-ofmt=[objectformat]` which can be any of the
   object formats. Only ELF and C are supported so far. Also added missing
   help to the help text.
 * Remove hard tabs from C backend test cases. Shame on you Noam, you
   are grounded, you should know better, etc. Bad boy.
 * Delete C backend code and test case that relied on comptime_int
   incorrectly making it all the way to codegen.
2020-07-23 23:05:26 -07:00
Andrew Kelley
b4d383a478 ci: looks like s3cmd wants a new path for the config file
Thanks Jakub Konka for exploring this.
2020-07-23 10:58:07 -07:00
heidezomp
32a6759a7a Fix std.log example to make the log handler print the newline
Follow up from #5910
2020-07-22 22:08:08 +00:00
luna
a6626802f9
Add signalfd support (#5322)
* add signalfd_siginfo to linux bits

* Cast sigaddset's shift value to u5

* linux: add signalfd4

* os: add signalfd
2020-07-22 17:26:27 -04:00
Andrew Kelley
9505bb74cd
Merge pull request #5879 from kubkon/readlink-win
Implement readlink on Windows
2020-07-22 17:59:40 +00:00
joachimschmidt557
c6bd8e8c53 Make the default log handler print a newline
Closes #5907
2020-07-22 17:02:27 +00:00