aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
AgeCommit message (Collapse)Author
2021-07-20stage2: separate work queue item for functions than declsAndrew Kelley
Previously we had codegen_decl for both constant values as well as function bodies. A recent commit updated the linker backends to add updateFunc as a separate function than updateDecl, and now this commit does the same with work queue tasks. The frontend now distinguishes between function pointers and function bodies.
2021-07-20Sema: reimplement runtime switchAndrew Kelley
Now supports multiple items pointing to the same body. This is a common pattern even when using a jump table, with multiple cases pointing to the same block of code. In the case of a range specified, the items are moved to branches in the else body. A future improvement may make it possible to have jump table items as well as ranges pointing to the same block of code.
2021-07-20stage2: codegen.zig updated to new AIR memory layoutAndrew Kelley
2021-07-20stage2: first pass at printing AIR/Liveness to textAndrew Kelley
* some instructions are not implemented yet * fix off-by-1 in Air.getMainBody * Compilation: use `@import("builtin")` rather than `std.builtin` for the values that are different for different build configurations. * Sema: avoid calling `addType` in between air_instructions.ensureUnusedCapacity and corresponding appendAssumeCapacity because it can possibly add an instruction. * Value: functions print their names
2021-07-20Sema: AIR memory layout reworking for noreturn instructionsAndrew Kelley
2021-07-20Sema: remove br_block_flat AIR instructionAndrew Kelley
Thanks to the new AIR memory layout, we can do this by turning a br operand into a block, rather than having this special purpose instruction.
2021-07-20Sema: more AIR memory layout reworking progressAndrew Kelley
Additionally: ZIR encoding for floats now supports float literals up to f64, not only f32. This is because we no longer need a source location for this instruction.
2021-07-20Sema: add a strategy for handling costly source locationsAndrew Kelley
Now you can pass `.unneeded` for a `LazySrcLoc` and if there ended up being a compile error that needed it, you'll get `error.NeededSourceLocation`. Callsites can now exploit this error to do the expensive computation to produce a source location object and then repeat the operation.
2021-07-20Sema: first pass reworking for AIR memory layoutAndrew Kelley
2021-07-20stage2: compile error fixes for AIR memory layout branchAndrew Kelley
Now the branch is compiling again, provided that one uses `-Dskip-non-native`, but many code paths are disabled. The code paths can now be re-enabled one at a time and updated to conform to the new AIR memory layout.
2021-07-20stage2: Air and Liveness are passed ephemerallyAndrew Kelley
to the link infrastructure, instead of being stored with Module.Fn. This moves towards a strategy to make more efficient use of memory by not storing Air or Liveness data in the Fn struct, but computing it on demand, immediately sending it to the backend, and then immediately freeing it. Backends which want to defer codegen until flush() such as SPIR-V must move the Air/Liveness data upon `updateFunc` being called and keep track of that data in the backend implementation itself.
2021-07-20stage2: first pass over Module.zig for AIR memory layoutAndrew Kelley
2021-07-20stage2: update Liveness, SPIR-V for new AIR memory layoutAndrew Kelley
also do the inline assembly instruction
2021-07-20stage2: rework AIR memory layoutAndrew Kelley
This commit changes the AIR file and the documentation of the memory layout. The actual work of modifying the surrounding code (in Sema and codegen) is not yet done.
2021-07-08plan9 linker: make runnable binariesJacob G-W
We can now run binaries! (they segfault, but still run!)
2021-07-08initial plan9 boilerplatejacob gw
The code now compiles and fails with Plan9ObjectFormatUnimplemented
2021-07-07stage2: basic inferred error set supportAndrew Kelley
* Inferred error sets are stored in the return Type of the function, owned by the Module.Fn. So it cleans up that memory in deinit(). * Sema: update the inferred error set in zirRetErrValue - Update relevant code in wrapErrorUnion * C backend: improve some some instructions to take advantage of liveness analysis to avoid being emitted when unused. * C backend: when an error union has a payload type with no runtime bits, emit the error union as the same type as the error set.
2021-07-07stage2: implement `@panic` and beginnigs of inferred error setsAndrew Kelley
* ZIR: add two instructions: - ret_err_value_code - ret_err_value * AstGen: add countDefers and utilize it to emit more efficient ZIR for return expressions in the presence of defers. * AstGen: implement |err| payloads for `errdefer` syntax. - There is not an "unused capture" error for it yet. * AstGen: `return error.Foo` syntax gets a hot path in return expressions, using the new ZIR instructions. This also is part of implementing inferred error sets, since we need to tell Sema to add an error value to the inferred error set before it gets coerced. * Sema: implement `@setCold`. - Implement `@setCold` support for C backend. * `@panic` and regular safety panics such as `unreachable` now properly invoke `std.builtin.panic`. * C backend: improve pointer and function value rendering. * C linker: fix redundant typedefs. * Add Type.error_set_inferred. * Fix Value.format for enum_literal, enum_field_index, bytes. * Remove the C backend test that checks for identical text I measured a 14% reduction in Total ZIR Bytes from master branch for std/os.zig.
2021-07-03stage2: add the zig version to AstGen cache hashAndrew Kelley
This solves the problem of different versions of Zig having different binary representations of ZIR code. closes #9290
2021-07-02stage2: improve AstGen FileNotFound error messageAndrew Kelley
Partially addresses #9203. It fixes the first case, but not the second one mentioned in the issue.
2021-07-02tokenizer: clean up invalid token errorAndrew Kelley
It now displays the byte with proper printability handling. This makes the relevant compile error test case no longer a regression in quality from stage1 to stage2.
2021-07-02stage2: improve compile errors from tokenizerAndrew Kelley
In order to not regress the quality of compile errors, some improvements had to be made. * std.zig.parseCharLiteral is improved to return more detailed parse failure information. * tokenizer is improved to handle null bytes in the middle of strings, character literals, and line comments. * validating how many unicode escape digits in string literals is moved to std.zig.parseStringLiteral rather than handled in the tokenizer. * when a tokenizer error occurs, if the reported token is the 'invalid' tag, an error note is added to point to the invalid byte location. Further improvements would be: - Mention the expected set of allowed bytes at this location. - Display the invalid byte (if printable, print it, otherwise escape-print it).
2021-07-02stage2: print valid filename in error messagesJ.C. Moyer
2021-06-27Revert "Include package root dir in stage2 error messages"Andrew Kelley
This reverts commit 15a030ef3d2d68992835568f2fb9d5deab18f39f. ast-check started crashing after this commit. Needs more QA before merging.
2021-06-27Include package root dir in stage2 error messagesJ.C. Moyer
2021-06-25stage2: implement @setRuntimeSafetyJacob G-W
2021-06-23stage2: slightly improve error reporting for missing importsAndrew Kelley
There is now a distinction between `@import` with a .zig extension and without. Without a .zig extension it assumes it is a package name, and returns error.PackageNotFound if not mapped into the package table.
2021-06-21stage2: remove unused parameter from importPkgAndrew Kelley
2021-06-21stage2: wire up AstGen to the progress barAndrew Kelley
2021-06-21fix code broken from previous commitJacob G-W
2021-06-21std, src, doc, test: remove unused variablesJacob G-W
2021-06-07stage2: implement comptime variablesVeikka Tuominen
2021-06-03Breaking hash map changes for 0.8.0Martin Wickham
- hash/eql functions moved into a Context object - *Context functions pass an explicit context - *Adapted functions pass specialized keys and contexts - new getPtr() function returns a pointer to value - remove functions renamed to fetchRemove - new remove functions return bool - removeAssertDiscard deleted, use assert(remove(...)) instead - Keys and values are stored in separate arrays - Entry is now {*K, *V}, the new KV is {K, V} - BufSet/BufMap functions renamed to match other set/map types - fixed iterating-while-modifying bug in src/link/C.zig
2021-05-25Re-enable building the self-hosted compiler for 32-bit targetsjoachimschmidt557
2021-05-22stage2: rename ir.zig to air.zigAndrew Kelley
We've settled on the nomenclature for the artifacts the compiler pipeline produces: 1. Tokens 2. AST (Abstract Syntax Tree) 3. ZIR (Zig Intermediate Representation) 4. AIR (Analyzed Intermediate Representation) 5. Machine Code Renaming `ir` identifiers to `air` will come with the inevitable air-memory-layout branch that I plan to start after the 0.8.0 release.
2021-05-18stage2: fix deletion of Decls that get re-referencedAndrew Kelley
When scanDecls happens, we create stub Decl objects that have not been semantically analyzed. When they get referenced, they get semantically analyzed. Before this commit, when they got unreferenced, they were completely deleted, including deleted from the containing Namespace. However, if the update did not cause the containing Namespace to get deleted, for example, if `std.builtin.ExportOptions` is no longer referenced, but `std.builtin` is still referenced, and then `ExportOptions` gets referenced again, the Namespace would be incorrectly missing the Decl, so we get an incorrect "no such member" error. The solution is to, when dealing with a no longer referenced Decl objects during an update, clear them to the state they would be in on a fresh scanDecl, rather than completely deleting them.
2021-05-17Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
Conflicts: * src/codegen/spirv.zig * src/link/SpirV.zig We're going to want to improve the stage2 test harness to print the source file name when a compile error occurs otherwise std lib contributors are going to see some confusing CI failures when they cause stage2 AstGen compile errors.
2021-05-17stage2: fix crash in switch compile errorAndrew Kelley
when the AST for the switch has never been loaded
2021-05-17Sema: use a hash map for ZIR->AIR mappingAndrew Kelley
Previously, ZIR was per-function so we could simply allocate a slice for all ZIR instructions. However now ZIR is whole-file, so we need a sparse mapping of ZIR to AIR instructions in order to not waste memory.
2021-05-17stage2: get rid of NameHashAndrew Kelley
Previously, stage2 used a global decl_table for all Decl objects, keyed by a 16-byte name hash that was hopefully unique. Now, there is a tree of Namespace objects that own their named Decl objects.
2021-05-17stage2: get rid of DeclRefAndrew Kelley
2021-05-17stage2: get rid of failed_root_src_fileAndrew Kelley
2021-05-17stage2: avoid calling freeDecl when hasCodeGenBits == falseAndrew Kelley
Previously the frontend incorrectly called freeDecl for structs, which never got allocateDecl called for them. There was simply a missing check for hasCodeGenBits().
2021-05-15stage2: omit Decl compile errors from failed AstGen filesAndrew Kelley
Just like when new parse errors occur during an update, when new AstGen errors occur during an update, we do not reveal compile errors for Decl objects which are inside of a newly failed File. Once the File passes AstGen successfully, it will be compared with the previously succeeded ZIR and the saved Decl compile errors will be handled properly.
2021-05-14stage2: compile log stores node offsetAndrew Kelley
Previously, compile log stored full SrcLoc info, which included absolute AST node index. This becomes invalid after an incremental compilation. To make it survive incremental compilation, store an offset from parent Decl instead.
2021-05-14stage2: improve Decl dependency managementAndrew Kelley
* Do not report export collision errors until the very end, because it is possible, during an update, for a new export to be added before an old one is semantically analyzed to be deleted. In such a case there should be no compile error. - Likewise we defer emitting exports until the end when we know for sure what will happen. * Sema: Fix not adding a Decl dependency on imported files. * Sema: Properly add Decl dependencies for all identifier and namespace lookups. * After semantic analysis for a Decl, if it is still marked as `in_progress`, change it to `dependency_failure` because if the Decl itself failed, it would have already been changed during the call to add the compile error.
2021-05-12stage2: fix source location of Decl compile errorsAndrew Kelley
In `Module.semaDecl`, the source location being used was double-relative to the `Decl`, causing a crash when trying to compute byte offset for the compile error. Change the source location to node_offset = 0 since the scope being used makes the source location relative to the Decl, which already has the source node index populated.
2021-05-12stage2: fix handling of "prev successful ZIR"Andrew Kelley
Before this change, the attempt to save the most recent successful ZIR code only worked in some cases; this reworks the code to be more robust, thereby fixing a crash when running the stage2 "enums" CBE test cases.
2021-05-12Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
Conflicts: * lib/std/os/linux.zig * lib/std/os/windows/bits.zig * src/Module.zig * src/Sema.zig * test/stage2/test.zig Mainly I wanted Jakub's new macOS code for respecting stack size, since we now depend on it for debug builds able to pass one of the test cases for recursive comptime function calls with `@setEvalBranchQuota`. The conflicts were all trivial.
2021-05-11stage2: more Decl lifetime fixesAndrew Kelley
* File stores `root_decl: Decl` instead of `namespace: *Namespace`. This maps more cleanly to the actual ownership, since the `File` does own the root decl, but it does not directly own the `Namespace`. * `semaFile` completes the creation of the `Decl` even when semantic analysis fails. The `analysis` field of the `Decl` will contain the results of semantic analysis. This prevents cleaning up of memory still referenced by other Decl objects. * `semaDecl` sets `Struct.zir_index` of the root struct decl, which fixes use of undefined value in case the first update contained a ZIR compile error.