aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
AgeCommit message (Collapse)Author
2022-07-21Sema: better source location for function call argsVeikka Tuominen
2022-07-21Sema: better function parameter source locationVeikka Tuominen
2022-07-21Sema: better source location for incompatible capture groupVeikka Tuominen
2022-07-21Sema: more union and enum tag type validationVeikka Tuominen
2022-07-21Sema: validate function parameter types and return typeVeikka Tuominen
2022-07-21Sema: validate function pointer alignmentVeikka Tuominen
2022-07-21Sema: explain why comptime is neededVeikka Tuominen
2022-07-21stage2: better pointer source locationVeikka Tuominen
2022-07-15Module: improve source spans for initializers and var typesVeikka Tuominen
```zig const U = union { foo: u32, bar: u32 }; test { var a = U{ .foo = 1213, .bar = 1123 }; _ = a; } test { var a: (123 + 5238094) = 0; _ = a; } ``` before: ``` :30: note: additional initializer here var a = U{ .foo = 1213, .bar = 1123 }; ^~~ :12: error: expected type 'type', found 'comptime_int' var a: (123 + 5238094) = 0; ^ ``` after: ``` :30: note: additional initializer here var a = U{ .foo = 1213, .bar = 1123 }; ~^~~~~~~~~~ :12: error: expected type 'type', found 'comptime_int' var a: (123 + 5238094) = 0; ^~~~~~~~~~~~~~~ ```
2022-07-15Compilation: point caret in error message at the main tokenVeikka Tuominen
2022-07-14stage2: point to error location using spansVeikka Tuominen
2022-07-13stage2: lower each struct field type, align, init separatelyAndrew Kelley
Previously, struct types, alignment values, and initialization expressions were all lowered into the same ZIR body, which caused false positive "depends on itself" errors when the initialization expression depended on the size of the struct. This also uses ResultLoc.coerced_ty for struct field alignment and initialization values. The resulting ZIR encoding ends up being roughly the same, neither smaller nor larger than previously. Closes #12029
2022-07-12stage2: handle parser notes in a more general wayVeikka Tuominen
2022-07-12parser: add helpful error for C style container declarationsVeikka Tuominen
```zig // a.zig struct Foo { a: u32, }; ``` before: ``` a.zig:1:1: error: expected test, comptime, var decl, or container field, found 'struct' struct Foo { ^ ``` after: ``` a.zig:1:8: error: 'struct Foo' is invalid struct Foo { ^ a.zig:1:8: note: to declare a container do 'const Foo = struct' struct Foo { ^ ```
2022-07-07Sema: improve slice source locationsVeikka Tuominen
2022-07-07Module: add `.node_offset_un_op`Veikka Tuominen
2022-06-30Sema: improve auto generated union enum nameVeikka Tuominen
2022-06-27Sema: honor the --test-filter flagAndrew Kelley
2022-06-11stage2: improve debugging toolsVeikka Tuominen
llvm: dump failed module when -femit-llvm-ir set print_air: * print fully qualified name * use Type.fmt and Value.fmtValue, fmtDebug is useless TypedValue * handle anon structs and tuples * fix bugs
2022-06-09stage2: use std.debug.Trace only when explicitly enabledAndrew Kelley
Because it bumps up the stack space requirements, which is making a test case fail on aarch64 drone CI.
2022-06-09std.debug.Trace: improve APIAndrew Kelley
Now `std.debug.Trace` is a concrete type with pre-chosen defaults. `std.debug.ConfigurableTrace` can be used for more advanced cases.
2022-06-09introduce std.debug.TraceAndrew Kelley
And use it to debug a LazySrcLoc in stage2 that is set to a bogus value. The actual fix in this commit is: ```diff - try sema.emitBackwardBranch(&child_block, call_src); + try sema.emitBackwardBranch(block, call_src); ```
2022-06-06stage2: use correct type (u29) for alignmentVeikka Tuominen
2022-05-30stage2: add missing data to ZIR encoding of functionsAndrew Kelley
The main purpose of this commit is to prepare to implement support for callconv(), align(), linksection(), and addrspace() annotations on generic functions where the provided expression depends on comptime parameters (making the function generic). It's a rather involved change, so this commit only makes the necessary changes to AstGen without regressing any behavior, and a follow-up commit can finish the task by making the enhancements to Sema. By my quick estimation, the new encoding for functions is a negligible improvement - along the lines of 0.005% fewer total ZIR bytes on average. Still, it's nice that this commit, while adding more data into ZIR, actually ends up reducing the storage size thanks to a slightly more sophisticated encoding. Zir.Inst.ExtendedFunc is renamed to Zir.Inst.FuncFancy to eliminate confusion about it being an extended instruction (it used to be but is no longer). The encoding for this instruction is completely reworked. The encoding for Zir.Inst.Func is also changed slightly - when the return type body length is 1, then only a Zir.Inst.Ref is provided; not a full body. linksection() and addrspace() are now communicated via func_fancy ZIR instruction rather than as part of the corresponding decl. This allows their expressions to observe comptime parameters.
2022-05-27math: make `cast` return optional instead of an errorAli Chraghi
2022-05-25Sema: generic function instantiations inherit branch quotaAndrew Kelley
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-16Sema: do not call `returnError` when returning payload of error unionVeikka Tuominen
2022-05-16stage2: implement error return tracesVeikka Tuominen
2022-05-06flatten lib/std/special and improve "pkg inside another" logicAndrew Kelley
stage2: change logic for detecting whether the main package is inside the std package. Previously it relied on realpath() which is not portable. This uses resolve() which is how imports already work. * stage2: fix cleanup bug when creating Module * flatten lib/std/special/* to lib/* - this was motivated by making main_pkg_is_inside_std false for compiler_rt & friends. * rename "mini libc" to "universal libc"
2022-05-06stage2: fix std lib tests always filtering out all testsAndrew Kelley
2022-05-04stage2: implement global assemblyAndrew Kelley
So far it's supported by the LLVM backend only. I recommend for the other backends to wait for the resolution of #10761 before adding support for this feature.
2022-04-30Zir: turn extended func into func_extendedVeikka Tuominen
2022-04-22Revert "Fix C include files not being in `whole` cache (#11365)"Andrew Kelley
This reverts commit a430630002bf02162ccbf8d3eb10fd73e490cefd. Wait a minute, I'm sorry, I need to revert this. The whole premise of this change is broken because the point of the hash is that it tells whether the same compilation has been done before. This requires items to be added to the hash in the same sequence every time. This means that introducing a lock is fundamentally broken because the order needs to be the same in future runs of the compiler, and not decided by threads racing against each other. The proper solution to this is to, in whole cache mode, append the hash inputs to some data structure, and then after the compilation is complete, do some kind of sorting on the hash inputs so that they will be the same order every time, then apply them in sequence. No lock on the Cache object is needed for this scheme.
2022-04-22Fix C include files not being in `whole` cache (#11365)Tom Read Cutting
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-18stage2: fix building stage3 in release modeAndrew Kelley
Previously, comptime function calls could cause a crash in the hash function due to a lazy value depending on an unresolved type.
2022-04-14stage2: progress towards stage3Andrew Kelley
* The `@bitCast` workaround is removed in favor of `@ptrCast` properly doing element casting for slice element types. This required an enhancement both to stage1 and stage2. * stage1 incorrectly accepts `.{}` instead of `{}`. stage2 code that abused this is fixed. * Make some parameters comptime to support functions in switch expressions (as opposed to making them function pointers). * Avoid relying on local temporaries being mutable. * Workarounds for when stage1 and stage2 disagree on function pointer types. * Workaround recursive formatting bug with a `@panic("TODO")`. * Remove unreachable `else` prongs for some inferred error sets. All in effort towards #89.
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-02stage2: more resilient error handlingAndrew Kelley
* If more than one error is reported for the same Decl, the first error message is kept and the second one discarded. * Prevent functions from being sent to codegen backends if there were any errors resolving any of their parameter types or return type.
2022-04-01stage2: hook up Sema to the progress barAndrew Kelley
2022-03-30Sema: fix usingnamespace decl Value in wrong arenaAndrew Kelley
closes #11297
2022-03-30Sema: enhance is_non_err to be comptime more oftenAndrew Kelley
* Sema: store the precomputed monomorphed_funcs hash inside Module.Fn. This is important because it may be accessed when resizing monomorphed_funcs while this Fn has already been added to the set, but does not have the owner_decl, comptime_args, or other fields populated yet. * Sema: in `analyzeIsNonErr`, take advantage of the AIR tag being `wrap_errunion_payload` to infer that `is_non_err` is comptime true without performing any error set resolution. - Also add some code to check for empty inferred error sets in this function. If necessary we do resolve the inferred error set. * Sema: queue full type resolution of payload type when `wrap_errunion_payload` AIR instruction is emitted. This ensures the backend may check the alignment of it. * Sema: resolveTypeFully now additionally resolves comptime-only status. closes #11306
2022-03-28stage2: LLVM: (WIP) add union fields debug infoJohn Schmidt
2022-03-27`Namespace.decls` use context to save memoryjagt
change `Module.Namespace.decls` from `AutoArrayHashMapUnmanaged` to `ArrayHashMapUnmanaged(*Decl, void)` with custom context to eliminate duplicated decl name strings. Also see: https://zig.news/andrewrk/how-to-use-hash-map-contexts-to-save-memory-when-doing-a-string-table-3l33
2022-03-26stage2: resolve types more lazilyAndrew Kelley
This avoids unwanted "foo depends on itself" compilation errors.
2022-03-23stage2: fix some generics issuesAndrew Kelley
* std.meta: correct use of `default_value` in reification. stage1 accepted a wrong type for `null`. * Sema: after instantiating a generic function, if the return type ends up being a comptime-known type, then we return an error, undoing the generic function instantiation, and making a comptime function call instead. - We also needed to clean up the dependency graph in this case. * Sema: reified enums set tag_ty_inferred to false since an integer tag type is provided. This is a limitation of the `@Type` builtin which will be addressed with #10710. * Sema: fix resolveInferredErrorSet incorrectly calling ensureFuncBodyAnalyzed on generic functions.
2022-03-23Sema: introduce a type resolution queueAndrew Kelley
That happens after a function body is analyzed. This prevents circular dependency compile errors and yet a way to mark types that need to be fully resolved before a given function is sent to the codegen backend.
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.
2022-03-22stage2: lazy `@alignOf`Andrew Kelley
Add a `target` parameter to every function that deals with Type and Value.