13396 Commits

Author SHA1 Message Date
Andrew Kelley
22015c1b3b std.MultiArrayList: ensureUnusedCapacity/ensureTotalCapacity
Same as c8ae581fef6506a8234cdba1355ba7f0f449031a, but for
MultiArrayList.
2021-04-19 15:02:37 -07:00
Andrew Kelley
27d4bea9a4 AstGen: implement if optional, if error union 2021-04-19 12:25:16 -07:00
Andrew Kelley
3dadccec45 AstGen: implement while optional and while error union 2021-04-19 12:02:11 -07:00
Andrew Kelley
3f60481be4 AstGen: implement the remaining struct init ResultLoc forms 2021-04-19 11:09:00 -07:00
Andrew Kelley
ae495de54d AstGen: implement all the builtin functions 2021-04-18 22:38:41 -07:00
Andrew Kelley
5a3045b5de AstGen: implement overflow arithmetic builtins 2021-04-17 13:00:10 -07:00
Andrew Kelley
8cf0ef2779 AstGen: implement simple enums and decls for enums 2021-04-16 22:21:26 -07:00
Andrew Kelley
0409d433ba AstGen: fix compile error using wrong node/token function 2021-04-16 19:49:19 -07:00
Andrew Kelley
e13fc6b119 stage2: make @import relative to the current file
previously, it was incorrectly relative to the package directory
2021-04-16 19:45:58 -07:00
Andrew Kelley
415ef1be51 AstGen: fix function decl astgen
it was using the wrong scope and other mistakes too
2021-04-16 19:45:24 -07:00
Andrew Kelley
dd5a1b1106 build.zig: add a way to skip installing lib/ files 2021-04-16 18:58:27 -07:00
Andrew Kelley
9375ad0d3b AstGen: implement global var decls
And fix bug with using `ensureCapacity` when I wanted
`ensureUnusedCapacity`.
2021-04-16 17:57:51 -07:00
Andrew Kelley
c8ae581fef std: deprecate ensureCapacity, add two other capacity functions
I've run into this footgun enough times, nearly every time I want
`ensureUnusedCapacity`, not `ensureCapacity`. This commit deprecates
`ensureCapacity` in favor of `ensureTotalCapacity` and introduces
`ensureUnusedCapacity`.
2021-04-16 17:56:30 -07:00
Andrew Kelley
5ff45b3f44 stage2: use import list from ZIR to queue up more AstGen tasks 2021-04-16 17:28:28 -07:00
Andrew Kelley
a271f12a14 AstGen: store list of imports 2021-04-16 16:20:29 -07:00
Andrew Kelley
edd75d03e3 ZIR: rename decl_val and decl_ref to remove redundant suffix 2021-04-16 15:52:26 -07:00
Andrew Kelley
adc2aed587 AstGen: require @import operand to be string literal
See #2206
2021-04-16 15:50:28 -07:00
Andrew Kelley
333a577d73 AstGen: put decls into blocks to be evaluated independently 2021-04-16 15:34:09 -07:00
Andrew Kelley
01b4bf34ea stage2: AstGen improvements
* AstGen: represent compile errors in ZIR rather than returning
   `error.AnalysisFail`.
 * ZIR: remove decl_ref and decl_val instructions. These are replaced by
   `decl_ref_named` and `decl_val_named`, respectively, which will
   probably get renamed in the future to the instructions that were just
   deleted.
 * AstGen: implement `@This()`, `@fence()`, `@returnAddress()`, and
   `@src()`.
 * AstGen: struct_decl improved to support fields_len=0 but have decls.
 * AstGen: fix missing null bytes after compile error messages.
 * SrcLoc: no longer depend on `Decl`. Instead have an explicit field
   `parent_decl_node` which is an absolute AST Node index.
 * Module: `failed_files` table can have null value, in which case the
   key, which is a `*Scope.File`, will have ZIR errors in it.
 * ZIR: implement text rendering of struct decls.
 * CLI: introduce debug_usage and `zig astgen` command which is enabled
   when the compiler is built in debug mode.
2021-04-16 14:48:10 -07:00
Andrew Kelley
cf57e8223f AstGen: implement comptimeDecl, usingnamespaceDecl, testDecl 2021-04-15 20:55:54 -07:00
Andrew Kelley
8387307807 AstGen: implement global variable decls 2021-04-15 20:34:21 -07:00
Andrew Kelley
7818586a2b fix new references to std.builtin that should have been std.Target 2021-04-15 19:14:54 -07:00
Andrew Kelley
f37451a63a stage2: fix zir.zig => Zir.zig in CMakeLists.txt 2021-04-15 19:12:05 -07:00
Andrew Kelley
3114115348 stage2: preliminary reworking for whole-file-AstGen
See #8516.

 * AstGen is now done on whole files at once rather than per Decl.

 * Introduce a new wait group for AstGen tasks. `performAllTheWork`
   waits for all AstGen tasks to be complete before doing Sema,
   single-threaded.
   - The C object compilation tasks are moved to be spawned after
     AstGen, since they only need to complete by the end of
     the function.

With this commit, the codebase compiles, but much more reworking is
needed to get things back into a useful state.
2021-04-15 19:06:39 -07:00
Andrew Kelley
9088d40e83 stage2: rename zir to Zir
since it now uses top level fields
2021-04-15 19:06:39 -07:00
Andrew Kelley
0170a242bb stage2: move zir.Code to become root level fields of zir.zig
next commit will do the rename
2021-04-15 19:06:39 -07:00
Andrew Kelley
798ad631f3 stage2 start.zig: slight simplification
fewer required language features to allow this to work
2021-04-15 19:06:39 -07:00
Andrew Kelley
6dba9bc6fc stage2: implement @bitSizeOf 2021-04-15 19:06:39 -07:00
Andrew Kelley
df983b30d2 stage2: implement comptime division 2021-04-15 19:06:39 -07:00
Andrew Kelley
69645e2817 stage2: implement @sizeOf 2021-04-15 19:06:39 -07:00
Andrew Kelley
0e50a0c1e5 stage2: implement non-trivial enums 2021-04-15 19:06:39 -07:00
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