aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
AgeCommit message (Collapse)Author
2023-06-10InternPool: remove memoized_declAndrew Kelley
This is neither a type nor a value. Simplifies `addStrLit` as well as the many places that switch on `InternPool.Key`. This is a partial revert of bec29b9e498e08202679aa29a45dab2a06a69a1e.
2023-06-10InternPool: add representation for value of empty enums and unionsmlugg
This is a bit odd, because this value doesn't actually exist: see #15909. This gets all the empty enum/union behavior tests passing. Also adds an assertion to `Sema.analyzeBodyInner` which would have helped figure out the issue here much more quickly.
2023-06-10InternPool: improve hashing performanceAndrew Kelley
Key.PtrType is now an extern struct so that hashing it can be done by reinterpreting bytes directly. It also uses the same representation for type_pointer Tag encoding and the Key. Accessing pointer attributes now requires packed struct access, however, many operations are now a copy of a u32 rather than several independent fields. This function moves the top two most used Key variants - pointer types and pointer values - to use a single-shot hash function that branches for small keys instead of calling memcpy. As a result, perf against merge-base went from 1.17x ± 0.04 slower to 1.12x ± 0.04 slower. After the pointer value hashing was changed, total CPU instructions spent in memcpy went from 4.40% to 4.08%, and after additionally improving pointer type hashing, it further decreased to 3.72%.
2023-06-10InternPool: pass by const pointerAndrew Kelley
The Zig language allows the compiler to make this optimization automatically. We should definitely make the compiler do that, and revert this commit. However, that will not happen in this branch, and I want to continue to explore achieving performance parity with merge-base. So, this commit changes all InternPool parameters to be passed by const pointer rather than by value. I measured a 1.03x ± 0.03 speedup vs the previous commit compiling the (set of passing) behavior tests. Against merge-base, this commit is 1.17x ± 0.04 slower, which is an improvement from the previous measurement of 1.22x ± 0.02. Related issue: #13510 Related issue: #14129 Related issue: #15688
2023-06-10cbe: fix InternPool regressionsJacob Young
2023-06-10behavior: fix more compiler crashesJacob Young
2023-06-10Module: move memoized data to the intern poolJacob Young
This avoids memory management bugs with the previous implementation.
2023-06-10C backend: InternPool fixesAndrew Kelley
2023-06-10InternPool: fix build-exe and compiler-rt crashesJacob Young
2023-06-10Module: rename functions to make ownership checks explicitJacob Young
This makes the difference between `decl.getOwnedFunction` and `decl.val.getFunction` more clear when reading the code.
2023-06-10AIR: eliminate the `values` arrayAndrew Kelley
2023-06-10Module: intern the values of decls when they are marked aliveJacob Young
I'm not sure if this is the right place for this to happen, and it should become obsolete when comptime mutation is rewritten and the remaining legacy value tags are remove, so keeping this as a separate revertable commit.
2023-06-10Air: remove constant tagJacob Young
Some uses have been moved to their own tag, the rest use interned. Also, finish porting comptime mutation to be more InternPool aware.
2023-06-10InternPool: remove more legacy valuesJacob Young
Reinstate some tags that will be needed for comptime init.
2023-06-10InternPool: port most of value tagsJacob Young
2023-06-10Sema: move `inferred_alloc_const/mut_type` to InternPoolAndrew Kelley
Now, all types are migrated to use `InternPool`. The `Type.Tag` enum is deleted in this commit.
2023-06-10Value: add `intern` and `unintern` to facilitate code conversionJacob Young
This allows some code (like struct initializers) to use interned types while other code (such as comptime mutation) continues to use legacy types. With these changes, an `zig build-obj empty.zig` gets to a crash on missing interned error union types.
2023-06-10compiler: move error union types and error set types to InternPoolAndrew Kelley
One change worth noting in this commit is that `module.global_error_set` is no longer kept strictly up-to-date. The previous code reserved integer error values when dealing with error set types, but this is no longer needed because the integer values are not needed for semantic analysis unless `@errorToInt` or `@intToError` are used and therefore may be assigned lazily.
2023-06-10compiler: eliminate legacy Type.Tag.pointerAndrew Kelley
Now pointer types are stored only in InternPool.
2023-06-10stage2: move function types to InternPoolAndrew Kelley
2023-06-10stage2: move anon tuples and anon structs to InternPoolAndrew Kelley
2023-06-10stage2: move enum tag values into the InternPoolAndrew Kelley
I'm seeing a new assertion trip: the call to `enumTagFieldIndex` in the implementation of `@Type` is attempting to query the field index of an union's enum tag, but the type of the enum tag value provided is not the same as the union's tag type. Most likely this is a problem with type coercion, since values are now typed. Another problem is that I added some hacks in std.builtin because I didn't see any convenient way to access them from Sema. That should definitely be cleaned up before merging this branch.
2023-06-10stage2: remove legacy Type array and array_sentinelAndrew Kelley
These are now handled by the InternPool.
2023-06-10InternPool: transition float valuesmlugg
2023-06-10stage2: move enum types into the InternPoolAndrew Kelley
Unlike unions and structs, enums are actually *encoded* into the InternPool directly, rather than using the SegmentedList trick. This results in them being quite compact, and greatly improved the ergonomics of using enum types throughout the compiler. It did however require introducing a new concept to the InternPool which is an "incomplete" item - something that is added to gain a permanent Index, but which is then mutated in place. This was necessary because enum tag values and tag types may reference the namespaces created by the enum itself, which required constructing the namespace, decl, and calling analyzeDecl on the decl, which required the decl value, which required the enum type, which required an InternPool index to be assigned and for it to be meaningful. The API for updating enums in place turned out to be quite slick and efficient - the methods directly populate pre-allocated arrays and return the information necessary to output the same compilation errors as before.
2023-06-10stage2: move union types and values to InternPoolAndrew Kelley
2023-06-10stage2: move struct types and aggregate values to InternPoolAndrew Kelley
2023-06-10stage2: move opaque types to InternPoolAndrew Kelley
2023-06-10stage2: move empty struct type and value to InternPoolAndrew Kelley
2023-06-10stage2: implement intTagType logicAndrew Kelley
This commit changes a lot of `*const Module` to `*Module` to make it work, since accessing the integer tag type of an enum might need to mutate the InternPool by adding a new integer type into it. An alternate strategy would be to pre-heat the InternPool with the integer tag type when creating an enum type, which would make it so that intTagType could accept a const Module instead of a mutable one, asserting that the InternPool already had the integer tag type.
2023-06-10stage2: bug fixes related to Type/Value/InternPoolAndrew Kelley
2023-06-10Replace uses of Value.zero, Value.one, Value.negative_onemlugg
This is a bit nasty, mainly because Type.onePossibleValue is now errorable, which is a quite viral change.
2023-06-10stage2: move integer values to InternPoolAndrew Kelley
2023-06-10InternPool: add a slice encodingAndrew Kelley
This uses the data field to reference its pointer field type, which allows for efficient and infallible access of a slice type's pointer type.
2023-06-10stage2: migrate many pointer types to the 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-10Type.isSlice: make it InternPool awareAndrew Kelley
2023-06-10stage2: move most simple values to InternPoolAndrew Kelley
2023-06-10stage2: move most simple types to InternPoolAndrew Kelley
2023-06-10InternPool: implement isSinglePointerAndrew 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-10cbe: use `Assignment` in `airSplat`Jacob Young
2023-05-06cbe: fix typosJacob Young
2023-04-28C backend: take advantage of Assignment abstraction in airMemsetAndrew Kelley
2023-04-28C backend: fix ptr comparison of array ptrs when one is null-terminatedAndrew Kelley
2023-04-28update codebase to use `@memset` and `@memcpy`Andrew Kelley
2023-04-28C backend: fix memset for structs and arraysAndrew Kelley
2023-04-26Merge pull request #15452 from mlugg/zig-cbe-optAndrew Kelley
CBE: minor optimizations to output source