Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stage2 whole file astgen #8554

Merged
merged 240 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
240 commits
Select commit Hold shift + click to select a range
f458192
stage2: entry point via std lib and proper updated file detection
andrewrk Apr 10, 2021
a4bb7c8
stage2: remove redundant source hash
andrewrk Apr 10, 2021
429cd2b
std: change `@import("builtin")` to `std.builtin`
andrewrk Apr 12, 2021
bcfebb4
stage2: improvements aimed at std lib integration
andrewrk Apr 12, 2021
0e50a0c
stage2: implement non-trivial enums
andrewrk Apr 13, 2021
69645e2
stage2: implement `@sizeOf`
andrewrk Apr 13, 2021
df983b3
stage2: implement comptime division
andrewrk Apr 13, 2021
6dba9bc
stage2: implement `@bitSizeOf`
andrewrk Apr 13, 2021
798ad63
stage2 start.zig: slight simplification
andrewrk Apr 13, 2021
0170a24
stage2: move zir.Code to become root level fields of zir.zig
andrewrk Apr 13, 2021
9088d40
stage2: rename zir to Zir
andrewrk Apr 13, 2021
3114115
stage2: preliminary reworking for whole-file-AstGen
andrewrk Apr 14, 2021
f37451a
stage2: fix zir.zig => Zir.zig in CMakeLists.txt
andrewrk Apr 16, 2021
7818586
fix new references to std.builtin that should have been std.Target
andrewrk Apr 16, 2021
8387307
AstGen: implement global variable decls
andrewrk Apr 16, 2021
cf57e82
AstGen: implement comptimeDecl, usingnamespaceDecl, testDecl
andrewrk Apr 16, 2021
01b4bf3
stage2: AstGen improvements
andrewrk Apr 16, 2021
333a577
AstGen: put decls into blocks to be evaluated independently
andrewrk Apr 16, 2021
adc2aed
AstGen: require `@import` operand to be string literal
andrewrk Apr 16, 2021
edd75d0
ZIR: rename decl_val and decl_ref to remove redundant suffix
andrewrk Apr 16, 2021
a271f12
AstGen: store list of imports
andrewrk Apr 16, 2021
5ff45b3
stage2: use import list from ZIR to queue up more AstGen tasks
andrewrk Apr 17, 2021
c8ae581
std: deprecate ensureCapacity, add two other capacity functions
andrewrk Apr 17, 2021
9375ad0
AstGen: implement global var decls
andrewrk Apr 17, 2021
dd5a1b1
build.zig: add a way to skip installing lib/ files
andrewrk Apr 17, 2021
415ef1b
AstGen: fix function decl astgen
andrewrk Apr 17, 2021
e13fc6b
stage2: make `@import` relative to the current file
andrewrk Apr 17, 2021
0409d43
AstGen: fix compile error using wrong node/token function
andrewrk Apr 17, 2021
8cf0ef2
AstGen: implement simple enums and decls for enums
andrewrk Apr 17, 2021
5a3045b
AstGen: implement overflow arithmetic builtins
andrewrk Apr 17, 2021
ae495de
AstGen: implement all the builtin functions
andrewrk Apr 19, 2021
3f60481
AstGen: implement the remaining struct init ResultLoc forms
andrewrk Apr 19, 2021
3dadcce
AstGen: implement while optional and while error union
andrewrk Apr 19, 2021
27d4bea
AstGen: implement if optional, if error union
andrewrk Apr 19, 2021
22015c1
std.MultiArrayList: ensureUnusedCapacity/ensureTotalCapacity
andrewrk Apr 19, 2021
2083208
AstGen: implement functions with inferred error sets
andrewrk Apr 19, 2021
7f931a7
AstGen: implement error set decls
andrewrk Apr 19, 2021
a136c09
zig astgen: print instruction counts and byte sizes
andrewrk Apr 19, 2021
4630e38
AstGen: implement inline asm output
andrewrk Apr 20, 2021
693dbee
stage2: make `@alignCast` accept 2 parameters
andrewrk Apr 20, 2021
e315120
AstGen: implement array initialization expressions
andrewrk Apr 20, 2021
ee3c1c7
stage2: astgen `try`
g-w1 Apr 19, 2021
b4baa9e
AstGen: `try` fixups
andrewrk Apr 20, 2021
6b94449
stage2: fix compile error in codegen
g-w1 Apr 20, 2021
b4aec0e
stage2: make std.fmt.parseInt ignore `_`
g-w1 Apr 20, 2021
a59bcae
AstGen: basic defer implementation
andrewrk Apr 20, 2021
458c4b6
AstGen: implement defer for `continue`
andrewrk Apr 20, 2021
a62db38
AstGen: implement defer for `break`
andrewrk Apr 21, 2021
30c9808
AstGen: implement anytype parameters
andrewrk Apr 21, 2021
e947704
AstGen: implement for loop payload
andrewrk Apr 21, 2021
a008fb0
std.fs: delete unused label
andrewrk Apr 21, 2021
c69a95f
AstGen: fix store_to_block_ptr elision for switch statements
andrewrk Apr 21, 2021
971f3d9
AstGen: implement size zero inferred length arrays
andrewrk Apr 21, 2021
a1ac2b9
AstGen: implement union decls
andrewrk Apr 21, 2021
d10ec6e
AstGen: slightly better eager-allocating heuristic
andrewrk Apr 21, 2021
4cfea2f
AstGen: fix `@floatCast` having wrong arity
andrewrk Apr 22, 2021
570ed7b
AstGen: implement `@bitCast` for other result location types
andrewrk Apr 22, 2021
8ee0cbe
AstGen: fix switch result location elision
andrewrk Apr 22, 2021
ea00ddf
AstGen: implement comptime locals
andrewrk Apr 22, 2021
3890200
AstGen: implement alignment on locals
andrewrk Apr 22, 2021
130ad08
AstGen: implement function prototypes
andrewrk Apr 22, 2021
3d637e6
AstGen: fix `@export`
andrewrk Apr 22, 2021
7c453b9
AstGen: implement `@extern` builtin
andrewrk Apr 22, 2021
507a809
std: fix compile errors caught by stage2 AstGen
andrewrk Apr 23, 2021
329a359
AstGen: implement align and linksection on globals
andrewrk Apr 23, 2021
8dd7378
delete packed enums from the language
andrewrk Apr 23, 2021
93d1c2d
std: fix compile errors caught by stage2 AstGen
andrewrk Apr 23, 2021
ce41ddc
std: fix potential bug in parseInt
g-w1 Apr 21, 2021
8df4bb7
stage2: fix builtin.zig for `zig test`
andrewrk Apr 23, 2021
a830ebe
ZIR: fix text printing of field_ptr_type
andrewrk Apr 23, 2021
2d290d6
stage2: write out builtin.zig before spawning AstGen tasks
andrewrk Apr 23, 2021
715abe8
AstGen: implement integers bigger than u64
andrewrk Apr 23, 2021
0262dda
std: remove `comptime const`
andrewrk Apr 23, 2021
183ee09
AstGen: compile error for unable to infer array size
andrewrk Apr 23, 2021
b40a8ef
stage2: implement `anyframe`, `anyframe->T` and fix assembly
andrewrk Apr 24, 2021
9a27134
AstGen: implement suspend blocks
andrewrk Apr 24, 2021
49be888
AstGen: implement nosuspend expressions
andrewrk Apr 24, 2021
fbfae83
AstGen: emit nosuspend function calls
andrewrk Apr 24, 2021
6b98384
stage2: remove dead ZIR instructions
andrewrk Apr 24, 2021
d2b06c2
stage2: remove call_none and call_none_chkused ZIR
andrewrk Apr 24, 2021
27fa4bc
AstGen: support struct init with ref result location
andrewrk Apr 24, 2021
224fbb2
stage2: better error reporting for LazySrcLoc.entire_file
andrewrk Apr 24, 2021
e86cee2
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk Apr 24, 2021
1592206
AstGen: implement await and resume
andrewrk Apr 24, 2021
15e8918
AstGen: parser ensures all suspend have blocks
andrewrk Apr 24, 2021
e018e64
stage2: move overflow builtin ZIR instructions to Extended
andrewrk Apr 25, 2021
ff2ec0d
AstGen: implement `@Vector`
andrewrk Apr 25, 2021
015cd79
stage2: implement caching for ZIR code
andrewrk Apr 25, 2021
5622644
stage2: pre-open ZIR cache dir handles
andrewrk Apr 25, 2021
646eb1f
AstGen: implement opaque decls
andrewrk Apr 26, 2021
91c317b
AstGen: improved handling of declarations
andrewrk Apr 27, 2021
bfded49
stage2: rewire the frontend driver to whole-file-zir
andrewrk Apr 27, 2021
3d9e4ed
link: fix compile error from previous commit
andrewrk Apr 27, 2021
eb9c29e
AstGen: fix function src hash not including body
andrewrk Apr 28, 2021
df24ce5
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk Apr 28, 2021
9db5b2c
AstGen: function prototypes can have alignment
andrewrk Apr 28, 2021
d3ffacb
AstGen: hook up hex float parsing to float literals
andrewrk Apr 28, 2021
c90e52b
std: remove redundant `comptime const`
andrewrk Apr 28, 2021
2354cba
stage2: implement #8364
g-w1 Apr 28, 2021
fa6bb4b
Sema: do not analyze test decls when not in test mode
andrewrk Apr 27, 2021
f86469b
stage2: semaDecl properly analyzes the decl block
andrewrk Apr 28, 2021
3462193
stage2: prepare for mainining Decl references to ZIR indexes
andrewrk Apr 28, 2021
0c71d2f
stage2: implement semantic analysis for functions and global vars
andrewrk Apr 29, 2021
c60d8f0
std: remove redundant comptime keyword
andrewrk Apr 29, 2021
d36a31b
stage2: fix scanDecls not advancing the field bits
andrewrk Apr 29, 2021
eb53680
tests: prepare behavior tests for stage2
andrewrk Apr 29, 2021
5a02c93
update behavior tests with respect to new builtin pkg
andrewrk Apr 29, 2021
4307436
move behavior tests from test/stage1/ to test/
andrewrk Apr 29, 2021
fb4cb43
std.enums: remove stuff for enums with field aliases
andrewrk Apr 29, 2021
55e86b7
AstGen: implement comptime struct fields
andrewrk Apr 29, 2021
9e49a65
AstGen: implement anytype struct fields
andrewrk Apr 30, 2021
478dac5
Sema: skip analysis of empty enum blocks
andrewrk Apr 30, 2021
47585cb
Sema: rename TZIR to AIR
andrewrk Apr 30, 2021
2eef83e
AstGen: fix comptime compile error source location
andrewrk Apr 30, 2021
ba9b9cb
AstGen: implement function prototypes with alignment exprs
andrewrk Apr 30, 2021
86d564e
AstGen: implement extern variables
andrewrk Apr 30, 2021
8944240
AstGen: represent global variables directly
andrewrk Apr 30, 2021
474ade8
std: fix compile errors found by stage2 AstGen
andrewrk Apr 30, 2021
8ab4a00
stage2: properly free Decl name
andrewrk Apr 30, 2021
5d696b0
stage2: fix File incorrectly freeing its Namespace
andrewrk Apr 30, 2021
2d8d681
stage2: un-tangle memory management of Decl and Namespace
andrewrk Apr 30, 2021
fb95fd8
start.zig: unconditionally import the root source file
andrewrk Apr 30, 2021
db7acd8
Sema: implement function declarations
andrewrk Apr 30, 2021
077b8d3
stage2: introduce new ZIR instruction: arg
andrewrk May 1, 2021
351b574
stage2: implement function body analysis
andrewrk May 1, 2021
dc28f5c
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk May 1, 2021
6248e2a
std.GeneralPurposeAllocator: print leaked memory addresses
andrewrk May 2, 2021
eadcefc
stage2: dbg_stmt ZIR instructions have line/col
andrewrk May 2, 2021
4dd724d
Sema: fix struct decl decoding ZIR incorrectly
andrewrk May 2, 2021
0611aa3
stage2: test decls encode that they are tests in ZIR
andrewrk May 2, 2021
d5f77c0
stage2: fix error reporting not loading AST
andrewrk May 2, 2021
a973c36
AstGen: decouple from Module/Compilation
andrewrk May 3, 2021
5f4c522
AstGen: fix outdated doc comment
andrewrk May 3, 2021
807a8b6
stage2: make struct field analysis lazy
andrewrk May 3, 2021
773902e
stage2: hook up semantic analysis of struct fields
andrewrk May 3, 2021
aa4e939
ZIR: implement debug text printing for struct_init and friends
andrewrk May 3, 2021
95b014c
Sema: implement struct_decl instruction
andrewrk May 4, 2021
69d18ad
ZIR: typeof uses the un_node field not un_tok
andrewrk May 4, 2021
2ae72c6
Sema: implement ExportOptions support in `@export`
andrewrk May 4, 2021
2910b10
build.zig: add -Dmem-leak-frames option
andrewrk May 4, 2021
3dafec0
stage2: fix structs and enums setting wrong owner_decl
andrewrk May 4, 2021
230ce72
stage2: fix "other symbol here" error note
andrewrk May 4, 2021
edfbf85
Sema: implement error sets
andrewrk May 4, 2021
1f0fd64
stage2: test coverage for inline asm return type not type
andrewrk May 4, 2021
7a27f0d
Sema: restore the extern lib name functionality
andrewrk May 4, 2021
fc40d23
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk May 5, 2021
6b5d0b3
std: fix compile errors found by stage2
andrewrk May 5, 2021
5d7f269
stage2: add `zig changelist` debug command
andrewrk May 5, 2021
c714a32
std.ArrayList: add clearRetainingCapacity and clearAndFree
andrewrk May 5, 2021
9b1aac8
stage2: mapping old to new ZIR recursively
andrewrk May 5, 2021
17067e0
stage2: fix contents hash computation
andrewrk May 6, 2021
426e4c7
std.ArrayHashMap: ensureUnusedCapacity and ensureTotalCapacity
andrewrk May 6, 2021
3791cd6
CLI: add 'run' command to the repl
andrewrk May 6, 2021
cdea22f
stage2: wire up outdated/deleted decl detection
andrewrk May 7, 2021
9b9ea40
CLI: add an update-and-run cmd and make enter re-run last cmd
andrewrk May 7, 2021
7dd33d4
stage2: fix compile errors in test harness
andrewrk May 7, 2021
3acd98f
stage2: CBE tests `pub export` instead of `export` main
andrewrk May 7, 2021
a7221ef
Sema: implement `@typeInfo` for functions
andrewrk May 7, 2021
47531b7
Sema: support enough to check main calling convention via `@typeInfo`
andrewrk May 7, 2021
6ac2047
stage2: implement extern functions
andrewrk May 7, 2021
e7c4d54
stage2: no '$' in anonymous decl names
andrewrk May 7, 2021
81d5104
stage2: implement global variables
andrewrk May 8, 2021
d577654
stage2: fix stack overflow in `@setEvalBranchQuota` test case
andrewrk May 8, 2021
f69cf93
std: start code increases stack size as appropriate on linux
andrewrk May 8, 2021
6ec24a6
std: start code on linux when -lc also expands stack size
andrewrk May 8, 2021
73bf530
ZIR: implement iteration over switch instructions
andrewrk May 8, 2021
28353b3
stage2: fix struct inits not getting fields resolved
andrewrk May 8, 2021
b6bb0ee
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk May 8, 2021
3d351c9
Type: fix abiAlignment calculation for unions
andrewrk May 8, 2021
b98a753
AstGen: fix incorrect logic for adding implicit return instruction
andrewrk May 8, 2021
aa0352f
Sema: fix `@setEvalBranchQuota` incorrectly requiring a function body
andrewrk May 8, 2021
5cd9afc
stage2: fully qualified names and better anonymous names
andrewrk May 8, 2021
5619ce2
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk May 8, 2021
6361d7a
stage2 test harness: report multiple failures
andrewrk May 8, 2021
9e72f31
stage1: ignore enum ContainerLayout for comptime memory purposes
andrewrk May 11, 2021
b9a099e
stage2: type declarations ZIR encode AnonNameStrategy
andrewrk May 11, 2021
dae22a0
stage2: struct, union, enum, opaque, error sets get better names
andrewrk May 11, 2021
bcf15e3
stage2: add `owns_tv` flag to `Module.Decl`
andrewrk May 11, 2021
fb39526
AstGen: support emitting multiple compile errors
andrewrk May 11, 2021
a74632b
C backend: fix emitting '$' in identifier names
andrewrk May 11, 2021
5d9fc11
stage2: update tests now that structs have fully qualified names
andrewrk May 11, 2021
cbbc7cc
stage2: better handling of file-level compile errors across updates
andrewrk May 12, 2021
7873e4f
stage2: lookupIdentifier can return error.AnalysisFailed
andrewrk May 12, 2021
d7567c0
Sema: implement duplicate enum tag compile error
andrewrk May 12, 2021
1ab1a96
stage2: improve Decl lifetime management
andrewrk May 12, 2021
71afc30
stage2: more Decl lifetime fixes
andrewrk May 12, 2021
c9cc09a
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk May 12, 2021
1ab3dff
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk May 13, 2021
417b5b1
std: fix redundant comptime keywords
andrewrk May 13, 2021
344dc0c
stage2: fix handling of "prev successful ZIR"
andrewrk May 13, 2021
a7aa3ca
stage2: build and provide libunwind when compiling for native libc
andrewrk May 13, 2021
c102e13
stage2: fix source location of Decl compile errors
andrewrk May 13, 2021
b109daa
stage2: fix test cases to add `pub` on exported _start fn
andrewrk May 13, 2021
e83cf6a
Sema: detect and skip over elided instructions
andrewrk May 13, 2021
7863289
AstGen: fix elision of store_to_block_ptr for condbr
andrewrk May 14, 2021
edab03b
link/MachO: fixes to debug symbols
andrewrk May 14, 2021
a854795
link: fix memory leak of system_libs
andrewrk May 14, 2021
2cee19a
CLI repl: "run" command handles cross compiled binaries
andrewrk May 14, 2021
5796948
Sema: remove compile error for comptime function calls
andrewrk May 14, 2021
134853f
stage2: fix tests expected values
andrewrk May 14, 2021
93896ef
std: dragonfly: fix duplicate definition of sockaddr_storage
andrewrk May 14, 2021
8344a50
AstGen: add compile error for decl name conflicts
andrewrk May 14, 2021
9958652
stage2: update test cases to improved source locations
andrewrk May 14, 2021
b4692c9
stage2: improve Decl dependency management
andrewrk May 15, 2021
5769ed2
stage2: compile log stores node offset
andrewrk May 15, 2021
dc036f5
codegen: implement const value rendering for ints <= 64 bits
andrewrk May 16, 2021
7cd94d2
stage2: omit Decl compile errors from failed AstGen files
andrewrk May 16, 2021
07606d1
stage2: remove SPU Mark II backend
andrewrk May 16, 2021
597082a
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk May 16, 2021
9a95478
cmake: remove deleted file
andrewrk May 16, 2021
ae04ec7
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk May 16, 2021
c8b7870
linker: update MachO DebugSymbols to use the new line/column Decl API
andrewrk May 16, 2021
f4ee46e
MachO/DebugSymbols: fix debug line offset
andrewrk May 16, 2021
751bb12
stage2: fix error message coloring
andrewrk May 16, 2021
d839835
stage2: add some debug logs for when link functions are called
andrewrk May 17, 2021
3697022
stage2: avoid calling freeDecl when hasCodeGenBits == false
andrewrk May 17, 2021
8405d6f
link/MachO: bring in some of the Elf logic
andrewrk May 17, 2021
23fd15f
link/Elf: remove unintended link again libunwind
andrewrk May 17, 2021
84fdeb4
compiler-rt: fix usage of builtin
andrewrk May 17, 2021
f41892f
std: `@import("builtin").StackTrace` -> `std.builtin.StackTrace`
andrewrk May 17, 2021
8cfa231
update langref, compile-error tests, safety tests
andrewrk May 17, 2021
8367707
std: update regarding std.builtin reorganization
andrewrk May 17, 2021
8a7a07f
stage2: test cases take advantage of `pub fn main` support
andrewrk May 17, 2021
ab6b0ad
test runner: prepare stage2 workaround
andrewrk May 17, 2021
d5e894a
stage2: get rid of failed_root_src_file
andrewrk May 17, 2021
3d99fb3
stage2: get rid of DeclRef
andrewrk May 17, 2021
731c35f
stage2: get rid of NameHash
andrewrk May 17, 2021
910f67f
behavior tests: re-enable commented out test
andrewrk May 17, 2021
98a28ec
remove separate issues from my branch todo file
andrewrk May 17, 2021
5cacc44
stage2: update `@import("builtin")` API usage
andrewrk May 18, 2021
67f5a28
Sema: use a hash map for ZIR->AIR mapping
andrewrk May 18, 2021
1d808d0
stage2: fix crash in switch compile error
andrewrk May 18, 2021
1d3f76b
stage2: skip recursion test on some hosts
andrewrk May 18, 2021
615d45d
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk May 18, 2021
93dbf30
std.fmt: fix regressions from master
andrewrk May 18, 2021
4187008
std: update freebsd bits to new builtin
andrewrk May 18, 2021
ab8f846
stage2: fix deletion of Decls that get re-referenced
andrewrk May 18, 2021
a9cd9b0
Merge remote-tracking branch 'origin/master' into stage2-whole-file-a…
andrewrk May 18, 2021
2c12f5f
stage2 tests: fix missing 'pub' in one of the test cases
andrewrk May 18, 2021
6672366
build.zig: blank out "*test.zig" files instead of omit
andrewrk May 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/codegen/llvm.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/llvm/bindings.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/riscv64.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/spu-mk2.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/wasm.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/x86_64.zig"
"${CMAKE_SOURCE_DIR}/src/glibc.zig"
Expand Down Expand Up @@ -595,7 +594,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/type.zig"
"${CMAKE_SOURCE_DIR}/src/value.zig"
"${CMAKE_SOURCE_DIR}/src/windows_sdk.zig"
"${CMAKE_SOURCE_DIR}/src/zir.zig"
"${CMAKE_SOURCE_DIR}/src/Zir.zig"
"${CMAKE_SOURCE_DIR}/src/Sema.zig"
)

Expand Down
43 changes: 28 additions & 15 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const builtin = @import("builtin");
const std = @import("std");
const builtin = std.builtin;
const Builder = std.build.Builder;
const tests = @import("test/tests.zig");
const BufMap = std.BufMap;
Expand Down Expand Up @@ -54,6 +54,7 @@ pub fn build(b: *Builder) !void {
const skip_compile_errors = b.option(bool, "skip-compile-errors", "Main test suite skips compile error tests") orelse false;
const skip_run_translated_c = b.option(bool, "skip-run-translated-c", "Main test suite skips run-translated-c tests") orelse false;
const skip_stage2_tests = b.option(bool, "skip-stage2-tests", "Main test suite skips self-hosted compiler tests") orelse false;
const skip_install_lib_files = b.option(bool, "skip-install-lib-files", "Do not copy lib/ files to installation prefix") orelse false;

const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
const is_stage1 = b.option(bool, "stage1", "Build the stage1 compiler, put stage2 behind a feature flag") orelse false;
Expand All @@ -62,19 +63,23 @@ pub fn build(b: *Builder) !void {
const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm);
const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h");

b.installDirectory(InstallDirectoryOptions{
.source_dir = "lib",
.install_dir = .Lib,
.install_subdir = "zig",
.exclude_extensions = &[_][]const u8{
"test.zig",
"README.md",
".z.0",
".z.9",
".gz",
"rfc1951.txt",
},
});
if (!skip_install_lib_files) {
b.installDirectory(InstallDirectoryOptions{
.source_dir = "lib",
.install_dir = .Lib,
.install_subdir = "zig",
.exclude_extensions = &[_][]const u8{
"README.md",
".z.0",
".z.9",
".gz",
"rfc1951.txt",
},
.blank_extensions = &[_][]const u8{
"test.zig",
},
});
}

if (only_install_lib_files)
return;
Expand All @@ -83,6 +88,12 @@ pub fn build(b: *Builder) !void {
const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;
const strip = b.option(bool, "strip", "Omit debug information") orelse false;

const mem_leak_frames: u32 = b.option(u32, "mem-leak-frames", "How many stack frames to print when a memory leak occurs. Tests get 2x this amount.") orelse blk: {
if (strip) break :blk @as(u32, 0);
if (mode != .Debug) break :blk 0;
break :blk 4;
};

const main_file = if (is_stage1) "src/stage1.zig" else "src/main.zig";

var exe = b.addExecutable("zig", main_file);
Expand All @@ -93,6 +104,7 @@ pub fn build(b: *Builder) !void {
toolchain_step.dependOn(&exe.step);
b.default_step.dependOn(&exe.step);

exe.addBuildOption(u32, "mem_leak_frames", mem_leak_frames);
exe.addBuildOption(bool, "skip_non_native", skip_non_native);
exe.addBuildOption(bool, "have_llvm", enable_llvm);
if (enable_llvm) {
Expand Down Expand Up @@ -228,6 +240,7 @@ pub fn build(b: *Builder) !void {
test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);
test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);
test_stage2.addBuildOption(bool, "enable_wasmtime", is_wasmtime_enabled);
test_stage2.addBuildOption(u32, "mem_leak_frames", mem_leak_frames * 2);
test_stage2.addBuildOption(bool, "enable_darling", is_darling_enabled);
test_stage2.addBuildOption(?[]const u8, "glibc_multi_install_dir", glibc_multi_dir);
test_stage2.addBuildOption([]const u8, "version", version);
Expand Down Expand Up @@ -266,7 +279,7 @@ pub fn build(b: *Builder) !void {
toolchain_step.dependOn(tests.addPkgTests(
b,
test_filter,
"test/stage1/behavior.zig",
"test/behavior.zig",
"behavior",
"Run the behavior tests",
modes,
Expand Down
52 changes: 16 additions & 36 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,6 @@ const nan = std.math.nan(f128);
{#code_release_fast#}
{#code_disable_cache#}
const std = @import("std");
const builtin = std.builtin;
const big = @as(f64, 1 << 40);

export fn foo_strict(x: f64) f64 {
Expand Down Expand Up @@ -2589,7 +2588,7 @@ test "default struct initialization fields" {
exactly their bit width.
</li>
<li>{#syntax#}bool{#endsyntax#} fields use exactly 1 bit.</li>
<li>A {#link|packed enum#} field uses exactly the bit width of its integer tag type.</li>
<li>An {#link|enum#} field uses exactly the bit width of its integer tag type.</li>
<li>A {#link|packed union#} field uses exactly the bit width of the union field with
the largest bit width.</li>
<li>Non-ABI-aligned fields are packed into the smallest possible
Expand All @@ -2603,7 +2602,7 @@ test "default struct initialization fields" {
</p>
{#code_begin|test#}
const std = @import("std");
const builtin = std.builtin;
const native_endian = @import("builtin").target.cpu.arch.endian();
const expect = std.testing.expect;

const Full = packed struct {
Expand All @@ -2625,7 +2624,7 @@ fn doTheTest() !void {
try expect(@sizeOf(Divided) == 2);
var full = Full{ .number = 0x1234 };
var divided = @bitCast(Divided, full);
switch (builtin.endian) {
switch (native_endian) {
.Big => {
try expect(divided.half1 == 0x12);
try expect(divided.quarter3 == 0x3);
Expand Down Expand Up @@ -3015,25 +3014,6 @@ export fn entry(foo: Foo) void { }
{#code_end#}
{#header_close#}

{#header_open|packed enum#}
<p>By default, the size of enums is not guaranteed.</p>
<p>{#syntax#}packed enum{#endsyntax#} causes the size of the enum to be the same as the size of the
integer tag type of the enum:</p>
{#code_begin|test#}
const std = @import("std");

test "packed enum" {
const Number = packed enum(u8) {
one,
two,
three,
};
try std.testing.expect(@sizeOf(Number) == @sizeOf(u8));
}
{#code_end#}
<p>This makes the enum eligible to be in a {#link|packed struct#}.</p>
{#header_close#}

{#header_open|Enum Literals#}
<p>
Enum literals allow specifying the name of an enum field without specifying the enum type:
Expand Down Expand Up @@ -4255,7 +4235,7 @@ test "noreturn" {
<p>Another use case for {#syntax#}noreturn{#endsyntax#} is the {#syntax#}exit{#endsyntax#} function:</p>
{#code_begin|test#}
{#target_windows#}
pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(if (@import("builtin").arch == .i386) .Stdcall else .C) noreturn;
pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(if (@import("builtin").target.cpu.arch == .i386) .Stdcall else .C) noreturn;

test "foo" {
const value = bar() catch ExitProcess(1);
Expand Down Expand Up @@ -4290,7 +4270,7 @@ export fn sub(a: i8, b: i8) i8 { return a - b; }
// at link time, when linking statically, or at runtime, when linking
// dynamically.
// The callconv specifier changes the calling convention of the function.
extern "kernel32" fn ExitProcess(exit_code: u32) callconv(if (@import("builtin").arch == .i386) .Stdcall else .C) noreturn;
extern "kernel32" fn ExitProcess(exit_code: u32) callconv(if (@import("builtin").target.cpu.arch == .i386) .Stdcall else .C) noreturn;
extern "c" fn atan2(a: f64, b: f64) f64;

// The @setCold builtin tells the optimizer that a function is rarely called.
Expand Down Expand Up @@ -7596,7 +7576,7 @@ export fn @"A function name that is a complete sentence."() void {}
The {#syntax#}fence{#endsyntax#} function is used to introduce happens-before edges between operations.
</p>
<p>
{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.
{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.
</p>
{#see_also|Compile Variables#}
{#header_close#}
Expand Down Expand Up @@ -7799,8 +7779,8 @@ test "@hasDecl" {
</p>
<ul>
<li>{#syntax#}@import("std"){#endsyntax#} - Zig Standard Library</li>
<li>{#syntax#}@import("builtin"){#endsyntax#} - Compiler-provided types and variables.
The command <code>zig builtin</code> outputs the source to stdout for reference.
<li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information
The command <code>zig build-exe --show-builtin</code> outputs the source to stdout for reference.
</li>
</ul>
{#see_also|Compile Variables|@embedFile#}
Expand Down Expand Up @@ -7931,11 +7911,11 @@ mem.set(u8, dest, c);{#endsyntax#}</pre>
</p>
{#code_begin|test#}
const std = @import("std");
const builtin = @import("builtin");
const native_arch = @import("builtin").target.cpu.arch;
const expect = std.testing.expect;

test "@wasmMemoryGrow" {
if (builtin.arch != .wasm32) return error.SkipZigTest;
if (native_arch != .wasm32) return error.SkipZigTest;

var prev = @wasmMemorySize(0);
try expect(prev == @wasmMemoryGrow(0, 1));
Expand Down Expand Up @@ -8103,7 +8083,7 @@ test "foo" {
{#header_close#}

{#header_open|@setFloatMode#}
<pre>{#syntax#}@setFloatMode(mode: @import("builtin").FloatMode){#endsyntax#}</pre>
<pre>{#syntax#}@setFloatMode(mode: @import("std").builtin.FloatMode){#endsyntax#}</pre>
<p>
Sets the floating point mode of the current scope. Possible values are:
</p>
Expand Down Expand Up @@ -8292,7 +8272,7 @@ test "vector @splat" {
{#header_close#}

{#header_open|@reduce#}
<pre>{#syntax#}@reduce(comptime op: builtin.ReduceOp, value: anytype) std.meta.Child(value){#endsyntax#}</pre>
<pre>{#syntax#}@reduce(comptime op: std.builtin.ReduceOp, value: anytype) std.meta.Child(value){#endsyntax#}</pre>
<p>
Transforms a {#link|vector|Vectors#} into a scalar value by performing a
sequential horizontal reduction of its elements using the specified operator {#syntax#}op{#endsyntax#}.
Expand Down Expand Up @@ -8584,7 +8564,7 @@ test "integer truncation" {
{#header_close#}

{#header_open|@Type#}
<pre>{#syntax#}@Type(comptime info: @import("builtin").TypeInfo) type{#endsyntax#}</pre>
<pre>{#syntax#}@Type(comptime info: std.builtin.TypeInfo) type{#endsyntax#}</pre>
<p>
This function is the inverse of {#link|@typeInfo#}. It reifies type information
into a {#syntax#}type{#endsyntax#}.
Expand Down Expand Up @@ -8626,7 +8606,7 @@ test "integer truncation" {
</ul>
{#header_close#}
{#header_open|@typeInfo#}
<pre>{#syntax#}@typeInfo(comptime T: type) @import("std").builtin.TypeInfo{#endsyntax#}</pre>
<pre>{#syntax#}@typeInfo(comptime T: type) std.builtin.TypeInfo{#endsyntax#}</pre>
<p>
Provides type reflection.
</p>
Expand Down Expand Up @@ -9647,7 +9627,7 @@ test "string literal to constant slice" {
</p>
{#code_begin|syntax#}
const builtin = @import("builtin");
const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
const separator = if (builtin.os.tag == builtin.Os.windows) '\\' else '/';
{#code_end#}
<p>
Example of what is imported with {#syntax#}@import("builtin"){#endsyntax#}:
Expand All @@ -9672,7 +9652,7 @@ const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
</p>
{#code_begin|test|detect_test#}
const std = @import("std");
const builtin = std.builtin;
const builtin = @import("builtin");
const expect = std.testing.expect;

test "builtin.is_test" {
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Thread/AutoResetEvent.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
state: usize = UNSET,

const std = @import("../std.zig");
const builtin = @import("builtin");
const builtin = std.builtin;
const testing = std.testing;
const assert = std.debug.assert;
const StaticResetEvent = std.Thread.StaticResetEvent;
Expand Down
4 changes: 2 additions & 2 deletions lib/std/Thread/StaticResetEvent.zig
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ pub const AtomicEvent = struct {
while (true) {
if (waiting == WAKE) {
rc = windows.ntdll.NtWaitForKeyedEvent(handle, key, windows.FALSE, null);
assert(rc == .WAIT_0);
assert(rc == windows.NTSTATUS.WAIT_0);
break;
} else {
waiting = @cmpxchgWeak(u32, waiters, waiting, waiting - WAIT, .Acquire, .Monotonic) orelse break;
Expand All @@ -271,7 +271,7 @@ pub const AtomicEvent = struct {
}
return error.TimedOut;
},
.WAIT_0 => {},
windows.NTSTATUS.WAIT_0 => {},
else => unreachable,
}
}
Expand Down
36 changes: 30 additions & 6 deletions lib/std/array_hash_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const trait = meta.trait;
const autoHash = std.hash.autoHash;
const Wyhash = std.hash.Wyhash;
const Allocator = mem.Allocator;
const builtin = @import("builtin");
const builtin = std.builtin;
const hash_map = @This();

pub fn AutoArrayHashMap(comptime K: type, comptime V: type) type {
Expand Down Expand Up @@ -158,10 +158,20 @@ pub fn ArrayHashMap(
return self.unmanaged.getOrPutValue(self.allocator, key, value);
}

/// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
pub const ensureCapacity = ensureTotalCapacity;

/// Increases capacity, guaranteeing that insertions up until the
/// `expected_count` will not cause an allocation, and therefore cannot fail.
pub fn ensureCapacity(self: *Self, new_capacity: usize) !void {
return self.unmanaged.ensureCapacity(self.allocator, new_capacity);
pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void {
return self.unmanaged.ensureTotalCapacity(self.allocator, new_capacity);
}

/// Increases capacity, guaranteeing that insertions up until
/// `additional_count` **more** items will not cause an allocation, and
/// therefore cannot fail.
pub fn ensureUnusedCapacity(self: *Self, additional_count: usize) !void {
return self.unmanaged.ensureUnusedCapacity(self.allocator, additional_count);
}

/// Returns the number of total elements which may be present before it is
Expand Down Expand Up @@ -472,10 +482,13 @@ pub fn ArrayHashMapUnmanaged(
return res.entry;
}

/// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
pub const ensureCapacity = ensureTotalCapacity;

/// Increases capacity, guaranteeing that insertions up until the
/// `expected_count` will not cause an allocation, and therefore cannot fail.
pub fn ensureCapacity(self: *Self, allocator: *Allocator, new_capacity: usize) !void {
try self.entries.ensureCapacity(allocator, new_capacity);
pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_capacity: usize) !void {
try self.entries.ensureTotalCapacity(allocator, new_capacity);
if (new_capacity <= linear_scan_max) return;

// Ensure that the indexes will be at most 60% full if
Expand All @@ -501,6 +514,17 @@ pub fn ArrayHashMapUnmanaged(
}
}

/// Increases capacity, guaranteeing that insertions up until
/// `additional_count` **more** items will not cause an allocation, and
/// therefore cannot fail.
pub fn ensureUnusedCapacity(
self: *Self,
allocator: *Allocator,
additional_capacity: usize,
) !void {
return self.ensureTotalCapacity(allocator, self.count() + additional_capacity);
}

/// Returns the number of total elements which may be present before it is
/// no longer guaranteed that no allocations will be performed.
pub fn capacity(self: Self) usize {
Expand Down Expand Up @@ -1310,7 +1334,7 @@ test "reIndex" {
}

test "fromOwnedArrayList" {
comptime const array_hash_map_type = AutoArrayHashMap(i32, i32);
const array_hash_map_type = AutoArrayHashMap(i32, i32);
var al = std.ArrayListUnmanaged(array_hash_map_type.Entry){};
const hash = getAutoHashFn(i32);

Expand Down
Loading