17246 Commits

Author SHA1 Message Date
Jakub Konka
caa4e30ef4 x64: impl airMemset using inline memset 2022-03-01 15:21:10 +01:00
Jakub Konka
5a6f4395e6 x64: impl airMemcpy using inline memcpy 2022-03-01 14:29:48 +01:00
joachimschmidt557
ca97caab8a stage2 ARM: implement return types with abi size > 4 2022-03-01 09:14:52 +01:00
Jakub Konka
ec54ceee6d
Merge pull request #11016 from ziglang/x64-more-codegen 2022-03-01 09:14:23 +01:00
Luuk de Gram
f5a31cb0d6 wasm-linker: Intern globals, exports & imports
Symbols that have globals used to have their lookup key be the symbol name.
This key is now the offset into the string table.

Imports have both the module name (library name) and name (of the symbol), those strings are now
also being interned. This can save us up to 24bytes per import which have both their module name and name de-duplicated.
Module names are almost entirely the same for all imports, providing us with a big chance of saving us 12 bytes at least.

Just like imports, exports can also have a seperate name than the internal symbol name. Rather than storing the slice,
we now store the offset of this string instead.
2022-03-01 08:35:20 +01:00
Luuk de Gram
b1159ab7ae wasm-linker: Intern all symbol names
For all symbols read from object files as well as generated from Zig code
will now be interned and have their offset into the string table saved on the `Symbol` instead.

Besides interning, local symbols now also use a decl's fully qualified name.
When a decl/symbol is extern/to-be-imported, the name of the decl itself will be used for symbol resolving.
Similarly for symbols that will be exported, will have their 'export name' set.
2022-03-01 08:35:20 +01:00
Luuk de Gram
49f01c0a0c wasm-object: Use given allocator rather than arena
This is preliminary work for string interning in the wasm linker.
Using an arena would defeat the purpose of de-duplicating strings as we wouldn't be able to free memory
of duplicated strings.
This change also means we can simplify wasm binary parsing, by creating a general purpose parser that
parses the binary into its sections, but untyped. Doing this, allows us to re-use the base of that, for
object file, but also debug info parsing.
2022-03-01 08:35:20 +01:00
Andrew Kelley
eaf1c97ce8
Merge pull request #11010 from mitchellh/peer-errors
stage2: peer resolve error sets and error unions
2022-03-01 01:22:50 -05:00
Andrew Kelley
4763fd1a41 Sema: clean up peer resolution of errors
* Fix compile error for `zirErrorUnionType`.
 * Convert zirMergeErrorSets logic to call `Type.errorSetMerge`.
   It does not need to create a Decl as the TODO comment hinted.
 * Extract out a function called `resolveInferredErrorSetTy`.
 * Rework `resolvePeerTypes` with respect to error unions and
   error sets. This is a less complex implementation that passes all the
   same tests and uses many fewer lines of code by taking advantage of
   the function `coerceInMemoryAllowedErrorSets`.
   - Always merge error sets in the order that makes sense, even when
     that means `@typeInfo` incompatibility with stage1.
 * `Type.errorSetMerge` no longer overallocates.
 * Don't skip passing tests.
2022-02-28 23:15:58 -07:00
Mitchell Hashimoto
5e2e7675d5 stage2: pass generic poison up the chain in peer type resolution 2022-02-28 20:42:13 -07:00
Mitchell Hashimoto
0ce2d46ff9 stage2: error union/set peer resolution switch to "else" form of for loop 2022-02-28 20:42:13 -07:00
Mitchell Hashimoto
ea00e50045 stage2: skip error union test on native 2022-02-28 20:42:13 -07:00
Mitchell Hashimoto
0eb3cb9e8c stage2: order of error set merging should match stage1 2022-02-28 20:42:13 -07:00
Mitchell Hashimoto
6dae1de017 skip tests on native backends 2022-02-28 20:42:13 -07:00
Mitchell Hashimoto
b4ce855788 stage2: error union and non-error set/union peer cast resolution 2022-02-28 20:42:13 -07:00
Mitchell Hashimoto
38aae2cb7c stage2: peer resolve error sets and unions, add more tests 2022-02-28 20:42:13 -07:00
Mitchell Hashimoto
bfada7c514 stage2: implement peer type resolution between error unions 2022-02-28 20:42:13 -07:00
Andrew Kelley
d5131e91eb Sema: complete the Type.hash function
Similar to how Type.eql was reworked in the previous commit, this commit
reworks Type.hash to check all the different kinds of tags that a Type
can be represented with. It also completes the implementation for all
types except error sets, which need to have Type.eql enhanced as well.
2022-02-28 20:05:21 -07:00
Andrew Kelley
157f66ec07 Sema: fix pointer type hash and equality functions
Several issues with pointer types are fixed:

Prior to this commit, Zig would not canonicalize a pointer type with
an explicit alignment to alignment=0 if it matched the pointee ABI
alignment. In order to fix this, `Type.ptr` now takes a Target
parameter. I also moved the host_size canonicalization to `Type.ptr`
since target is now available. Similarly, is_allowzero in the case of
C pointers is now treated as a canonicalization done by the function
rather than a precondition.

in-memory coercion for pointers now properly checks ABI alignment
of pointee types instead of incorrectly treating the 0 value as an
alignment.

Type equality is completely reworked based on the tag() rather than the
zigTypeTag(). It's still semantically based on zigTypeTag() but that
knowledge is implied rather than dictating the control flow of the
logic. Importantly, this fixes cases for opaques, structs, tuples,
enums, and unions, where type equality was incorrectly returning based
on whether the tag() values were equal.

Additionally, pointer type equality now takes into account alignment.
Because we canonicalize non-zero alignment which equals pointee type ABI
alignment to alignment=0, this now can be a simple integer comparison.

Type hashing is implemented for pointers and floats. Array types now
additionally hash their sentinels.

This regressed some behavior tests that were passing but only because
of bugs regarding type equality.

The C backend has a noticeable problem with lowering differently-aligned
pointers (particularly slices) as the same type, causing C compilation
errors due to duplicate declarations.
2022-02-28 19:22:16 -07:00
Jakub Konka
cfbc3537ef x64: pass more behavior tests 2022-02-28 23:20:05 +01:00
Jakub Konka
66d28d0f20 x64: implement get_union_tag for register 2022-02-28 23:20:05 +01:00
Jakub Konka
decc90e0e7 x64: clean up loadMemPtrIntoRegister abstraction 2022-02-28 23:20:05 +01:00
Jakub Konka
12cdb36c5b codegen: fix padding calculation for error unions when lowering
* do not track `rdi` register before `call` inst, but instead freeze
  it from further use, until `call` has been realised
* pass more error union tests
2022-02-28 23:20:05 +01:00
Jakub Konka
05431d7c4a x64: impl unwrap_errunion_payload and unwrap_errunion_err for register 2022-02-28 23:20:05 +01:00
Mitchell Hashimoto
a7ca40b281 stage2: sentinel comp during peer type resolution should use elem type
We were using the array type, not the element type. Also, we should do
the sentinel comparison after we verify that the element types of both
are compatible.
2022-02-28 16:27:16 -05:00
Motiejus Jakštys
d1a4654834 std.BufSet: add clone and cloneWithAllocator
Following how ArrayList and HashMap does things. This is useful when one
wants to, ahem, clone the BufSet.
2022-02-28 15:51:58 -05:00
Andrew Kelley
2dd5e8b6f8
Merge pull request #11011 from Vexu/stage2
stage2: tuple/slice mul/cat
2022-02-28 15:39:43 -05:00
Andrew Kelley
d5100dc815 stage2: fix frame_address AIR instruction
Various places were assuming different union tags. Now it is
consistently a no-op instruction, just like the similar
instruction ret_addr.
2022-02-28 13:38:33 -07:00
Veikka Tuominen
90bce11f62 stage2: implement @frameAddress 2022-02-28 13:09:14 -07:00
Veikka Tuominen
2682b41da5 make gpa.deinit work with stage2 2022-02-28 13:09:14 -07:00
Veikka Tuominen
dfeffcfbf8 stage2: tuple mul/cat 2022-02-28 13:09:14 -07:00
Veikka Tuominen
3a65fa269f stage2: slice mul/cat 2022-02-28 13:09:14 -07:00
Andrew Kelley
e1375942e5 zig cc: special handling of /dev/null
Now we handle -o /dev/null equivalent to -fno-emit-bin because
otherwise our atomic rename into place will fail. This also
makes Zig do less work, avoiding pointless file system operations.
2022-02-28 12:36:45 -07:00
Jakub Konka
331cc810de
Merge pull request #11012 from ziglang/x64-union-tag
stage2,x64: basic (un)tagged unions
2022-02-28 17:42:59 +01:00
Jakub Konka
16f9774d2d x64: fix switch condition mir; pass more union tests 2022-02-28 15:25:40 +01:00
Jakub Konka
a61ac9ecbf x64: fix store with ABI size > 8 on stack; pass union tests 2022-02-28 12:14:41 +01:00
Jakub Konka
57a823582c x64: impl airGetUnionTag 2022-02-28 11:40:25 +01:00
Jakub Konka
4d0c48738b x64: make lowerUnnamedConst a fallthrough condition 2022-02-28 11:40:25 +01:00
Jakub Konka
06f58a0b3b codegen: impl lowering of union type to memory 2022-02-28 11:40:25 +01:00
Jakub Konka
1dc05e9e77 x64: impl airSetUnionTag 2022-02-28 11:40:21 +01:00
Jakub Konka
90059a12e0
Merge pull request #11008 from joachimschmidt557/stage2-arm
stage2 ARM: pass more behavior tests
2022-02-28 09:59:44 +01:00
Veikka Tuominen
87dc60e8de stage2: implement builtin_call 2022-02-27 18:59:44 -05:00
Andrew Kelley
720a5f87d4
Merge pull request #11006 from topolarity/resolve-union-alignment
stage2: Resolve alignment for union field in `@TypeInfo`
2022-02-27 18:58:28 -05:00
Andrew Kelley
9d4cfd9048 Sema: resolve necessary information ahead of time
Do the fallible logic in Sema where we have access to error reporting
mechanisms, rather than in Type/Value.

We can't just do the best guess when resolving queries of "is this type
comptime only?" or "what is the ABI alignment of this field?". The
result needs to be accurate. So we need to keep the assertions that the
data is available active, and instead compute the necessary information
before such functions get called.

Unfortunately we are stuck with two versions of such functions because
the various backends need to be able to ask such queries of Types and
Values while assuming the result has already been computed and validated
by Sema.
2022-02-27 16:51:33 -07:00
Cody Tapscott
71aa5084ed stage2: Resolve alignment for union field in @TypeInfo
This also includes two other small fixes:
 - Instantiate void TypeInfo fields as void
 - Return error in `type.comptimeOnly` on unresolved comptime requirements
2022-02-27 14:24:47 -07:00
joachimschmidt557
1bf8da19e1
stage2 ARM: implement slice and array_to_slice 2022-02-27 21:38:56 +01:00
joachimschmidt557
91fbcf7093
stage2 ARM: enable more behavior tests 2022-02-27 21:38:56 +01:00
joachimschmidt557
528008a981
stage2 ARM: reduce Mir.Inst.Data to 8 bytes 2022-02-27 21:38:55 +01:00
David John
139b731d82 std: rename sched_yield to yield and move it to std.Thread 2022-02-27 15:34:02 -05:00
Andrew Kelley
104a8840db
Merge pull request #11002 from topolarity/comptime-int-comparison
stage2: Add comptime result for certain unsigned/comptime comparisons
2022-02-27 15:32:46 -05:00