13365 Commits

Author SHA1 Message Date
Andrew Kelley
bcfebb4b2b stage2: improvements aimed at std lib integration
* AstGen: emit decl lookup ZIR instructions rather than directly
   looking up decls in AstGen. This is necessary because we want to
   reuse the same immutable ZIR code for multiple generic instantiations
   (and comptime function calls).
 * AstGen: fix using members_len instead of fields_len for struct decls.
 * structs: the struct_decl ZIR instruction is now also a block. This is
   so that the type expressions, default field value expressions, and
   alignment expressions can be evaluated in a scope that contains the
   decls from the struct namespace itself.
 * Add "std" and "builtin" packages to the builtin package.
 * Don't try to build glibc, musl, or mingw-w64 when using `-ofmt=c`.
 * builtin.zig is generated without `usingnamespace`.
 * builtin.zig takes advantage of `std.zig.fmtId` for CPU features.
 * A first pass at implementing `usingnamespace`. It's problematic and
   should either be deleted, or polished, before merging this branch.
 * Sema: allow explicitly specifying the namespace in which to look up
   Decls. This is used by `struct_decl` in order to put the decls from
   the struct namespace itself in scope when evaluating the type
   expressions, default value expressions, and alignment expressions.
 * Module: fix `analyzeNamespace` assuming that it is the top-level root
   declaration node.
 * Sema: implement comptime and runtime cmp operator.
 * Sema: implement peer type resolution for enums and enum literals.
 * Pull in the changes from master branch:
   262e09c482d98a78531c049a18b7f24146fe157f.
 * ZIR: complete out simple_ptr_type debug printing
2021-04-15 19:06:39 -07:00
Andrew Kelley
429cd2b5dd std: change @import("builtin") to std.builtin 2021-04-15 19:06:39 -07:00
Andrew Kelley
a4bb7c8bb1 stage2: remove redundant source hash 2021-04-15 19:06:39 -07:00
Andrew Kelley
f458192e56 stage2: entry point via std lib and proper updated file detection
Instead of Module setting up the root_scope with the root source file,
instead, Module relies on the package table graph being set up properly,
and inside `update()`, it does the equivalent of `_ = @import("std");`.
This, in term, imports start.zig, which has the logic to call main (or
not). `Module` no longer has `root_scope` - the root source file is no
longer special, it's just in the package table mapped to "root".

I also went ahead and implemented proper detection of updated files.
mtime, inode, size, and source hash are kept in `Scope.File`.
During an update, iterate over `import_table` and stat each file to find
out which ones are updated.

The source hash is redundant with the source hash used by the struct
decl that corresponds to the file, so it should be removed in a future
commit before merging the branch.

 * AstGen: add "previously declared here" notes for variables shadowing
   decls.
 * Parse imports as structs. Module now calls `AstGen.structDeclInner`,
   which is called by `AstGen.containerDecl`.
   - `importFile` is a bit kludgy with how it handles the top level Decl
     that kinda gets merged into the struct decl at the end of the
     function. Be on the look out for bugs related to that as well as
     possibly cleaner ways to implement this.
 * Module: factor out lookupDeclName into lookupIdentifier and lookupNa
 * Rename `Scope.Container` to `Scope.Namespace`.
 * Delete some dead code.

This branch won't work until `usingnamespace` is implemented because it
relies on `@import("builtin").OutputMode` and `OutputMode` comes from a
`usingnamespace`.
2021-04-15 19:06:39 -07:00
Andrew Kelley
ccdf55310b stage2: properly model miscellaneous failed tasks
with error messages that go away after updates
2021-04-15 19:01:55 -07:00
Andrew Kelley
2b2920f599 ci: drone: disable stage2 tests
See #8545
2021-04-15 16:20:43 -07:00
Andrew Kelley
c795e82cbc ci: windows: update to llvm 12 msvc tarball 2021-04-15 12:40:22 -07:00
Andrew Kelley
c49fe52cb1 ci: update macos tarball to llvm 12 2021-04-15 11:27:02 -07:00
Andrew Kelley
68e69aae2b build.zig: omit LLVMTableGen from llvm libs 2021-04-15 10:58:53 -07:00
Andrew Kelley
2a6ec2e155 build.zig: update llvm libs 2021-04-15 10:43:39 -07:00
Andrew Kelley
a38042e3ac ci: windows: proper flags to zig build 2021-04-15 02:02:36 -07:00
Andrew Kelley
fa633a658f ci: windows: try the dev kit strategy 2021-04-15 01:44:17 -07:00
Andrew Kelley
4a1d3465cc ci: windows: ranlib take 2 2021-04-15 01:22:42 -07:00
Andrew Kelley
3266f326de ci: windows: better -DCMAKE_RANLIB option 2021-04-15 01:14:33 -07:00
Andrew Kelley
04b8354702 freebsd: disable failing test
See #8538
2021-04-15 00:59:40 -07:00
Andrew Kelley
996193c228 ci: freebsd: don't try to compile with zig cc 2021-04-15 00:51:26 -07:00
Andrew Kelley
a680c7ba98 ci: windows: use llvm-ar.exe from the tarball 2021-04-15 00:41:30 -07:00
Andrew Kelley
c59241bda0 ci: better handle of -mcpu 2021-04-15 00:18:21 -07:00
Andrew Kelley
553fbeba82 ci: better target triple and mcpu cmake args 2021-04-14 23:49:16 -07:00
Andrew Kelley
85755c51d5 ci: freebsd: set the target triple 2021-04-14 23:35:51 -07:00
Andrew Kelley
df319db058 ci: windows: install git 2021-04-14 23:18:03 -07:00
Andrew Kelley
3967823f3a ci: freebsd: pass -DZIG_USE_LLVM_CONFIG=OFF 2021-04-14 23:17:08 -07:00
Andrew Kelley
ee42178b43 ci: aarch64-linux: disable run-translated-c tests
See #8537
2021-04-14 23:10:51 -07:00
Andrew Kelley
45eb9554c4 ci: windows: try using zig-bootstrap to build zig 2021-04-14 23:03:16 -07:00
Andrew Kelley
406353103a ci: freebsd: update to llvm 12 2021-04-14 22:59:34 -07:00
Andrew Kelley
1438c324a4 ci: update drone CI to llvm 12 2021-04-14 21:18:23 -07:00
Andrew Kelley
391a40d601 ci: update linux to llvm12 tarball 2021-04-14 20:35:33 -07:00
Michael Dusan
6a7f21d1b8 ci: macos-aarch64 update dep tarballs for llvm12 2021-04-14 19:43:17 -07:00
lithdew
81adcd533e os/posix: handle ECONNRESET for write/writev 2021-04-14 16:40:06 -07:00
Andrew Kelley
5a3ea9bece Merge remote-tracking branch 'origin/llvm12'
Happy LLVM 12 Release Day.

Please note that the llvm 12 tag does not include the latest commit in
the release/12.x branch, which is in fact a bug fix for a regression
that is causing a failure in Zig's test suite.

Zig master branch is tracking release/12.x, and will be enabling the
test that is fixed by that commit.
2021-04-14 14:41:57 -07:00
Frank Denis
1fada37466
Merge pull request #8518 from akvadrako/doc-field-align
Update doc for struct field alignment.
2021-04-14 10:56:37 +02:00
Evan Haas
e761e0ac18 translate-c: wrap switch statements in a while (true) loop
This allows `break` statements to be directly translated from the original C.
Add a break statement as the last statement of the while loop to ensure we
don't have an infinite loop if no breaks / returns are hit in the switch.

Fixes #8387
2021-04-13 11:45:03 -07:00
Jakub Konka
36a33c99e3
Merge pull request #8517 from ziglang/zld-archive-fix
zld: fix symbol resolution from interdependent static archives
2021-04-13 17:12:26 +02:00
Devin Bayer
ca3aa02206 Update doc for struct field alignment. 2021-04-13 14:53:44 +02:00
Jakub Konka
461543a5fd zld: fix symbol resolution from interdep archives
Fixes symbol resolution if an archive occurring later in the linker
line depends on a object embedded within the archive that occurred
before.
2021-04-13 13:36:08 +02:00
Jakub Konka
65e4725aba Add standalone test for interdep C archives
Tests a scenario where the linker line has the following:

```
main.o libA.a libB.a
```

where `main.o` pulls a symbol from `libB.a`, which in turn is
dependent on a symbol from `libA.a`.
2021-04-13 13:32:59 +02:00
Jakub Konka
a5bbc66f10 zld: cleanup redundant changes 2021-04-13 10:56:03 +02:00
Jakub Konka
db30033de2 zld: rebase to new naming conv for aarch64 2021-04-13 10:56:03 +02:00
Jakub Konka
1119970d22 zld: add x86_64 relocs 2021-04-13 10:56:03 +02:00
Jakub Konka
b1f9db75f3 zld: save locals per TU 2021-04-13 10:56:03 +02:00
Jakub Konka
3b7c9dd6bd zld: differentiate between static and global in stabs 2021-04-13 10:56:03 +02:00
Jakub Konka
717d382871 zld: streamline tags for Symbol 2021-04-13 10:56:03 +02:00
Jakub Konka
b377e0b370 zld: fix indirect symtab 2021-04-13 10:56:03 +02:00
Jakub Konka
b0a4e1fa46 zld: fix rebase vs bind for GOT entries 2021-04-13 10:56:03 +02:00
Jakub Konka
6e3f82ef28 zld: fix parsing debug info 2021-04-13 10:56:03 +02:00
Jakub Konka
65c27d51f6 zld: limit exports to just main entrypoint 2021-04-13 10:56:03 +02:00
Jakub Konka
421102ba72 zld: move parsing debug info into object 2021-04-13 10:56:03 +02:00
Jakub Konka
dc7cff8ebc zld: add prelim support for locals 2021-04-13 10:56:03 +02:00
Jakub Konka
23bb6fa9f4 zld: flush MachO 2021-04-13 10:56:03 +02:00
Jakub Konka
db44a7803f zld: resolve target addresses for relocs 2021-04-13 10:56:03 +02:00