Commit Graph

16623 Commits

Author SHA1 Message Date
Andrew Kelley
f037029283 behavior tests: prevent disabled tests from lowering std.Target 2022-01-24 22:04:28 -07:00
Andrew Kelley
a2abbeef90 stage2: rework a lot of stuff
AstGen:
 * rename the known_has_bits flag to known_non_opv to make it better
   reflect what it actually means.
 * add a known_comptime_only flag.
 * make the flags take advantage of identifiers of primitives and the
   fact that zig has no shadowing.
 * correct the known_non_opv flag for function bodies.

Sema:
 * Rename `hasCodeGenBits` to `hasRuntimeBits` to better reflect what it
   does.
   - This function got a bit more complicated in this commit because of
     the duality of function bodies: on one hand they have runtime bits,
     but on the other hand they require being comptime known.
 * WipAnonDecl now takes a LazySrcDecl parameter and performs the type
   resolutions that it needs during finish().
 * Implement comptime `@ptrToInt`.

Codegen:
 * Improved handling of lowering decl_ref; make it work for
   comptime-known ptr-to-int values.
   - This same change had to be made many different times; perhaps we
     should look into merging the implementations of `genTypedValue`
     across x86, arm, aarch64, and riscv.
2022-01-24 21:53:57 -07:00
Andrew Kelley
8bb679bc6e Sema: resolveBody takes a parameter for break blocks
Previously, break instructions which wanted to break out of multiple
nesting layers did not work correctly at comptime.
2022-01-24 21:47:53 -07:00
Andrew Kelley
65576ea2ea llvm backend: fix not updating map after deleting global
This was uncaught UB!
2022-01-24 21:47:53 -07:00
Andrew Kelley
b34f994c0b stage2: type system treats fn ptr and body separately
This commit updates stage2 to enforce the property that the syntax
`fn()void` is a function *body* not a *pointer*. To get a pointer, the
syntax `*const fn()void` is required.

ZIR puts function alignment into the func instruction rather than the
decl because this way it makes it into function types. LLVM backend
respects function alignments.

Struct and Union have methods `fieldSrcLoc` to help look up source
locations of their fields. These trigger full loading, tokenization, and
parsing of source files, so should only be called once it is confirmed
that an error message needs to be printed.

There are some nice new error hints for explaining why a type is
required to be comptime, particularly for structs that contain function
body types.

`Type.requiresComptime` is now moved into Sema because it can fail and
might need to trigger field type resolution. Comptime pointer loading
takes into account types that do not have a well-defined memory layout
and does not try to compute a byte offset for them.

`fn()void` syntax no longer secretly makes a pointer. You get a function
body type, which requires comptime. However a pointer to a function body
can be runtime known (obviously).

Compile errors that report "expected pointer, found ..." are factored
out into convenience functions `checkPtrOperand` and `checkPtrType` and
have a note about function pointers.

Implemented `Value.hash` for functions, enum literals, and undefined values.

stage1 is not updated to this (yet?), so some workarounds and disabled
tests are needed to keep everything working. Should we update stage1 to
these new type semantics? Yes probably because I don't want to add too
much conditional compilation logic in the std lib for the different
backends.
2022-01-24 21:47:53 -07:00
Andrew Kelley
0866fa9d1d
Merge pull request #10688 from topolarity/c-backend-union-support
stage2: Add `union` support to C backend
2022-01-24 23:47:41 -05:00
Andrew Kelley
913d61ebb9 Revert "MultiArrayList: Fix error when struct is 0 sized"
This reverts commit 1f10cf4edf.

Re-opens #10618

I want to solve this a different way. `align(S)` where S is a 0-byte
type should work in this context.

This also caused issues such as
https://github.com/Vexu/arocc/issues/221
2022-01-24 21:29:04 -07:00
mparadinha
2e9ce6facd stage2: x64: fix printing of callee preserved regs instructions 2022-01-24 23:19:53 +01:00
joachimschmidt557
7665401500 stage2 ARM: re-enable debug info for arguments
These were disabled during the MIR transition
2022-01-24 23:18:13 +01:00
Frank Denis
4e5495e443 std.crypto.25519.scalar: implement edwards25519 scalar field inversion
This operation is extremely useful for multiplicative blinding.
2022-01-24 23:09:45 +01:00
Cody Tapscott
60e6bf112c Cleanup unnecessary switches in union logic 2022-01-24 12:49:14 -07:00
Cody Tapscott
cb24799368 Run zig fmt 2022-01-24 12:18:16 -07:00
Cody Tapscott
587a4437db Add union support to the C backend.
There are some differences vs. the union encoding in the LLVM backend:
   - Tagged unions with a 0-bit payload do not become their tag type. Instead,
     they are a struct with an empty `union` as their payload field.
   - We do not order the `payload`/`tag` storage based on their alignment
2022-01-24 12:00:04 -07:00
Cody Tapscott
983dfcd3fb Fix rendering of void function args 2022-01-24 12:00:04 -07:00
Cody Tapscott
8c96c64fbb Add support for rendering .enum_numbered 2022-01-24 12:00:04 -07:00
Cody Tapscott
52517e86d6 Avoid identifier conflicts with reserved C keywords 2022-01-24 12:00:01 -07:00
Cody Tapscott
799bd81b08 Add support for rendering .elem_ptr 2022-01-24 11:58:43 -07:00
John Schmidt
40b3c9a592 Handle FormatOptions in fmtDuration/fmtDurationSigned 2022-01-24 20:30:36 +02:00
riverbl
a0732117d0 HashMap: add removeByPtr 2022-01-24 20:29:05 +02:00
Sizhe Zhao
15ef251a15 Avoid duplicate TLS startup symbols 2022-01-24 20:26:29 +02:00
Jonathan Marler
3f341bdc26
Normalize some build function names
An attempt to normalize some of the function names in build.zig.  Normalize add*Dir to add*Path.  Also use "Library" instead of the "Lib" abbreviation.

The PR does not remove the old names, only adds the new normalized ones to faciliate a transition period.
2022-01-24 20:15:32 +02:00
Pablo Santiago Blum de Aguiar
5ba4385971 readUntilDelimiter*: read only if buffer not full
Ref.: #9594
2022-01-24 17:44:26 +02:00
Jonathan Marler
2fc2d88fc6 use explicit integer bit widths for windows GUID
The size of a GUID is not platform-dependent, it's always a fixed number of bits.  So I've updated guid to use fixed bit integer types rather than platform-dependent C integer types.
2022-01-24 17:35:15 +02:00
fifty-six
da8d4d9225 std/fs: Support XDG_DATA_HOME
This is generally used for user-specific data on linux, with the
default being ~/.local/share
2022-01-24 17:33:38 +02:00
riverbl
1f10cf4edf
MultiArrayList: Fix error when struct is 0 sized
Also fixes error with ArrayHashMap when both key and value are 0 sized
2022-01-24 17:31:27 +02:00
Lee Cannon
c54a7ca4b2 allow expected_exit_code to be null 2022-01-24 17:29:19 +02:00
Andrew Kelley
12c2de6ee2
Merge pull request #10662 from ziglang/doc-comments-zir
Doc comments zir
2022-01-23 18:31:55 -05:00
Andrew Kelley
8a69726209 AstGen: doc comment fixups
* AstGen: use Ast.zig helper methods to avoid copy pasting token counting logic
   - take advantage of the `first_doc_comment` field we already have for
     param AST nodes
 * Add missing ZIR docs
2022-01-23 16:24:46 -07:00
Jimmi Holst Christensen
f1b91bb41b c backend: Implement aligning fields and local/global variables
There are some restrictions here.

- We either need C11 or a compiler that supports the aligned attribute
- We cannot provide align less than the type's natural C alignment.
2022-01-23 17:23:55 -05:00
Jimmi Holst Christensen
7287c7482a Stop using LinearFifo in BufferedWriter
Looking at the BufferedWriter assembly generated, one can see that is
has to do a lot of work, just to copy over some bytes and increase an
offset. This is because the LinearFifo is a much more general construct
than what BufferedWriter needs and the optimizer cannot prove that we
don't need to do this extra work.
2022-01-23 14:41:15 -05:00
Hadrien Dorio
490f067de8
compress: add a deflate compressor
Replaces the inflate API from `inflateStream(reader: anytype, window_slice: []u8)` to
`decompressor(allocator: mem.Allocator, reader: anytype, dictionary: ?[]const u8)` and
`compressor(allocator: mem.Allocator, writer: anytype, options: CompressorOptions)`
2022-01-23 19:30:06 +01:00
Hadrien Dorio
dba04a272a
compress: remove sha256 checks from tests
Read bytes to check expected values instead of reading and hashing them.
Hashing is a waste of time when we can just read and compare.
This also removes a dependency on std.crypto.hash.sha2.Sha256 for tests.
2022-01-23 19:29:57 +01:00
joachimschmidt557
fa84625aeb std: Add some missing termios types to c/linux.zig and os.zig 2022-01-23 17:12:07 +01:00
Jakub Konka
36f13f5911 stage2: remove asserts and comments which are Emit.zig responsibility 2022-01-23 00:31:37 +01:00
Jakub Konka
081ce09575
Merge pull request #10664 from ziglang/stage2-x86_64-refactor-air-call
stage2: refactor how we preserve callee regs and how we pass args on the stack in x86_64 backend
2022-01-23 00:01:12 +01:00
Jakub Konka
406c85f9ba macho+elf: fix integer overflow in allocateAtom
If there is a big atom available for re-use in the free list, and
it's the last atom in section, it's ideal capacity might span the
entire section in which case we do not want to calculate the actual
end VM addr of the symbol since it may overflow. Instead, we just take
the max capacity available as end VM addr estimate. In this case,
the max capacity equals `std.math.maxInt(u64)`.
2022-01-22 08:50:01 +01:00
Jakub Konka
062ddb693f stage2: fix improper capacity prealloc in lowerToRm encoding 2022-01-22 00:58:18 +01:00
Jakub Konka
5fb921539b stage2: do not copy args passed via stack into functions locals 2022-01-22 00:46:35 +01:00
Jakub Konka
4a5e75245b stage2: clean up preserving callee regs on the stack
Instead of using `push` and `pop` combo, we now re-use our stack
allocation mechanism which means we don't have to worry about
16-byte stack adjustments on macOS as it is handled automatically
for us. Another benefit is that we don't have to backpatch stack
offsets when pulling args from the stack.
2022-01-22 00:46:35 +01:00
Loris Cro
8c23b81e86 fix incorrect zir offset loading in sema 2022-01-21 22:46:12 +01:00
Andrew Kelley
d819663543 disable some broken stuff for stage2 llvm backend on aarch64 2022-01-21 14:42:58 -07:00
Loris Cro
ba55e32ef2 add function param doc comment info in zir 2022-01-21 22:00:57 +01:00
Loris Cro
1f56ff8343 add support for more decl attributes in doc comment zir
The previous commit that implemented doc comment zir support for
decls did not properly account for all the possible attribute
keyword combinations (threadlocal, extern, and such).
2022-01-21 22:00:57 +01:00
Loris Cro
98fddd1c54 add field doc comments to zir
Doc comment information is stored in `extra` unconditionally for
each field. This commmit covers Structs, Enums, Unions, and ErrSets.
2022-01-21 22:00:57 +01:00
Loris Cro
3010ccfca5 astgen saves decl doc comments in zir
The field is saved in `extra` unconditionally for each decl.
2022-01-21 22:00:56 +01:00
Andrew Kelley
c9ae24503d
Merge pull request #10649 from ziglang/stage2-tuples
stage2: implement tuples
2022-01-20 18:24:01 -05:00
Andrew Kelley
1f823eecdd stage2: fix compilation on 32 bit targets 2022-01-20 16:21:49 -07:00
Luuk de Gram
f763000dc9 Fix abi size of optional slices
Previously, optional slices returned the pointer size as abi size.
We now account for slices to calculate the correct size which is abi-alignment + slice ABI size.
2022-01-20 18:19:20 -05:00
Andrew Kelley
1417698c11 Sema: storePtr optimization for tuples
To generate better code for tuples, we detect a tuple operand in
storePtr, and analyze field loads and stores directly. This avoids
an extra allocation + memcpy which would occur if we used `coerce`.
2022-01-20 16:17:16 -07:00
Andrew Kelley
4fccc95b01 Sema: fix requiresComptime infinite recursion
When asking a struct or union whether the type requires comptime, it may
need to ask itself recursively, for example because of a field which is
a pointer to itself. This commit adds a field to each to keep track of
when computing the "requires comptime" value and returns `false` if the
check is already ongoing.
2022-01-20 16:17:16 -07:00