Commit Graph

2205 Commits

Author SHA1 Message Date
Andrew Kelley
bc176fb739
Merge pull request #6002 from MasterQ32/zig_fmt_align_fix
Fixes floating point alignment in std.fmt.format
2020-08-10 20:09:11 -04:00
Andrew Kelley
56e1080ba3 std: dwarf_bits correction 2020-08-10 17:05:39 -07:00
Jakub Konka
901bf0a2e2 Convert prefix from u8 to u16 programmatically 2020-08-10 20:44:22 +02:00
Jakub Konka
73b9f65746 Validate DOS path before returning
And some other minor refactors which address more review comments.
2020-08-10 16:39:02 +02:00
Felix Queißner
6701046cdd
Uses getWritten instead of .pos + slicing
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-08-09 17:40:58 +02:00
Felix (xq) Queißner
ada06e2996 Makes formatFloatValue not return error.NoSpaceLeft anymore. 2020-08-09 14:09:02 +02:00
Felix (xq) Queißner
06a1184c92 Fixes double alignment 2020-08-09 12:48:26 +02:00
Jakub Konka
cd8e6b66d0 Address some review comments 2020-08-09 10:47:52 +02:00
Andrew Kelley
f98cffc615 std: general purpose allocator: use AutoHashMap
As pointed out by Sahnvour, AutoHashMap is both more convenient and will
have better performance in this case.
2020-08-08 15:59:03 -07:00
Andrew Kelley
5b57e35ce0 fix general purpose allocator test cases on Windows
The tests are cleverly testing some alignment stuff, but were getting
thwarted by Windows choosing to allocate 64K aligned pages.
2020-08-08 13:46:18 -07:00
Andrew Kelley
4d0f83e23e GeneralPurposeAllocator: naming convention refactor 2020-08-08 13:05:04 -07:00
Andrew Kelley
a2f8c23a96 std.heap.page_allocator: Windows support for growing without remapping 2020-08-08 13:04:30 -07:00
Andrew Kelley
cb9405cdbd don't collect stack trace frames in release safe mode by default
We don't pass no-omit-frame-pointer in release safe by default, so it
also makes sense to not try to collect stack trace frames by default in
release safe mode.
2020-08-08 12:04:19 -07:00
Andrew Kelley
051aadd781 std lib general purpose allocator: disable stack tracing on mips
Sadly, trying to collect stack frames goes into an infinite loop on
mips. This sets the default number of stack frames to collect to 0 on
mips.
2020-08-08 02:38:32 -07:00
Andrew Kelley
88ac0c1287 restore previous behavior of allowing std.testing.allocator
even outside of unit tests
2020-08-08 01:21:08 -07:00
Andrew Kelley
1b1921f0e2 stage1: deal with WebAssembly not supporting @returnAddress()
This makes `@returnAddress()` return 0 for WebAssembly (when not using
the Emscripten OS) and avoids trying to capture stack traces for the
general purpose allocator on that target.
2020-08-08 01:00:29 -07:00
Andrew Kelley
9f5a7d5922 utilize math.ceilPowerOfTwo 2020-08-08 00:39:46 -07:00
Andrew Kelley
cd6cdd0a75 std.mem.Allocator: add return_address to the interface
The high level Allocator interface API functions will now do a
`@returnAddress()` so that stack traces captured by allocator
implementations have a return address that does not include the
Allocator overhead functions. This makes `4` a more reasonable default
for how many stack frames to capture.
2020-08-08 00:34:13 -07:00
Andrew Kelley
0347df82e8 improvements & fixes for general purpose allocator integration
* std.Mutex API is improved to not have init() deinit(). This API is
   designed to support static initialization and does not require any
   resource cleanup. This also happens to work around some kind of
   stage1 behavior that wasn't letting the new allocator mutex code
   get compiled.
 * the general purpose allocator now returns a bool from deinit()
   which tells if there were any leaks. This value is used by the test
   runner to fail the tests if there are any.
 * self-hosted compiler is updated to use the general purpose allocator
   when not linking against libc.
2020-08-07 23:26:58 -07:00
Andrew Kelley
cc17f84ccc std: introduce GeneralPurposeAllocator
`std.GeneralPurposeAllocator` is now available. It is a function that
takes a configuration struct (with default field values) and returns an
allocator. There is a detailed description of this allocator in the
doc comments at the top of the new file.

The main feature of this allocator is that it is *safe*. It
prevents double-free, use-after-free, and detects leaks.

Some deprecation compile errors are removed.

The Allocator interface gains `old_align` as a new parameter to
`resizeFn`. This is useful to quickly look up allocations.

`std.heap.page_allocator` is improved to use mmap address hints to avoid
obtaining the same virtual address pages when unmapping and mapping
pages. The new general purpose allocator uses the page allocator as its
backing allocator by default.

`std.testing.allocator` is replaced with usage of this new allocator,
which does leak checking, and so the LeakCheckAllocator is retired.

stage1 is improved so that the `@typeInfo` of a pointer has a lazy value
for the alignment of the child type, to avoid false dependency loops
when dealing with pointers to async function frames.

The `std.mem.Allocator` interface is refactored to be in its own file.

`std.Mutex` now exposes the dummy mutex with `std.Mutex.Dummy`.

This allocator is great for debug mode, however it needs some work to
have better performance in release modes. The next step will be setting
up a series of tests in ziglang/gotta-go-fast and then making
improvements to the implementation.
2020-08-07 22:45:45 -07:00
Jakub Konka
310aa87198 Fix alignment issue 2020-08-07 23:21:06 +02:00
Jakub Konka
bdda8fa7a8 Redo GetFinalPathNameByHandle using DeviceIoControl
This commit reimagines `std.os.windows.GetFinalPathNameByHandle`
using `DeviceIoControl` to query the OS mount manager for the DOS
(symlink) paths for the given NT volume name. In particular,
it uses `IOCTL_MOUNTMGR_QUERY_POINTS` ioctl opcode to query the
manager for the available moount points.
2020-08-07 11:33:05 +02:00
Jakub Konka
e8abfef2aa Add docs 2020-08-06 23:56:37 +02:00
Jakub Konka
2628a8846e Use NtQueryInformationFile unless unavailable
Favour newer API which uses `NtQueryInformationFile` with class flags
`FileNormalizedNameInformation` and `FileVolumeNameInformation`
instead of lower-level `NtQueryObject`. `NtQueryObject` is still
used as a fallback in case the former are unavailable.
2020-08-06 23:56:37 +02:00
Jakub Konka
747d46f22c Initial draft of GetFinalPathNameByHandle
This commit proposes an initial draft of `GetPathNameByHandle` function
which wraps NT syscalls and strives to emulate (currently only
partially) the `kernel32.GetFinalPathNameByHandleW` function.
2020-08-06 23:56:37 +02:00
Andrew Kelley
a2bb246db4 Revert "std.fmt.format: small optimization to avoid runtime bloat"
This reverts commit 11d38a7e52.

The benefits of this commit are not enough to justify the compromise
that it made.

closes #5977
2020-08-05 13:30:43 -07:00
Andrew Kelley
cf4936bcb0 std.os tests: improve robustness of "symlink with relative paths" 2020-08-04 23:45:53 -07:00
Andrew Kelley
d159ba9295 zig fmt 2020-08-04 23:04:20 -07:00
Andrew Kelley
f23fb3087b zig build: fix addBuildOption for []const u8 and ?[]const u8 2020-08-04 22:55:45 -07:00
Andrew Kelley
c594f8dc26 stage2 tests: support the -Denable-qemu options and friends 2020-08-04 15:32:16 -07:00
Andrew Kelley
edfede575c self-hosted: add build option for log scopes
Now you can enable a set of log scopes by passing -Dlog=<scope>
2020-08-03 21:56:21 -07:00
Andrew Kelley
d624bf8059 stage2 .debug_line stepping with gdb is working 2020-08-03 21:01:06 -07:00
Andrew Kelley
659603c621 codegen: emit .debug_line ops for IR instructions 2020-08-02 21:28:06 -07:00
Andrew Kelley
1a3f250f19 .debug_line incremental compilation initial support
Supports writing the first function. Still TODO is:
 * handling the .debug_line header growing too large
 * adding a new file to an existing compilation
 * adding an additional function to an existing file
 * handling incremental updates
 * adding the main IR debug ops for IR instructions

There are also issues to work out:
 * readelf --debug-dump=rawline is saying there is no .debug_str section
   even though there is
 * readelf --debug-dump=decodedline is saying the file index 0 is bad
   and reporting some other kind of corruption.
2020-08-02 19:25:26 -07:00
Andrew Kelley
ba6e5cbfd2 stage2: add the .debug_line header and associated data types
* the .debug_line header is written properly
 * link.File.Elf gains:
   - SrcFn, which is now a field in Module.Fn
   - SrcFile, which is now a field in Module.Scope.File
 * link.File.Elf gets a whole *Package field rather than only
   root_src_dir_path.
 * the fields first_dbg_line_file and last_dbg_line_file tell where the
   Line Number Program begins and ends, which alows moving files when
   the header gets too big, and allows appending files to the end.
 * codegen is passed a buffer for emitting .debug_line
   Line Number Program opcodes for functions.

See #5963

There is some work-in-progress code here, but I need to go make some
experimental changes to changing how to represent source locations and I
want to do that in a separate commit.
2020-08-02 12:02:43 -07:00
Andrew Kelley
c0654d2db2 std.dwarf: add LNCT constants from DWARF v5 2020-08-02 11:09:39 -07:00
Andrew Kelley
d4bb2b1513 std: add function for writing fixed width ULEB128 2020-08-02 11:09:35 -07:00
S0urc3C0de
5ae88e919b Add rdynamic option to build.zig 2020-08-02 17:50:06 +00:00
Andrew Kelley
35391f1709
Merge pull request #5968 from haliucinas/blake2
Blake2 improvements
2020-08-02 17:47:06 +00:00
Andrew Kelley
6df35c5877
Merge pull request #5960 from kubkon/windows-dir-refactor
Refactor out file and dir creation routines in Windows
2020-08-02 17:41:47 +00:00
Jakub Konka
4b0ab0c186
Apply suggestions from code review
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-08-02 19:36:49 +02:00
Jay Petacat
cf15b4c269 elf: Iterate over headers w/o need for allocator 2020-08-01 16:01:48 +00:00
Mantas Jonytis
1df33936d6 remove unnecessary operations 2020-08-01 17:15:53 +03:00
Mantas Jonytis
8286cc77f8 implement keyed blake2 2020-08-01 16:56:11 +03:00
Mantas Jonytis
36ed4623a8 make blake2 public 2020-08-01 16:05:20 +03:00
Mantas Jonytis
42dd737c9e compute blake2 at compile time 2020-08-01 16:00:22 +03:00
Mantas Jonytis
1ae40146e6 blake2b: off-by-one on update 2020-08-01 15:31:46 +03:00
Mantas Jonytis
eee9abe1b4 add more blake2b test cases 2020-08-01 15:31:36 +03:00
Mantas Jonytis
b1cf0196df blake2s: off-by-one on update 2020-08-01 15:15:45 +03:00
Mantas Jonytis
fad87bef9a add more blake2s tests 2020-08-01 15:15:04 +03:00
Jakub Konka
f6ae2505d9 Fix opening NUL device on Windows 2020-07-31 19:16:04 +02:00
Jakub Konka
4d9eff4bdb Add prelim openW and openatW
Added POSIX functions targeting Windows pass `open` and `openat`
smoke tests.
2020-07-31 16:41:25 +02:00
Jakub Konka
a694f575ad Add some os.open and os.openat smoke tests 2020-07-31 16:33:02 +02:00
Jakub Konka
390194431e Use NtCreateFile directly in ReadLink
This shaves off one syscall (we use one instead of two if we were to
use `windows.OpenFile` wrapper). Clean up flag generation in `OpenFile`.
Hopefully, we're in a much better place to *almost* support `openW`
and `openatW`.
2020-07-31 16:32:21 +02:00
Jakub Konka
8981b18fee Move delete file logic into windows.DeleteFile fn
This way, we can remove more `kernel32` calls such as `RemoveDirectoryW`
or `DeleteFileW`, and use `std.os.windows.DeleteFile` instead which
is purely NT-based.
2020-07-31 16:31:51 +02:00
Jakub Konka
66bbe4ec4c Refactor internal Win routines to reuse OpenFile
This covers mainly `ReadLink` and `CreateSymolicLink` functions.
2020-07-31 16:31:44 +02:00
Jakub Konka
a89d5cfc3e Remove CreateDirectoryW and CreateFileW calls
Replace them with `std.os.windows.OpenFile` instead. To allow
creation/opening of directories, `std.os.windows.OpenFileOptions`
now features a `.expect_dir: bool` member which is meant to emualate
POSIX's `O_DIRECTORY` flag.
2020-07-31 16:31:23 +02:00
Sam Tebbs
0d31877444
Print } as format argument in enum build option (#5953)
Co-authored-by: Veikka Tuominen <git@vexu.eu>
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-31 11:37:40 +03:00
Andrew Kelley
9d0872a625 std.ArrayList: add appendNTimesAssumeCapacity 2020-07-31 01:16:17 -07:00
Andrew Kelley
f1c1b8c02d stage2: add DWARF info for the main compilation unit 2020-07-31 06:48:17 +00:00
Vexu
f962315363
fix missing parser error for missing comma before eof
Closes #5952
2020-07-30 13:10:55 +03:00
Vexu
1f8f434b9c
compiler_rt: add floatditf 2020-07-29 18:03:44 +03:00
Jakub Konka
547e520359 Split DeviceIoControl path into two fn call paths
As discussed in the previous commit, it would be better to avoid
function pointers to syscalls and explicitly split the control
path into two function calls instead. This commit addresses that
for `std.os.windows.DeviceIoControl`.
2020-07-29 14:17:49 +02:00
Andrew Kelley
11d38a7e52 std.fmt.format: small optimization to avoid runtime bloat
When there are no format parameters, it simply calls `writeAll`. This
has the effect of no longer emitting a compile error for using `{}` and
not having any parameters, however, at this point in the development
process of Zig I think that tradeoff is worthwhile.

On the other hand, it might be OK to simply define formatting to work
this way. It's a common pattern to use the formatting function's format
string `"like this", .{}` instead of `"{}", .{"like this"}`, which can
lead to accidentally putting control characters in the formatting
string, however, with this change that works just fine.
2020-07-29 02:29:36 -07:00
Jakub Konka
4fdfaf69c8 Add Zig wrapper for kernel32.DeviceIoControl
This commit adds a Zig wrapper for `kernel32.DeviceIoControl` which
applies ReactOS logic for deciding whether to use
`ntdll.NtDeviceIoControlFile` or `ntdll.NtFsControlFile` based on the
value of passed `IO_CONTROL_CODE`. The decision logic is based on the
logic found in ReactOS found in the following [link].

Thanks to Daurnimator for finding this bit in ReactOS!

[link]: https://doxygen.reactos.org/d3/d74/deviceio_8c.html
2020-07-29 01:19:10 +00:00
Felix (xq) Queißner
606b6462ce Fixes atomicSymLink looping when new_path already exists. 2020-07-28 17:04:46 +00: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
bd9b3fe1e6
Merge pull request #5511 from jessrud/arraylist-replaceRange
add replaceRange() function to ArrayList
2020-07-27 20:04:19 +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
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
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
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
daurnimator
978a38ee40 std: fix json parsing into unions 2020-07-24 20:35:47 +00: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
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
Jakub Konka
aa6fcaf76f Add missing cross-platform Dir.readLink fns 2020-07-22 08:51:23 +02:00
Jakub Konka
65581b37cb Enable std.os.symlinkat tests on Windows 2020-07-22 08:51:23 +02:00
Jakub Konka
3d41d3fb6e Draft out ReadLinkW using NT primitives 2020-07-22 08:51:23 +02:00
Jakub Konka
4887350bf4 Finish drafting CreateSymolicLink using NT calls 2020-07-22 08:51:23 +02:00
Jakub Konka
99f0e64fa0 Draft out dir symlinks branch 2020-07-22 08:51:23 +02:00
Jakub Konka
c53bcd027f Start drafting CreateSymbolicLink using ntdll syscalls 2020-07-22 08:51:23 +02:00
Jakub Konka
2c9c13f624 Add various build fixes
Fix WASI build, fix atomicSymlink by using `cwd().symLink`, add
`Dir.symLink` on supported targets.
2020-07-22 08:51:22 +02:00
Jakub Konka
e0b77a6b77 Ensure Dir.deleteTree does not dereference symlinks
Otherwise, the behaviour can lead to unexpected results, resulting
in removing an entire tree that's not necessarily under the root.
Furthermore, this change is needed if are to properly handle dir
symlinks on Windows. Without explicitly requiring that a directory
or file is opened with `FILE_OPEN_REPARSE_POINT`, Windows automatically
dereferences all symlinks along the way. This commit adds another
option to `OpenDirOptions`, namely `.no_follow`, which defaults to
`false` and can be used to specifically open a directory symlink on
Windows or call `openat` with `O_NOFOLLOW` flag in POSIX.
2020-07-22 08:51:22 +02:00
Jakub Konka
3c8ceb674e Fix Windows build 2020-07-22 08:51:22 +02:00
Jakub Konka
fc7d87fef1 Move symlink to fs.symlinkAbsolute with SymlinkFlags
This way `std.fs.symlinkAbsolute` becomes cross-platform and we can
legally include `SymlinkFlags` as an argument that's only used on
Windows. Also, now `std.os.symlink` generates a compile error on
Windows with a message to instead use `std.os.windows.CreateSymbolicLink`.
Finally, this PR also reshuffles the tests between `std.os.test` and
`std.fs.test`.
2020-07-22 08:51:22 +02:00
Jakub Konka
dd366d316d Fix more compilation errors on other hosts 2020-07-22 08:51:22 +02:00
Jakub Konka
08e7ac3028 Fix compilation on other hosts 2020-07-22 08:51:22 +02:00