Commit graph

25109 commits

Author SHA1 Message Date
Luuk de Gram
388589987c
wasm-linker: allow explicit memory exports
Rather than verifying if importing memory is false, we now rely
on the option that was passed to the CLI (where export is defaulted
to `true` unless only import-memory is given).
2023-07-19 17:22:45 +02:00
Andrew Kelley
d5d067211b Autodoc: fix crash on new InternPool addition 2023-07-18 23:45:47 -07:00
Andrew Kelley
9262b6076f Sema: fix generic function instances not respecting linksection 2023-07-18 21:46:30 -07:00
Andrew Kelley
c597ba32d9 Sema: fix return type of generic function is function pointer
also that's one less standalone test and one more behavior test.
2023-07-18 21:15:16 -07:00
Andrew Kelley
3145ae561d Sema: fix compile error source location regressions 2023-07-18 19:02:06 -07:00
Andrew Kelley
8daa8d255b Sema: fix fn_proto_param LazySrcLoc resolution
to match source code span from merge-base.
2023-07-18 19:02:06 -07:00
Andrew Kelley
727b371bbc Sema: fix source location crash for function prototypes 2023-07-18 19:02:06 -07:00
Andrew Kelley
0153f3a8f9 Sema: fix crash: array_in_c_exported_function
Fuck it, we're storing decl indexes in LazySrcLoc now.
2023-07-18 19:02:06 -07:00
Andrew Kelley
47499bf47b Sema: enhance generic call error message
when the type of an anytype parameter is a comptime-only type but the
argument at the callsite is runtime-known.
2023-07-18 19:02:06 -07:00
Andrew Kelley
abe71b40c5 Sema: use src_decl for exported status
Fixes wrong calling convention in instantiated functions.
2023-07-18 19:02:06 -07:00
Andrew Kelley
3f2a4720b1 compiler: fix branch regressions
* getOwnedFunctionIndex no longer checks if the value is actually a
   function.
 * The callsites to `intern` that I added want to avoid the `getCoerced`
   call, so I added `intern2`.
 * Adding to inferred error sets should not happen if the destination
   error set is not the inferred error set of the current Sema instance.
 * adhoc_inferred_error_set_type can be seen by the backend. Treat it
   like anyerror.
2023-07-18 19:02:06 -07:00
Andrew Kelley
b03d34429d compiler: work around slightly different generics semantics
Both of these cases are interesting, were not covered by behavior tests,
and should be inspected carefully with regards to the language
specification.
2023-07-18 19:02:06 -07:00
Andrew Kelley
d15e8f8017 Sema: resolve inferred error set with function state in_progress
This way dependency loops are reported instead of the compiler crashing.
2023-07-18 19:02:06 -07:00
Andrew Kelley
e1935d4d16 InternPool: fix funcAnalysis through func_coerced 2023-07-18 19:02:06 -07:00
Andrew Kelley
ad8c250103 Sema: reset generic_owner for inline/comptime calls 2023-07-18 19:02:06 -07:00
Andrew Kelley
e27b2b3ab9 Sema: restore WipCaptures logic
Earlier in this branch, I failed to properly port this logic while
reworking generic functions. This commit fixes it.
2023-07-18 19:02:06 -07:00
Andrew Kelley
3a4d565254 Sema: fix zirStoreNode crash
when other function's inferred error set is the return type of a
function, it should not try to insert the error set into it.

this implies that this branch fixes a bug in master branch.
2023-07-18 19:02:06 -07:00
Andrew Kelley
7c66bd39be Sema: fix analyzeIsNonErrComptimeOnly false positive
The logic here was not properly ported from master branch which broke
errdefers.
2023-07-18 19:02:06 -07:00
Andrew Kelley
45a8c6c1f4 AstGen: idiomatic use of switch 2023-07-18 19:02:06 -07:00
Andrew Kelley
6754d1a182 Sema: fix access of inactive union field
When instantiating a generic function call, in the case of a function
call generated by the language, the LazySrcLoc provided for `call_src`
may not point to anything interesting.
2023-07-18 19:02:06 -07:00
Andrew Kelley
9f61c29bfb InternPool: unwrap func_coerced when using it as generic_owner 2023-07-18 19:02:06 -07:00
Andrew Kelley
1b70fca534 Sema: fix generic function instance with comptime return type 2023-07-18 19:02:06 -07:00
Andrew Kelley
722bd22508 Sema: fix not setting up adhoc inferred error set correctly
for comptime/inline calls.
2023-07-18 19:02:06 -07:00
Andrew Kelley
684aee3220 frontend: fixes for function regressions in this branch
* Introduce InternPool.Tag.func_coerced to handle the case of a
   function body coerced to a new type. `InternPool.getCoerced` is now
   implemented for function bodies in this branch.
 * implement resolution of ad-hoc inferred error sets in
   `Sema.analyzeCall`.
 * fix generic_owner being set wrong for child Sema bodies of param
   expressions.
 * fix `Sema.resolveInferredErrorSetTy` when passed `anyerror`.
2023-07-18 19:02:06 -07:00
Andrew Kelley
927f6ec8ca frontend: fix inferred error sets of comptime/inline calls
Previously, they shared function index with the owner decl, but that
would clobber the data stored for inferred error sets of runtime calls.

Now there is an adhoc_inferred_error_set_type which models the problem
much more correctly.
2023-07-18 19:02:06 -07:00
Andrew Kelley
82db06fa67 InternPool: fix regression in getting error sets
Missing call to `addStringsToMap`.
2023-07-18 19:02:06 -07:00
Andrew Kelley
d98526f912 Type.print: fix inferred error set crash
The index is a function, not an inferred error set.
2023-07-18 19:02:05 -07:00
Andrew Kelley
b81d193021 InternPool: implement getFuncInstanceIes
and fix bug in equality checking for functions with inferred error sets.
2023-07-18 19:02:05 -07:00
Andrew Kelley
8f37b794a5 InternPool: fix debug info helpers for changes to functions
It still doesn't work correctly due to incorrect debug info for packed
structs.
2023-07-18 19:02:05 -07:00
Andrew Kelley
cbbb5cc2ec InternPool: implement getFuncInstance
This handles the case without an inferred error set. Still TODO is the
case with one.

Also fixes branchQuota returning a pointer to the wrong field.
2023-07-18 19:02:05 -07:00
Andrew Kelley
6d72f971af InternPool: implement getExternFunc 2023-07-18 19:02:05 -07:00
Andrew Kelley
8fd77395d6 InternPool: fix getErrorSetType
Before, it incorrectly passed an InternPool.Index where an extra array
index was expected (to the function which is renamed to `extraErrorSet`
in this commit).
2023-07-18 19:02:05 -07:00
Andrew Kelley
c193872c81 InternPool: implement indexToKey for func_instance and func_decl
Also delete incorrect frees an arena-allocated parameters.
2023-07-18 19:02:05 -07:00
Andrew Kelley
4a55fc6c53 InternPool: avoid false negatives for functions with inferred error sets
There is one case where function types may be inequal but we still want
to find the same function body instance in InternPool.

In the case of the functions having an inferred error set, the key used
to find an existing function body will necessarily have a unique
inferred error set type, because it refers to the function body
InternPool Index. To make this case work we omit the inferred error set
from the equality and hashing functions.
2023-07-18 19:02:05 -07:00
Andrew Kelley
f3dc53f6b5 compiler: rework inferred error sets
* move inferred error sets into InternPool.
   - they are now represented by pointing directly at the corresponding
     function body value.
 * inferred error set working memory is now in Sema and expires after
   the Sema for the function corresponding to the inferred error set is
   finished having its body analyzed.
 * error sets use a InternPool.Index.Slice rather than an actual slice
   to avoid lifetime issues.
2023-07-18 19:02:05 -07:00
Andrew Kelley
55e89255e1 compiler: begin untangling anonymous decls from source decls
The idea here is to move towards a future where anonymous decls are
represented entirely by an `InternPool.Index`. This was needed to start
implementing `InternPool.getFuncDecl` which requires moving creation and
deletion of Decl objects into InternPool.

 * remove `Namespace.anon_decls`
 * remove the concept of cleaning up resources from anonymous decls,
   relying on InternPool instead.
 * move namespace and decl object allocation into InternPool
2023-07-18 19:02:05 -07:00
Andrew Kelley
db33ee45b7 rework generic function calls
Abridged summary:

 * Move `Module.Fn` into `InternPool`.
 * Delete a lot of confusing and problematic `Sema` logic related to
   generic function calls.

This commit removes `Module.Fn` and replaces it with two new
`InternPool.Tag` values:

 * `func_decl` - corresponding to a function declared in the source
   code. This one contains line/column numbers, zir_body_inst, etc.

 * `func_instance` - one for each monomorphization of a generic
   function. Contains a reference to the `func_decl` from whence the
   instantiation came, along with the `comptime` parameter values (or
   types in the case of `anytype`)

Since `InternPool` provides deduplication on these values, these fields
are now deleted from `Module`:

 * `monomorphed_func_keys`
 * `monomorphed_funcs`
 * `align_stack_fns`

Instead of these, Sema logic for generic function instantiation now
unconditionally evaluates the function prototype expression for every
generic callsite. This is technically required in order for type
coercions to work. The previous code had some dubious, probably wrong
hacks to make things work, such as `hashUncoerced`. I'm not 100% sure
how we were able to eliminate that function and still pass all the
behavior tests, but I'm pretty sure things were still broken without
doing type coercion for every generic function call argument.

After the function prototype is evaluated, it produces a deduplicated
`func_instance` `InternPool.Index` which can then be used for the
generic function call.

Some other nice things made by this simplification are the removal of
`comptime_args_fn_inst` and `preallocated_new_func` from `Sema`, and the
messy logic associated with them.

I have not yet been able to measure the perf of this against master
branch. On one hand, it reduces memory usage and pointer chasing of the
most heavily used `InternPool` Tag - function bodies - but on the other
hand, it does evaluate function prototype expressions more than before.
We will soon find out.
2023-07-18 19:02:05 -07:00
Jacob Young
70c71935c7 cbe: fix pointers to aliases of extern values 2023-07-18 17:58:39 -07:00
Mathew R Gordon
11695745e5 getenv: remove unnessary small key block
The code removed does unnecessary copying in order to create a null-terminated pointer, just to pass it to libc getenv. It only does this for `small keys`, which are under 64 bytes in size.

Instead of going out of the way to add a null byte to a function that takes normal slices, this should just be handled by the loop below, which scans c.environ to find the value
2023-07-18 11:44:23 +02:00
Frank Denis
a0b35249a2
Replace hand-written endian-specific loads with std.mem.readInt*() (#16431)
And when we have the choice, favor little-endian because it's 2023.

Gives a slight performance improvement:

   md5: 552 -> 555 MiB/s
  sha1: 768 -> 786 MiB/s
sha512: 211 -> 217 MiB/s
2023-07-18 00:40:31 +02:00
Luiz Berti
a86f589a9f
Small documentation fixes on std.crypto (#16427)
* Small documentation fix of ChaCha variants

Previous documentation was seemingly copy-pasted and left
behind some errors where the number of rounds was not
properly updated.

* Suggest `std.crypto.utils.secureZero` on `@memset` docs

* Revert previous change
2023-07-17 21:16:41 +00:00
Mathew R Gordon
bf827d0b55
std: Make getenv return 0-terminated slice 2023-07-17 10:57:41 +00:00
George Zhao
9abe392647
std.crypto: add finalResult and peek api for Sha1 (#16426)
close #16250
2023-07-17 10:02:57 +00:00
Andrew Kelley
a576082170 std: reword some comments 2023-07-16 18:32:52 -07:00
Erik Arvstedt
c6aa29b6fd SinglyLinkedList: rename invert -> reverse 2023-07-15 21:37:54 -07:00
Loris Cro
7dd1cf26f9 autodoc: improved linking for declrefs 2023-07-14 19:11:55 +02:00
Loris Cro
a187141056
Autodoc tokenizer (#16409)
* autodoc: init work to refactor exprName

* autodoc: Implement more expressions in exprName refactor

* autodoc: more work

* autodoc: More exprName to ex refactoring

* autodoc: Remove whitespace flag from renderer; Add pre tags in
value and variable drawing in renderContainer

* autodoc: add inline styling to pre blocks

* autodoc: move renderer code to main.js

* autodoc: More exprName to ex refactoring; Fn signatures rendered with new code

* autodoc: Fix function rendering. Add more things to ex

* autodoc: nuke exprName

---------

Co-authored-by: Krzysztof Wolicki <der.teufel.mail@gmail.com>
2023-07-14 16:27:09 +02:00
e4m2
3022c525ec
std.crypto.sha3: Minor TurboSHAKE/Keccak fixes (#16408) 2023-07-14 14:02:01 +00:00
Casey Banner
094cd92615
macho: fix __unwind_info sentinel entry not always being the upper bound (#16395)
macho: record highest address of unwind records before folding

---------

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2023-07-14 11:47:00 +00:00
xdBronch
b177e17d15 fix alignment error in uefi FileInfo protocol
previously complained about `[*]const u8` having alignment 1 and `[*:0]const u16` having alignment 2
2023-07-14 00:31:31 -07:00