aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
AgeCommit message (Collapse)Author
2022-09-02Sema: resolve lazy value before intToFloatVeikka Tuominen
Closes #12698
2022-08-24Merge pull request #12623 from Vexu/stage2-fixesAndrew Kelley
Stage2 fixes
2022-08-24stage2: handle `int_u64` in `elemValueAdvanced`Veikka Tuominen
Closes #12599
2022-08-22stage2+stage1: remove type parameter from bit builtinsVeikka Tuominen
Closes #12529 Closes #12511 Closes #6835
2022-08-17Sema: fix generics with struct literal coerced to tagged unionAndrew Kelley
The `Value.eql` function has to test for value equality *as-if* the lhs value parameter is coerced into the type of the rhs. For tagged unions, there was a problematic case when the lhs was an anonymous struct, because in such case the value is empty_struct_value and the type contains all the value information. But the only type available in the function was the rhs type. So the fix involved making `Value.eqlAdvanced` also accept the lhs type, and then enhancing the logic to handle the case of the `.anon_struct` tag. closes #12418 Tests run locally: * test-behavior * test-cases
2022-08-10stage2: fix crash with comptime vector reduceAndrew Kelley
2022-08-10stage2: Handle lazy values for the % operatorIsaac Freund
2022-07-31Merge pull request #12289 from Vexu/stage2Andrew Kelley
Stage2: reify functions + fixes
2022-07-30stage2: Fix AIR printingCody Tapscott
Packed structs never have comptime fields, and a slice might actually be backed by a variable, which we need to catch before iterating its elements.
2022-07-30Sema: implement `@Type` for functionsVeikka Tuominen
Closes #12280
2022-07-30stage2: fix hashing of struct valuesVeikka Tuominen
Closes #12279
2022-07-14Sema: fix coerce_result_ptr in case of inferred result typeAndrew Kelley
Previously, the logic for analyzing coerce_result_ptr would generate invalid bitcast instructions which did not include coercion logic, such as optional wrapping, resulting in miscompilations. Now, the logic of resolve_inferred_alloc goes back over all the placeholders inserted by coerce_result_ptr, and replaces them with logic doing the proper coercions. Closes #12045
2022-07-13stage2: fix comptime bitcast involving f80Andrew Kelley
* Sema: implement comptime bitcast of f80 with integer-like types bitwise rather than taking a round trip through memory layout. * Type: introduce `isAbiInt`. * Value: comptime memory write of f80 writes 0 bytes for padding instead of leaving the memory uninitialized. * Value: floatReadFromMemory has a more general implementation, checking the endianness rather than checking for specific architectures. This fixes behavior test failures occurring on MIPS.
2022-07-07stage2: make line field of `@src` runtime knownVeikka Tuominen
2022-06-30stage2: hash/eql of fixed-size floats use bit patternAndrew Kelley
Zig guarantees the memory layout of f16, f32, f64, f80, and f128 which means for generic function purposes, values of these types need to be compared on the basis of their bits in memory. This means nan-packing can be used with generic functions, for example. For comptime_float, the sign is observable, whether it is nan is observable, but not any more kinds of bit patterns are observable. This fixes the std.fmt tests that check printing "-nan".
2022-06-18value: handle slices in canMutateComptimeVarStateVeikka Tuominen
2022-06-17Merge pull request #11881 from Vexu/stage2Andrew Kelley
Stage2: fixes for bugs found while looking for miscompilations
2022-06-17stage2: check that struct is a tuple when value tags differ in eqlVeikka Tuominen
2022-06-17stage2: comptime @bitCast packed struct bug fixOmar Alhammadi
2022-06-12Merge pull request #11837 from Vexu/stage2Andrew Kelley
Fix (nearly) all stage2 crashes when testing stdlib
2022-06-11stage2: small fixes + adjustments to std testsVeikka Tuominen
2022-06-11Sema: type safety for "runtime_index" fieldAndrew Kelley
This commit does not change any behavior, but changes the type of the runtime_index field from u32 to a non-exhaustive enum. This allows us to put `std.math.maxInt(u32)` only in the enum type definition and give it an official meaning.
2022-06-06stage2: use correct type (u29) for alignmentVeikka Tuominen
2022-06-06Sema: validate equality on store to comptime fieldVeikka Tuominen
2022-06-03Value: implement {read,write}Value for more typesVeikka Tuominen
2022-05-25stage2: packed struct fields do not have a byte offsetVeikka Tuominen
2022-05-24stage2: string literal interningAndrew Kelley
This is a temporary addition to stage2 in order to match stage1 behavior, however the end-game once the lang spec is settled will be to use a global InternPool for comptime memoized objects, making this behavior consistent across all types, not only string literals. Or, we might decide to not guarantee string literals to have equal comptime pointers, in which case this commit can be reverted.
2022-05-20Sema: introduce laziness to `@sizeOf`Andrew Kelley
Motivation: the behavior test that is now passing. The main change in this commit is introducing `Type.abiSizeAdvanced`, `Value.Tag.lazy_size`, and adjusting `Sema.zirSizeOf` to take advantage of these. However, the bulk of lines changed in this commit ended up being moving logic from value.zig and type.zig into Sema.zig. This logic had no business being in Type/Value as it was only called from a Sema context, and we need access to the Sema context for error reporting when a lazy Value is resolved. Also worth mentioning is that I bumped up the comptime `@floatToInt` implementation from using f64 to f128.
2022-05-17stage2: fix pointer arithmetic result typeAndrew Kelley
This makes it so the result of doing pointer arithmetic creates a new pointer type that has adjusted alignment.
2022-05-16stage2: perform comptime vectorization of `*_with_overflow` in `Value`William Sengir
2022-05-16stage2: clean up creation of boolean `Value`sWilliam Sengir
2022-05-16stage2: handle vectors in `Value.intFitsInType`William Sengir
2022-05-10Sema: comptime float negation supports negative zeroAndrew Kelley
When handling the `negate` ZIR instruction, Zig now checks for a comptime operand and handles it as a special case rather than lowering it as `0 - x` so that the expression `-x` where `x` is a floating point value known at compile-time, will get the negative zero bitwise representation.
2022-05-03Sema: fix bigIntToFloatAndrew Kelley
The implementation had the `@mulAdd` parameters mixed up.
2022-04-28Merge pull request #11541 from Vexu/stage2-slice-field-ptrVeikka Tuominen
Stage2: fix slice field modification at comptime
2022-04-28Sema: fix slice field modification at comptimeVeikka Tuominen
2022-04-27enable newly passing behavior testsAndrew Kelley
closes #11030
2022-04-27add new builtin function `@tan`Andrew Kelley
The reason for having `@tan` is that we already have `@sin` and `@cos` because some targets have machine code instructions for them, but in the case that the implementation needs to go into compiler-rt, sin, cos, and tan all share a common dependency which includes a table of data. To avoid duplicating this table of data, we promote tan to become a builtin alongside sin and cos. ZIR: The tag enum is at capacity so this commit moves `field_call_bind_named` to be `extended`. I measured this as one of the least used tags in the zig codebase. Fix libc math suffix for `f32` being wrong in both stage1 and stage2. stage1: add missing libc prefix for float functions.
2022-04-27compiler-rt: math functions reorgAndrew Kelley
* unify the logic for exporting math functions from compiler-rt, with the appropriate suffixes and prefixes. - add all missing f128 and f80 exports. Functions with missing implementations call other functions and have TODO comments. - also add f16 functions * move math functions from freestanding libc to compiler-rt (#7265) * enable all the f128 and f80 code in the stage2 compiler and behavior tests (#11161). * update std lib to use builtins rather than `std.math`.
2022-04-20stage2: use indexes for Decl objectsAndrew Kelley
Rather than allocating Decl objects with an Allocator, we instead allocate them with a SegmentedList. This provides four advantages: * Stable memory so that one thread can access a Decl object while another thread allocates additional Decl objects from this list. * It allows us to use u32 indexes to reference Decl objects rather than pointers, saving memory in Type, Value, and dependency sets. * Using integers to reference Decl objects rather than pointers makes serialization trivial. * It provides a unique integer to be used for anonymous symbol names, avoiding multi-threaded contention on an atomic counter.
2022-04-18Sema: fix not reserving enough memory for comptime shlAndrew Kelley
2022-04-14Sema: fix generic instantiation false negativesAndrew Kelley
The problem was that types of non-anytype parameters were being included as part of the check to see if generic function instantiations were equal. Now, Module.Fn additionally stores the information for whether each parameter is anytype or not. `generic_poison` cannot be used to signal this because the type is still needed for comptime arguments; in such case the type will not be present in the newly generated function prototype. This presented one additional challenge: we need to compare equality of two values where one of them is post-coercion and the other is not. So we make some minor adjustments to `Type.eql` to support this. I think this small complexity tradeoff is worth it because it means the compiler does much less work on the hot path that a generic function is called and there is already an existing matching instantiation. closes #11146
2022-04-12Sema: fix comptime equality of extern unions with same tagAndrew Kelley
2022-03-28Value.hashPtr: handle lazy_align as an integerAndrew Kelley
Although lazy_align is a different tag than integer values, it needs to be hashed and equality-tested as if it were a simple integer. Otherwise our basic data structure guarantees fall apart.
2022-03-27Value: hash lazy_alignVeikka Tuominen
2022-03-26stage2: resolve types more lazilyAndrew Kelley
This avoids unwanted "foo depends on itself" compilation errors.
2022-03-26stage2: result location types for function call argumentsAndrew Kelley
* AstGen: restore the param_type ZIR instruction and pass it to the expression for function call arguments. This does not solve the problem for generic function parameters, but it catches stage2 up to stage1 which also does not solve the problem for generic function parameters. - Most of the enhancements in this commit will still be needed for a more sophisticated further improvement to handle generic function types. - In Sema, handling of `as` coercion recognizes the `var_args_param` Type Tag and passes the operand through doing no coercion. - That was the last ZIR tag and we are now using all 256 ZIR tags. * AstGen: array init and struct init expressions use the anon form even when the result location has a type. Prevents the type system incorrectly believing, for example, that a tuple is actually an array when the result location is a param_type of a function with `anytype` parameter. * Sema: add missing coercion in `unionInit` to coerce the init to the corresponding union field type. * `Value.fieldValue` now takes a type and does not take an allocator. closes #11293 After this commit, stage2 passes all the parser tests.
2022-03-23Sema: fix comptime elem_ptr compare fixed addressAndrew Kelley
2022-03-23Sema: Value.copy: we gotta copy the bytesAndrew Kelley
For Value.Tag.bytes, the value copy implementation did not copy the bytes array. No good. This operation must do a deep copy. If we want some other mechanism for not copying very large byte buffers then it has to work differently than this one.
2022-03-22Sema: introduce a mechanism in Value to resolve typesAndrew Kelley
This commit adds a new optional argument to several Value methods which provides the ability to resolve types if it comes to it. This prevents having duplicated logic inside both Sema and Value. With this commit, the "struct contains slice of itself" test is passing by exploiting the new lazy_align Value Tag.