Commit Graph

10138 Commits

Author SHA1 Message Date
StrangeBug
59711becc7 Add handler for INVALID_HANDLE to prevent infinite loop when stderr is not available. 2020-08-19 20:49:25 -07:00
Andrew Kelley
b1c7334355
Merge pull request #5745 from lun-4/ebadf-error
map EBADF to error values for read and write
2020-08-19 23:46:22 -04:00
Andrew Kelley
a30950706f Merge branch 'Vexu-stage2'
closes #6093
2020-08-19 17:59:37 -07:00
Andrew Kelley
9ec9c0f5e5 optimize the memory layout of Module.Fn and Module.Var
`is_pub` added to `Fn` would cost us an additional 8
bytes of memory per function, which is a real bummer
since it's only 1 bit of information.

If we wanted to really remove this, I suspect we could
make this a function isPub() which looks at the AST of
the corresponding Decl and finds if the FnProto AST node
has the pub token. However I saw an easier approach -

The data of whether something is pub or not is actually
a property of a Decl anyway, not a function, so we can
look at moving the field into Decl. Indeed, doing this,
we see that Decl already has deletion_flag: bool which
is hiding in the padding bytes between the enum (1 byte)
and the following u32 field (generation). So if we put
the is_pub bool there, it actually will take up no
additional space, with 1 byte of padding remaining.

This was an easy reworking of the code since any
func.is_pub could be changed simply to func.owner_decl.is_pub.

I also modified `Var` to make the init value non-optional
and moved the optional bit to a has_init: bool field. This is worse from
the perspective of control flow and safety, however it makes
`@sizeOf(Var)` go from 32 bytes to 24 bytes. The more code we can fit
into memory at once, the more justified we are in using the compiler as
a long-running process that does incremental updates.
2020-08-19 17:52:22 -07:00
Vexu
5fdcb1a792 stage2: emit zir variable fix, array type and enum literal support 2020-08-19 16:12:29 -07:00
Vexu
9801047bdb stage2: handle var attributes 2020-08-19 16:12:29 -07:00
Vexu
ab8a9a6605 stage2: fix astgen of decl ref, add test for global consts 2020-08-19 16:12:29 -07:00
Vexu
338a495648 stage2: implement global variables 2020-08-19 16:12:29 -07:00
Vincent Rischmann
b0846b6ecb builder: implement integer options 2020-08-19 17:41:43 -04:00
dbandstra
a237283d90 fixes and improvements for parseCharLiteral 2020-08-19 16:30:42 -04:00
Andrew Kelley
083c0f1ceb stage2 codegen: proper abstraction for re-using dying operands
closes #6064
2020-08-18 23:11:56 -07:00
Andrew Kelley
dc35b8641b stage2: Module enumerates the possible top level decls 2020-08-18 23:11:56 -07:00
Jakub Konka
5fe878cd42
Merge pull request #6085 from kubkon/macho-header
Write out Mach-O header
2020-08-19 07:50:11 +02:00
Jakub Konka
ffdeb6af91
Update src-self-hosted/link/MachO.zig
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-08-19 07:43:33 +02:00
Nathan Michaels
4237f1afc7
Change std.debug.warn to std.log.info in init-exe template. (#5941) 2020-08-18 22:47:38 -04:00
Andrew Kelley
771f40204e
Merge pull request #6086 from Vexu/stage2
Stage2: more astgen stuff
2020-08-18 22:02:55 -04:00
Andrew Kelley
626d94c2a1
Merge pull request #6088 from ifreund/s2-wasm-rework
stage2/wasm: do incremental compilation in-memory
2020-08-18 21:37:20 -04:00
Isaac Freund
6242ae35f3
stage2/wasm: implement function calls
During codegen we do not yet know the indexes that will be used for
called functions. Therefore, we store the offset into the in-memory
code where the index is needed with a pointer to the Decl and use this
data to insert the proper indexes while writing the binary in the flush
function.
2020-08-19 02:05:13 +02:00
Isaac Freund
fe3aa4ccd0
stage2/wasm: do incremental compilation in-memory
Before this commit the wasm backend worked similarly to elf. As
functions were generated they were written directly to the output file
and existing code was shifted around in the file as necessary. This
approach had several disadvantages:

- Large amounts of padding in the output were necessary to avoid
expensive copying of data within the file.
- Function/type/global/etc indexes were required to be known at the time
of preforming codegen, which severely limited the flexibility of where
code could be placed in the binary
- Significant complexity to track the state of the output file through
incremental updates

This commit takes things in a different direction. Code is incrementally
compiled into in-memory buffers and the entire binary is rewritten using
these buffers on flush. This has several advantages:

- Significantly smaller resulting binaries
- More performant resulting binaries due to lack of indirection
- Significantly simpler compiler code
- Indexes no longer need to be known before codegen. We can track where
Decls must be referenced by index insert the proper indexes while
writing the code in the flush() function. This is not yet implemented
but is planned for the next commit.

The main disadvantage is of course increased memory usage in order to
store these buffers of generated code.
2020-08-19 02:05:01 +02:00
Isaac Freund
741fb8d306 stage2/link: clarify comments on calling order 2020-08-18 19:47:20 -04:00
Andrew Kelley
15bcfcd368 stage2: fix use-after-free when printing ZIR 2020-08-18 15:25:01 -07:00
Andrew Kelley
31b58acdae stage2: minor cleanup 2020-08-18 15:11:24 -07:00
Andrew Kelley
f950f5452b test_runner: don't assume the GeneralPurposeAllocator config
This allows changing the config in only 1 location (std.testing)
2020-08-18 15:10:31 -07:00
Andrew Kelley
583b843803 std.heap.GeneralPurposeAllocator: add never_unmap config option
This is a temporary debugging trick you can use to turn segfaults into more helpful
logged error messages with stack trace details. The downside is that every allocation
will be leaked!
2020-08-18 15:09:48 -07:00
Andrew Kelley
5547abd2d1 build: -Dforce-link-libc now also applies to test-stage2 2020-08-18 15:08:43 -07:00
Jakub Konka
34e628a0a0 Fix compile error
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-18 23:35:31 +02:00
Jakub Konka
e4b3da2720 Write out Mach-O header
This commit write out Mach-O header in the linker's `flush`
method. The header currently only populates the magic number,
filetype, and cpu info.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-18 23:35:31 +02:00
Veikka Tuominen
d139e44cfa
Merge pull request #5495 from xackus/fix_5314
stage1: fix non-exhaustive enums with one field
2020-08-18 23:55:44 +03:00
Andrew Kelley
e2c741f1e7 std.cache_hash: additionally use file size to detect modifications
I have observed on Linux writing and reading the same file many times
without the mtime changing, despite the file system having nanosecond
granularity (and about 1 millisecond worth of nanoseconds passing between
modifications). I am calling this a Linux Kernel Bug and adding file
size to the cache hash manifest as a mitigation. As evidence, macOS does
not exhibit this behavior.

This means it is possible, on Linux, for a file to be added to the cache
hash, and, if it is updated with the same file size, same inode, within
about 1 millisecond, the cache system will give us a false positive,
saying it is unmodified. I don't see any way to improve this situation
without fixing the bug in the Linux kernel.

closes #6082
2020-08-18 12:44:00 -07:00
Vexu
e4aefc6d0f
stage2: split ref from lvalue and add compile error for invalid assignments 2020-08-18 22:42:35 +03:00
Vexu
2b45e23477
stage2: character literals and multiline strings 2020-08-18 20:10:18 +03:00
Andrew Kelley
bdb8c49418 stage1: update compile error tests
follow-up to 56c81c713f
2020-08-18 08:44:34 -07:00
Vexu
e0b01bd4a9
stage2: enum literals 2020-08-18 14:28:33 +03:00
Vexu
31d8efc6b3
stage2: validate param and variable types 2020-08-18 13:57:09 +03:00
Vexu
7c15c9428e
stage2: array types 2020-08-18 12:36:00 +03:00
Vexu
3eb8f7be10
stage2: astgen bool and/or 2020-08-18 11:38:56 +03:00
Andrew Kelley
c0517bf1f6 std.cache_hash: temporary workaround for mtime precision on linux
See #6082
2020-08-18 01:30:57 -07:00
Andrew Kelley
56c81c713f stage1: let \r\n slide 2020-08-18 01:29:34 -07:00
Vexu
0977e41407
stage2: ensure discarded error union payload is void 2020-08-18 10:36:57 +03:00
Soren
60ea87340e Fix opaque structs and C++ mangling 2020-08-18 00:31:29 -04:00
Frank Denis
8d60047697 ristretto255: add uniform string->element map & fast equivalence check 2020-08-18 00:31:02 -04:00
Eleanor Bartle
fa8935426b
Cleaned up RISC-V instruction creation, added 32-bit immediates (#6077)
* Implemented all R-type arithmetic/logical instructions

* Implemented all I-type arithmetic/logical instructions

* Implemented all load and store instructions

* Implemented all of RV64I except FENCE
2020-08-18 00:30:00 -04:00
Andrew Kelley
3cc1f8b624
Merge pull request #6056 from ifreund/wasm-backend
stage2: add a wasm backend
2020-08-18 00:28:05 -04:00
Andrew Kelley
ce8b9c0c5c std.cache_hash: don't trust mtime granularity to be better than 1ms
I empirically observed mtime not changing when rapidly writing the same
file name within the same millisecond of wall clock time, despite the
mtime field having nanosecond precision.

I believe this fixes the CI test failures.
2020-08-17 21:26:33 -07:00
Ashish Shekar
27cb23cbc5
Handle singular param count word in error messages (#6073) 2020-08-17 22:18:29 -04:00
Matthew Knight
d605af511a
added bpf() syscall and some supporting structs (#6061)
* added bpf syscall and some supporting structs

* moved bpf to bits and added flags
2020-08-17 22:17:04 -04:00
Andrew Kelley
e26dda5308 Merge branch 'Sergeeeek-master'
closes #5394
closes #4427
2020-08-17 18:57:34 -07:00
Andrew Kelley
4462c60639 stage2: implement compiler id hash and add it to zig env 2020-08-17 18:56:27 -07:00
Andrew Kelley
a916f63940 std.cache_hash: fix bug parsing inode
This resulted in false negatives cache misses.
2020-08-17 18:49:33 -07:00
Andrew Kelley
18ac998767 zig env: add global_cache_dir field 2020-08-17 17:52:13 -07:00