aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
AgeCommit message (Collapse)Author
2024-03-19extract std.posix from std.osAndrew Kelley
closes #5019
2024-03-17Merge pull request #19333 from Vexu/fixesAndrew Kelley
Miscellaneous error fixes
2024-03-17Sema: fix printing of inferred error set of generic fnVeikka Tuominen
Closes #19332
2024-03-17AstGen: disallow alignment on function typesJacob Young
A pointer type already has an alignment, so this information does not need to be duplicated on the function type. This already has precedence with addrspace which is already disallowed on function types for this reason. Also fixes `@TypeOf(&func)` to have the correct addrspace and alignment.
2024-03-14Zcu: preserve ordering of `usingnamespace` declsmlugg
See comment. This slightly regresses a previous fix from this branch. A proper solution will come soon, with the splitting up of `Decl` into `Cau` and `Nav`.
2024-03-14Zcu: perform orphan checks against uncoerced functionmlugg
2024-03-14compiler: add `func_ies` incremental dependenciesmlugg
This was an oversight in my original design. This new form of dependency is invalidated when the resolved IES for a runtime function changes.
2024-03-14compiler: progress towards incrementalmlugg
Most basic re-analysis logic is now in place. Trivial updates are hitting linker assertions.
2024-03-14Zcu: handle updates to file root structmlugg
2024-03-14Zcu: handle incremental updates (more) correctly when scanning namespacesmlugg
2024-03-14Zcu: convert Decl.zir_inst_index to a TrackedInst.Index.Optionalmlugg
This makes tracking easier across incremental updates: `scanDecl` can now tell whether an existing decl in a namespace was mapped to the one it's analyzing in the new ZIR.
2024-03-14Zcu: remove old decls after scanning namespacemlugg
2024-03-14Zcu: rename implicitly-named decls to avoid overriding by explicit declsmlugg
2024-03-14compiler: detect duplicate test names in AstGenmlugg
There is no reason to perform this detection during semantic analysis. In fact, doing so is problematic, because we wish to utilize detection of existing decls in a namespace in incremental compilation.
2024-03-11std.builtin: make global linkage fields lowercaseTristan Ross
2024-03-11std.builtin: make container layout fields lowercaseTristan Ross
2024-03-06compiler: namespace type equivalence based on AST node + capturesmlugg
This implements the accepted proposal #18816. Namespace-owning types (struct, enum, union, opaque) are no longer unique whenever analysed; instead, their identity is determined based on their AST node and the set of values they capture. Reified types (`@Type`) are deduplicated based on the structure of the type created. For instance, if two structs are created by the same reification with identical fields, layout, etc, they will be the same type. This commit does not produce a working compiler; the next commit, adding captures for decl references, is necessary. It felt appropriate to split this up. Resolves: #18816
2024-03-06compiler: represent captures directly in InternPoolmlugg
These were previously associated with the type's namespace, but we need to store them directly in the InternPool for #18816.
2024-03-06InternPool: create specialized functions for loading namespace typesmlugg
Namespace types (`struct`, `enum`, `union`, `opaque`) do not use structural equality - equivalence is based on their Decl index (and soon will change to AST node + captures). However, we previously stored all other information in the corresponding `InternPool.Key` anyway. For logical consistency, it makes sense to have the key only be the true key (that is, the Decl index) and to load all other data through another function. This introduces those functions, by the name of `loadStructType` etc. It's a big diff, but most of it is no-brainer changes. In future, it might be nice to eliminate a bunch of the loaded state in favour of accessor functions on the `LoadedXyzType` types (like how we have `LoadedUnionType.size()`), but that can be explored at a later date.
2024-03-06compiler: change representation of closuresmlugg
This changes the representation of closures in Zir and Sema. Rather than a pair of instructions `closure_capture` and `closure_get`, the system now works as follows: * Each ZIR type declaration (`struct_decl` etc) contains a list of captures in the form of ZIR indices (or, for efficiency, direct references to parent captures). This is an ordered list; indexes into it are used to refer to captured values. * The `extended(closure_get)` ZIR instruction refers to a value in this list via a 16-bit index (limiting this index to 16 bits allows us to store this in `extended`). * `Module.Namespace` has a new field `captures` which contains the list of values captured in a given namespace. This is initialized based on the ZIR capture list whenever a type declaration is analyzed. This change eliminates `CaptureScope` from semantic analysis, which is a nice simplification; but the main motivation here is that this change is a prerequisite for #18816.
2024-03-02Merge pull request #19117 from mlugg/dbg-var-blocksMatthew Lugg
Major ZIR size optimizations & small cleanups in Sema
2024-03-01compiler: audit debug mode checksJacob Young
* Introduce `-Ddebug-extensions` for enabling compiler debug helpers * Replace safety mode checks with `std.debug.runtime_safety` * Replace debugger helper checks with `!builtin.strip_debug_info` Sometimes, you just have to debug optimized compilers...
2024-02-29Sema: simplify and clarify analyzeBodyInner and wrapper functionsmlugg
The signature and variants of Sema's main loop have evolved over time to what was a quite confusing state of affairs. This commit makes minor changes to how `analyzeBodyInner` works, and restructures/renames the wrapper functions, adding doc comments to clarify their purposes. The most notable change is that `analyzeBodyInner` now returns `CompileError!void`; inline breaks are now all communicated via `error.ComptimeBreak`.
2024-02-26compiler: JIT zig fmtAndrew Kelley
See #19063
2024-02-26move AstGen to std.zig.AstGenAndrew Kelley
Part of an effort to ship more of the compiler in source form.
2024-02-26move Zir to std.zig.ZirAndrew Kelley
Part of an effort to ship more of the compiler in source form.
2024-02-26move Zcu.LazySrcLoc to std.zig.LazySrcLocAndrew Kelley
Part of an effort to ship more of the compiler in source form.
2024-02-25test: rework how filtering worksJacob Young
* make test names contain the fully qualified name * make test filters match the fully qualified name * allow multiple test filters, where a test is skipped if it does not match any of the specified filters
2024-02-24Fix handling of Windows (WTF-16) and WASI (UTF-8) pathsRyan Liptak
Windows paths now use WTF-16 <-> WTF-8 conversion everywhere, which is lossless. Previously, conversion of ill-formed UTF-16 paths would either fail or invoke illegal behavior. WASI paths must be valid UTF-8, and the relevant function calls have been updated to handle the possibility of failure due to paths not being encoded/encodable as valid UTF-8. Closes #18694 Closes #1774 Closes #2565
2024-02-22Module: fix `@embedFile` of files containing zero bytesJacob Young
If an adapted string key with embedded nulls was put in a hash map with `std.hash_map.StringIndexAdapter`, then an incorrect hash would be entered for that entry such that it is possible that when looking for the exact key that matches the prefix of the original key up to the first null would sometimes match this entry due to hash collisions and sometimes not if performed later after a grow + rehash, causing the same key to exist with two different indices breaking every string equality comparison ever, for example claiming that a container type doesn't contain a field because the field name string in the struct and the string representing the identifier to lookup might be equal strings but have different string indices. This could maybe be fixed by changing `std.hash_map.StringIndexAdapter.hash` to only hash up to the first null, therefore ensuring that the entry's hash is correct and that all future lookups will be consistent, but I don't trust anything so instead I assert that there are no embedded nulls.
2024-02-16Sema: correct source location for return value coercion errorsmlugg
When coercing the operand of a `ret_node` etc instruction, the source location for errors used to point to the entire `return` statement. Instead, we now point to the operand, as would be expected if there was an explicit `as_node` instruction (like there used to be).
2024-02-09Merge pull request #18712 from Vexu/std.optionsAndrew Kelley
std: make options a struct instance instead of a namespace
2024-02-06Merge pull request #18814 from mlugg/incremental-dependenciesMatthew Lugg
Begin re-implementing incremental compilation
2024-02-05compiler: rename value.zig to Value.zigAndrew Kelley
This commit only does the file rename to be friendlier to version control conflicts.
2024-02-04compiler: lock incremental dependency tracking behind --debug-incrementalmlugg
This logic (currently) has a non-trivial cost (particularly in terms of peak RSS) for tracking dependencies. Until incremental compilation is in use in the wild, it doesn't make sense for users to pay that cost.
2024-02-04Zcu: refactor Decl.analysis fieldmlugg
* Functions failing codegen now set this failure on the function analysis state. Decl analysis `codegen_failure` is reserved for failures generating constant values. * `liveness_failure` is consolidated into `codegen_failure`, as we do not need to distinguish these, and Liveness.Verify is just a debugging feature anyway. * `sema_failure_retryable` and `codegen_failure_retryable` are removed. Instead, retryable failures are recorded in the new `Zcu.retryable_failures` list. On an incremental update, this list is flushed, and all elements are marked as outdated so that we re-attempt analysis and code generation. Also remove the `generation` fields from `Zcu` and `Decl` as these are not needed by our new strategy for incremental updates.
2024-02-04Zcu: incremental compilation improvementsmlugg
* Mark root Decls for re-analysis separately * Check for re-analysis of root Decls * Remove `outdated` entry when analyzing fn body * Remove legacy `outdated` field from Decl analysis state
2024-02-04Zcu: more dependency tracking logicmlugg
* Invalidate `decl_val` dependencies * Recursively mark and un-mark all dependencies correctly * Queue analysis of outdated dependers in `Compilation.performAllTheWork` Introduces logic to invalidate `decl_val` dependencies after `Zcu.semaDecl` completes. Also, recursively un-mark dependencies as PO where needed. With this, all dependency invalidation logic is in place. The next step is analyzing outdated dependencies and triggering appropriate re-analysis.
2024-02-04Zir: store extra source hashes required for incrementalmlugg
Also add corresponding invaidation logic to Zcu. Therefore, the only invalidation logic which is not yet in place is `decl_val` dependencies.
2024-02-04compiler: re-introduce dependencies for incremental compilationmlugg
Sema now tracks dependencies appropriately. Early logic in Zcu for resolving outdated decls/functions is in place. The setup used does not support `usingnamespace`; compilations using this construct are not yet supported by this incremental compilation model.
2024-02-02InternPool: use separate key for slicesmlugg
This change eliminates some problematic recursive logic in InternPool, and provides a safer API.
2024-02-01remove std.io.ModeVeikka Tuominen
2024-02-01Module: remove dependency handling of test function arrayVeikka Tuominen
Follow up to 1ccc68f307d4a2208118a8798d43119d63b53e05
2024-01-23InternPool: introduce TrackedInstmlugg
It is problematic for the cached `InternPool` state to directly reference ZIR instruction indices, as these are not stable across incremental updates. The existing ZIR mapping logic attempts to handle this by iterating the existing Decl graph for a file after `AstGen` and update ZIR indices on `Decl`s, struct types, etc. However, this is unreliable due to generic instantiations, and relies on specialized logic for everything which may refer to a ZIR instruction (e.g. a struct's owner decl). I therefore determined that a prerequisite change for incremental compilation would be to rework how we store these indices. This commit introduces a `TrackedInst` type which provides a stable index (`TrackedInst.Index`) for a single ZIR instruction in the compilation. The `InternPool` now stores these values in place of ZIR instruction indices. This makes the ZIR mapping logic relatively trivial: after `AstGen` completes, we simply iterate all `TrackedInst` values and update those indices which have changed. In future, if the corresponding ZIR instruction has been removed, we must also invalidate any dependencies on this instruction to trigger any required re-analysis, however the dependency system does not yet exist.
2024-01-23Zir: represent declarations via an instructionmlugg
This commit changes how declarations (`const`, `fn`, `usingnamespace`, etc) are represented in ZIR. Previously, these were represented in the container type's extra data (e.g. as trailing data on a `struct_decl`). However, this introduced the complexity of the ZIR mapping logic having to also correlate some ZIR extra data indices. That isn't really a problem today, but it's tricky for the introduction of `TrackedInst` in the commit following this one. Instead, these type declarations now simply contain a trailing list of ZIR indices to `declaration` instructions, which directly encode all data related to the declaration (including containing the declaration's body). Additionally, the ZIR for `align` etc have been split out into their own bodies. This is not strictly necessary, but it's much simpler to understand for an insignificant cost in bytes, and will simplify the resolution of #131 (where we may need to evaluate the pointer type, including align etc, without immediately evaluating the value body).
2024-01-22Sema: implement comptime error return tracesVeikka Tuominen
2024-01-08add type safety to ZIR for null terminated stringsAli Chraghi
2024-01-04Use `std.fs.path.relative` for `@import` and `@embedFile` sub pathsRyan Liptak
Fixes edge cases where the `startsWith` that was used previously would return a false positive on a resolved path like `foo.zig` when the resolved root was `foo`. Before this commit, such a path would be treated as a sub path of 'foo' with a resolved sub file path of 'zig' (and the `.` would be assumed to be a path separator). After this commit, `foo.zig` will be correctly treated as outside of the root of `foo`. Closes #18355
2024-01-01frontend: fix populateTestFunctions accessing the wrong moduleAndrew Kelley
The test runner reads the list of test function pointers from its own builtin module, which is the root_mod, not main_mod.
2024-01-01restore -fno-emit-bin -femit-llvm-ir functionalityAndrew Kelley
Now, link.File will always be null when -fno-emit-bin is specified, and in the case that LLVM artifacts are still required, the Zcu instance has an LlvmObject.