Commit Graph

523 Commits

Author SHA1 Message Date
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