13605 Commits

Author SHA1 Message Date
Andrew Kelley
eadcefc124 stage2: dbg_stmt ZIR instructions have line/col
instead of node indexes.

 * AstGen: dbg_stmt instructions now have line and column indexes,
   relative to the parent declaration. This allows codegen to emit debug
   info without having the source bytes, tokens, or AST nodes loaded
   in memory.
 * ZIR: each decl has the absolute line number. This allows computing
   line numbers from offsets without consulting source code bytes.

Memory management: creating a function definition does not prematurely
set the Decl arena. Instead the function is allocated with the general
purpose allocator.

Codegen no longer looks at source code bytes for any reason. They can
remain unloaded from disk.
2021-05-01 21:57:52 -07:00
Andrew Kelley
6248e2a560 std.GeneralPurposeAllocator: print leaked memory addresses
This helps when using it with other tools, such as memory watchpoints.
2021-05-01 21:25:01 -07:00
Andrew Kelley
dc28f5c3ec Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
	lib/std/crypto/25519/field.zig
	lib/std/crypto/poly1305.zig

I had resolved those by removing `comptime` but master branch decided to
make the parameters `comptime`.

This also pulls in the updated default `zig build` install directory.
2021-04-30 23:13:17 -07:00
Andrew Kelley
351b57497b stage2: implement function body analysis
now with whole-file-astgen
2021-04-30 23:11:20 -07:00
Andrew Kelley
557eb414ee CLI: fix incorrect error message with -cflags 2021-04-30 21:55:28 -07:00
Andrew Kelley
077b8d3def stage2: introduce new ZIR instruction: arg
* AstGen: LocalVal and LocalPtr use string table indexes for their
   names. This is more efficient because local variable declarations do
   need to include the variable names so that semantic analysis can emit
   a compile error if a declaration is shadowed. So we take advantage of
   this fact by comparing string table indexes when resolving names.

 * The arg ZIR instructions are needed for the above reasoning, as well
   as to emit equivalent AIR instructions for debug info.
   Now that we have these arg instructions, get rid of the special
   `Zir.Inst.Ref` range for parameters. ZIR instructions now refer
   to the arg instructions for parameters.

 * Move identAsString and strLitAsString from Module.GenZir to AstGen
   where they belong.
2021-04-30 21:43:18 -07:00
Devin Bayer
5fcc922ff2
add doc in Anonymous Struct Literal section for special @"0" syntax. (#8630) 2021-05-01 01:05:45 +02:00
Frank Denis
33cb660838
Doc: zig-cache/bin -> zig-out/bin (#8659) 2021-05-01 00:41:59 +02:00
Andrew Kelley
db7acd83d2 Sema: implement function declarations 2021-04-30 14:36:02 -07:00
Devin Bayer
d3f55782b0
rename doc refs to deprecated functions like openC (#8467) 2021-04-30 21:31:01 +02:00
Andrew Kelley
fb95fd8443 start.zig: unconditionally import the root source file
stage1 did this by accident by unconditionally semantically analyzing
std.builtin.panic, which imports the root source file to look for a
panic handler override. But stage2 is smarter; it will only semantically
analyze std.builtin.panic if any panic calls are emitted. So for very
simple compilations, the root source file was being ignored, even if it
contained `export` functions in it.
2021-04-30 11:24:15 -07:00
Andrew Kelley
2d8d681b5e stage2: un-tangle memory management of Decl and Namespace
Before there was this "top_decl" and "tmp_namespace" stack values that
were kludgy and buggy. Now Sema is slightly reworked so that files which
are structs are analyzed with their own Decl and Namespace already set
up.

After this commit there are no memory leaks for a successful build-obj.
2021-04-30 11:07:31 -07:00
Yorhel
f79b487337 Handle EPERM and ELOOP in os.fstatat() 2021-04-30 15:08:07 +02:00
Andrew Kelley
4e07755ce7
Merge pull request #8638 from ifreund/build-default-prefix
std/build: change default install prefix to zig-out
2021-04-30 00:10:44 -04:00
Andrew Kelley
5d696b0706 stage2: fix File incorrectly freeing its Namespace 2021-04-29 20:49:31 -07:00
Andrew Kelley
8ab4a003c8 stage2: properly free Decl name
Two problems solved:

 * The Decl name may be allocated with gpa or it may be a reference to
   the ZIR string table.

 * The main update() function was freeing the ZIR when we still had
   Decl objects referencing it.
2021-04-29 20:34:33 -07:00
Andrew Kelley
474ade88b5 std: fix compile errors found by stage2 AstGen 2021-04-29 20:33:29 -07:00
Andrew Kelley
8944240aec AstGen: represent global variables directly
Rather than with `block_inline_var`. This matches how function
declarations work and how extern variables work.
2021-04-29 19:56:01 -07:00
Andrew Kelley
86d564eed8 AstGen: implement extern variables 2021-04-29 19:44:51 -07:00
Andrew Kelley
ba9b9cb38d AstGen: implement function prototypes with alignment exprs 2021-04-29 18:25:25 -07:00
Andrew Kelley
2eef83e85f AstGen: fix comptime compile error source location 2021-04-29 17:43:07 -07:00
Andrew Kelley
47585cbe12 Sema: rename TZIR to AIR
Analyzed Intermediate Representation
2021-04-29 17:26:21 -07:00
Andrew Kelley
478dac5346 Sema: skip analysis of empty enum blocks
For these, the ZIR code has an empty block rather than a block with a
single `break_inline` instruction.
2021-04-29 17:25:10 -07:00
Andrew Kelley
9e49a65e1b AstGen: implement anytype struct fields 2021-04-29 17:13:18 -07:00
Andrew Kelley
55e86b724a AstGen: implement comptime struct fields 2021-04-29 16:57:13 -07:00
Andrew Kelley
fb4cb430e0 std.enums: remove stuff for enums with field aliases
This will probably conflict with the real patch to rework this code, and
in such case this commit should be discarded in favor of the other
commit.
2021-04-29 16:05:30 -07:00
Andrew Kelley
4307436b99 move behavior tests from test/stage1/ to test/
And fix test cases to make them pass. This is in preparation for
starting to pass behavior tests with self-hosted.
2021-04-29 15:54:04 -07:00
Andrew Kelley
5a02c938da update behavior tests with respect to new builtin pkg 2021-04-29 15:18:40 -07:00
Isaac Freund
5079d11b21
std/build: change default install prefix to zig-out
Currently the default install prefix is $BUILD_ROOT/zig-cache,
but mixing cache and artifacts makes little sense. Instead make
$BUILD_ROOT/zig-out the default.
2021-04-29 23:58:45 +02:00
Andrew Kelley
eb53680bce tests: prepare behavior tests for stage2 2021-04-29 14:51:21 -07:00
Matthew Borkowski
585479500e check for overflow when reading code lengths for a block with dynamic Huffman codes 2021-04-29 17:48:08 -04:00
Frank Denis
687ef42f98
x: comptime bool -> comptime x: bool (#8639) 2021-04-29 16:27:50 +02:00
Isaac Freund
2ed368fb92
std/build: add -p alias for --prefix 2021-04-29 14:25:58 +02:00
Andrew Kelley
d36a31ba75 stage2: fix scanDecls not advancing the field bits
Also fix `semaFile` not handling compile errors properly.
2021-04-28 23:16:13 -07:00
Andrew Kelley
c60d8f017e std: remove redundant comptime keyword
@g-w1's fancy new compile error in action
2021-04-28 22:58:12 -07:00
Andrew Kelley
0c71d2fdc1 stage2: implement semantic analysis for functions and global vars
* AstGen: add missing `break_inline` for comptime blocks.
 * Module: call getTree() in byteOffset(). This generates the AST when
   using cached ZIR and compile errors need to be reported.
 * Scope.File: distinguish between successful ZIR generation and AIR
   generation (when Decls in scope have been scanned).
   - `semaFile` correctly avoids doing work twice.
 * Implement first pass at `lookupInNamespace`. It has various TODOs
   left, such as `usingnamespace`, and setting up Decl dependencies.
2021-04-28 22:43:26 -07:00
Andrew Kelley
3462193d30 stage2: prepare for mainining Decl references to ZIR indexes 2021-04-28 16:57:01 -07:00
Andrew Kelley
f86469bc5e stage2: semaDecl properly analyzes the decl block
Also flattened out Decl TypedValue fields into
ty, val, has_tv
and add relevant fields to Decl for alignment and link section.
2021-04-28 16:57:01 -07:00
Andrew Kelley
fa6bb4b662 Sema: do not analyze test decls when not in test mode
We do this by reserving string table indexes 0 and 1 in ZIR to be
special. Decls now have 0 to mean comptime or usingnamespace, and 1 to
mean an unnamed test decl.
2021-04-28 16:57:01 -07:00
jacob gw
2354cbafdb stage2: implement #8364 2021-04-28 19:54:04 -04:00
Andrew Kelley
c90e52b74c std: remove redundant comptime const 2021-04-28 15:15:44 -07:00
Andrew Kelley
d3ffacb55c AstGen: hook up hex float parsing to float literals
Thanks @LemonBoy!
2021-04-28 15:13:43 -07:00
Andrew Kelley
9db5b2c5c6 AstGen: function prototypes can have alignment 2021-04-28 15:02:52 -07:00
Andrew Kelley
df24ce52b1 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted to take advantage of the new hex float parsing
code.
2021-04-28 14:57:38 -07:00
LemonBoy
55c58f226d std: Add a parser for hexadecimal floating point numbers
Should be good enough to unblock progress on the stage2 compiler.

Unifying this parser and the regular one (and perhaps rewrite it, #2207)
is left as an exercise for the reader.
2021-04-28 17:36:12 -04:00
Andrew Kelley
86e129eff6 std.Target: bump freebsd known maximum version 2021-04-28 10:26:47 -07:00
Andrew Kelley
2c9ed6daee
Merge pull request #8472 from sreehax/master
callconv: add SysV
2021-04-28 13:11:40 -04:00
joachimschmidt557
bc06e19828 stage2 riscv64: cleanup code and add tests 2021-04-28 07:20:45 +02:00
Andrew Kelley
eb9c29eb81 AstGen: fix function src hash not including body 2021-04-27 22:20:25 -07:00
Andrew Kelley
3d9e4edb57 link: fix compile error from previous commit 2021-04-27 14:46:55 -07:00