4890 Commits

Author SHA1 Message Date
Jakub Konka
2a410baa2b stage2: implement basic function params aarch64
Implement missing `.register` prong for `aarch64` `genSetReg`.
2021-01-03 23:03:20 +01:00
Andrew Kelley
d8f3f14532
Merge pull request #7647 from ziglang/stage2-comptime-fn-call
stage2: comptime function calls and inline function calls
2021-01-02 22:01:51 -08:00
Andrew Kelley
654832253a stage2: support recursive inline/comptime functions
zir.Inst no longer has an `analyzed_inst` field. This is previously how
we mapped ZIR to their TZIR counterparts, however with the way inline
and comptime function calls work, we can potentially have the same ZIR
structure being analyzed by multiple different analyses, such as during
a recursive inline function call. This would cause the `analyzed_inst`
field to become clobbered. So instead, we use a table to map the
instructions to their semantically analyzed counterparts. This will help
with multi-threaded compilation as well.

Scope.Block.Inlining is split into 2 different layers of "sharedness".
The first layer is shared by the whole inline/comptime function call
stack. It contains the callsite where something is being inlined and the
branch count/quota. The second layer is different per function call but
shared by all the blocks within the function being inlined.

Add support for debug dumping br and brvoid TZIR instructions.

Remove the "unreachable code" error. It was happening even for this case:

```zig
if (comptime_condition) return;
bar(); // error: unreachable code
```

We will need smarter logic for when it is legal to emit this compile
error.

Remove the ZIR test cases. These are redundant with other higher level
Zig source tests we have, and maintaining support for ZIRModule as a
first-class top level abstraction is getting in the way of clean
compiler design for the main use case. We will have ZIR/TZIR based test
cases someday to help with testing optimization passes and ZIR to TZIR
analysis, but as is, these test cases are not accomplishing that, and
they are getting in the way.
2021-01-02 22:42:07 -07:00
g-w1
3d151fbfc8 fix 7665:
only add self exe path when testing
2021-01-02 20:35:44 -08:00
Andrew Kelley
50a530196c stage2: fix handling compile error in inline fn call
* scopes properly inherit inlining information
 * compile errors of inline function calls are properly attached to the
   caller rather than the callee.
   - added a test case for this
 * --watch still opens a repl if compile errors happen.
2021-01-02 19:11:56 -07:00
Andrew Kelley
006e7f6805 stage2: re-use ZIR for comptime and inline calls
Instead of freeing ZIR after semantic analysis, we keep it around so
that it can be used for comptime calls, inline calls, and generic
function calls. ZIR memory is now managed by the Decl arena.

Debug dump() functions are conditionally compiled; only available in
Debug builds of the compiler.

Add a test for an inline function call.
2021-01-02 19:11:55 -07:00
Andrew Kelley
9362f382ab stage2: implement function call inlining in the frontend
* remove the -Ddump-zir thing. that's handled through --verbose-ir
 * rework Fn to have an is_inline flag without requiring any more memory
   on the heap per function.
 * implement a rough first version of dumping typed zir (tzir) which is
   a lot more helpful for debugging than what we had before. We don't
   have a way to parse it though.
 * keep track of whether the inline-ness of a function changes because
   if it does we have to go update callsites.
 * add compile error for inline and export used together.

inline function calls and comptime function calls are implemented the
same way. A block instruction is set up to capture the result, and then
a scope is set up that has a flag for is_comptime and some state if the
scope is being inlined.

when analyzing `ret` instructions, zig looks for inlining state in the
scope, and if found, treats `ret` as a `break` instruction instead, with
the target block being the one set up at the inline callsite.

Follow-up items:
 * Complete out the debug TZIR dumping code.
 * Don't redundantly generate ZIR for each inline/comptime function
   call. Instead we should add a new state enum tag to Fn.
 * comptime and inlining branch quotas.
 * Add more test cases.
2021-01-02 19:11:19 -07:00
Andrew Kelley
fea8659b82 stage2: comptime function calls
* Function calls that happen in a comptime scope get called at
   compile-time. We do this by putting the parameters in place as
   constant values and then running regular function analysis on the
   body.
 * Added `Scope.Block.dump()` for debugging purposes.
 * Fixed some code to call `identifierTokenString` rather than
   `tokenSlice`, making it work for `@""` syntax.
 * Implemented `Value.copy` for big integers.

Follow-up issues to tackle:
 * Adding compile errors to the callsite instead of the callee Decl.
 * Proper error notes for "called from here".
   - Related: #7555
 * Branch quotas.
 * ZIR support?
2021-01-02 19:10:11 -07:00
Andrew Kelley
974c008a0e convert more {} to {d} and {s} 2021-01-02 19:03:14 -07:00
LemonBoy
5b981b1be7 Remove some unwanted changes
Leftovers after a long rebase.
2021-01-02 17:12:58 -07:00
LemonBoy
04f37dcd8e stage2: Use {z} instead of {s} in generated Zig code 2021-01-02 17:12:57 -07:00
LemonBoy
1fbe89dc2e langref: Update langref to use {s} 2021-01-02 17:12:57 -07:00
LemonBoy
d2f6fa1608 Fix more stray uses of {} for formatting strings 2021-01-02 17:12:57 -07:00
LemonBoy
1c13ca5a05 stage2: Use {s} instead of {} when formatting strings 2021-01-02 17:12:57 -07:00
LemonBoy
1856dfea6b stage1: Use correct format specifier for size_t parameters
Use `Iu` on Windows, the integer width depends on the target being
a 32bit or a 64bit one.
2021-01-02 16:04:34 -08:00
Sizhe Zhao
af8eab546e Fix usage message 2021-01-02 16:03:41 -08:00
Jakub Konka
763d807377 Duplicate OSAtomic.h between aarch64 and x86_64
The reason this is required is for two reasons: 1) the libc
targeting `aarch64` macOS is slightly newer than that targeting
`x86_64`, and 2) `OSAtomic.h` uses relative imports rather than
system-wide imports for accompanying headers which clearly is an
oversight on Apple's part. Until such time when `libkern` headers
between `x86_64` and `aarch64` are identical, this will require a
manual intervention to duplicate the relevant headers between the
respective architectures.
2021-01-02 15:30:14 +01:00
Jakub Konka
91a35e1a92 Detect native iframework dirs on macOS
This commit adds default search paths for system frameworks
on macOS while also adding `-isysroot` for OS versions at least BigSur.
Since BigSur (11.0.1), neither headers nor libs exist in standard
root locations (`/usr/include`, `/System/Library/Frameworks`). Instead, they
are now exclusively part of the installed developer toolchain (either
via XCode.app or CLT), and specifying `-isysroot` allows us to keep
using universal search paths such as `/System/Library/Frameworks` while
only changing the include flag from `-iframework` to
`-iframeworkwithsysroot`.
2021-01-02 15:29:05 +01:00
Andrew Kelley
ec8c25fd8f Restore the reverted semantic versioning commits
restore "Comply with semantic versioning pre-release format"
restore "stage2: SemVer compliance for development builds"
restore "Remove 'g' prefix from commit hash in Zig semver"

This reverts commit d96d8639e592b4bb4b2e330c4bd7412256b297d2.
This reverts commit e8810f579406673edad0c9780c9d990f3034717a.
This reverts commit 9afe5859a3e428b259a306c36a860e4d82dbb4bb.
2021-01-01 21:02:32 -07:00
daurnimator
9c97a07f18 std: have std.meta.fieldInfo take an enum rather than a string 2021-01-01 15:48:46 -07:00
joachimschmidt557
c5ec096b2f stage2 AArch64: add logical (shifted register) instructions 2021-01-01 14:43:12 -08:00
Sizhe Zhao
3bce5b2f30 Fix ssize_t definition 2021-01-01 13:47:18 -08:00
Andrew Kelley
dfacac916f
Merge pull request #7565 from joachimschmidt557/stage2-arm
stage2 ARM: add conditional branches
2021-01-01 13:19:11 -08:00
Jakub Konka
5dfeb6cbc8
macho: unblock stage2 on 32bit platforms (#7632)
* macho: unblock stage2 on 32bit platforms

Unblocks compilation of stage2 on 32bit platforms, and fixes #7630.

* Use libstd convention: reads - usize, writes - u64
2021-01-01 21:28:52 +01:00
joachimschmidt557
c52ca0b178
stage2 ARM: implement genSetReg with compare_flags 2021-01-01 12:22:16 +01:00
joachimschmidt557
85e1b47c40
stage2 ARM: implement genCondBr for compare_flags 2021-01-01 12:22:16 +01:00
joachimschmidt557
4d2919a1ee
stage2 ARM: implement genCondBr 2021-01-01 12:22:14 +01:00
Andrew Kelley
93bb1d93cd
Merge pull request #7616 from ziglang/stage2-inferred-vars
stage2: inferred local variables
2020-12-31 16:28:08 -08:00
Andrew Kelley
982acc22fd stage2: compile error for invalid var type 2020-12-31 17:25:42 -07:00
Andrew Kelley
79a9391414 stage2: no Payload for Type.Tag.inferred_alloc
Simpler, less memory usage. The Value has all the info needed.
2020-12-31 16:51:40 -07:00
Andrew Kelley
e8810f5794 Revert "stage2: SemVer compliance for development builds"
This reverts commit 4af763d401b48f7186650335c8e42e8fe29751bf.
2020-12-31 16:41:35 -07:00
Jakub Konka
fbf269cc47 More MachO.zig fixes ensuring 32bit compat
Partial resolution to #7614.
2020-12-31 14:57:08 +01:00
LemonBoy
102e45e04f stage1: Remove stray brace in rarely-tested code path
This should fix #7614 or part of it.
2020-12-31 14:35:19 +01:00
Jakub Konka
707b81ec37 Make sure MachO.zig compiles on 32bit hosts
This should fix #7614 or part of it.
2020-12-31 14:30:53 +01:00
Andrew Kelley
7deb1f4f6c stage2: type inference for local var 2020-12-31 02:42:48 -07:00
Jakub Konka
0fd3015e55 macho: sentinel can be 4 byte long 2020-12-31 10:19:04 +01:00
Jakub Konka
9369176332 macho: advance VM address of DWARF sections when relocating 2020-12-31 10:19:04 +01:00
Jakub Konka
ea4ff34e13 macho: put all DWARF-related logic into DebugSymbols 2020-12-31 10:19:04 +01:00
Jakub Konka
d189614647 macho: move updateDeclLineNumber logic to DebugSymbols 2020-12-31 10:19:04 +01:00
Jakub Konka
60b3c4ae3c macho: refactor and fix stage2 tests 2020-12-31 10:19:04 +01:00
Jakub Konka
364691fa1f macho: add decl line and file info to subprogram 2020-12-31 10:19:04 +01:00
Jakub Konka
fa28f7006d macho: fix bundle name to .dSYM 2020-12-31 10:19:04 +01:00
Jakub Konka
9318656ce2 macho: use 32bit DWARF format 2020-12-31 10:19:04 +01:00
Jakub Konka
2875a7335a macho: add Elf dwarf sections 2020-12-31 10:19:04 +01:00
Jakub Konka
d4725cb40b macho: prealloc space for debug sections in dSym 2020-12-31 10:19:04 +01:00
Jakub Konka
3174508903 macho: write symbol and string tables to dSym 2020-12-31 10:19:04 +01:00
Jakub Konka
d9ce7a021b macho: copy snapshots of segment commands 2020-12-31 10:19:04 +01:00
Jakub Konka
a7bae1b857 macho: write matching UUID to dSym bundle 2020-12-31 10:19:04 +01:00
Jakub Konka
cf94341910 macho: write Mach-O dSym header 2020-12-31 10:19:04 +01:00
Jakub Konka
bd99a87dc2 macho: create dSym bundle next to final artefact
macOS requires the debug symbols to either be part of the intermediate
object file `whatever.o` or a companion `whatever.dSym` bundle. The
former case seems ill-suited for our needs since it subscribes to
the old-fashioned compilation strategy using intermediate compilation
units; the latter is what we need however on macOS the debug symbols
unlike in Elf are not part of the final artefact; rather they sit
next to it in its own Mach-O file.
2020-12-31 10:19:04 +01:00