aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
AgeCommit message (Collapse)Author
2023-06-10stage2: add missing comptimeOnly logic for InternPoolAndrew Kelley
2023-06-10fill out more InternPool Type methodsAndrew Kelley
particularly, printing types
2023-06-10stage2: migrate many pointer types to the InternPoolAndrew Kelley
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-10stage2: move all integer types to InternPoolAndrew Kelley
2023-06-10Type.isSlice: make it InternPool awareAndrew Kelley
2023-06-10Type: update to use InternPool for some methodsAndrew 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 isSinglePointerAndrew Kelley
2023-06-10InternPool: implement typePtrOrOptionalPtrTyAndrew Kelley
2023-06-10InternPool: implement resolveTypeFieldsAndrew Kelley
2023-06-10InternPool: implement hasWellDefinedLayout for simple_typeAndrew Kelley
2023-06-10InternPool: implement hasRuntimeBitsAdvanced for simple_typeAndrew Kelley
2023-06-10InternPool: implement typeHasOnePossibleValue for simple_typeAndrew Kelley
2023-06-10stage2: isGenericPoison InternPool awarenessAndrew 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-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-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-05-19Sema: eliminate `Type.Tag.var_args_param`Andrew Kelley
This was a special type tag used for hacky stuff in Semantic Analysis. Move the hacky stuff to use a dedicated `Air.Inst.Ref` instead. This way, `var_args_param` is not involved in the type system or intern pool.
2023-05-15x86_64: redo movement, float negation, and `@fabs`Jacob Young
2023-05-09fix `[x]u65529` and above overflowingr00ster91
``` $ cat overflow.zig test { var a: [1]u65535 = undefined; _ = a; } $ zig-out/bin/zig test overflow.zig thread 290266 panic: integer overflow zig/src/type.zig:3604:55: 0xada43d in intAbiAlignment (zig) std.math.ceilPowerOfTwoPromote(u16, (bits + 7) / 8), ^ zig/src/type.zig:3598:42: 0xadd4ea in intAbiSize (zig) const alignment = intAbiAlignment(bits, target); ^ zig/src/type.zig:3500:61: 0x92be91 in abiSizeAdvanced (zig) return AbiSizeAdvanced{ .scalar = intAbiSize(bits, target) }; ^ zig/src/type.zig:3385:62: 0x928933 in abiSizeAdvanced (zig) switch (try payload.elem_type.abiSizeAdvanced(target, strat)) { ^ zig/src/type.zig:3268:32: 0x92c012 in abiSize (zig) return (abiSizeAdvanced(ty, target, .eager) catch unreachable).scalar; ^ ``` This is only noticed in a debug build of zig and silently does the wrong thing and overflows in release builds. This happened to `[x]u65529` and above because of the ` + 7` on a `u16`.
2023-05-02Implement multi-argument @min/@max and notice boundsmlugg
Resolves: #14039
2023-04-29Merge pull request #15503 from r00ster91/noinlineAndrew Kelley
Sema: emit error for always_inline call of noinline function
2023-04-29Sema: emit error for always_inline call of noinline functionr00ster91
Fixes #15489 This also lays the groundwork for exposing the whether or not a function is noinline in std.builtin.Fn as an `is_noinline: bool` field if we ever want to do that.
2023-04-28compiler: use `@memcpy` instead of `std.mem.copy`Andrew Kelley
2023-04-25update `@memcpy` to require equal src and dest lensAndrew Kelley
* Sema: upgrade operands to array pointers if possible when emitting AIR. * Implement safety checks for length mismatch and aliasing. * AIR: make ptrtoint support slice operands. Implement in LLVM backend. * C backend: implement new `@memset` semantics. `@memcpy` is not done yet.
2023-04-13add c_char typeAndrew Kelley
closes #875
2023-04-09amdgpu,nvptx: unify kernel calling conventionsRobin Voetter
AmdgpuKernel and NvptxKernel are unified into a Kernel calling convention. There is really no reason for these to be separate; no backend is allowed to emit the calling convention of the other. This is in the same spirit as the .Interrupt calling convention lowering to different LLVM calling conventions, and opens the way for SPIR-V kernels to be exported using the Kernel calling convention.
2023-02-27tools: implement more lldb pretty printersJacob Young
2023-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2023-02-18Sema: implement for_lenAndrew Kelley
This also makes another breaking change to for loops: in order to capture a pointer of an element, one must take the address of array values. This simplifies a lot of things, and makes more sense than how it was before semantically. It is still legal to use a for loop on an array value if the corresponding element capture is byval instead of byref.
2023-01-31move compiler's CType logic to std.TargetAndrew Kelley
This API only depends on std.Target and is extremely useful in build scripts when populating configure files.
2023-01-22Value: implement `compareAllWithZero` for `bytes` and `str_lit`Veikka Tuominen
Closes #10692
2023-01-22type: correct condition for eliding pointer alignment canonicalizationVeikka Tuominen
Closes #14373
2023-01-16Sema: automatically optimize order of struct fieldsVeikka Tuominen
This is a simple starting version of the optimization described in #168 where the fields are just sorted by order of descending alignment.
2023-01-16swap align and callconv in function typeNameTechatrix
2023-01-05resolve some TODOsVeikka Tuominen
2022-12-29Type: fix printing of default alignment on non-byte aligned pointersVeikka Tuominen
2022-12-27Sema: make overflow arithmetic builtins return tuplesVeikka Tuominen
2022-12-18Merge pull request #13914 from Vexu/variadicAndrew Kelley
implement defining C variadic functions
2022-12-17std.builtin: rename Type.UnionField and Type.StructField's field_type to typer00ster91
2022-12-17Type: fix incorrect usage of `hasRuntimeBits`Veikka Tuominen
Closes #13962
2022-12-15port packed vector elem ptr logic from stage1Veikka Tuominen
Closes #12812 Closes #13925