6965 Commits

Author SHA1 Message Date
Matt Knight
a53becc034 don't invoke linker when just building an object 2021-11-07 10:28:25 -08:00
joachimschmidt557
0fb26b0369 stage2 RISCV64: introduce MIR 2021-11-05 15:30:28 -04:00
LemonBoy
2551946a51 std: Fix path resolution on Windows
GetCurrentDirectory returns a path with a trailing slash iff the cwd is
a root directory, making the code in `resolveWindows` return an invalid
path with two consecutive slashes.

Closes #10093
2021-11-04 21:05:14 -04:00
Ryan Liptak
e97feb96e4 Replace ArrayList.init/ensureTotalCapacity pairs with initCapacity
Because ArrayList.initCapacity uses 'precise' capacity allocation, this should save memory on average, and definitely will save memory in cases where ArrayList is used where a regular allocated slice could have also be used.
2021-11-04 14:54:25 -04:00
Andrew Kelley
a55dc4a3bc
Merge pull request #10079 from mattbork/astgen-temp-allocs
stage2: Reduce temporary allocations in AstGen
2021-11-03 18:30:08 -04:00
joachimschmidt557
5ebdc8c46c stage2 RISCV64: move codegen to separate file 2021-11-02 13:05:01 -04:00
Emily Bellows
674932e503 C backend: implement ?void, and other zero sized types 2021-11-02 12:45:29 -04:00
Ryan Liptak
70ef9bc75c Fix ensureTotalCapacity calls that should be ensureUnusedCapacity calls
If these functions are called more than once, then the array list would no longer be guaranteed to have enough capacity during the appendAssumeCapacity calls. With ensureUnusedCapacity, they will always be guaranteed to have enough capacity regardless of how many times the function is called.
2021-11-01 15:08:41 -04:00
Andrew Kelley
77eefebe65
Merge pull request #10077 from squeek502/arraylist-capacity
std.ArrayList: add ensureTotalCapacityPrecise and update doc comments
2021-11-01 14:28:27 -04:00
joachimschmidt557
002fbb0af0 stage2 AArch64: implement unconditional branches 2021-11-01 14:23:38 -04:00
Lee Cannon
f951bf8aeb correct bug with omit frame pointer logic 2021-11-01 14:14:07 -04:00
Matthew Borkowski
01842a6ead astgen.zig: avoid temporary allocations by sharing the instructions ArrayList between a GenZir and its sub-blocks wherever their use of it is strictly nested 2021-11-01 05:42:39 -04:00
Matthew Borkowski
65c27e8e66 astgen.zig: delay adding closure_capture instructions to preserve GenZir nesting. Only containers create Namespaces, so the declaring_gz is always the GenZir passed to containerDecl, and containerDecl will always add exactly one instruction (an extended *_decl) to that GenZir. Thus, closure_capture instructions are always lined up immediately after a container decl instruction, so rather than adding them at the point of first mention, where we're nested arbitrarily deep, simply walk through the Namespace captures hash map at the end of each containerDecl branch and add them then. 2021-11-01 05:42:32 -04:00
Matthew Borkowski
92d2aa1b48 astgen.zig: use scratch buffer for temporary allocations in switchExpr and WipMembers 2021-11-01 05:42:25 -04:00
Matthew Borkowski
5760ba949f astgen.zig: simplify container functions by pulling out common processing of members 2021-11-01 05:42:19 -04:00
Matthew Borkowski
e712f87a66 astgen.zig: replace WipDecls with WipMembers, use one allocation to collect container decls, fields, and bits, instead of up to four 2021-11-01 05:41:37 -04:00
Matthew Borkowski
f0260555d6 astgen.zig: simplify switchExpr and collect payload in one ArrayList instead of three 2021-11-01 05:28:03 -04:00
Matthew Borkowski
a0bf620fbf astgen.zig: avoid unnecessary allocation in identifier for @"" syntax 2021-11-01 05:27:52 -04:00
Matthew Borkowski
2561be2e34 astgen.zig: avoid temporary allocations in arrayInit* and structInit*, callExpr, errorSetDecl, typeOf, and builtinCall's compile_log branch 2021-11-01 05:09:19 -04:00
Ryan Liptak
a343758141 Update ensureTotalCapacity to ensureTotalCapacityPrecise where it makes sense
These calls are all late-initialization of ArrayList's that were initialized outside the current scope. This allows us to still get the potential memory-saving benefits of the 'precision' of initCapacity.
2021-11-01 00:57:33 -07:00
Lee Cannon
83dcfd6205 optimize AstGen.callExpr 2021-10-31 18:11:53 -04:00
Andrew Kelley
8346e011c9
Merge pull request #10068 from leecannon/tracy_improvements
stage2: tracy integration improvements
2021-10-31 17:55:29 -04:00
Jakub Konka
91d93b6395 stage2: move x86_64 codegen to arch/x86_64/CodeGen.zig
This mimics steps taken for aarch64 and preps stage2 x86_64
for a rewrite introducing MIR for this arch.
2021-10-31 17:32:39 -04:00
Lee Cannon
2d1efba8c5 watch marks a new frame on every recompilation 2021-10-31 14:35:36 +00:00
Lee Cannon
8a3a6a98aa use named frames to mark the stages of compilation 2021-10-31 14:29:49 +00:00
Lee Cannon
49d8723408 add functionality to trace allocations 2021-10-31 14:16:59 +00:00
Lee Cannon
10c9fa0e08 make tracy.zig more feature complete 2021-10-31 14:12:36 +00:00
joachimschmidt557
8a55e6b6c4
stage2 AArch64: introduce Emit.fail for handling errors in MIR emit 2021-10-31 14:27:05 +01:00
joachimschmidt557
0bdb367ee4
stage2 AArch64: implement emit debug line info 2021-10-31 12:32:11 +01:00
joachimschmidt557
9471e3da35
stage2 AArch64 Emit: implement call_extern and load_memory 2021-10-31 12:32:07 +01:00
joachimschmidt557
7fc89f64b4
stage2 AArch64: begin transition to MIR
This commit includes the transitions for the following instructions:
- add_immediate
- b
- bl
- blr
- brk
- ldp
- ldr
- ldrb
- ldrh
- mov_to_from_sp
- mov_register
- movk
- movz
- nop
- ret
- stp
- str
- strb
- strh
- sub_immediate
- svc
2021-10-31 09:22:24 +01:00
Emily Bellows
969bcb6a59 C backend: implement signed trunc 2021-10-30 16:09:55 -04:00
Andrew Kelley
d6067db062 stage2: implement @popCount for non-vectors 2021-10-29 17:49:02 -07:00
Andrew Kelley
66b4bd19c0 CLI: clarify help text for -z 2021-10-29 16:18:44 -07:00
Kenta Iwasaki
2cdffc97f0 zig: expose linker options and include '-z notext'
Add an option to allow the '-z notext' option to be passed to the linker
via. the compiler frontend, which is a flag that tells the linker that
relocations in read-only sections are permitted. Certain targets such as
Solana BPF rely on this flag.

Expose all linker options i.e. '-z nodelete', '-z now', '-z relro' in
the compiler frontend. Usage documentation has been updated accordingly.

Expose the '-z notext' flag in the standard library build runner.
2021-10-29 19:18:44 -04:00
Andrew Kelley
bbe4a9fa99 C backend: implement trunc for unsigned non-pow2 ints 2021-10-28 18:33:13 -07:00
Andrew Kelley
98009a2f66 C backend: implement trunc instruction
Note that there is not any test coverage yet for integer
truncation involving non-power-of-two integers.
2021-10-28 17:41:45 -07:00
Andrew Kelley
5479c0f9ac C backend: fix @boolToInt 2021-10-28 17:33:05 -07:00
Andrew Kelley
1c93cf52d8 C backend: fix crash when number of Decls passes a threshold
The ensureUnusedCapacity did not reserve a big enough number. I changed
it to no longer guess the capacity because I saw that the number of
possible items was not determinable ahead of time and this can therefore
avoid allocating more memory than necessary.
2021-10-28 17:23:02 -07:00
Andrew Kelley
c59ee3157f C backend: fix ptrtoint and wrap_errunion_err 2021-10-28 17:05:17 -07:00
Andrew Kelley
d2f9646d98 C backend: fix enough that zig test works
* test_functions: properly add dependencies of the array on test
   functions and test names so that the order comes out correctly.
 * fix lowering of struct literals to add parentheses around the type
   name.
 * omit const qualifier in slices because otherwise slices cannot be
   reassigned even when they are local variables.
 * special case pointer to functions and double pointer to functions in
   renderTypeAndName. This code will need to be cleaned up but for now
   it helps us make progress on other C backend stuff.
 * fix slice element access to lower to `.ptr[` instead of `[`.
 * airSliceElemVal: respect volatile slices
2021-10-28 15:59:14 -07:00
Andrew Kelley
234d94e42b C backend: emit decls sorted by dependencies
The C backend is the only backend that requires each decl to be output
in an order that satisfies the dependency graph. Here it is implemented
with a simple algorithm based on a `remaining_decls` set, using the
`dependencies` edges that are already stored for each Decl.

This satisfies incremental compilation as well as how `zig test` works,
which calls `updateDecl` on `test_functions`.
2021-10-28 13:21:37 -07:00
Andrew Kelley
e02caa7e29 zig test: when -ofmt=c, default to zig run as test exec
Previously when running `zig test` with the C backend, it would return
`error.InvalidExe` because it would try to run the C code source file as
a binary. Now, by default, it will try to run it with
`zig run -lc foo.c` and this can be overridden with the standard
`--test-cmd` flags.
2021-10-27 15:28:33 -07:00
Andrew Kelley
6504c57176 Compilation: fix crash in the compile error system
There is a table of `misc_failures` which previously did not allow
multiple errors for the same enum tag. Now it allows this by freeing the
previous compile error and replacing it with the new one. Typically this
will happen because multiple sub-Compilation objects fail with the same
problem, such as not being able to build glibc because of not having
LLVM extensions enabled.
2021-10-27 15:26:59 -07:00
Andrew Kelley
e494ce7604 stage2: fix small memory leak of test_functions when using zig test
The way `zig test` works is that it uses a stand-in

var test_functions: []const TestFn = undefined;

during semantic analysis, but then just before codegen, it swaps out the
value with a constant like this:

const test_functions: []const TestFn = .{foo, bar, baz, etc};

Before this commit, the `Module.Variable` associated with the stand-in
value was leaked; now it is properly cleaned up before being replaced.
2021-10-27 14:52:00 -07:00
Andrew Kelley
9024f27d8f
Merge pull request #10040 from mattbork/extern-fn-scopes
stage2: fix extern fn decl parsing and astgen
2021-10-27 15:58:33 -04:00
LemonBoy
3568cd4b8f stage1: Fix path normalization on Windows
Backport a missing change from `path.zig`.

Fixes #9465
2021-10-27 15:45:42 -04:00
Andrew Kelley
3af9731600 stage2: implement runtime pointer access to global constants
The main problem that motivated these changes is that global constants
which are referenced by pointer would not be emitted into the binary.
This happened because `semaDecl` did not add `codegen_decl` tasks for
global constants, instead relying on the constant values being copied as
necessary. However when the global constants are referenced by pointer,
they need to be sent to the linker to be emitted.

After making global const arrays, structs, and unions get emitted, this
uncovered a latent issue: the anonymous decls that they referenced would
get garbage collected (via `deleteUnusedDecl`) even though they would
later be referenced by the global const.

In order to solve this problem, I introduced `anon_work_queue` which is
the same as `work_queue` except a lower priority. The `codegen_decl`
task for anon decls goes into the `anon_work_queue` ensuring that the
owner decl gets a chance to mark its anon decls as alive before they are
possibly deleted.

This caused a few regressions, which I made the judgement call to add
workarounds for. Two steps forward, one step back, is still progress.

The regressions were:
 * Two behavior tests having to do with unions. These tests were
   intentionally exercising the LLVM constant value lowering, however,
   due to the bug with garbage collection that was fixed in this commit,
   the LLVM code was not getting exercised, and union types/values were
   not implemented correctly, due to me forgetting that LLVM does not
   allow bitcasting aggregate values.
   - This is worked around by allowing those 2 test cases to regress,
     moving them to the "passing for stage1 only" section.
 * The test-stage2 test cases (in test/cases/*) for non-LLVM backends
   previously did not have any calls to lower struct values, but now
   they do. The code that was there was just `@panic("TODO")`. I
   replaced that code with a stub that generates the wrong value. This
   is an intentional miscompilation that will obviously need to get
   fixed before any struct behavior tests pass. None of the current
   tests we have exercise loading any values from these global const
   structs, so there is not a problem until we try to improve these
   backends.
2021-10-26 22:41:19 -07:00
Andrew Kelley
c1fd459f14 stage2: fix crash report code in release builds 2021-10-26 22:08:51 -07:00
Andrew Kelley
11a60e8779 stage2 LLVM backend: fix bitcast
Properly handle when the operand type, the result type, or both, are
by-ref values.
2021-10-26 16:43:18 -07:00