aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
AgeCommit message (Collapse)Author
2021-04-20stage2: astgen `try`jacob gw
2021-04-19AstGen: implement array initialization expressionsAndrew Kelley
2021-04-19AstGen: implement inline asm outputAndrew Kelley
2021-04-19AstGen: implement error set declsAndrew Kelley
2021-04-19AstGen: implement functions with inferred error setsAndrew Kelley
This commit also reclaims +2 ZIR instruction tags by moving the following to `extended`: * func_var_args * func_extra * func_extra_var_args The following ZIR instruction tag is added: * func_inferred
2021-04-19AstGen: implement if optional, if error unionAndrew Kelley
2021-04-19AstGen: implement while optional and while error unionAndrew Kelley
2021-04-19AstGen: implement the remaining struct init ResultLoc formsAndrew Kelley
2021-04-18AstGen: implement all the builtin functionsAndrew Kelley
2021-04-17AstGen: implement overflow arithmetic builtinsAndrew Kelley
2021-04-16AstGen: implement simple enums and decls for enumsAndrew Kelley
2021-04-16AstGen: fix compile error using wrong node/token functionAndrew Kelley
2021-04-16AstGen: fix function decl astgenAndrew Kelley
it was using the wrong scope and other mistakes too
2021-04-16AstGen: implement global var declsAndrew Kelley
And fix bug with using `ensureCapacity` when I wanted `ensureUnusedCapacity`.
2021-04-16AstGen: store list of importsAndrew Kelley
2021-04-16ZIR: rename decl_val and decl_ref to remove redundant suffixAndrew Kelley
2021-04-16AstGen: require `@import` operand to be string literalAndrew Kelley
See #2206
2021-04-16AstGen: put decls into blocks to be evaluated independentlyAndrew Kelley
2021-04-16stage2: AstGen improvementsAndrew Kelley
* AstGen: represent compile errors in ZIR rather than returning `error.AnalysisFail`. * ZIR: remove decl_ref and decl_val instructions. These are replaced by `decl_ref_named` and `decl_val_named`, respectively, which will probably get renamed in the future to the instructions that were just deleted. * AstGen: implement `@This()`, `@fence()`, `@returnAddress()`, and `@src()`. * AstGen: struct_decl improved to support fields_len=0 but have decls. * AstGen: fix missing null bytes after compile error messages. * SrcLoc: no longer depend on `Decl`. Instead have an explicit field `parent_decl_node` which is an absolute AST Node index. * Module: `failed_files` table can have null value, in which case the key, which is a `*Scope.File`, will have ZIR errors in it. * ZIR: implement text rendering of struct decls. * CLI: introduce debug_usage and `zig astgen` command which is enabled when the compiler is built in debug mode.
2021-04-15AstGen: implement comptimeDecl, usingnamespaceDecl, testDeclAndrew Kelley
2021-04-15AstGen: implement global variable declsAndrew Kelley
2021-04-15stage2: preliminary reworking for whole-file-AstGenAndrew Kelley
See #8516. * AstGen is now done on whole files at once rather than per Decl. * Introduce a new wait group for AstGen tasks. `performAllTheWork` waits for all AstGen tasks to be complete before doing Sema, single-threaded. - The C object compilation tasks are moved to be spawned after AstGen, since they only need to complete by the end of the function. With this commit, the codebase compiles, but much more reworking is needed to get things back into a useful state.
2021-04-15stage2: rename zir to ZirAndrew Kelley
since it now uses top level fields
2021-04-15stage2: move zir.Code to become root level fields of zir.zigAndrew Kelley
next commit will do the rename
2021-04-15stage2: implement `@bitSizeOf`Andrew Kelley
2021-04-15stage2: implement `@sizeOf`Andrew Kelley
2021-04-15stage2: implement non-trivial enumsAndrew Kelley
2021-04-15stage2: improvements aimed at std lib integrationAndrew Kelley
* AstGen: emit decl lookup ZIR instructions rather than directly looking up decls in AstGen. This is necessary because we want to reuse the same immutable ZIR code for multiple generic instantiations (and comptime function calls). * AstGen: fix using members_len instead of fields_len for struct decls. * structs: the struct_decl ZIR instruction is now also a block. This is so that the type expressions, default field value expressions, and alignment expressions can be evaluated in a scope that contains the decls from the struct namespace itself. * Add "std" and "builtin" packages to the builtin package. * Don't try to build glibc, musl, or mingw-w64 when using `-ofmt=c`. * builtin.zig is generated without `usingnamespace`. * builtin.zig takes advantage of `std.zig.fmtId` for CPU features. * A first pass at implementing `usingnamespace`. It's problematic and should either be deleted, or polished, before merging this branch. * Sema: allow explicitly specifying the namespace in which to look up Decls. This is used by `struct_decl` in order to put the decls from the struct namespace itself in scope when evaluating the type expressions, default value expressions, and alignment expressions. * Module: fix `analyzeNamespace` assuming that it is the top-level root declaration node. * Sema: implement comptime and runtime cmp operator. * Sema: implement peer type resolution for enums and enum literals. * Pull in the changes from master branch: 262e09c482d98a78531c049a18b7f24146fe157f. * ZIR: complete out simple_ptr_type debug printing
2021-04-15stage2: entry point via std lib and proper updated file detectionAndrew Kelley
Instead of Module setting up the root_scope with the root source file, instead, Module relies on the package table graph being set up properly, and inside `update()`, it does the equivalent of `_ = @import("std");`. This, in term, imports start.zig, which has the logic to call main (or not). `Module` no longer has `root_scope` - the root source file is no longer special, it's just in the package table mapped to "root". I also went ahead and implemented proper detection of updated files. mtime, inode, size, and source hash are kept in `Scope.File`. During an update, iterate over `import_table` and stat each file to find out which ones are updated. The source hash is redundant with the source hash used by the struct decl that corresponds to the file, so it should be removed in a future commit before merging the branch. * AstGen: add "previously declared here" notes for variables shadowing decls. * Parse imports as structs. Module now calls `AstGen.structDeclInner`, which is called by `AstGen.containerDecl`. - `importFile` is a bit kludgy with how it handles the top level Decl that kinda gets merged into the struct decl at the end of the function. Be on the look out for bugs related to that as well as possibly cleaner ways to implement this. * Module: factor out lookupDeclName into lookupIdentifier and lookupNa * Rename `Scope.Container` to `Scope.Namespace`. * Delete some dead code. This branch won't work until `usingnamespace` is implemented because it relies on `@import("builtin").OutputMode` and `OutputMode` comes from a `usingnamespace`.
2021-04-08AstGen: implement `@typeInfo` builtinAndrew Kelley
2021-04-08AstGen: implement struct init with ResultLoc.tyAndrew Kelley
2021-04-08stage2: implement array access to a global arrayAndrew Kelley
2021-04-08stage2: revert to only has_decl and export ZIR supportAndrew Kelley
Reverting most of the code from the previous commits in this branch. Will pull in the code with modifications bit by bit.
2021-04-08stage2: implement builtin function hasDeclTimon Kruiper
2021-04-08stage2: add a simplified export builtin callTimon Kruiper
std.builtin.ExportOptions is not yet supported, thus the second argument of export is now a simple string that specifies the exported symbol name.
2021-04-07Merge pull request #8449 from ziglang/stage2-enumsAndrew Kelley
stage2: implement simple enums
2021-04-07AstGen: fix incorrect source loc for duplicate enum tagAndrew Kelley
2021-04-07stage2: fix incremental compilation Decl deletion logicAndrew Kelley
* `analyzeContainer` now has an `outdated_decls` set as well as `deleted_decls`. Instead of queuing up outdated Decls for re-analysis right away, they are added to this new set. When processing the `deleted_decls` set, we remove deleted Decls from the `outdated_decls` set, to avoid deleted Decl pointers from being in the work_queue. Only after processing the deleted decls do we add analyze_decl work items to the queue. * Module.deletion_set is now an `AutoArrayHashMap` rather than `ArrayList`. `declareDeclDependency` will now remove a Decl from it as appropriate. When processing the `deletion_set` in `Compilation.performAllTheWork`, it now assumes all Decl in the set are to be deleted. * Fix crash when handling parse errors. Currently we unload the `ast.Tree` if any parse errors occur. Previously the code emitted a LazySrcLoc pointing to a token index, but then when we try to resolve the token index to a byte offset to create a compile error message, the ast.Tree` would be unloaded. Now we use `LazySrcLoc.byte_abs` instead of `token_abs` so the error message can be created even with the `ast.Tree` unloaded. Together, these changes solve a crash that happened with incremental compilation when Decls were added and removed in some combinations.
2021-04-07AstGen: fix ZIR struct encodingAndrew Kelley
off by one error in the bits that describe defaults/field alignments as soon as we have tests for struct field alignment and default values, there will be coverage for this.
2021-04-07AstGen: fix switch expressions with all prongs noreturnAndrew Kelley
2021-04-07zir: use `node` union field for `alloc_inferred`Andrew Kelley
Previously we used `un_node` and passed `undefined` for the operand, but this causes illegal behavior when printing ZIR code.
2021-04-07AstGen: fix `@breakpoint` ZIRAndrew Kelley
Previously it relied on the breakpoint ZIR instruction being void, but that's no longer how things work.
2021-04-06stage2: implement simple enumsAndrew Kelley
A simple enum is an enum which has an automatic integer tag type, all tag values automatically assigned, and no top level declarations. Such enums are created directly in AstGen and shared by all the generic/comptime instantiations of the surrounding ZIR code. This commit implements, but does not yet add any test cases for, simple enums. A full enum is an enum for which any of the above conditions are not true. Full enums are created in Sema, and therefore will create a unique type per generic/comptime instantiation. This commit does not implement full enums. However the `enum_decl_nonexhaustive` ZIR instruction is added and the respective Type functions are filled out. This commit makes an improvement to ZIR code, removing the decls array and removing the decl_map from AstGen. Instead, decl_ref and decl_val ZIR instructions index into the `owner_decl.dependencies` ArrayHashMap. We already need this dependencies array for incremental compilation purposes, and so repurposing it to also use it for ZIR decl indexes makes for efficient memory usage. Similarly, this commit fixes up incorrect memory management by removing the `const` ZIR instruction. The two places it was used stored memory in the AstGen arena, which may get freed after Sema. Now it properly sets up a new anonymous Decl for error sets and uses a normal decl_val instruction. The other usage of `const` ZIR instruction was float literals. These are now changed to use `float` ZIR instruction when the value fits inside `zir.Inst.Data` and `float128` otherwise. AstGen + Sema: implement int_to_enum and enum_to_int. No tests yet; I expect to have to make some fixes before they will pass tests. Will do that in the branch before merging. AstGen: fix struct astgen incorrectly counting decls as fields. Type/Value: give up on trying to exhaustively list every tag all the time. This makes the file more manageable. Also found a bug with i128/u128 this way, since the name of the function was more obvious when looking at the tag values. Type: implement abiAlignment and abiSize for structs. This will need to get more sophisticated at some point, but for now it is progress. Value: add new `enum_field_index` tag. Value: add hash_u32, needed when using ArrayHashMap.
2021-04-02stage2: progress towards basic structsAndrew Kelley
Introduce `ResultLoc.none_or_ref` which is used by field access expressions to avoid unnecessary loads when the field access itself will do the load. This turns: ```zig p.y - p.x - p.x ``` from ```zir %14 = load(%4) node_offset:8:12 %15 = field_val(%14, "y") node_offset:8:13 %16 = load(%4) node_offset:8:18 %17 = field_val(%16, "x") node_offset:8:19 %18 = sub(%15, %17) node_offset:8:16 %19 = load(%4) node_offset:8:24 %20 = field_val(%19, "x") node_offset:8:25 ``` to ```zir %14 = field_val(%4, "y") node_offset:8:13 %15 = field_val(%4, "x") node_offset:8:19 %16 = sub(%14, %15) node_offset:8:16 %17 = field_val(%4, "x") node_offset:8:25 ``` Much more compact. This requires `Sema.zirFieldVal` to support both pointers and non-pointers. C backend: Implement typedefs for struct types, as well as the following TZIR instructions: * mul * mulwrap * addwrap * subwrap * ref * struct_field_ptr Note that add, addwrap, sub, subwrap, mul, mulwrap instructions are all incorrect currently and need to be updated to properly handle wrapping and non wrapping for signed and unsigned. C backend: change indentation delta to 1, to make the output smaller and to process fewer bytes. I promise I will add a test case as soon as I fix those warnings that are being printed for my test case.
2021-04-01stage2: implement structs in the frontendAndrew Kelley
New ZIR instructions: * struct_decl_packed * struct_decl_extern New TZIR instruction: struct_field_ptr Introduce `Module.Struct`. It uses `Value` to store default values and abi alignments. Implemented Sema.analyzeStructFieldPtr and zirStructDecl. Some stuff I changed from `@panic("TODO")` to `log.warn("TODO")`. It's becoming more clear that we need the lazy value mechanism soon; Type is becoming unruly, and some of these functions have too much logic given that they don't have any context for memory management or error reporting.
2021-04-01stage2: AstGen and ZIR printing for struct declsAndrew Kelley
2021-04-01stage2: implement struct init syntax with ptr result locAndrew Kelley
2021-03-31stage2: finish implementation of LazySrcLocAndrew Kelley
2021-03-31stage2: finish source location reworkings in the branchAndrew Kelley
* remove the LazySrcLoc.todo tag * finish updating Sema and AstGen, remove the last of the `@panic("TODO")`.
2021-03-31stage2: compile error for duplicate switch value on booleanAndrew Kelley