aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
AgeCommit message (Collapse)Author
2023-06-10InternPool: add optional valuesAndrew Kelley
2023-06-10Sema: introduce Value.enum_field_0Andrew Kelley
and use it to fix typeHasOnePossibleValue logic in two different places.
2023-06-10stage2: more InternPool related fixesAndrew Kelley
* make Sema.zirPtrType coerce the sentinel value against the element type * fix lazyAbiAlignment wrong result type * typeHasOnePossibleValue no longer tries to create interned enum tag value with integer zero, instead uses enum_field_index * Type.ptr avoids trying to store typed null values into the intern pool
2023-06-10stage2: move empty struct type and value to InternPoolAndrew Kelley
2023-06-10stage2: more InternPool-related fixesAndrew 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-10wip: progress towards compiling testsmlugg
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-10fill out more InternPool Type methodsAndrew Kelley
particularly, printing types
2023-06-10InternPool: enhance integer valuesAndrew Kelley
The Key struct now has a Storage tagged union which can store a u64, i64, or big int. This is needed so that indexToKey can be implemented for integers stored compactly in the data structure.
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-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-10stage2: move named int types to InternPoolAndrew Kelley
2023-06-10stage2: move float types to InternPoolAndrew Kelley
2023-06-10InternPool: implement typePtrOrOptionalPtrTyAndrew Kelley
2023-06-10stage2: isGenericPoison InternPool awarenessAndrew Kelley
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-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-29fix #15778: Binary operations on empty vectors crashEvin Yulo
2023-05-26std.Target adjustmentsVeikka Tuominen
* move `ptrBitWidth` from Arch to Target since it needs to know about the abi * double isn't always 8 bits * AVR uses 1-byte alignment for everything in GCC
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-04-30fix compilation error on 32-bit LLVM-enabled compiler buildsAndrew Kelley
Fixes a regression introduced in 9295355985202c267b4326b5a6e2ad5158b48e5d that caused 32-bit builds with `-Denable-llvm` to fail to build from source due to that common u64/usize casting issue.
2023-04-28Sema: fix false negative Value.isComptimePtr for slicesAndrew Kelley
2023-04-28update codebase to use `@memset` and `@memcpy`Andrew Kelley
2023-04-28stage2: avoid panicking for unimplemented compiler codeAndrew Kelley
Prevents the compiler from crashing when using `@memset` on extern unions, for example.
2023-04-28LLVM backend: optimize memset with comptime-known elementAndrew Kelley
When the element is comptime-known, we can check if it has a repeated byte representation. In this case, `@memset` can be lowered with the LLVM intrinsic rather than with a loop.
2023-04-26add support for .field_ptr in elemValueAdvancedkcbanner
This fixes a crash when @compileLog is passed a slice backed by an aggregate field at comptime.
2023-04-13add c_char typeAndrew Kelley
closes #875
2023-03-21Value: implement reinterpreting enum field index as integerVeikka Tuominen
Closes #15019
2023-03-21Value: handle comparisons of runtime_valuesVeikka Tuominen
Closes #15004
2023-03-14Implement readFromMemory/writeToMemory for ptrLikeOptionalDerryAlex
2023-03-10Sema: correctly detect use of undefined within slices in @Typemlugg
Resolves: #14712
2023-03-05CBE: implement vector operationsJacob Young
Also, bigint add and sub which is all I was actually trying to do.
2023-02-27tools: implement more lldb pretty printersJacob Young
2023-02-19implement `writeToMemory`/`readFromMemory` for pointersVeikka Tuominen
2023-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2023-02-18Value: implement writeToMemory for packed unionsMatt Knight
2023-01-22Value: implement `compareAllWithZero` for `bytes` and `str_lit`Veikka Tuominen
Closes #10692
2023-01-11Value: implement more pointer eql casesVeikka Tuominen
Closes #14234
2023-01-05resolve some TODOsVeikka Tuominen
2022-12-27value: fix bitcasting packed structs with `u0` fieldsVeikka Tuominen
Closes #13942
2022-12-27Sema: make overflow arithmetic builtins return tuplesVeikka Tuominen
2022-12-20Merge pull request #14004 from Vexu/packed-struct-vectorVeikka Tuominen
llvm: handle vectors in packed structs