Commit Graph

745 Commits

Author SHA1 Message Date
Jakub Konka
e7ac05e882 stage2: rename Emit to Isel for x86_64 2021-12-31 11:18:23 +01:00
Jan Philipp Hafer
17046674a7 compiler_rt: add __negvsi2, __negvdi2, __negvti2
- neg can only overflow, if a == MIN
- case `-0` is properly handled by hardware, so overflow check by comparing
  `a == MIN` is sufficient
- tests: MIN, MIN+1, MIN+4, -42, -7, -1, 0, 1, 7..

See #1290
2021-12-27 14:35:45 -08:00
Jan Philipp Hafer
405ff911da compiler_rt: add __absvsi2, __absvdi2, __absvti2
- abs can only overflow, if a == MIN
- comparing the sign change from wrapping addition is branchless
- tests: MIN, MIN+1,..MIN+4, -42, -7, -1, 0, 1, 7..

See #1290
2021-12-26 13:21:18 -08:00
Andrew Kelley
3763580e1e add missing files to CMakeLists 2021-12-23 17:48:58 -07:00
Andrew Kelley
e3e6516d08 start the 0.10.0 release cycle 2021-12-20 13:13:48 -07:00
Jan Philipp Hafer
20328e976f compiler_rt: add __cmpXi2 and __ucmpXi2
- adds __cmpsi2, __cmpdi2, __cmpti2
- adds __ucmpsi2, __ucmpdi2, __ucmpti2
- use 2 if statements with 2 temporaries and a constant
- tests: MIN, MIN+1, MIN/2, -1, 0, 1, MAX/2, MAX-1, MAX if applicable

See #1290
2021-12-14 14:21:30 -08:00
Jan Philipp Hafer
eb1e75b2b8 compiler_rt: refactor __mulodi2 and __muloti2 to get __mulosi2
- use comptime instead of 2 identical implementations
- tests: port missing tests and link to archived llvm-mirror release 80

See #1290
2021-12-14 14:16:24 -08:00
Jan Philipp Hafer
c56663dee8 compiler_rt: add __negsi2, __negdi2, __negti2
- use negXi2.zig to prevent confusion with negXf2.zig
- used for size optimized builds and machines without carry instruction
- tests: special cases 0, -INT_MIN
  * use divTrunc range and shift with constant offsets

See #1290
2021-12-14 14:14:31 -08:00
Jan Philipp Hafer
efdb94486b compiler_rt: add __bswapsi2, __bswapdi2 and __bswapti2
- each byte gets masked, shifted and combined
- use boring masks instead of comptime for readability
- tests: bit patterns with reverse operation, if applicable

See #1290
2021-12-11 01:43:37 -08:00
Jakub Konka
828f61e8df macho: move all helpers from commands.zig into std.macho
This way we will finally be able to share common parsing logic
between different Zig components and 3rd party packages.
2021-12-10 18:18:28 +01:00
Andrew Kelley
f3edff439e improve detection of how to execute binaries on the host
`getExternalExecutor` is moved from `std.zig.CrossTarget` to
`std.zig.system.NativeTargetInfo.getExternalExecutor`.

The function also now communicates a bit more information about *why*
the host is unable to execute a binary. The CLI is updated to report
this information in a useful manner.

`getExternalExecutor` is also improved to detect such patterns as:
 * x86_64 is able to execute x86 binaries
 * aarch64 is able to execute arm binaries
 * etc.

Added qemu-hexagon support to `getExternalExecutor`.

`std.Target.canExecBinaries` of is removed; callers should use the more
powerful `getExternalExecutor` instead.

Now that `zig test` tries to run the resulting binary no matter what,
this commit has a follow-up change to the build system and docgen to
utilize the `getExternalExecutor` function and pass `--test-no-exec`
in some cases to avoid getting the error.

Additionally:

 * refactor: extract NativePaths and NativeTargetInfo into their own
   files named after the structs.
 * small improvement to langref to reduce the complexity of the `callconv`
   expression in a couple examples.
2021-12-02 21:51:14 -07:00
Jan Philipp Hafer
e4c053f047 compiler_rt: add __paritysi2, __paritydi2, __parityti2
- use Bit Twiddling Hacks: Compute parity in parallel
- test cases derived from popcount.zig
- tests: compare naive approach 10_000 times with random numbers created
  from naive seed 42
- compiler_rt.zig: sort by LLVM builtin order and add comments to improve structure

See #1290
2021-12-01 13:35:19 -08:00
Andrew Kelley
902df103c6 std lib API deprecations for the upcoming 0.9.0 release
See #3811
2021-11-30 00:13:07 -07:00
Jan Philipp Hafer
1ea650bb75 compiler_rt: add __popcountsi2, __popcountdi2 and __popcountti2
- apply simpler approach than LLVM for __popcountdi2
  taken from The Art of Computer Programming and generalized
- rename popcountdi2.zig to popcount.zig
- test cases derived from popcountdi2_test.zig
- tests: compare naive approach 10_000 times with
  random numbers created from naive seed 42

    See #1290
2021-11-29 12:50:25 -08:00
Stephen Gutekanst
b613210140
compiler_rt: implement __isPlatformVersionAtLeast (Objective-C @available expressions) for Darwin (#10232) 2021-11-29 14:54:23 -05:00
Jakub Konka
2ca5a859e9 Force static libncurses in CMakeLists when static zig on macos
Add additional search paths pointing at homebrew prefixes as Apple
doesn't ship a static libncurses for linking - only a stub for dynamic
linking `libncurses.tbd`.
2021-11-28 21:10:33 -08:00
Luuk de Gram
d3135f7682
Stage2: wasm - Implement the MIR pass (#10153)
* wasm: Move wasm's codegen to arch/wasm/CodeGen.zig

* wasm: Define Wasm's Mir

This declares the initial most-used instructions for wasm as
well as the data that represents them.
TODO: Add binary operand opcodes.

By re-using the wasm opcode values, we can emit each opcode very easily
by simply using `@enumToInt()`. However, this poses a possible problem:
If we use all of wasm's opcodes, it leaves us no room to use synthetic opcodes such as debugging instructions.
We could use reserved opcodes, but the wasm spec may use them at some point.
TODO: Check if we should perhaps use a 16bit tag where the highest bits are used for synthetic opcodes.

* wasm: Define basic Emit structure

* wasm: Implement corresponding Emit functions for MIR

* wasm: Initial lowering to MIR

- This implements lowering to MIR from AIR for storing and loading of locals
as well as emitting immediates.
- Relocating function indexes has been simplified a lot as well as we no
longer need to patch offsets and we write a relocatable value instead.
- Locals are now emitted at the beginning of the function section entry
meaning all offsets we generate are stable.

* wasm: Lower all AIR instructions to MIR

* wasm: Implement remaining MIR instructions

* wasm: Fix function relocations

* wasm: Get all tests working

* wasm: Make `Data` 4 bytes instead of 8.

- 64bit immediates are now stored in 2 seperate u32's.
- 64bit floats are now stored in 2 seperate u32's.
- `mem_arg` is now stored as a seperate payload in extra.
2021-11-15 18:02:24 +01:00
Martin Hafskjold Thoresen
e04ab39036 Cmake: Specify LLVM versions
Systems with multiple LLVM toolchains installed (e.g. one globally and one
in $HOME/local) would get confused and fail to compile.  Being explicit
about the version required will force CMake to find the right version of LLVM.
2021-11-09 13:39:32 -05:00
joachimschmidt557
8f58e2d779 stage2 codegen: move bit definitions to src/arch 2021-09-24 13:47:59 -04:00
Andrew Kelley
f3147de7a2 stage2: extract ZIR printing code into print_zir.zig
also implement textual printing of the ZIR instruction `atomic_rmw`.
2021-09-20 14:45:40 -07:00
Jakub Konka
a38b636045 Merge remote-tracking branch 'origin/master' into zld-incr 2021-09-13 23:40:38 +02:00
Jakub Konka
aaacfc0d0a macho: init process of renaming TextBlock to Atom
Initially, internally within the linker.
2021-09-09 18:32:03 +02:00
Andrew Kelley
3940a1be18 rename std.zig.ast to std.zig.Ast; use top-level fields 2021-09-01 17:54:07 -07:00
Andrew Kelley
ca21cad2bf move syntax tests out of behavior tests
parser_test.zig is where the syntax tests go
2021-09-01 17:54:06 -07:00
Andrew Kelley
c05a20fc8c std: reorganization that allows new usingnamespace semantics
The proposal #9629 is now accepted, usingnamespace stays but no longer
puts identifiers in scope.
2021-09-01 17:54:06 -07:00
Andrew Kelley
3deda15e21 std.os reorganization, avoiding usingnamespace
The main purpose of this branch is to explore avoiding the
`usingnamespace` feature of the zig language, specifically with regards
to `std.os` and related functionality.

If this experiment is successful, it will provide a data point on
whether or not it would be practical to entirely remove `usingnamespace`
from the language.

In this commit, `usingnamespace` has been completely eliminated from
the Linux x86_64 compilation path, aside from io_uring.

The behavior tests pass, however that's as far as this branch goes. It is
very breaking, and a lot more work is needed before it could be
considered mergeable. I wanted to put a pull requset up early so that
zig programmers have time to provide feedback.

This is progress towards closing #6600 since it clarifies where the
actual "owner" of each declaration is, and reduces the number of
different ways to import the same declarations.

One of the main organizational strategies used here is to do namespacing
with real namespaces (e.g. structs) rather than by having declarations
share a common prefix (the C strategy). It's no coincidence that
`usingnamespace` has similar semantics to `#include` and becomes much
less necessary when using proper namespaces.
2021-09-01 17:54:06 -07:00
Jan Philipp Hafer
81e2034d4a compiler_rt: add __clzdi2 and __clzti2
- structure derived from shift.zig
- rename clzsi2.zig to count0bits.zig
- test cases derived from clzsi2_test.zig

See #1290
2021-09-01 16:15:21 -04:00
Andrew Kelley
a98fa56ae9 std: [breaking] move errno to become an nonexhaustive enum
The primary purpose of this change is to eliminate one usage of
`usingnamespace` in the standard library - specifically the usage for
errno values in `std.os.linux`.

This is accomplished by truncating the `E` prefix from error values, and
making errno a proper enum.

A similar strategy can be used to eliminate some other `usingnamespace`
sites in the std lib.
2021-08-24 01:23:28 -04:00
Jakub Konka
5533f77054 Merge remote-tracking branch 'origin/master' into zld-incremental-2 2021-07-23 17:06:19 +02:00
Andrew Kelley
7c25390c95 support -fcompiler-rt in conjunction with build-obj
When using `build-exe` or `build-lib -dynamic`, `-fcompiler-rt` means building
compiler-rt into a static library and then linking it into the executable.

When using `build-lib`, `-fcompiler-rt` means building compiler-rt into an
object file and then adding it into the static archive.

Before this commit, when using `build-obj`, zig would build compiler-rt
into an object file, and then on ELF, use `lld -r` to merge it into the
main object file. Other linker backends of LLD do not support `-r` to
merge objects, so this failed with error messages for those targets.

Now, `-fcompiler-rt` when used with `build-obj` acts as if the user puts
`_ = @import("compiler_rt");` inside their root source file. The symbols
of compiler-rt go into the same compilation unit as the root source file.

This is hooked up for stage1 only for now. Once stage2 is capable of
building compiler-rt, it should be hooked up there as well.
2021-07-22 19:51:32 -07:00
Jakub Konka
def1359187 Merge remote-tracking branch 'origin/master' into zld-incremental-2 2021-07-22 09:34:44 +02:00
Andrew Kelley
0ffc6b5cc3 cmake: fix Liveness.zig file path 2021-07-20 12:19:16 -07:00
Andrew Kelley
5d6f7b44c1 stage2: rework AIR memory layout
This commit changes the AIR file and the documentation of the memory
layout. The actual work of modifying the surrounding code (in Sema and
codegen) is not yet done.
2021-07-20 12:18:14 -07:00
Jakub Konka
f6d13e9d6f zld: move contents of Zld into MachO module 2021-07-18 17:48:00 +02:00
Jakub Konka
407745a5e9 zld: simplify and move Relocations into TextBlock
It makes sense to have them as a dependent type since they only ever
deal with TextBlocks. Simplify Relocations to rely on symbol indices
and symbol resolver rather than pointers.
2021-07-17 01:03:40 +02:00
Jakub Konka
54a403d4ff zld: replace parsed reloc with a simple wrapper around macho.relocation_info 2021-07-16 17:18:53 +02:00
Jakub Konka
f519e781c6 zld: move TextBlock into standalone file
which should make managing the logic of parsing and resolving relocs
that much simpler to parse.
2021-07-15 18:49:48 +02:00
Jakub Konka
0135b46659 zld: remove StringTable abstraction 2021-07-15 18:49:47 +02:00
Jakub Konka
dbd2eb7c7f zld: simplify relocation parsing 2021-07-15 18:49:47 +02:00
Jakub Konka
3622fe08db zld: abstract away string table with fewer allocs 2021-07-15 18:49:46 +02:00
Andrew Kelley
476faef97a plan9 cleanups
* rename files to adhere to conventions
 * remove unnecessary function / optionality
 * fix merge conflict
 * better panic message
 * remove unnecessary TODO comment
 * proper namespacing of declarations
 * clean up documentation comments
 * no copyright header needed for a brand new zig file that is not
   copied from anywhere
2021-07-08 14:24:16 -07:00
jacob gw
34c21affa2 initial plan9 boilerplate
The code now compiles and fails with Plan9ObjectFormatUnimplemented
2021-07-08 14:10:49 -07:00
Jakub Konka
3cb6b6bd90 zld: merge Stub with Dylib struct
After giving it more thought, it doesn't make sense to separate
the two structurally. Instead, there should be two constructors
for a Dylib struct: one from binary file, and the other from a stub
file. This cleans up a lot of code and opens the way for recursive
parsing of re-exports from a dylib which are a hard requirement for
native feel when linking frameworks.
2021-06-24 18:57:04 +02:00
Jakub Konka
bc78b02c04 zld: introduce Stub.zig which represents parsed stub file
Instead of trying to fit a stub file into the frame of a Dylib struct,
I think it makes more sense to keep them as separate entities with
possibly shared interface (which would be added in the future).

This cleaned up a lot of logic in Dylib as well as Stub. Also, while
here I've made creating actual *Symbols lazy in the sense Dylib and
Stub only store hash maps of symbol names that they expose but we
defer create and referencing given dylib/stub until link time when
a symbol is actually referenced. This should reduce memory usage
and speed things up a bit.
2021-06-24 14:45:45 +02:00
Jakub Konka
fbdc515418 link: add basic TAPI parser for linkers
Parser uses kubkon/zig-yaml gitrev c3eae1e40a02aedd44ad1171e5c8b259896cbda0
2021-06-24 14:45:45 +02:00
Andrew Kelley
c3f637a54c cmake: debug builds of zig enable logging by default
when logging is enabled, the --debug-log flag is available.
2021-06-23 10:44:46 -07:00
Andrew Kelley
193c529b8c CLI: rename --override-lib-dir to --zig-lib-dir
This breaking change disambiguates between overriding the lib dir when
performing an installation with the Zig Build System, and overriding the
lib dir that the Zig installation itself uses.
2021-06-14 11:33:27 -07:00
protty
2ba68f9f4c
std.Thread.Futex addition (#9070)
* std.Thread.Futex: implementation + tests

* std.Thread.Futex: fix darwin compile errors

* std.Thread.Futex: fix wait() documentation typo

* std.Thread.Futex: fix darwin version check

* std.Thread.Futex: remove unnecessary comptime keyword
2021-06-12 08:51:37 -05:00
Andrew Kelley
b755c46d70 start the 0.9.0 release cycle 2021-06-04 11:29:01 -07:00
Andrew Kelley
87dae0ce98
Merge pull request #8932 from ziglang/llvm-needs-zlib
cmake: LLVM needs to link against zlib
2021-06-03 02:13:37 -04:00
protty
eb6975f088
std.sync.atomic: extended atomic helper functions (#8866)
- deprecates `std.Thread.spinLoopHint` and moves it to `std.atomic.spinLoopHint`
- added an Atomic(T) generic wrapper type which replaces atomic.Bool and atomic.Int
- in Atomic(T), selectively expose member functions depending on T and include bitwise atomic methods when T is an Integer
- added fence() and compilerFence() to std.atomic
2021-05-31 11:11:30 -05:00
Andrew Kelley
f8bc5294f2 cmake: LLVM needs to link against zlib
For more details on why this dependency is needed, see
https://github.com/ziglang/zig-bootstrap/issues/57
2021-05-29 17:22:27 -07:00
Andrew Kelley
0afb5b2ec6 stage2: add zig ar subcommand
The same entrypoint supports the following commands:

 * ar
 * ranlib
 * dlltool
 * lib

For now, our strategy is to bundle the (renamed) `main()` function of
llvm-ar, same as our strategy for `zig clang`. However, as Zig matures,
a goal will be to replace the dependency on LLVM  with our own
implementation of this tool, so that it is available in builds of zig
that do not have LLVM extensions enabled.

This commit also categorizes the subcommands into categories in the
--help menu.
2021-05-28 20:54:11 -07:00
Andrew Kelley
2a990d6966 stage1: rework tokenizer to match stage2
* Extracts AstGen logic from ir.cpp into astgen.cpp. Reduces the
   largest file of stage1 from 33,551 lines to 25,510.
 * tokenizer: rework it completely to match the stage2 tokenizer logic.
   They can now be maintained together; when one is changed, the other
   can be changed in the same way.
   - Each token now takes up 13 bytes instead of 64 bytes. The tokenizer
     does not parse char literals, string literals, integer literals,
     etc into meaningful data. Instead, that happens during parsing or
     astgen.
   - no longer store line offsets. Error messages scan source
     files to find the line/column as needed (same as stage2).
   - main loop: instead of checking the loop, handle a null byte
     explicitly in the switch statements. This is a nice improvement
     that we may want to backport to stage2.
   - delete some dead tokens, artifacts of past syntax that no longer
     exists.
 * Parser: fix a TODO by parsing builtin functions as tokens rather than
   `@` as a separate token. This is how stage2 does it.
 * Remove some debugging infrastructure. These will need to be redone,
   if at all, as the code migrates to match stage2.
   - remove the ast_render code.
   - remove the IR debugging stuff
   - remove teh token printing code
2021-05-28 12:58:40 -07:00
Andrew Kelley
79dee75b1c stage2: rename ir.zig to air.zig
We've settled on the nomenclature for the artifacts the compiler
pipeline produces:

1. Tokens
2. AST (Abstract Syntax Tree)
3. ZIR (Zig Intermediate Representation)
4. AIR (Analyzed Intermediate Representation)
5. Machine Code

Renaming `ir` identifiers to `air` will come with the inevitable
air-memory-layout branch that I plan to start after the 0.8.0 release.
2021-05-22 14:29:16 -07:00
Jakub Konka
7b74de7d71 wasi,cc: fix naming and add stubs for building
Rename include dir to match the convention:
  from `wasm32-wasi` to `wasm-wasi-musl`

Add building stubs which will be used to build and cache WASI
libc sysroot.
2021-05-20 16:54:00 +02:00
Andrew Kelley
a9cd9b021b Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
I want the updated Drone CI stuff to get the CI green.
2021-05-18 12:37:03 -07:00
Jakub Konka
138cecc028 zld: add prelim way of linking dylibs
The support is minimalistic in the sense that we only support actual
dylib files and not stubs/tbds yet, and we also don't support re-exports
just yet.
2021-05-18 09:28:00 +02:00
Andrew Kelley
9a95478c62 cmake: remove deleted file
This should have been part of 07606d12da
2021-05-15 21:46:36 -07:00
Andrew Kelley
f37451a63a stage2: fix zir.zig => Zir.zig in CMakeLists.txt 2021-04-15 19:12:05 -07:00
Jakub Konka
1119970d22 zld: add x86_64 relocs 2021-04-13 10:56:03 +02:00
Jakub Konka
6a866f1a96 zld: preprocess relocs on arm64 2021-04-13 10:56:03 +02:00
Jakub Konka
988b184d03 zld: redo symbol resolution in objects
Store only globals and undefs at the linker level, while all locals
stay scoped to the actual object file they were defined in. This is
fine since the relocations referencing locals will always be resolved
first using the local symbol table before checking for the reference
within the linker's global symbol table.

This also paves the way for proper symbol resolution from within static
and dynamic libraries.
2021-04-13 10:56:03 +02:00
Andrew Kelley
281a7baaea Merge remote-tracking branch 'origin/master' into zir-memory-layout
Wanted to make sure those new test cases still pass.

Also grab that CI fix so we can get those green check marks.
2021-03-28 19:42:43 -07:00
Isaac Freund
402f87a213
stage2: rename WipZirCode => AstGen, astgen.zig => AstGen.zig 2021-03-28 19:10:10 +02:00
Jakub Konka
ba8ac46e1f stage1: add cmake flag for enabling logging
Now that we ship our own linker for MachO by default in both stage1
and stage2, we need a way to enable logs for verbose debugging.
This commit adds `ZIG_ENABLE_LOGGING` cmake option which is equivalent
to stage2's `-Dlog` flag.

To enable it when building stage1 with cmake, add:

```
cmake .. -DZIG_ENABLE_LOGGING=on
```
2021-03-21 18:03:55 -07:00
Michael Dusan
e35f325dd1 azure: produce macos arm64 binaries
new pipeline `BuildMacOS_arm64`
  - `vmImage: 'macOS-10.15' `

new `macos_arm64_script`
  - switch from using `make` to `ninja`
  - select xcode 12.4
  - set zig-cache env variables
  - build host-zig binary with xcode, link against llvm for x86_64 (target macos 10.15)
  - build arm64-zig binary with xcode and host-zig, link against llvm for arm64 (target macos 11.0)
  - ad-hoc codesign arm64 binary with linker
  - use host-zig for docgen
  - use host-zig for experimental std lib docs
  - sync final `release/` hierarchy with `linux_script`
  - use gnu-tar for good-practices (set owner, set sort)

enhance `CMakeLists.txt`
  - do not build `zig0` when cross-compiling
  - disable `BYPRODUCTS` directive `zig1.o` to avoid `ninja` error

see #8265
2021-03-20 22:50:51 +01:00
Andrew Kelley
f5aca4a6a1 Merge remote-tracking branch 'origin/master' into zir-memory-layout
I need the enum arrays that were just merged into master.
2021-03-18 15:52:12 -07:00
Jakub Konka
7516dfff83 zld: use zld when linking aarch64 by default and cross-comp 2021-03-18 00:37:13 +01:00
Andrew Kelley
099af0e008 stage2: rename zir_sema.zig to Sema.zig 2021-03-16 00:04:17 -07:00
Andrew Kelley
4e9894cfc4 cmake build: allow overriding whether to use llvm-config
Previously, there was an option ZIG_PREFER_LLVM_CONFIG which would
override the default of not using llvm-config when cross compiling.

That option is now removed in favor of the more powerful
ZIG_USE_LLVM_CONFIG which defaults to OFF for cross compiling and ON for
native compilation. The option overrides the default.

This will be used in zig-bootstrap to improve support for native builds.
2021-03-13 14:30:56 -07:00
daurnimator
1f861ecc95 Bring back ZIG_SKIP_INSTALL_LIB_FILES 2021-03-01 16:23:10 -08:00
Andrew Kelley
38441b5eab MultiArrayList: use @memcpy as a workaround
Reverts bf642204b3 and uses a different
workaround, suggested by @LemonBoy.

There is either a compiler bug or a design flaw somewhere around here.
It does not have to block this branch, but I need to understand exactly
what's going on here and make it so that nobody ever has to run into
this problem again.
2021-02-24 12:49:12 -07:00
Andrew Kelley
f041425e48 translate-c: fix using wrong slice and AST tag 2021-02-23 13:55:12 -07:00
Veikka Tuominen
d672c20b8a
Merge pull request #7479 from ziglang/translate-c-ast
Make translate-c use intermediate AST
2021-02-19 13:03:29 +02:00
Isaac Freund
070e548acf
std: remove io.AutoIndentingStream
This type is not widely applicable enough to be a public part of the
public interface of the std.

The current implementation in only fully utilized by the zig fmt
implementation, which could benefit by even tighter integration as
will be demonstrated in the next commit. Therefore, move the current
io.AutoIndentingStream to lib/std/zig/render.zig.

The C backend of the self hosted compiler also use this type currently,
but it does not require anywhere near its full complexity. Therefore,
implement a greatly simplified version of this interface in
src/codegen/c.zig.
2021-02-16 23:20:46 +01:00
Veikka Tuominen
13a9db2085
translate-c: begin implementing ast.render 2021-02-16 16:40:06 +02:00
Andrew Kelley
a9667b5a85 organize std lib concurrency primitives and add RwLock
* move concurrency primitives that always operate on kernel threads to
   the std.Thread namespace
 * remove std.SpinLock. Nobody should use this in a non-freestanding
   environment; the other primitives are always preferable. In
   freestanding, it will be necessary to put custom spin logic in there,
   so there are no use cases for a std lib version.
 * move some std lib files to the top level fields convention
 * add std.Thread.spinLoopHint
 * add std.Thread.Condition
 * add std.Thread.Semaphore
 * new implementation of std.Thread.Mutex for Windows and non-pthreads Linux
 * add std.Thread.RwLock

Implementations provided by @kprotty
2021-01-14 20:41:37 -07:00
Andrew Kelley
d68adc5382 std.EarlyEOFReader: rename to LimitedReader 2021-01-11 16:51:56 -07:00
daurnimator
e873668d38 std: add LimitedReader: reader that returns EOF early 2021-01-11 16:48:30 -07:00
Jay Petacat
e72472d953 io: FindByteOutStream to FindByteWriter
See #4917
2021-01-08 16:54:56 -05:00
Andrew Kelley
2f58efcc1f std.SpinLock: flatten and remove init/deinit
structs which are intended to be directly initialized and support static
initialization should not have init/deinit methods.
2021-01-06 17:36:06 -07:00
Andrew Kelley
76870a2265
Merge pull request #7700 from FireFox317/more-stage2-stuff-llvm
stage2: improvements to LLVM backend
2021-01-06 16:06:32 -08:00
Timon Kruiper
b1cfa923be stage2: rename and move files related to LLVM backend 2021-01-06 10:52:20 +01:00
Andrew Kelley
3e39d0c44f minor fixups from moving identifiers and files around 2021-01-05 17:41:22 -07:00
Andrew Kelley
2fe8a48215 ci: omit stage2 backend from stage1 on Windows
to avoid out-of-memory on the CI runs.
2021-01-04 14:59:18 -07: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 d96d8639e5.
This reverts commit e8810f5794.
This reverts commit 9afe5859a3.
2021-01-01 21:02:32 -07:00
Andrew Kelley
d96d8639e5 Revert "Comply with semantic versioning pre-release format"
This reverts commit bbe2cca1ae.
2020-12-31 16:41:42 -07:00
Andrew Kelley
e8810f5794 Revert "stage2: SemVer compliance for development builds"
This reverts commit 4af763d401.
2020-12-31 16:41:35 -07:00
Andrew Kelley
9afe5859a3 Revert "Remove 'g' prefix from commit hash in Zig semver"
This reverts commit 02438aabe3.
2020-12-31 16:41:24 -07:00
Jay Petacat
02438aabe3 Remove 'g' prefix from commit hash in Zig semver 2020-12-30 20:57:50 -06:00
Jay Petacat
4af763d401 stage2: SemVer compliance for development builds
This matches the behavior of CMake builds. These changes should have
been in PR #6509, but were missed.
2020-12-29 23:25:58 -06:00
Jay Petacat
bbe2cca1ae Comply with semantic versioning pre-release format
Example version: 0.8.0-dev.460+g81b343a16

From a semantic versioning perspective, development builds will now be
considered distinct from a tagged release. The number of commits added
since the last tag is included in the pre-release component.

Updates #6466
2020-12-29 13:17:08 -08:00
Timon Kruiper
071417161d stage2: add initial impl of LLVM backend in self-hosted compiler 2020-12-28 21:19:40 +01:00
Timon Kruiper
4a0d64300b stage2: rename llvm.zig to llvm_bindings.zig
Putting functions in this file will create functions like
`llvm.function`, and the compiler thinks these are llvm intrinsics.
2020-12-28 21:15:13 +01:00
Andrew Kelley
42b4a48bc9 WIP start adding support for TSAN 2020-12-24 01:18:47 -07:00
Andrew Kelley
177377b6e3 rework std.ResetEvent, improve std lib Darwin integration
* split std.ResetEvent into:
   - ResetEvent - requires init() at runtime and it can fail. Also
     requires deinit().
   - StaticResetEvent - can be statically initialized and requires no
     deinitialization. Initialization cannot fail.
 * the POSIX sem_t implementation can in fact fail on initialization
   because it is allowed to be implemented as a file descriptor.
 * Completely define, clarify, and explain in detail the semantics of
   these APIs. Remove the `isSet` function.
 * `ResetEvent.timedWait` returns an enum instead of a possible error.
 * `ResetEvent.init` takes a pointer to the ResetEvent instead of
   returning a copy.
 * On Darwin, `ResetEvent` is implemented using Grand Central Dispatch,
   which is exposed by libSystem.

stage2 changes:
 * ThreadPool: use a single, pre-initialized `ResetEvent` per worker.
 * WaitGroup: now requires init() and deinit() and init() can fail.
   - Add a `reset` function.
   - Compilation initializes one for the work queue in creation and
     re-uses it for every update.
   - Rename `stop` to `finish`.
   - Simplify the implementation based on the usage pattern.
2020-12-23 16:57:18 -08:00
Andrew Kelley
829c00a77f kprotty ThreadPool and WaitGroup patch 2020-12-23 13:36:21 -08:00
tgschultz
ab6183e119 Added std.io.counting_reader 2020-12-23 01:27:12 +02:00
Andrew Kelley
1d94a68936 add an option to compile zig in single-threaded mode
And enable it for Drone CI. I hate to do this, but I need to make
progress on other fronts.
2020-12-20 15:37:58 -07:00
Andrew Kelley
aa6ef10cc6 std.Progress: make the API thread-safe
We generally get away with atomic primitives, however a lock is required
around the refresh function since it traverses the Node graph, and we
need to be sure no references to Nodes remain after end() is called.
2020-12-20 15:08:59 -07:00
Andrew Kelley
481ce7361e bump version to 0.7.0 => 0.7.1
The official tag is in the 0.7.x branch.
2020-12-13 12:53:31 -07:00
Andrew Kelley
88dc688bbf restore the option to build with cmake
restore cmake to be capable of figuring out the zig version

restore config.h and config.zig. config.h is used to detect whether we
should propagate cmake configuration information to build.zig; however
it can be overridden with -Dstatic-llvm.

fix not passing -DZIG_LINK_MODE with zig build.

when using the cmake build path, build.zig no longer tries to call
llvm-config. Instead it relies 100% on the LLVM_LIBRARIES cmake variable.

build.zig logic reworked and simplified.
2020-12-07 17:27:09 -07:00
Andrew Kelley
5a65caa2a3 ability to build stage1 using only a zig tarball
The main idea here is that there are now 2 ways to get a stage1 zig
binary:

 * The cmake path. Requirements: cmake, system C++ compiler, system
   LLVM, LLD, Clang libraries, compiled by the system C++ compiler.

 * The zig path. Requirements: a zig installation, system LLVM, LLD,
   Clang libraries, compiled by the zig installation.

Note that the former can be used to now take the latter path.

Removed config.h.in and config.zig.in. The build.zig script no longer is
coupled to the cmake script.

cmake no longer tries to determine the zig version. A build with cmake
will yield a stage1 zig binary that reports 0.0.0+zig0. This is going to
get reverted.

`zig build` now accepts `-Dstage1` which will build the stage1 compiler,
and put the stage2 backend behind a feature flag.

build.zig is simplified to only support the use case of enabling LLVM
support when the LLVM, LLD, and Clang libraries were built by zig. This
part is probably sadly going to have to get reverted to make package
maintainers happy.

Zig build system addBuildOption supports a couple new types.

The biggest reason to make this change is that the zig path is an
attractive option for doing compiler development work on Windows. It
allows people to work on the compiler without having MSVC installed,
using only a .zip file that contains Zig + LLVM/LLD/Clang libraries.
2020-12-07 17:27:09 -07:00
Jonathan Marler
a1fb10b766 fix for GCC 9.2: -Wno-maybe-uninitialized 2020-11-23 17:55:48 -08:00
Frank Denis
70c8cabb34 Update the minimum cmake version we require
Recent versions of cmake complain about it:

<<
  CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.
>>

We don't require anything from version 2.8.5, and version 2.8.12 was
released in 2011, so it is very unlikely that anyone still uses 2.8.5.
2020-11-23 12:44:54 -08:00
daurnimator
767dd772c0
std: add std.atomic.Bool 2020-11-19 00:58:13 +11:00
Andrew Kelley
3348cb915f cmake: add the correct set of zig stage2 sources 2020-11-16 17:57:22 -07:00
johnLate
77d67aa662 CMake: try to avoid compilation for install target
This is andrewrk's patch from ziglang#6724 (rebased)

CMake: Fix dependency problem

I don't know whether the error was expected cmake behavior or a bug.
This change seems to fix the issue. See ziglang#6724 for details.
2020-11-16 17:45:13 -07:00
Andrew Kelley
0c90ccc297 Release 0.7.0 2020-11-08 12:02:09 -07:00
Andrew Kelley
a0f4606f32 ci: still build zig even though we are using (older) zig cc 2020-10-26 10:50:43 -07:00
Andrew Kelley
540364e6c1 ci: macos: update to new cache tarball
This tarball contains LLVM, Clang, LLD, Zig, and libz.a for macOS. This
is everything we need for the CI to produce a working Zig executable.
2020-10-14 17:36:43 -07:00
Andrew Kelley
ea45ee5484 cmake: remove all the LLVM 10 workarounds 2020-10-12 22:35:06 -07:00
Andrew Kelley
b5a36f676b Merge remote-tracking branch 'origin/master' into llvm11
Conflicts:
  cmake/Findllvm.cmake

The llvm11 branch changed 10's to 11's and master branch added the
"using LLVM_CONFIG_EXE" help message, so the resolution was to merge
these changes together.

I also added a check to make sure LLVM is built with AVR enabled, which
is no longer an experimental target.
2020-10-07 00:46:05 -07:00
Timon Kruiper
75db8d9e2c Fix cross-compiling the zig compiler
zig0 is only used for building objects, thus it has no options like
`build-exe/obj`. But when cross-compiling, we have a working zig
compiler on the host, thus we need to pass `build-obj` to the zig compiler.
2020-10-05 22:18:42 -04:00
Jan200101
d0a4110d34 Allow specifying build version using cmake 2020-10-04 21:40:48 -04:00
Andrew Kelley
2de53592a1 stage1: better value for builtin.link_mode
Now it is Dynamic unless -DZIG_STATIC=on is passed to cmake.

This partially addresses #6469.
2020-10-03 23:15:45 -07:00
John Sullivan
ab7ea53541 cmake: add option to use llvm-config to find cross-target llvm deps 2020-10-04 00:41:32 -04:00
Tadeo Kondrak
26546af1b8 Revert "Include dbg.h to third-party libs"
This reverts commit c8b4cc2ff9.

This includes many C++ standard library headers:

  #include <algorithm>
  #include <chrono>
  #include <ctime>
  #include <iomanip>
  #include <ios>
  #include <iostream>
  #include <memory>
  #include <sstream>
  #include <string>
  #include <tuple>
  #include <type_traits>
  #include <vector>

which adds more than a second of compile time for each file that
includes the header:

  ir.cpp before: 8.041s
  ir.cpp after: 6.847s
2020-10-03 21:29:29 -04:00
Andrew Kelley
7067764ed3 Merge remote-tracking branch 'origin/master' into llvm11
The changes to install_files.h needed to put into src/libcxx.zig
2020-09-30 02:55:41 -07:00
Andrew Kelley
750b00c642 Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-29 00:27:48 -07:00
Andrew Kelley
6af2990549 implement -femit-asm, -femit-docs, -femit-llvm-ir, etc
These CLI options are now forwarded to the stage1 backend.

We're not going to support the -mllvm CLI option any longer. As a
compromise, we unconditionally tell LLVM to output intel x86 syntax when
using -femit-asm.

Simplify stage1 logic; it no longer has the concept of an output
directory. --output-dir is no longer a valid CLI option. cmake uses
the `-femit-bin=[path]` option.

Note the changes to test/cli.zig. This breaks the CLI API that Godbolt
is using so we're going to want to open a PR to help them upgrade to the
new CLI for the upcoming Zig 0.7.0 release.
2020-09-26 01:47:27 -07:00
Andrew Kelley
800a4a6ceb eliminate dependency of libzigcpp.a on libzigstage1.a
This allows us to create a build of self-hosted with LLVM extensions
enabled but without the stage1 backend.
2020-09-23 00:00:24 -07:00
Andrew Kelley
528832bd3a rename src-self-hosted/ to src/ 2020-09-21 18:38:55 -07:00
Andrew Kelley
bd1465a3fe cmake: output better message when building self-hosted
Thanks @bfredl!
2020-09-21 16:32:56 -07:00
Andrew Kelley
2ef68631cb stage2 now supports using stage1 as a backend for compiling zig code
* move stage2.cpp code into zig0.cpp for simplicity
 * add -ftime-report and some more CLI options to stage2
 * stage2 compites the llvm cpu features string
 * classifyFileExt understands more file extensions
 * correction to generateBuiltinZigSource using the wrong allocator
   (thanks dbandstra!)
 * stage2 is now able to build hello.zig into hello.o using stage1 as a
   library however it fails linking due to missing compiler-rt
 * remove dead code
 * simplify zig0 builtin.zig source
 * fix not resolving builtin.zig source path causing duplicate imports
 * fix stage1.h not being valid C code
 * fix stage2.h not being valid C code
2020-09-18 22:48:28 -07:00
Calle Englund
d08842887f
Workaround MacOS build failure due to #6087 2020-09-18 17:03:50 +02:00
Andrew Kelley
dc79651e6a stage2: add CLI for zig translate-c 2020-09-18 01:33:32 -07:00
Andrew Kelley
dc478687d9 delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
 * an implementation of blake hashing
 * the cache hash system
 * compiler.cpp
 * all the linking code, and everything having to do with building
   glibc, musl, and mingw-w64
 * much of the stage1 compiler internals got slimmed down since it
   now assumes it is always outputting an object file.

More stuff:
 * stage1 is now built with a different strategy: we have a tiny
   zig0.cpp which is a slimmed down version of what stage1 main.cpp used
   to be. Its only purpose is to build stage2 zig code into an object
   file, which is then linked by the host build system (cmake) into
   stage1. zig0.cpp uses the same C API that stage2 now has access to,
   so that stage2 zig code can call into stage1 c++ code.
   - stage1.h is
   - stage2.h is
   - stage1.zig is the main entry point for the Zig/C++
     hybrid compiler. It has the functions exported from Zig, called
     in C++, and bindings for the functions exported from C++, called
     from Zig.
 * removed the memory profiling instrumentation from stage1.
   Abandon ship!
 * Re-added the sections to the README about how to build stage2 and
   stage3.
 * stage2 now knows as a comptime boolean whether it is being compiled
   as part of stage1 or as stage2.
   - TODO use this flag to call into stage1 for compiling zig code.
 * introduce -fdll-export-fns and -fno-dll-export-fns and clarify
   its relationship to link_mode (static/dynamic)
 * implement depending on LLVM to detect native target cpu features when
   LLVM extensions are enabled and zig lacks CPU feature detection for
   that target architecture.
 * C importing is broken, will need some stage2 support to function
   again.
2020-09-17 18:29:38 -07:00
Andrew Kelley
1de2c647df Merge remote-tracking branch 'origin/master' into llvm11 2020-08-18 15:32:42 -07:00
Andrew Kelley
502d413621 simplify zig info and rename it to zig env
also add version to it
2020-08-17 17:06:43 -07:00
Andrew Kelley
bd121f3af4 update clang drivers from llvm 10 to 11 2020-07-24 17:01:52 -07:00
Andrew Kelley
f281b928d9 cmake: add -DZIG_WORKAROUND_POLLY_SO
to work around #4799 until a newer llvm version is released.
2020-07-03 04:48:48 +00:00
Timothee Cour
9a7f05378f fix https://github.com/ziglang/zig/issues/4799 2020-07-03 04:40:25 +00:00
antlilja
1157ee1307 Improve builtin op support for f128/comptime_float
* Add support for fabs, floor, ceil, trunc and round
* Add behavior tests
2020-06-17 17:35:45 +02:00
data-man
b6e1670d2b Use ccache (optionally) 2020-05-26 16:04:40 -04:00
Ryan Liptak
a80ad0782d CMake: Make fallthrough support version check specific to GCC 2020-05-18 18:19:00 -04:00
Noam Preil
03ed9e4173 Fix compilation with GCC 5 2020-05-17 12:18:53 -04:00
data-man
c8b4cc2ff9 Include dbg.h to third-party libs 2020-05-02 18:29:02 -04:00
Andrew Kelley
cf750a58d5 Release 0.6.0 2020-04-13 13:36:30 -04:00
emekoi
de08d283da fix compilation under mingw 2020-04-11 15:18:54 -05:00
Andrew Kelley
e857190dab put the previous commit behind cmake option ZIG_PREFER_CLANG_CPP_DYLIB
Without this, building from source caused:

CommandLine Error: Option 'mc-relax-all' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options

This is due to LLVM static libs compiled in multiple times. But without
the LLVM static libs on the linker line, it caused undefined symbol
linker errors.

So our hands are tied. Homebrew users will have to specify
`-DZIG_PREFER_CLANG_CPP_DYLIB`.
2020-04-10 01:25:15 -04:00
Andrew Kelley
d5087ccbc8
cmake: expose ZIG_TARGET_MCPU option 2020-04-08 17:41:51 -04:00
Andrew Kelley
15ab61b2a0
cmake: improvements to cross-compiling for Windows
* don't unconditionally pass -lz3 for mingw builds. If mingw builds
   require this then the llvm-config executable should put it as part of
   --system-libs. If there is a bug and it does not do that, and we need
   a workaround, then the workaround should be an explicit cmake option.
 * don't link libstage2.a against -lntdll. This causes zig to set
   `builtin.link_mode == .Dynamic` and include the TLS definitions,
   which then collide with the mingw-w64 symbols. This should probably
   be addressed separately, but for now this solves the problem and
   there is no reason to link a static library against a DLL.
 * Findllvm.cmake no longer treats the libraries as "optional" and will
   emit a cmake error if one is not found. Additionally, the
   not-required LLVM library LLVMTableGen is omitted.
2020-04-06 18:38:09 -04:00
Andrew Kelley
96ed544665
build.zig supports specifying config.h location explicitly
also it does not try to run llvm-config executable when -Dlib-files-only

This fixes cross-compiling using the bootstrap repository.
2020-04-06 13:07:19 -04:00
Michael Dusan
212e2354b8 stage1: make C++ switch fallthrough an error
Make fallthrough an error when compiler supports it. This requires a new
macro that is defined with such compilers to be used as a statement, at
all fallthrough sites:

    switch (...) {
        case 0:
            ...
            ZIG_FALLTHROUGH;
        case 1:
            ...
            break;
        default:
            ...
            break;
    }

If we ever move to C++17 as minimal requirement, then the macro can be
replaced with `[[fallthrough]];` at statement sites.
2020-04-01 15:56:00 -04:00
Bodie Solomon
9bb76f8ce0 Use correct compiler flags in MSVC bootstrap builds of Zig
https://github.com/ziglang/zig/issues/4877

The CMake build of Zig from C++ uses hand-set compiler flags which are
not compatible with the Microsoft C/C++ Optimizing Compiler (cl.exe)
used by Visual Studio.

This commit attempts to conform them to match the Clang/GCC options
under MSVC builds.

Note that CL does not have a concept of C99 or "-O3", and may imply
other optimizations in "/O2" than are implied by Clang/GCC "-O3".

Visual Studio 2019 documentation for cl.exe's optimization options:
https://docs.microsoft.com/en-us/cpp/build/reference/o-options-optimize-code?view=vs-2019

Visual Studio 2019 doc for cl.exe's C++ standard options:
https://docs.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=vs-2019
2020-03-31 14:23:34 -04:00
Andrew Kelley
69aa09948b
cmake: support cross compiling 2020-03-27 23:43:21 -04:00
Andrew Kelley
23c263776c
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-22 15:09:29 -04:00
Andrew Kelley
3a2c490889 "generate .h files" feature is no longer supported in stage1 2020-03-20 18:33:36 -04:00
Andrew Kelley
f33bf48af7
Merge remote-tracking branch 'origin/master' into llvm10 2020-02-25 16:30:40 -05:00
Andrew Kelley
e381a42de9
quick fix: add -mcpu=baseline support to zig0
When the build.zig logic to build libzigstage2 was converted to a cmake
command, it neglected to use baseline CPU features rather than compiling
with native features.

This adds a hard coded flag `-mcpu=baseline` which can be used to detect
the native target, but mark it as non-native so that it does not get the
CPU features specific to the host used to compile libzigstage2.

Full `-mcpu` support is happening in the upcoming pull request #4509,
and so this "quick fix" will be cleaned up in that branch, before it is
merged to master.

closes #4506
2020-02-20 17:02:29 -05:00
Andrew Kelley
a26800c099
stage1: don't copy unchanged output files
when both `--cache on` and `--output-dir` parameters
are provided. This prevents re-linking `zig` with every
`make` even when `libzigstage2.a` was unchanged.
2020-02-16 21:10:03 -05:00
Andrew Kelley
20f3b0efff rename libuserland to libstage2 2020-02-16 19:16:08 -05:00
Andrew Kelley
c25742010d add the dummy libc paths back in 2020-02-16 19:02:26 -05:00
Andrew Kelley
7eb0a3edce
remove libc dependency of zig0 building libstage2
Rather than `zig0 build ...` the build now does
`zig0 build-lib ...`, avoiding the requirement of linking the build
script, and thus avoiding the requirement of finding native libc,
for systems where libc is the system ABI.
2020-02-16 18:57:34 -05:00
Andrew Kelley
4b02a39aa9
self-hosted libc detection
* libc_installation.cpp is deleted.
   src-self-hosted/libc_installation.zig is now used for both stage1 and
   stage2 compilers.
 * (breaking) move `std.fs.File.access` to `std.fs.Dir.access`. The API
   now encourages use with an open directory handle.
 * Add `std.os.faccessat` and related functions.
 * Deprecate the "C" suffix naming convention for null-terminated
   parameters. "C" should be used when it is related to libc. However
   null-terminated parameters often have to do with the native system
   ABI rather than libc. "Z" suffix is the new convention. For example,
   `std.os.openC` is deprecated in favor of `std.os.openZ`.
 * Add `std.mem.dupeZ` for using an allocator to copy memory and add a
   null terminator.
 * Remove dead struct field `std.ChildProcess.llnode`.
 * Introduce `std.event.Batch`. This API allows expressing concurrency
   without forcing code to be async. It requires no Allocator and does
   not introduce any failure conditions. However it is not thread-safe.
 * There is now an ongoing experiment to transition away from
   `std.event.Group` in favor of `std.event.Batch`.
 * `std.os.execvpeC` calls `getenvZ` rather than `getenv`. This is
   slightly more efficient on most systems, and works around a
   limitation of `getenv` lack of integration with libc.
 * (breaking) `std.os.AccessError` gains `FileBusy`, `SymLinkLoop`, and
   `ReadOnlyFileSystem`. Previously these error codes were all reported
   as `PermissionDenied`.
 * Add `std.Target.isDragonFlyBSD`.
 * stage2: access to the windows_sdk functions is done with a manually
   maintained .zig binding file instead of `@cImport`.
 * Update src-self-hosted/libc_installation.zig with all the
   improvements that stage1 has seen to src/libc_installation.cpp until
   now. In addition, it now takes advantage of Batch so that evented I/O
   mode takes advantage of concurrency, but it still works in blocking
   I/O mode, which is how it is used in stage1.
2020-02-16 13:25:30 -05:00
Andrew Kelley
a8b36fbe34
Merge remote-tracking branch 'origin/master' into llvm10 2020-02-14 10:27:44 -05:00
Andrew Kelley
fb6b94f80f
cmake: remove case mismatch detection on build mode
See discussion here for context:
c6df5deb34 (comments)

Michael - I appreciate what you did here, making the configure script
work better for people in practice. When it was checking the build type
against a whitelist, I think it was worth it. However, now that we are
supporting systems which use non-standard cmake build modes, I don't
think this case-mismatch detection thing is worth it. It's starting to
get to the point where it's a lot of complication for very little
benefit. Besides, cmake is not case sensitive. If we support
non-standard build modes, then we would need to support a hypothetical
build mode of `release` (lower case).

So let's just remove this and rely on people to use the build system
correctly (like they will have to do when building any cmake project
from source).
2020-02-13 20:47:44 -05:00
Michael Dusan
471662f7c9
stage1: limit cmake checks on build type
Various maintainers pass custom build types and we don't need to check
those. We are interested only in checking and diagnosing common errors
for Zig project supported types.

Check is now limited to look for case-mismatch only on the well-known
values { Debug, Release, RelWithDebInfo, MinSizeRel }.
2020-02-12 17:23:48 -05:00
Michael Dusan
edb210905d
stage1: memory/report overhaul
- split util_base.hpp from util.hpp
- new namespaces: `mem` and `heap`
- new `mem::Allocator` interface
- new `heap::CAllocator` impl with global `heap::c_allocator`
- new `heap::ArenaAllocator` impl
- new `mem::TypeInfo` extracts names without RTTI
- name extraction is enabled w/ ZIG_ENABLE_MEM_PROFILE=1
- new `mem::List` takes explicit `Allocator&` parameter
- new `mem::HashMap` takes explicit `Allocator&` parameter
- add Codegen.pass1_arena and use for all `ZigValue` allocs
- deinit Codegen.pass1_arena early in `zig_llvm_emit_output()`
2020-02-10 21:08:08 -05:00
Andrew Kelley
cdc5070f21
Merge remote-tracking branch 'origin/master' into llvm10 2020-02-10 00:26:33 -05:00
Michael Dusan
d0a9da74ef
stage1: fix cmake regression
- add `None` as a valid CMAKE_BUILD_TYPE
- this is a legitimate setting used by packagers

regression was caused by c6df5deb34
2020-02-05 08:24:50 -05:00
Michael Dusan
c6df5deb34
stage1: guard against case-mismatched build types
- zig CMakeLists.txt CMAKE_BUILD_TYPE string comparisons are case-sensitive
- cmake itself is unclear about how tolerant it is for case-mismatches
- add CMAKE_BUILD_TYPE guard in CMakeLists.txt to force exact matches
2020-02-04 20:39:05 -05:00
Andrew Kelley
a9df637fb1
fix undef clang library symbols when linking self-hosted 2020-02-04 03:39:40 -05:00
Andrew Kelley
97b2ac598b
Merge remote-tracking branch 'origin/master' into llvm10 2020-01-22 12:12:36 -05:00
Michael Dusan
b9f4ac86ef
cmake: support make and make install
(2nd attempt to get this right)
2020-01-17 19:39:43 -05:00
Michael Dusan
d53e8a5751 Revert "cmake: support make and make install"
This reverts commit cd062b08d0.
2020-01-17 14:24:54 -05:00
Michael Dusan
97cca1376a
cmake: fix install lib path message 2020-01-17 00:53:41 -05:00
Michael Dusan
cd062b08d0
cmake: support make and make install
- `make` or `ninja` will not build but not install
- `make install` or `ninja install` will build __and__ install

Only for build system generator Visual Studio, specify the following
to disable installation of lib files:

    ZIG_SKIP_INSTALL_LIB_FILES=ON
2020-01-16 18:56:13 -05:00
Andrew Kelley
ba4cc03b4f
remove embedded LLD
we no longer have any patches against upstream LLD
2020-01-16 13:09:45 -05:00
Andrew Kelley
fbe6af81fd
Merge remote-tracking branch 'origin/master' into llvm10 2020-01-16 13:01:36 -05:00
Vexu
fceda07f94
use self hosted translate-c for cimports 2019-12-29 11:04:45 +02:00
Michael Dusan
fe254ea309 stage1: avoid building empty memory_profiling.cpp
During build an empty .o on macOS/Xcode emits warning:

    ranlib: file: zig_cpp/libcompiler.a(memory_profiling.cpp.o) has no symbols
    ranlib: file: zig_cpp/libcompiler.a(memory_profiling.cpp.o) has no symbols
2019-11-25 19:08:36 -05:00
emekoi
cb8dacabd8 explicity linked ntdll on mingw-w64 2019-10-22 20:42:51 -04:00
Andrew Kelley
87f632b08a fs.Dir.openDir: use empty object name for "." on Windows 2019-10-21 19:19:49 -04:00
Andrew Kelley
fa9f1d2396
add -DZIG_ENABLE_MEM_PROFILE option and -fmem-report flag
This can be used to find what's taking up memory in the compiler.
Here's an example of how to use it:

```
./zig test ../lib/std/std.zig --cache off -fmem-report
```

And here's the output I get for this on x86_64-linux-gnu today:

```
Const: 6462833 items, 152 bytes each, total 936.84 MiB
ConstGlobalRefs: 17236534 items, 24 bytes each, total 394.51 MiB
ResetResult: 1698108 items, 160 bytes each, total 259.11 MiB
ConstExprValue: 3118299 items, 80 bytes each, total 237.91 MiB
EndExpr: 1345395 items, 168 bytes each, total 215.56 MiB
Unknown_8: 27370821 items, 8 bytes each, total 208.82 MiB
VarPtr: 1127866 items, 168 bytes each, total 180.70 MiB
IrBasicBlock: 794834 items, 120 bytes each, total 90.96 MiB
LoadPtr: 554024 items, 160 bytes each, total 84.54 MiB
Unknown_64: 1245715 items, 64 bytes each, total 76.03 MiB
Unknown_40: 1879218 items, 40 bytes each, total 71.69 MiB
Unknown_72: 989117 items, 72 bytes each, total 67.92 MiB
Return: 423783 items, 160 bytes each, total 64.66 MiB
Unknown_168: 332480 items, 168 bytes each, total 53.27 MiB
Unknown_152: 336890 items, 152 bytes each, total 48.84 MiB
AddImplicitReturnType: 230819 items, 168 bytes each, total 36.98 MiB
Br: 217835 items, 168 bytes each, total 34.90 MiB
Unknown_184: 179529 items, 184 bytes each, total 31.50 MiB
FieldPtr: 179388 items, 184 bytes each, total 31.48 MiB
BinOp: 171004 items, 176 bytes each, total 28.70 MiB
LoadPtrGen: 173287 items, 168 bytes each, total 27.76 MiB
CondBr: 137864 items, 192 bytes each, total 25.24 MiB
Unknown_720: 30918 items, 720 bytes each, total 21.23 MiB
CallSrc: 99320 items, 216 bytes each, total 20.46 MiB
Unknown_160: 129243 items, 160 bytes each, total 19.72 MiB
Unknown_1: 19339456 items, 1 bytes each, total 18.44 MiB
CheckStatementIsVoid: 119838 items, 160 bytes each, total 18.29 MiB
Unknown_48: 371178 items, 48 bytes each, total 16.99 MiB
TestComptime: 101443 items, 160 bytes each, total 15.48 MiB
DeclVarSrc: 72578 items, 184 bytes each, total 12.74 MiB
StorePtr: 72776 items, 176 bytes each, total 12.22 MiB
ZigVar: 79201 items, 160 bytes each, total 12.09 MiB
Unknown_16: 770643 items, 16 bytes each, total 11.76 MiB
Phi: 60482 items, 184 bytes each, total 10.61 MiB
TestErrSrc: 66177 items, 168 bytes each, total 10.60 MiB
Unknown_240: 45164 items, 240 bytes each, total 10.34 MiB
ElemPtr: 58232 items, 184 bytes each, total 10.22 MiB
AllocaSrc: 60053 items, 176 bytes each, total 10.08 MiB
CallGen: 44873 items, 224 bytes each, total 9.59 MiB
SaveErrRetAddr: 63787 items, 152 bytes each, total 9.25 MiB
Unknown_112: 82283 items, 112 bytes each, total 8.79 MiB
AllocaGen: 51909 items, 176 bytes each, total 8.71 MiB
Unknown_24: 373599 items, 24 bytes each, total 8.55 MiB
ResultLocPeer: 113683 items, 72 bytes each, total 7.81 MiB
DeclRef: 36343 items, 168 bytes each, total 5.82 MiB
UnwrapErrPayload: 34603 items, 168 bytes each, total 5.54 MiB
Ref: 33414 items, 168 bytes each, total 5.35 MiB
Unknown_104: 53882 items, 104 bytes each, total 5.34 MiB
DeclVarGen: 32540 items, 168 bytes each, total 5.21 MiB
StructFieldPtr: 30449 items, 176 bytes each, total 5.11 MiB
UnwrapErrCode: 31508 items, 168 bytes each, total 5.05 MiB
Unknown_56: 90256 items, 56 bytes each, total 4.82 MiB
SpillBegin: 28722 items, 168 bytes each, total 4.60 MiB
SpillEnd: 28722 items, 160 bytes each, total 4.38 MiB
ResultLocReturn: 64573 items, 48 bytes each, total 2.96 MiB
PtrType: 14702 items, 184 bytes each, total 2.58 MiB
SliceType: 15005 items, 176 bytes each, total 2.52 MiB
Unknown_176: 13326 items, 176 bytes each, total 2.24 MiB
RefGen: 12881 items, 168 bytes each, total 2.06 MiB
UnOp: 12102 items, 176 bytes each, total 2.03 MiB
SwitchBr: 9453 items, 200 bytes each, total 1.80 MiB
TestErrGen: 11143 items, 160 bytes each, total 1.70 MiB
Unknown_32: 52359 items, 32 bytes each, total 1.60 MiB
CheckSwitchProngs: 9094 items, 184 bytes each, total 1.60 MiB
TypeOf: 9259 items, 160 bytes each, total 1.41 MiB
IntCast: 8772 items, 168 bytes each, total 1.41 MiB
OptionalUnwrapPtr: 8755 items, 168 bytes each, total 1.40 MiB
SwitchTarget: 9094 items, 160 bytes each, total 1.39 MiB
Cast: 8198 items, 176 bytes each, total 1.38 MiB
WidenOrShorten: 8448 items, 160 bytes each, total 1.29 MiB
ErrorUnion: 7613 items, 176 bytes each, total 1.28 MiB
SliceSrc: 6249 items, 192 bytes each, total 1.14 MiB
ErrWrapCode: 7133 items, 168 bytes each, total 1.14 MiB
TypeName: 7328 items, 160 bytes each, total 1.12 MiB
ImplicitCast: 5480 items, 176 bytes each, total 941.88 KiB
ResolveResult: 5638 items, 168 bytes each, total 924.98 KiB
ResultLocInstruction: 22696 items, 40 bytes each, total 886.56 KiB
BitCastSrc: 4947 items, 168 bytes each, total 811.62 KiB
CompileErr: 5148 items, 160 bytes each, total 804.38 KiB
ReturnPtr: 5305 items, 152 bytes each, total 787.46 KiB
Unreachable: 5038 items, 152 bytes each, total 747.83 KiB
TestNonNull: 4716 items, 160 bytes each, total 736.88 KiB
BitCastGen: 4431 items, 160 bytes each, total 692.34 KiB
PtrToInt: 4289 items, 160 bytes each, total 670.16 KiB
SliceGen: 3573 items, 192 bytes each, total 669.94 KiB
ArrayType: 4081 items, 168 bytes each, total 669.54 KiB
IntType: 3868 items, 168 bytes each, total 634.59 KiB
Unknown_88: 7213 items, 88 bytes each, total 619.87 KiB
Truncate: 3771 items, 168 bytes each, total 618.68 KiB
TypeInfo: 3740 items, 160 bytes each, total 584.38 KiB
SwitchVar: 3385 items, 176 bytes each, total 581.80 KiB
ContainerInitFields: 3223 items, 184 bytes each, total 579.13 KiB
ContainerInitList: 2309 items, 192 bytes each, total 432.94 KiB
PtrCastGen: 2626 items, 168 bytes each, total 430.83 KiB
BoolNot: 2457 items, 160 bytes each, total 383.91 KiB
FnProto: 2054 items, 184 bytes each, total 369.08 KiB
MergeErrSets: 1927 items, 176 bytes each, total 331.20 KiB
Unknown_136: 2486 items, 136 bytes each, total 330.17 KiB
Unknown_80: 4059 items, 80 bytes each, total 317.11 KiB
Bswap: 1670 items, 168 bytes each, total 273.98 KiB
TypeId: 1680 items, 160 bytes each, total 262.50 KiB
PtrCastSrc: 1371 items, 176 bytes each, total 235.64 KiB
ErrName: 1193 items, 160 bytes each, total 186.41 KiB
UnionTag: 1120 items, 160 bytes each, total 175.00 KiB
TagName: 1050 items, 160 bytes each, total 164.06 KiB
SizeOf: 942 items, 160 bytes each, total 147.19 KiB
MemberName: 871 items, 168 bytes each, total 142.90 KiB
Import: 881 items, 160 bytes each, total 137.66 KiB
PtrOfArrayToSlice: 758 items, 168 bytes each, total 124.36 KiB
UnionFieldPtr: 710 items, 176 bytes each, total 122.03 KiB
EnumToInt: 778 items, 160 bytes each, total 121.56 KiB
CheckRuntimeScope: 700 items, 168 bytes each, total 114.84 KiB
FieldParentPtr: 632 items, 184 bytes each, total 113.56 KiB
BoolToInt: 719 items, 160 bytes each, total 112.34 KiB
ResultLocPeerParent: 904 items, 104 bytes each, total 91.81 KiB
IntToPtr: 537 items, 168 bytes each, total 88.10 KiB
AlignOf: 561 items, 160 bytes each, total 87.66 KiB
AtomicRmw: 356 items, 208 bytes each, total 72.31 KiB
MemberCount: 441 items, 160 bytes each, total 68.91 KiB
Memset: 342 items, 176 bytes each, total 58.78 KiB
PopCount: 321 items, 168 bytes each, total 52.66 KiB
AlignCast: 251 items, 168 bytes each, total 41.18 KiB
IrInstruction *: 5230 items, 8 bytes each, total 40.86 KiB
IrBasicBlock *: 5230 items, 8 bytes each, total 40.86 KiB
TagType: 261 items, 160 bytes each, total 40.78 KiB
HasDecl: 234 items, 168 bytes each, total 38.39 KiB
OverflowOp: 191 items, 200 bytes each, total 37.30 KiB
Export: 209 items, 176 bytes each, total 35.92 KiB
SetCold: 219 items, 160 bytes each, total 34.22 KiB
ReturnAddress: 216 items, 152 bytes each, total 32.06 KiB
FromBytes: 178 items, 176 bytes each, total 30.59 KiB
SetRuntimeSafety: 188 items, 160 bytes each, total 29.38 KiB
OptionalWrap: 151 items, 168 bytes each, total 24.77 KiB
Clz: 143 items, 168 bytes each, total 23.46 KiB
ResizeSlice: 135 items, 168 bytes each, total 22.15 KiB
UnionInitNamedField: 106 items, 184 bytes each, total 19.05 KiB
Panic: 102 items, 160 bytes each, total 15.94 KiB
SwitchElseVar: 93 items, 168 bytes each, total 15.26 KiB
ToBytes: 89 items, 168 bytes each, total 14.60 KiB
IntToFloat: 78 items, 168 bytes each, total 12.80 KiB
Unknown_4360: 3 items, 4360 bytes each, total 12.77 KiB
ErrWrapPayload: 72 items, 168 bytes each, total 11.81 KiB
FloatOp: 62 items, 176 bytes each, total 10.66 KiB
FloatToInt: 47 items, 168 bytes each, total 7.71 KiB
FloatCast: 46 items, 168 bytes each, total 7.55 KiB
ErrToInt: 47 items, 160 bytes each, total 7.34 KiB
Asm: 33 items, 216 bytes each, total 6.96 KiB
ErrSetCast: 40 items, 168 bytes each, total 6.56 KiB
Memcpy: 34 items, 176 bytes each, total 5.84 KiB
AtomicLoad: 17 items, 184 bytes each, total 3.05 KiB
AwaitSrc: 16 items, 168 bytes each, total 2.62 KiB
Resume: 14 items, 160 bytes each, total 2.19 KiB
AwaitGen: 12 items, 176 bytes each, total 2.06 KiB
ArgType: 12 items, 168 bytes each, total 1.97 KiB
AnyFrameType: 12 items, 160 bytes each, total 1.88 KiB
SuspendFinish: 10 items, 160 bytes each, total 1.56 KiB
SuspendBegin: 10 items, 160 bytes each, total 1.56 KiB
Ctz: 9 items, 168 bytes each, total 1.48 KiB
FrameHandle: 8 items, 152 bytes each, total 1.19 KiB
SetEvalBranchQuota: 7 items, 160 bytes each, total 1.09 KiB
AssertZero: 7 items, 160 bytes each, total 1.09 KiB
UndeclaredIdent: 7 items, 160 bytes each, total 1.09 KiB
CmpxchgSrc: 5 items, 216 bytes each, total 1.05 KiB
CmpxchgGen: 5 items, 200 bytes each, total 1000.00 bytes
IntToEnum: 4 items, 168 bytes each, total 672.00 bytes
VectorType: 4 items, 168 bytes each, total 672.00 bytes
ErrorReturnTrace: 2 items, 160 bytes each, total 320.00 bytes
Breakpoint: 2 items, 152 bytes each, total 304.00 bytes
FrameAddress: 2 items, 152 bytes each, total 304.00 bytes
Unknown_4: 61 items, 4 bytes each, total 244.00 bytes
VectorToArray: 1 items, 168 bytes each, total 168.00 bytes
SetAlignStack: 1 items, 160 bytes each, total 160.00 bytes
Unknown_12: 2 items, 12 bytes each, total 24.00 bytes
ErrorTableEntry *: 0 items, 8 bytes each, total 0.00 bytes
AstNode *: 0 items, 8 bytes each, total 0.00 bytes
Total bytes used: 3.51 GiB
```

You can see that most of the memory is taken up by IR instructions,
as well as comptime values. This points toward 2 changes which will
greatly reduce memory usage:

 * Rework semantic analysis so that IR instructions can be freed.
   Currently the comptime value struct (ConstExprValue) is embedded
   directly into the IrInstruction struct. If this is made to be
   separate, at the very least pass 1 IR instructions can be freed.
   This includes `Const` which is the largest usage of memory currently.

 * Rework the ConstExprValue struct to no longer be a tagged union.
   For example, there's no need for an integer comptime value to be
   80 bytes.

From this you can also see that this eliminates some things from being
the culprit. Before doing this analysis, I considered whether doing
string interning would help. From the above output, you can see that all
strings in the compiler account for only 18 MiB, so string interning
would have been a dead end.
2019-10-19 03:23:23 -04:00
Sahnvour
5b51f41cee
stage1: override cmake's default compilation flags to statically link the CRT on windows
we want to use /MT instead of /MD for a fully static executable
2019-10-16 19:04:50 -04:00
Andrew Kelley
59ac7b91da
add -fdump-analysis to dump type information to json
This commit adds -fdump-analysis which creates
a `$NAME-analysis.json` file with all of the finished
semantic analysis that the stage1 compiler produced.
It contains types, packages, declarations, and files.

This is an initial implementation; some data will be
missing. However it's easy to improve the implementation,
which is in `src/dump_analysis.cpp`.

The next step for #21 will be to create Zig code which parses
this json file and creates user-facing HTML documentation.

This feature has other uses, however; for example, it could
be used for IDE integration features until the self-hosted
compiler is available.
2019-10-03 17:58:22 -04:00
Andrew Kelley
ce56ae8afe
we have to use c++14 now for llvm10 2019-10-02 13:05:10 -04:00
Andrew Kelley
0dd8adcdb4
Release 0.5.0 2019-09-30 10:09:33 -04:00
Andrew Kelley
2f20833097
add -DZIG_SKIP_INSTALL_LIB_FILES cmake option
closes #2221
2019-09-26 02:21:29 -04:00
Andrew Kelley
dc7016344e
remove --override-std-dir. fix issues caused by moving std lib 2019-09-25 23:59:07 -04:00
Andrew Kelley
185cb13278
Merge remote-tracking branch 'origin/master' into llvm9 2019-09-10 13:00:35 -04:00
Andrew Kelley
0489d06c24
make the std lib support event-based I/O
also add -fstack-report
2019-09-10 10:26:52 -04:00
Andrew Kelley
2482bdf22b
release builds of stage1 have llvm ir verification
the stage2 zig code however gets compiled in release mode,
and stripped.
2019-09-09 09:33:33 -04:00
Sahnvour
19cf9bd062 use /debug:fastlink when building with msvc and debug info 2019-09-09 00:26:39 -04:00
emekoi
9423d382fb fixed compiler error for gcc 9.2.0 2019-09-06 19:20:25 -04:00
Michael Dusan
00d82e34df cmake: improve building without git repository
- quiet `fatal: not a git repository` message
- if git probe fails skip ZIG_VERSION modification
2019-09-02 21:36:16 -04:00
Andrew Kelley
6529658ad8
Merge remote-tracking branch 'origin/master' into llvm9 2019-08-16 16:43:56 -04:00
Andrew Kelley
8b97a1aee2
Merge pull request #3033 from ziglang/rewrite-coroutines
rework async function semantics
2019-08-15 14:01:01 -07:00
Andrew Kelley
729807203a
force static libs for vendored dependencies 2019-08-15 14:34:52 -04:00
Andrew Kelley
ffab950e0c
update embedded LLD to 9.0.0rc1 2019-08-03 12:56:35 -04:00
Andrew Kelley
b3b6a98451
Merge remote-tracking branch 'origin/master' into rewrite-coroutines 2019-08-02 16:31:43 -04:00
emekoi
357fb4f143 avoid passing -static to msvc when static linking 2019-07-27 17:54:20 -05:00
emekoi
5593c63e12 improved CMake file for MinGW 2019-07-26 16:26:01 -05:00
Andrew Kelley
72e983670e
simple async function call working 2019-07-21 16:21:16 -04:00
daurnimator
3a67c13b5d cmake: allow user to select static vs dynamic LLVM 2019-07-16 12:33:13 -04:00
Andrew Kelley
0cd660462f
move install_files.h to not be generated code 2019-07-15 01:47:26 -04:00
Andrew Kelley
40a562f26d
cmake: fix incorrect dependencies 2019-07-15 01:45:26 -04:00