aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
AgeCommit message (Collapse)Author
2023-06-10stage2: add a few more Value checks for InternPoolAndrew Kelley
2023-06-10stage2: move undef, unreach, null values to InternPoolAndrew Kelley
2023-06-10stage2: move many Type encodings to InternPoolAndrew Kelley
Notably, `vector`. Additionally, all alternate encodings of `pointer`, `optional`, and `array`.
2023-06-10stage2: move most simple values to InternPoolAndrew Kelley
2023-06-10stage2: move most simple types to InternPoolAndrew Kelley
2023-06-10stage2: isGenericPoison InternPool awarenessAndrew Kelley
2023-06-10stage2: add `interned` AIR tagAndrew Kelley
This required additionally passing the `InternPool` into some AIR methods. Also, implement `Type.isNoReturn` for interned types.
2023-06-10stage2: start the InternPool transitionAndrew Kelley
Instead of doing everything at once which is a hopelessly large task, this introduces a piecemeal transition that can be done in small increments at a time. This is a minimal changeset that keeps the compiler compiling. It only uses the InternPool for a small set of types. Behavior tests are not passing. Air.Inst.Ref and Zir.Inst.Ref are separated into different enums but compile-time verified to have the same fields in the same order. The large set of changes is mainly to deal with the fact that most Type and Value methods now require a Module to be passed in, so that the InternPool object can be accessed.
2023-05-31don't crash when can't evaluate comptime expression with inferred typeyujiri8
Closes #15911.
2023-05-29Prevent analysis of functions only referenced at comptimemlugg
The idea here is that there are two ways we can reference a function at runtime: * Through a direct call, i.e. where the function is comptime-known * Through a function pointer This means we can easily perform a form of rudimentary escape analysis on functions. If we ever see a `decl_ref` or `ref` of a function, we have a function pointer, which could "leak" into runtime code, so we emit the function; but for a plain `decl_val`, there's no need to. This change means that `comptime { _ = f; }` no longer forces a function to be emitted, which was used for some things (mainly tests). These use sites have been replaced with `_ = &f;`, which still triggers analysis of the function body, since you're taking a pointer to the function. Resolves: #6256 Resolves: #15353
2023-05-25std.fs.file: Rename File.Lock enum values to snake caseLinus Groh
2023-05-20Zir: eliminate `field_call_bind` and `field_call_bind_named`mlugg
This commit removes the `field_call_bind` and `field_call_bind_named` ZIR instructions, replacing them with a `field_call` instruction which does the bind and call in one. `field_call_bind` is an unfortunate instruction. It's tied into one very specific usage pattern - its result can only be used as a callee. This means that it creates a value of a "pseudo-type" of sorts, `bound_fn` - this type used to exist in Zig, but now we just hide it from the user and have AstGen ensure it's only used in one way. This is quite silly - `Type` and `Value` should, as much as possible, reflect real Zig types and values. It makes sense to instead encode the `a.b()` syntax as its own ZIR instruction, so that's what we do here. This commit introduces a new instruction, `field_call`. It's like `call`, but rather than a callee ref, it contains a ref to the object pointer (`&a` in `a.b()`) and the string field name (`b`). This eliminates `bound_fn` from the language, and slightly decreases the size of generated ZIR - stats below. This commit does remove a few usages which used to be allowed: - `@field(a, "b")()` - `@call(.auto, a.b, .{})` - `@call(.auto, @field(a, "b"), .{})` These forms used to work just like `a.b()`, but are no longer allowed. I believe this is the correct choice for a few reasons: - `a.b()` is a purely *syntactic* form; for instance, `(a.b)()` is not valid. This means it is *not* inconsistent to not allow it in these cases; the special case here isn't "a field access as a callee", but rather this exact syntactic form. - The second argument to `@call` looks much more visually distinct from the callee in standard call syntax. To me, this makes it seem strange for that argument to not work like a normal expression in this context. - A more practical argument: it's confusing! `@field` and `@call` are used in very different contexts to standard function calls: the former normally hints at some comptime machinery, and the latter that you want more precise control over parts of a function call. In these contexts, you don't want implicit arguments adding extra confusion: you want to be very explicit about what you're doing. Lastly, some stats. I mentioned before that this change slightly reduces the size of ZIR - this is due to two instructions (`field_call_bind` then `call`) being replaced with one (`field_call`). Here are some numbers: +--------------+----------+----------+--------+ | File | Before | After | Change | +--------------+----------+----------+--------+ | Sema.zig | 4.72M | 4.53M | -4% | | AstGen.zig | 1.52M | 1.48M | -3% | | hash_map.zig | 283.9K | 276.2K | -3% | | math.zig | 312.6K | 305.3K | -2% | +--------------+----------+----------+--------+
2023-05-18Sema: simplify "duplicate test name" error messageAndrew Kelley
* Avoid redundant words ("found") - All compile errors are found by the compiler * Avoid unnecessary prepositions ("with") - There is a grammatically correct alternate word order without the preposition.
2023-05-11fix incorrect use of mutable pointers to temporary valuesVeikka Tuominen
2023-05-11module: return null if no candidate srcJohn Schmidt
Closes #15572.
2023-05-08Disallow named test decls with duplicate namesDominic
2023-05-05main: add debug dump-zir commandJacob Young
2023-04-27sema: add `prev` to ValueArena to allow freeing previous arenas when new ↵kcbanner
ones are created during re-analysis In semaDecl, it was possible for a new ArenaAllocators state to replace an existing one that hadn't been freed yet. Instead of the ref_count (which was made redundant by adding the allocator parameter to `release`), I now store a pointer to the previous arena, if one exists. This allows a recursive deinit to happen when the last arena created is destroyed.
2023-04-27sema: Rework Decl.value_arena to fix another memory corruption issuekcbanner
This fixes a bug where resolveStructLayout to was promoting from stale value_arena state which was then overwrriten when another ArenaAllocator higher in the call stack saved its state back. This resulted in the memory for struct_obj.optmized_order overlapping existing allocations. My initial fix in c7067ef wasn't sufficient, as it only checked if the struct being resolved had the same owner as the current sema instance. However, it's possible for resolveStructLayout to be called when the sema instance has a different owner, but the struct decl's value_arena is currently in use higher up in the callstack. This change introduces ValueArena, which holds the arena state as well as tracks if an arena has already been promoted from it. This allows callers to use the value_arena storage without needing to be aware of another user of this same storage higher up in the call stack.
2023-04-26enable debugging infrastructure when using C backendAndrew Kelley
Thanks to @jacobly0's recent enhancements to the C backend, this stuff works now.
2023-04-25cbe: fix mutability issues with builtin test_functionsJacob Young
2023-04-22wasm: implement `error_set_has_value`Luuk de Gram
This implements the safety check for error casts. The instruction generates a jump table with 2 possibilities. The operand is used as an index into the jump table. For cases where the value does not exist within the error set, it will generate a jump to the 'false' block. For cases where it does exist, it will generate a jump to the 'true' block. By calculating the highest and lowest value we can keep the jump table smaller, as it doesn't need to contain an index into the entire error set.
2023-04-20Liveness: add a liveness verification passJacob Young
This code only runs in a debug zig compiler, similar to verifying llvm modules.
2023-04-20Module: mark function body dependencies, don't re-analyze anonymous declsmlugg
2023-04-03link: cleanup lazy symbolsJacob Young
We now only update one lazy symbol in flushModule. Updating the rest from updateDecl is TBD.
2023-03-26Module: fix lazy srcloc resolution for new for loop syntaxVeikka Tuominen
Closes #15081
2023-03-21Improve error messages for break type coercionJohn Schmidt
2023-03-17main: add debug option to dump unoptimized llvm irJacob Young
2023-03-15Module: handle incremental update from ZIR with AST errorsAndrew Kelley
2023-03-15progress towards semantic error serializationAndrew Kelley
Introduces std.zig.ErrorBundle which is a trivially serializeable set of compilation errors. This is in the standard library so that both the compiler and the build runner can use it. The idea is they will use it to communicate compilation errors over a binary protocol. The binary encoding of ErrorBundle is a bit problematic - I got a little too aggressive with compaction. I need to change it in a follow-up commit to use some indirection in the error message list, otherwise iteration is too unergonomic. In fact it's so problematic right now that the logic getAllErrorsAlloc() actually fails to produce a viable ErrorBundle because it puts SourceLocation data in between the root level ErrorMessage data. This commit has a simplification - redundant logic for rendering AST errors to stderr has been removed in favor of moving the logic for lowering AST errors into AstGen. So even if we get parse errors, the errors will get lowered into ZIR before being reported. I believe this will be useful when working on --autofix. Either way, some redundant brittle logic was happily deleted. In Compilation, updateSubCompilation() is improved to properly perform error reporting when a sub-compilation object fails. It no longer dumps directly to stderr; instead it populates an ErrorBundle object, which gets added to the parent one during getAllErrorsAlloc(). In package fetching code, instead of dumping directly to stderr, it now populates an ErrorBundle object, and gets properly reported at the CLI layer of abstraction.
2023-03-11Module: retry ZIR cache file creationAndrius Bentkus
There are no dir components, so you would think that this was unreachable, however we have observed on macOS two processes racing to do openat() with O_CREAT manifest in ENOENT. closes #12138
2023-03-08Module: rewrite zir caching logicJacob Young
Multiple processes can sit waiting for the exclusive lock at the same time, so we want to recheck whether it needs to be updated whenever we get an exclusive lock. This also fixes a race condition between one process truncating the cache file and another process reading it without atomic locking.
2023-03-05stage2: add zig_backend to ZIR cache namespaceAndrew Kelley
2023-02-21Improve multi-module error messagesmlugg
- Fix assertion failure if AstGen failed on a multi-module file - Cap number of per-error reference notes and total multi-module errors each at 5 - Always put "root of package" reference notes first Resolves: #14499
2023-02-21Implement new module CLImlugg
2023-02-18improve error message for byref capture of byval arrayAndrew Kelley
2023-02-18Sema: improve error message for mismatched for loop lengthsAndrew Kelley
2023-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2023-02-13move the cache system from compiler to std libAndrew Kelley
2023-02-05make `@embedFile` support module-mapped names the same way as `@import`Andrew Kelley
closes #14553
2023-02-03link: remove `FnData` and make it self-ownedLuuk de Gram
This finishes the work started in #14502 where atoms are owned by the linker themselves. This now makes debug atoms fully owned by dwarf, and no information is left stored on the decl.
2023-02-03introduce ZON: Zig Object NotationAndrew Kelley
* std.zig.parse is moved to std.zig.Ast.parse * the new function has an additional parameter that requires passing Mode.zig or Mode.zon * moved parser.zig code to Parse.zig * added parseZon function next to parseRoot function
2023-02-01link: remove union types which are now internal to backendsJakub Konka
2023-02-01link: make Wasm atoms fully owned by the linkerLuuk de Gram
2023-02-01link: make SpirV atoms fully owned by the linkerJakub Konka
2023-02-01link: decouple DI atoms from linker atoms, and manage them in Dwarf linkerJakub Konka
2023-02-01link: make Plan9 atoms fully owned by the linkerJakub Konka
2023-01-31link: make Coff atoms fully owned by the linkerJakub Konka
2023-01-31link: make Elf atoms fully owned by the linkerJakub Konka
2023-01-31link: make MachO atoms fully owned by the linkerJakub Konka