aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
AgeCommit message (Collapse)Author
2021-05-01stage2: dbg_stmt ZIR instructions have line/colAndrew Kelley
instead of node indexes. * AstGen: dbg_stmt instructions now have line and column indexes, relative to the parent declaration. This allows codegen to emit debug info without having the source bytes, tokens, or AST nodes loaded in memory. * ZIR: each decl has the absolute line number. This allows computing line numbers from offsets without consulting source code bytes. Memory management: creating a function definition does not prematurely set the Decl arena. Instead the function is allocated with the general purpose allocator. Codegen no longer looks at source code bytes for any reason. They can remain unloaded from disk.
2021-04-30stage2: introduce new ZIR instruction: argAndrew Kelley
* AstGen: LocalVal and LocalPtr use string table indexes for their names. This is more efficient because local variable declarations do need to include the variable names so that semantic analysis can emit a compile error if a declaration is shadowed. So we take advantage of this fact by comparing string table indexes when resolving names. * The arg ZIR instructions are needed for the above reasoning, as well as to emit equivalent AIR instructions for debug info. Now that we have these arg instructions, get rid of the special `Zir.Inst.Ref` range for parameters. ZIR instructions now refer to the arg instructions for parameters. * Move identAsString and strLitAsString from Module.GenZir to AstGen where they belong.
2021-04-29AstGen: represent global variables directlyAndrew Kelley
Rather than with `block_inline_var`. This matches how function declarations work and how extern variables work.
2021-04-29AstGen: implement extern variablesAndrew Kelley
2021-04-29AstGen: implement function prototypes with alignment exprsAndrew Kelley
2021-04-29AstGen: fix comptime compile error source locationAndrew Kelley
2021-04-29AstGen: implement anytype struct fieldsAndrew Kelley
2021-04-29AstGen: implement comptime struct fieldsAndrew Kelley
2021-04-28stage2: implement semantic analysis for functions and global varsAndrew Kelley
* AstGen: add missing `break_inline` for comptime blocks. * Module: call getTree() in byteOffset(). This generates the AST when using cached ZIR and compile errors need to be reported. * Scope.File: distinguish between successful ZIR generation and AIR generation (when Decls in scope have been scanned). - `semaFile` correctly avoids doing work twice. * Implement first pass at `lookupInNamespace`. It has various TODOs left, such as `usingnamespace`, and setting up Decl dependencies.
2021-04-28Sema: do not analyze test decls when not in test modeAndrew Kelley
We do this by reserving string table indexes 0 and 1 in ZIR to be special. Decls now have 0 to mean comptime or usingnamespace, and 1 to mean an unnamed test decl.
2021-04-28stage2: implement #8364jacob gw
2021-04-28AstGen: hook up hex float parsing to float literalsAndrew Kelley
Thanks @LemonBoy!
2021-04-28AstGen: function prototypes can have alignmentAndrew Kelley
2021-04-27AstGen: fix function src hash not including bodyAndrew Kelley
2021-04-26stage2: rewire the frontend driver to whole-file-zirAndrew Kelley
* Remove some unused imports in AstGen.zig. I think it would make sense to start decoupling AstGen from the rest of the compiler code, similar to how the tokenizer and parser are decoupled. * AstGen: For decls, move the block_inline instructions to the top of the function so that they get lower ZIR instruction indexes. With this, the block_inline instruction index combined with its corresponding break_inline instruction index can be used to form a ZIR instruction range. This is useful for allocating an array to map ZIR instructions to semantically analyzed instructions. * Module: extract emit-h functionality into a struct, and only allocate it when emit-h is activated. * Module: remove the `decl_table` field. This previously was a table of all Decls in the entire Module. A "name hash" strategy was used to find decls within a given namespace, using this global table. Now, each Namespace has its own map of name to children Decls. - Additionally, there were 3 places that relied on iterating over decl_table in order to function: - C backend and SPIR-V backend. These now have their own decl_table that they keep populated when `updateDecl` and `removeDecl` are called. - emit-h. A `decl_table` field has been added to the new GlobalEmitH struct which is only allocated when emit-h is activated. * Module: fix ZIR serialization/deserialization bug in debug mode having to do with the secret safety tag for untagged unions. There is still an open TODO to investigate a friendlier solution to this problem with the language. * Module: improve deserialization of ZIR to allocate only exactly as much capacity as length in the instructions array so as to not waste space. * Module: move `srcHashEql` to `std.zig` to live next to the definition of `SrcHash` itself. * Module: re-introduce the logic for scanning top level declarations within a namespace. * Compilation: add an `analyze_pkg` Job which is used to kick off the start of semantic analysis by doing the equivalent of `_ = @import("std");`. The `analyze_pkg` job is unconditionally added to the work queue on every update(), with pkg set to the std lib pkg. * Rename TZIR to AIR in a few places. A more comprehensive rename will come later.
2021-04-26AstGen: improved handling of declarationsAndrew Kelley
* Every decl provides a 16 byte source hash which can be used to detect if the source code for any particular decl has changed. * Include comptime decls, test decls, and usingnamespace decls in the decls list of namespaces. - Tests are encoded as extended functions with is_test bit set.
2021-04-26AstGen: implement opaque declsAndrew Kelley
Also move the decls to the beginning in ZIR encoding because in Sema we want to create the namespace with the decls before evaluating the fields.
2021-04-24AstGen: implement `@Vector`Andrew Kelley
2021-04-24stage2: move overflow builtin ZIR instructions to ExtendedAndrew Kelley
make some more room in our ZIR enum tag space
2021-04-24AstGen: parser ensures all suspend have blocksAndrew Kelley
See #8603.
2021-04-24AstGen: implement await and resumeAndrew Kelley
based on @Vexu's code from before
2021-04-23AstGen: support struct init with ref result locationAndrew Kelley
2021-04-23stage2: remove call_none and call_none_chkused ZIRAndrew Kelley
These are unproven optimizations and we need some more room in the `Zir.Inst.Tag` enum for some more syntax.
2021-04-23stage2: remove dead ZIR instructionsAndrew Kelley
clearing up some enum tag space for future added instructions
2021-04-23AstGen: emit nosuspend function callsAndrew Kelley
Inside a nosuspend block, emit function calls as nosuspend calls. Also inside a comptime block, emit function calls as comptime calls. Also emit `async foo()` calls as async calls. Remove compile error for `nosuspend` block inside `suspend` block. Instead of implicitly treating every `suspend` block also as a `nosuspend` block (which would make sense), we leave suspension points as compile errors, to hint to the programmer about accidents. Of course they may then assert `nosuspend` by introducing a block within their suspend block. To make room in `Zir.Inst.Tag` I moved `typeof_peer` and `compile_log` to `Extended`.
2021-04-23AstGen: implement nosuspend expressionsAndrew Kelley
Also implement ZIR error notes
2021-04-23AstGen: implement suspend blocksAndrew Kelley
2021-04-23stage2: implement `anyframe`, `anyframe->T` and fix assemblyAndrew Kelley
* AstGen: implement `anyframe_literal` and `anyframe_type`. * Introduce `makeSubBlock` to avoid redundant AstGen code for GenZir scopes. Allows adding/removing a field without possibility of accidentally introducing a bug of forgetting to set the new field. * Add to GenZir `nosuspend_node` and `suspend_node` in preparation for implementing `suspend` blocks and `nosuspend` blocks. * AstGen: fix assembly to support clobbers, multiple outputs, and outputs without `->` syntax. - `asm` and `asm_volatile` move to `Extended` enum with `small` being repurposed for a few things. This frees up 2 ZIR tags, 1 of which is used in this commit and 1 is leftover. * AstGen: fix `simple_types` incorrectly having multiple conflicting values for "undefined" and "null". - Also add "anyframe" to `simple_types`. * Add `anyframe_type` to type.zig, value.zig and `Zir.Inst.Ref`. - Also add i128 and u128 types to `Zir.Inst.Ref` and `simple_types`. * Sema/Zir: Fix incorrect math causing the function body to be messed up for Extended-encoded functions. * Zir: support `i32` fields for "extra" payloads.
2021-04-23AstGen: compile error for unable to infer array sizeAndrew Kelley
2021-04-22AstGen: implement integers bigger than u64Andrew Kelley
also get rid of the `optional_type_from_ptr_elem` instruction.
2021-04-22AstGen: implement align and linksection on globalsAndrew Kelley
2021-04-22std: fix compile errors caught by stage2 AstGenAndrew Kelley
* `comptime const` is redundant * don't use `extern enum`; specify a tag type. `extern enum` is only when you need tags to alias. But aliasing tags is a smell. I will be making a proposal shortly to remove `extern enum` from the language. * there is no such thing as `packed enum`. * instead of `catch |_|`, omit the capture entirely. * unused function definition with missing parameter name * using `try` outside of a function or test
2021-04-22AstGen: implement `@extern` builtinAndrew Kelley
2021-04-22AstGen: fix `@export`Andrew Kelley
Make it properly use `std.builtin.ExportOptions`.
2021-04-22AstGen: implement function prototypesAndrew Kelley
2021-04-21AstGen: implement alignment on localsAndrew Kelley
2021-04-21AstGen: implement comptime localsAndrew Kelley
2021-04-21AstGen: fix switch result location elisionAndrew Kelley
It was eliding wrong instructions for nested break from labeled block
2021-04-21AstGen: implement `@bitCast` for other result location typesAndrew Kelley
2021-04-20AstGen: slightly better eager-allocating heuristicAndrew Kelley
Some early ensureCapacity calls to avoid needless reallocations.
2021-04-20AstGen: implement union declsAndrew Kelley
2021-04-20AstGen: implement size zero inferred length arraysAndrew Kelley
2021-04-20AstGen: fix store_to_block_ptr elision for switch statementsAndrew Kelley
to make sure it matches the expected block
2021-04-20AstGen: implement for loop payloadAndrew Kelley
2021-04-20AstGen: implement anytype parametersAndrew Kelley
2021-04-20AstGen: implement defer for `break`Andrew Kelley
2021-04-20AstGen: implement defer for `continue`Andrew Kelley
2021-04-20AstGen: basic defer implementationAndrew Kelley
2021-04-20stage2: make std.fmt.parseInt ignore `_`jacob gw
2021-04-20AstGen: `try` fixupsAndrew Kelley
Primarily this required fixing `setCondBrPayloadElideBlockStorePtr` to not assume there would always be two `store_to_block_ptr` instructions in each of the condbr prongs.