Commit Graph

16683 Commits

Author SHA1 Message Date
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
Andrew Kelley
e86ff712a6 stage2: implement tuples
* AIR instruction vector_init gains the ability to init arrays and
   tuples in addition to vectors. This will probably also gain the
   ability to initialize structs and be renamed to `aggregate_init`.
 * AstGen prefers to use an `anon_array_init` ZIR instruction for
   local variables when the init expr is an array literal and there is
   no type.
2022-01-20 16:17:16 -07:00
Jakub Konka
eb70f6e8d7
Merge pull request #10638 from Luukdegram/wasm-refactor
Stage2: wasm - Refactor lowering constants
2022-01-20 20:26:09 +01:00
Andrew Kelley
664e1a892c stage1: remove the "referenced here" error note
It's generally noise. The parts where it is useful will need to be
redone to not be annoying for the general case.
2022-01-20 13:27:52 -05:00
Jonathan Marler
0e682e71b0 remove unnecessary self argument 2022-01-20 10:55:10 +02:00
Meghan Denny
b7ba728929 std: add meta.DeclEnum 2022-01-20 10:54:45 +02:00
Jakub Konka
5eaac2fb99 macho: do not write out ZEROFILL physically to file
Prior to this change, `__DATA,__bss` and `__DATA,__thread_bss` would
get actually, physically written out to the output file, unnecessarily
filling the output file with 0s.
2022-01-20 02:21:58 -05:00
Jakub Konka
538c9e7baf
Merge pull request #10635 from ziglang/stage2-x86_64-params-stack
stage2: fix passing arguments on the stack on x86_64
2022-01-20 00:45:34 +01:00
Daniel Saier
4a401b20e4 glibc: fix passing of __GNU_MINOR__
This was originally introduced in 4d48948b52
but broken immediately afterwards in c8af00c66e.
2022-01-19 17:56:58 -05:00
Luuk de Gram
b9fe6a93ff
wasm: Re-use genTypedValue for constants
When a constant will be passed by reference, such as a struct, we will call into genTypedValue
to lower the constant to bytes and store them into the `rodata` section. We will then return the address
of this constant as a `WValue`.
This change means we will have all constants lowered during compilation time, and no longer have
to sacrifice runtime to lower them onto the stack.
2022-01-19 22:29:36 +01:00
C-BJ
7767e52bbf Update CONTRIBUTING.md
Delete unavailable content!
2022-01-19 14:29:55 -05:00
Jakub Konka
7c831cc266 stage2: add tweak to please Apple re stack alignment
This is more like a temp hack than anything else - I think the
mechanism we use for adjusting the stack when pushing args onto
the stack could/should be reused - i.e., we should just calculate
the stack alignment before each call and then reset the `rsp`
rather than relying on the current hack in `gen()` logic.
2022-01-19 20:21:05 +01:00
Jakub Konka
df6c0067b2 stage2: fix passing arguments on the stack
* push the arguments in reverse order
* add logic for pushing args of any abi size to stack - very similar to
  `genSetStack` however, uses `.rsp` as the base register
* increment and decrement `.rsp` if we called a function with args on
  the stack in `airCall`
* add logic for recovering args from the caller's stack in the callee
2022-01-19 20:21:00 +01:00
Luuk de Gram
1fe1e4d292
wasm: Split funcgen and declgen
This allows us to get rid of unused fields when generating code for non-function decls.
We can now create seperate instances of `DeclGen` which in turn can then be used
to generate the code for a constant.
Besides those reasons, it will be much easier to switch to the generic purpose `codegen.zig` that any
backend should use. Allowing us to deduplicate this code.
2022-01-19 20:01:23 +01:00
Luuk de Gram
28acbdb02f
wasm-linker: Allow for creation of local symbols
The backend can create annonymous local symbols. This can be used for constants
that will be passed by reference so it will not have to be lowered to the stack, and then
stored into the data section. This also means it's valid to return a pointer to a constant array.

Those local symbols that are created, will be managed by the parent decl. Free'ing the parent decl,
will also free all of its locals.

When a local symbol was created, the index of said symbol will be returned and saved in the `memory`
tag of a `WValue` which is then memoized. This means that each 'emit' of this WValue will create a relocation
for that constant/symbol and the actual pointer value will be set after relocation phase.
2022-01-19 20:01:23 +01:00
Luuk de Gram
9615d7aee7
wasm: Refactor storing values.
Due to the new structure of lowerConstant, we can now simplify the logic in a lot of situations.
- We no longer have to check the `WValue`'s tag to determine how to load/store a value.
- We can now provide simple memcopy's for aggregate types.
- Constants are now memoized, meaning we do no longer lower constants on each callsite.
2022-01-19 20:01:23 +01:00
Luuk de Gram
38253a680d
wasm: Refactor emitConstant to lower to WValue 2022-01-19 20:01:23 +01:00
Andrew Kelley
7c6981e0c0 stage2: fix ABI size of slice types to be 2 * ptr size
Previously it was returning 1 * ptr size.
2022-01-19 11:56:01 -07:00
Andrew Kelley
4e8fedffd1
Merge pull request #10475 from lithdew/master
lld: allow for entrypoint symbol name to be set
2022-01-19 13:43:40 -05:00
Andrew Kelley
fd6d1fe015 stage2: improvements to entry point handling
* rename `entry` to `entry_symbol_name` for the zig build API
 * integrate with `zig cc` command line options
 * integrate with COFF linking with LLD
 * integrate with self-hosted ELF linker
 * don't put it in the hash for MachO since it is ignored
2022-01-19 11:41:08 -07:00
Kenta Iwasaki
5ae3e4e9bd lld: allow for entrypoint symbol name to be set
This commit enables for the entrypoint symbol to be set when linking ELF
or WebAssembly modules with lld using the Zig compiler.
2022-01-19 11:22:10 -07:00
Andrew Kelley
beb7495e19
Merge pull request #10624 from ziglang/prefetch
stage2: implement `@prefetch`
2022-01-18 23:25:44 -05:00
Andrew Kelley
de5908548c disable failing atomicrmw test on llvm + aarch64 2022-01-18 21:25:22 -07:00
Andrew Kelley
8375b71f75 Sema: implement declarations for @typeInfo
In the behavior test listings, I had to move type_info.zig test import
to a section that did not include the x86 backend because it got to the
point where adding another test to the file, even if it was an empty
test that just returned immediately, caused a runtime failure when
executing the test binary.

Anyway, type info for opaques is implemented, and the declarations slice
is shared between it, enums, and unions.

Still TODO is the `data` field of a `Declaration`. I want to consider
removing it from the data returned from `@typeInfo` and introducing
`@declInfo` or similar for this data. This would avoid the complexity of
a lazy mechanism.
2022-01-18 18:22:48 -07:00
joachimschmidt557
cd594d10bd stage2 ARM: basic implementation of ptr_slice_{len,ptr}_ptr 2022-01-19 01:33:18 +01:00
Jakub Konka
e80ebc6740
Merge pull request #10625 from ziglang/stage2-x86_64-inline-memset
stage2: add inline memset, partial intcast and more array goodness for x86_64
2022-01-18 22:23:58 +01:00
John Schmidt
305a7def13 Implement segfault handler for macOS x86_64 2022-01-18 15:10:49 -05:00
Andrew Kelley
30efcf22d7 stage2: implement @prefetch
This reverts commit f423b5949b,
re-instating commit d48e4245b6.
2022-01-18 11:59:09 -07:00
Jakub Konka
8201939d7f stage2: implement airArrayElemVal 2022-01-18 18:55:02 +01:00
Andrew Kelley
f423b5949b Revert "stage2: implement @prefetch"
This reverts commit d48e4245b6.

I have no idea why this is failing Drone CI, but in a branch, reverting
this commit solved the problem.
2022-01-18 10:47:02 -07:00
Jakub Konka
8c233687b4 stage2: partially implement intcast on x86_64
* fix violating encoding invariant for memory encoding
* enable some cast tests for x86_64 and arm
2022-01-18 13:18:59 +01:00
Jakub Konka
aaa641feba stage2: add inline memset for x86_64 backend
* introduce new Mir tag `mov_mem_index_imm` which selects instruction
  of the form `OP ptr [reg + rax*1 + imm32], imm32` where the encoded
  flags select the appropriate ptr width for memory store operation
  (note that scale is fixed and set at 1)
2022-01-18 11:58:22 +01:00
Andrew Kelley
4938fb8f5c test runner: stage2 llvm backend prints stats 2022-01-17 22:17:02 -07:00
Andrew Kelley
4d05f2ae5f remove zig_is_stage2 from @import("builtin")
Instead use the standarized option for communicating the
zig compiler backend at comptime, which is `zig_backend`. This was
introduced in commit 1c24ef0d0b.
2022-01-17 21:55:49 -07:00
Andrew Kelley
84c2c47fae Sema: implement else capture value
The ZIR instructions `switch_capture_else` and `switch_capture_ref` are
removed because they are not needed. Instead, the prong index is set to
max int for the special prong.

Else prong with error sets is not handled yet.

Adds a new behavior test because there was not a prior on to cover only
the capture value of else on a switch.
2022-01-17 20:45:55 -07:00
Andrew Kelley
2600978a9d behavior tests: a couple more switch cases are passing 2022-01-17 19:52:24 -07:00
Jakub Konka
e69cb9105a
Merge pull request #10616 from ziglang/stage2-x86_64-array-to-slice
stage2: implement airArrayToSlice for x86_64
2022-01-18 01:25:48 +01:00
Andrew Kelley
f4e051e35d Sema: fix comptime break semantics
Previously, breaking from an outer block at comptime would result in
incorrect control flow. Now there is a mechanism, `error.ComptimeBreak`,
similar to `error.ComptimeReturn`, to send comptime control flow further
up the stack, to its matching block.

This commit also introduces a new log scope. To use it, pass
`--debug-log sema_zir` and you will see 1 line per ZIR instruction
semantically analyzed. This is useful when you want to understand what
comptime control flow is doing while debugging the compiler.

One more `switch` test case is passing.
2022-01-17 15:23:50 -07:00
Jakub Konka
3145fa97c2 stage2: separate ptr and stack offset codepaths in genSetStack 2022-01-17 21:52:15 +01:00
Jakub Konka
ab204f81b0 stage2: return error.SkipZigTest in unsupported behavior tests 2022-01-17 20:30:44 +01:00
Jakub Konka
9b715cb462 stage2: implement airArrayToSlice for x86_64
* implement `genSetStack` for `ptr_stack_offset`
* handle `ptr_add`
* implement storing from register into pointer in register
* split alignment and array tests into those that pass on x86_64 and
  those that do not
* pass more tests on x86_64
2022-01-17 20:24:14 +01:00