12417 Commits

Author SHA1 Message Date
Jacob Young
66ae42bb72 Sema: fix pointer arithmetic on single array pointers 2023-06-10 20:47:56 -07:00
Andrew Kelley
55cda9a592 InternPool: avoid indexToKey recursion for ptr_slice
Recursion makes this hot function more difficult to profile and
optimize.

The ptr_slice encoding now additionally includes the slice type. This
makes typeOf() implementable without indexToKey() as well as no longer
using recursion in the ptr_slice prong of indexToKey itself.

Unfortunately some logic had to be duplicated. However, I think that a
future enhancement could eliminate the duplication as well as remove
some other unwanted code, improving performance, by representing a slice
value in `Key.Ptr` without `addr` populated directly, but with an
`Index` pointing to the underlying manyptr value.
2023-06-10 20:47:56 -07:00
Andrew Kelley
f7177fb821 InternPool: avoid indexToKey recursion for opt_payload
This is a hot function, and recursion makes it more difficult to
profile, as well as likely making it more difficult to optimize.

Previously, indexToKey for opt_payload would call getAssumeExists() on
the optional type. This made it possible to omit the optional type in
the encoding of opt_payload. However, getAssumeExists() *must* call
indexToKey because of hashing/equality.

So, this commit adds the optional type to the opt_payload encoding,
which increases its "extra" size from 0 to 8 bytes. As a result,
the opt_payload encoding went from not showing up on the top 25 largest
tags to...still not showing up in the top 25 largest tags.

This also helps make InternPool.typeOf() no longer need to call
indexToKey which is another hot function and another source of
recursion.
2023-06-10 20:47:56 -07:00
Andrew Kelley
f2778f7ca0 InternPool: avoid indexToKey recursion for only_possible_value
This is a hot function, and recursion makes it more difficult to
profile, as well as likely making it more difficult to optimize.
2023-06-10 20:47:56 -07:00
Andrew Kelley
b336866fbc InternPool: avoid indexToKey recursion for ptr_elem,ptr_field
This is a hot function, and recursion makes it more difficult to
profile, as well as likely making it more difficult to optimize.
2023-06-10 20:47:56 -07:00
Andrew Kelley
804740af4c InternPool: avoid indexToKey recursion for type_slice
This is a hot function, and recursion makes it more difficult to
profile, as well as likely making it more difficult to optimize.
2023-06-10 20:47:56 -07:00
Jacob Young
5580a69d71 cbe: fix InternPool regressions 2023-06-10 20:47:56 -07:00
Jacob Young
a702af062b x86_64: fix InternPool regressions 2023-06-10 20:47:56 -07:00
Jacob Young
4f70863a55 InternPool: fix various pointer issues 2023-06-10 20:47:56 -07:00
Jacob Young
3269256965 behavior: fix more compiler crashes 2023-06-10 20:47:56 -07:00
Jacob Young
3064d2aa7b behavior: additional llvm fixes 2023-06-10 20:47:56 -07:00
Jacob Young
3b6ca1d35b Module: move memoized data to the intern pool
This avoids memory management bugs with the previous implementation.
2023-06-10 20:47:56 -07:00
Jacob Young
d40b83de45 behavior: pass more tests on llvm again 2023-06-10 20:47:56 -07:00
Jacob Young
2d5bc01469 behavior: get more test cases passing with llvm 2023-06-10 20:47:56 -07:00
Andrew Kelley
c8b0d4d149 InternPool: optimize zigTypeTag()
This is a particularly hot function, so we operate directly on encodings
rather than the more straightforward implementation of calling
`indexToKey`.

I measured this as 1.05 ± 0.04 times faster than the previous commit
with a ReleaseFast build against hello world (which includes std.debug
and formatted printing).

I also profiled the function and found that zigTypeTag() went from being
a major caller of `indexToKey` to being completely insignificant due to
being so fast.
2023-06-10 20:47:56 -07:00
Andrew Kelley
fc358435cb C backend: InternPool fixes 2023-06-10 20:47:56 -07:00
Andrew Kelley
a596ea683c CLI: introduce --verbose-intern-pool
and stop dumping to stderr without the user's consent.
2023-06-10 20:47:56 -07:00
Andrew Kelley
8011faa004 compiler: fix populateTestFunctions InternPool usage 2023-06-10 20:47:56 -07:00
Andrew Kelley
270f9e24dd AstGen: generate tests with anyerror!void
rather than inferred error sets. This avoids extra unnecessary work for
the compiler since inferred error sets are unique types.
2023-06-10 20:47:56 -07:00
Andrew Kelley
e156c1c07e InternPool: correct the logic for struct size dump 2023-06-10 20:47:56 -07:00
Jacob Young
1dc01f1140 InternPool: fix build-exe and compiler-rt crashes 2023-06-10 20:47:55 -07:00
Jacob Young
9cd0ca9f48 Module: rename functions to make ownership checks explicit
This makes the difference between `decl.getOwnedFunction` and
`decl.val.getFunction` more clear when reading the code.
2023-06-10 20:47:55 -07:00
Andrew Kelley
d5f0ee0d62 codegen: fix lowering of constant structs 2023-06-10 20:47:55 -07:00
Andrew Kelley
ace5a5e3cc llvm: simplify control flow lowering structs 2023-06-10 20:47:55 -07:00
Andrew Kelley
63dc0447fc wasm: fix error union constant lowering 2023-06-10 20:47:55 -07:00
Jacob Young
abded5cbb0 TypedValue: implement more prints 2023-06-10 20:47:55 -07:00
Jacob Young
f2c716187c InternPool: fix more crashes 2023-06-10 20:47:55 -07:00
Andrew Kelley
66c4396854 AIR: eliminate the values array 2023-06-10 20:47:55 -07:00
Jacob Young
9afa974183 InternPool: fix enough crashes to run build-obj on a simple program 2023-06-10 20:47:55 -07:00
Jacob Young
9a738c0be5 Module: intern the values of decls when they are marked alive
I'm not sure if this is the right place for this to happen, and
it should become obsolete when comptime mutation is rewritten
and the remaining legacy value tags are remove, so keeping this
as a separate revertable commit.
2023-06-10 20:47:55 -07:00
Andrew Kelley
f37c0a4593 Sema: inferred allocations no longer abuse type/value system
Previously, there were types and values for inferred allocations and a
lot of special-case handling. Now, instead, the special casing is
limited to AIR instructions for these use cases.

Instead of storing data in Value payloads, the data is now stored in AIR
instruction data as well as the previously `void` value type of the
`unresolved_inferred_allocs` hash map.
2023-06-10 20:47:55 -07:00
Jacob Young
5d0d5893fd Sema: fix some issues with the inferred alloc tag change 2023-06-10 20:47:55 -07:00
Jacob Young
70cc68e999 Air: remove constant tag
Some uses have been moved to their own tag, the rest use interned.

Also, finish porting comptime mutation to be more InternPool aware.
2023-06-10 20:47:55 -07:00
Jacob Young
72e4ea3821 InternPool: fix crashes up to in progress comptime mutation 2023-06-10 20:47:55 -07:00
Jacob Young
1a4626d2cf InternPool: remove more legacy values
Reinstate some tags that will be needed for comptime init.
2023-06-10 20:47:54 -07:00
Jacob Young
6e0de1d116 InternPool: port most of value tags 2023-06-10 20:47:54 -07:00
Andrew Kelley
5555bdca04 InternPool: support int->comptime_int in getCoerced 2023-06-10 20:47:54 -07:00
Andrew Kelley
2052260039 Sema: update zirSliceLength to avoid resolveInst(.none) 2023-06-10 20:47:54 -07:00
Andrew Kelley
01ca841f12 Sema: improve the types_to_resolve mechanism
Store `InternPool.Index` as the key instead which means that an AIR
instruction no longer needs to be burned to store the type, and also
that we can use AutoArrayHashMap instead of an ArrayList, which avoids
storing duplicates into the set, potentially saving CPU time.
2023-06-10 20:47:54 -07:00
Andrew Kelley
1b64eed107 remove the kludges from std.builtin
I added these in an earlier commit in this branch. This commit removes
them before the branch is merged.
2023-06-10 20:47:54 -07:00
Jacob Young
484c3e8cbc llvm: fix incorrect slice lowering 2023-06-10 20:47:54 -07:00
Jacob Young
a7c3ca3531 InternPool: add lldb pretty printing for indices 2023-06-10 20:47:54 -07:00
Jacob Young
a6fcf469fc Value: remove legacy type values 2023-06-10 20:47:54 -07:00
Jacob Young
84099e50fc TypedValue: fix debug print crashes 2023-06-10 20:47:54 -07:00
Jacob Young
be1b231206 InternPool: add missing logic 2023-06-10 20:47:54 -07:00
Jacob Young
9584feae5f InternPool: fix logic bugs 2023-06-10 20:47:54 -07:00
Jacob Young
dfd91abfe1 InternPool: add more pointer values 2023-06-10 20:47:54 -07:00
Jacob Young
cbf304d8c3 InternPool: fix coersion issues 2023-06-10 20:47:54 -07:00
Jacob Young
25cd4bb3c9 Type: hack around isNoReturn queries for the remaining legacy tags 2023-06-10 20:47:54 -07:00
Andrew Kelley
e4d498cd3a InternPool: add missing ensureCapacity call with enums 2023-06-10 20:47:54 -07:00