15330 Commits

Author SHA1 Message Date
Andrew Kelley
60b6e74468 ci: fix typo introduced in earlier commit
c2a7542df5e9e93289a5d487ba3bbc37c12ffc11 introduced a typo in the linux
CI script.
2021-09-28 09:50:25 -07:00
Andrew Kelley
09e1f37cb6 stage2: implement union coercion to its own tag
* AIR: add `get_union_tag` instruction
   - implement in LLVM backend
 * Sema: implement == and != for union and enum literal
   - Also implement coercion from union to its own tag type
 * Value: implement hashing for union values

The motivating example is this snippet:

    comptime assert(@typeInfo(T) == .Float);

This was the next blocker for stage2 building compiler-rt.
Now it is switch at compile-time on an integer.
2021-09-27 23:11:00 -07:00
Andrew Kelley
c2a7542df5 ci: azure: run build steps independently to save ram
Azure is hitting OOM on test-toolchain. This commit is trying to
coast for another week until we switch to Drone CI for this job.
2021-09-27 21:39:27 -07:00
Andrew Kelley
c0aa4a1a42 stage2: implement basic unions
* AIR instructions struct_field_ptr and related functions now are also
   emitted by the frontend for unions. Backends must inspect the type
   of the pointer operand to lower the instructions correctly.
   - These will be renamed to `agg_field_ptr` (short for "aggregate") in
     the future.
 * Introduce the new `set_union_tag` AIR instruction.
 * Introduce `Module.EnumNumbered` and associated `Type` methods. This
   is for enums which have no decls, but do have the possibility of
   overriding the integer tag type and tag values.
 * Sema: Implement support for union tag types in both the
   auto-generated and explicitly-provided cases, as well as explicitly
   provided enum tag values in union declarations.
 * LLVM backend: implement lowering union types, union field pointer
   instructions, and the new `set_union_tag` instruction.
2021-09-27 19:53:29 -07:00
Mr. Paul
25266d0804 Langref: fix HTML escaped symbol WASM JavaScript code example
docgen HTML escapes characters inside of `syntax_block`s. This commit replaces the escaped
greater than with the `>` character. No other occurrences were found.

Fixes #9840
2021-09-27 18:22:56 +03:00
Andrew Kelley
1f2f9f05c2 stage2: implement zirCoerceResultPtr
and remove Module.simplePtrType and Module.ptrType in favor of `Type.ptr`.
2021-09-25 22:18:43 -07:00
Andrew Kelley
04366576ea stage2: implement @sizeOf for non-packed structs 2021-09-25 17:54:52 -07:00
xackus
15f55b2805 os.flock: FreeBSD can return EOPNOTSUPP 2021-09-25 15:55:15 -04:00
Andrew Kelley
42aa1ea115 stage2: implement @memset and @memcpy builtins 2021-09-24 17:33:06 -07:00
Stephen Gregoratto
87fd502fb6 Initial bringup of the Solaris/Illumos port 2021-09-24 14:06:16 -04:00
Stephen Gregoratto
a032fd01e8 Resolve scope IDs using IPv6 sockets
On certain systems (Solaris), resolving the scope id from an interface
name can only be done on AF_INET-domain sockets. While we're here,
simplify the test while we're here, since there's only one address.

Also note that the loopback interface name is not stable across OSs.
BSDs and Solaris use `lo0` whilst Linux uses `l0`.
2021-09-24 13:50:18 -04:00
Martin Wickham
1e7009a9d9 Fix error references across inline and comptime functions 2021-09-24 13:49:18 -04:00
joachimschmidt557
8f58e2d779 stage2 codegen: move bit definitions to src/arch 2021-09-24 13:47:59 -04:00
Josh Soref
664941bf14
Spelling corrections (#9833)
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2021-09-24 13:39:20 -04:00
Andrew Kelley
ef7fa76001 stage2: enable building freestanding libc with LLVM backend
* LLVM backend: respect `sub_path` just like the other stage2 backends
   do.
 * Compilation has some new logic to only emit work queue jobs for
   building stuff when it believes itself to be capable. The linker
   backends no longer have duplicate logic; instead they respect the
   optional bit on the respective asset.
2021-09-24 01:00:15 -07:00
Andrew Kelley
f215d98043 stage2: LLVM backend: improved naming and exporting
Introduce an explicit decl_map for *Decl to LLVMValueRef. Doc comment
reproduced here:

Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to
LLVM function, but that has some downsides:
* we have to compute the fully qualified name every time we want to do the lookup
* for externally linked functions, the name is not fully qualified, but when
  a Decl goes from exported to not exported and vice-versa, we would use the wrong
  version of the name and incorrectly get function not found in the llvm module.
* it works for functions not all globals.
Therefore, this table keeps track of the mapping.

Non-exported functions now use fully-qualified symbol names.
`Module.Decl.getFullyQualifiedName` now returns a sentinel-terminated
slice which is useful to pass to LLVMAddFunction.

Instead of using aliases for all external symbols, now the LLVM backend
takes advantage of LLVMSetValueName to rename functions that become
exported. Aliases are still used for the second and remaining exports.

freeDecl is now handled properly in the LLVM backend, deleting the
LLVMValueRef corresponding to the Decl being deleted. The linker
backends for ELF, COFF, Mach-O, and Wasm had to be updated to forward
the freeDecl call to the LLVM backend.
2021-09-23 23:46:45 -07:00
Andrew Kelley
418105589a stage2: prepare for building freestanding libc
Extracts lib/std/special/c_stage1.zig from lib/std/special/c.zig.

When the self-hosted compiler is further along, all the logic from c_stage1.zig will
be migrated back c.zig and then c_stage1.zig will be deleted. Until then we have a
simpler implementation of c.zig that only uses features already implemented in self-hosted.

So far it only contains memcpy and memset, with slightly different
(arguably more correct!) implementations that are compatible with
self-hosted.

Additionally, this commit improves the LLVM backend:
 * use the more efficient and convenient fnInfo() when lowering function
   type info.
 * fix incremental compilation not deleting all basic blocks of a
   function.
 * hook up calling conventions
 * hook up the following function attributes:
   - noredzone, nounwind, uwtable, minsize, optsize, sanitize_thread
2021-09-23 20:16:57 -07:00
Michael Dusan
cc4d38ed57 ci linux: bump qemu-6.1.0.1
closes #8653
2021-09-23 21:22:53 -04:00
Koakuma
bdbd060cc7 Linux/sparc64 bits: Add missing C type definitions 2021-09-23 13:57:55 -04:00
Martin Wickham
ef6fbbdab6 Fix the failing "bad import" test on Windows 2021-09-23 13:17:48 -04:00
Andrew Kelley
dd81a2147d
Merge pull request #9825 from Snektron/big-int-signed-and-or
big ints: 2s complement signed and/or
2021-09-23 13:17:32 -04:00
Martin Wickham
a0a847f2e4
Stage2: Implement comptime closures and the This builtin (#9823) 2021-09-23 13:17:06 -04:00
Robin Voetter
cd3dcc225b big ints: only write xor overflow if required 2021-09-23 06:28:09 +02:00
Hadrien Dorio
f615648d7b stage2: enhance zig init-lib and zig init-exe
Stop `src/main.zig` from being overwritten.
2021-09-23 00:20:21 -04:00
Robin Voetter
351e4f07ce big ints: 2s complement signed and + or fixes 2021-09-23 06:19:08 +02:00
Andrew Kelley
736d14fd5f stage2: fix AstGen for some struct syntaxes
* AstGen: fix not emitting `struct_init_empty` when an explicit type is
   present in struct initialization syntax.
 * AstGen: these two syntaxes now lower to identical ZIR:
   - `var a = A{ .b = c };`
   - `var a = @as(A, .{ .b = c });`
 * Zir: clarify `auto_enum_tag` in the doc comments.
 * LLVM Backend: fix lowering of function return types when the type has
   0 bits.
2021-09-22 21:06:00 -07:00
Andrew Kelley
0ec01e58b4
Merge pull request #9717 from SpexGuy/stage2-start-windows
Make stage2 start.zig work on Windows
2021-09-22 22:08:34 -04:00
Robin Voetter
f5c27dd11a big ints: 2s complement signed or 2021-09-23 04:08:27 +02:00
Andrew Kelley
e03095f167 stage2: remove 2 assertions that were too aggressive
* `Type.hasCodeGenBits` this function is used to find out if it ever
   got sent to a linker backend for lowering. In the case that a struct
   never has its struct fields resolved, this will be false. In such a
   case, no corresponding `freeDecl` needs to be issued to the linker
   backend. So instead of asserting the fields of a struct are resolved,
   this function now returns `false` for this case.

 * `Module.clearDecl` there was logic that asserted when there is no
   outdated_decls map, any dependants of a Decl being cleared had to be
   in the deletion set. However there is a possible scenario where the
   dependant is not in the deletion set *yet* because there is a Decl
   which depends on it, about to be deleted. If it were added to an
   outdated_decls map, it would be subsequently removed from the map
   when it gets deleted recursively through its dependency being
   deleted.

These issues were uncovered via unrelated changes which are the two
commits immediately preceding this one.
2021-09-22 19:05:56 -07:00
Martin Wickham
d86678778a Fix failing tests and windows link dependencies 2021-09-22 14:39:02 -05:00
Martin Wickham
4782bededa Remove reference to stage2_os 2021-09-22 14:14:03 -05:00
Martin Wickham
d6e87da47b Make stage2 start.zig work on Windows 2021-09-22 13:58:49 -05:00
Ryan Liptak
3b09262c12 tokenizer: Fix index-out-of-bounds on unfinished unicode escapes before EOF 2021-09-22 14:33:33 -04:00
Coleman Broaddus
e14fcd60cb
FIX resize() for non u8 element types. (#9806) 2021-09-22 12:09:16 +03:00
Robin Voetter
4afe4bdfe7 big ints: 2s complement signed xor 2021-09-22 02:21:55 -04:00
Andrew Kelley
aecebf38ac stage2: progress towards ability to compile compiler-rt
* prepare compiler-rt to support being compiled by stage2
   - put in a few minor workarounds that will be removed later, such as
     using `builtin.stage2_arch` rather than `builtin.cpu.arch`.
   - only try to export a few symbols for now - we'll move more symbols
     over to the "working in stage2" section as they become functional
     and gain test coverage.
   - use `inline fn` at function declarations rather than `@call` with an
     always_inline modifier at the callsites, to avoid depending on the
     anonymous array literal syntax language feature (for now).
 * AIR: replace floatcast instruction with fptrunc and fpext for
   shortening and widening floating point values, respectively.
 * Introduce a new ZIR instruction, `export_value`, which implements
   `@export` for the case when the thing to be exported is a local
   comptime value that points to a function.
   - AstGen: fix `@export` not properly reporting ambiguous decl
     references.
 * Sema: handle ExportOptions linkage. The value is now available to all
   backends.
   - Implement setting global linkage as appropriate in the LLVM
     backend. I did not yet inspect the LLVM IR, so this still needs to
     be audited. There is already a pending task to make sure the alias
     stuff is working as intended, and this is related.
   - Sema almost handles section, just a tiny bit more code is needed in
     `resolveExportOptions`.
 * Sema: implement float widening and shortening for both `@floatCast`
   and float coercion.
   - Implement the LLVM backend code for this as well.
2021-09-21 23:21:07 -07:00
Andrew Kelley
0e2b9ac777 stage2: fix unsigned integer to signed integer coercion 2021-09-21 23:21:07 -07:00
Andrew Kelley
be71195bba stage2: enable f16 math
There was panic that said TODO add __trunctfhf2 to compiler-rt, but I
checked and that function has been in compiler-rt since April.
2021-09-21 23:21:07 -07:00
Vincent Rischmann
01f20c7f48 io_uring: implement read_fixed/write_fixed 2021-09-22 00:47:45 -04:00
Isaac Freund
8c86043178 std.build: fix handling of -Dcpu
Currently -Dcpu is completely ignored if -Dtarget isn't passed as well.
Further, -Dcpu=baseline is ignored even if -Dtarget=native is passed.

This patch fixes these 2 issues, always respecting the -Dcpu option if
present.
2021-09-22 00:46:37 -04:00
Andrew Kelley
5913140b6b stage2: free Sema's arena after generating machine code
Previously, linker backends or machine code backends were able to hold
on to references to inside Sema's temporary arena. However there can
be large objects stored there that we want to free after machine code is
generated.

The primary change in this commit is to use a temporary arena for Sema
of function bodies that gets freed after machine code backend finishes
handling `updateFunc` (at the same time that Air and Liveness get freed).

The other changes in this commit are fixing issues that fell out from
the primary change.

 * The C linker backend is rewritten to handle updateDecl and updateFunc
   separately. Also, all Decl updates get access to typedefs and
   fwd_decls, not only functions.
 * The C linker backend is updated to the new API that does not depend
   on allocateDeclIndexes and does not have to handle garbage collected
   decls.
 * The C linker backend uses an arena for Type/Value objects that
   `typedefs` references. These can be garbage collected every so often
   after flush(), however that garbage collection code is not
   implemented at this time. It will be pretty simple, just allocate a
   new arena, copy all the Type objects to it, update the keys of the
   hash map, free the old arena.
 * Sema: fix a handful of instances of not copying Type/Value objects
   from the temporary arena into the appropriate Decl arena.
 * Type: fix some function types not reporting hasCodeGenBits()
   correctly.
2021-09-21 15:23:29 -07:00
Jakub Konka
affd8f8b59 macho: fix incorrect segment/section growth calculation
Otherwise, for last sections in segments it could happen we would
not expand the segment when actually required thus exceeding the
segment's size and causing data clobbering and dyld runtime errors.
2021-09-21 20:22:52 +02:00
Veikka Tuominen
a2dd0c387d
Merge pull request #9652 from g-w1/p9d
plan9: emit debug info
2021-09-21 19:38:12 +03:00
Jakub Konka
d722f0cc62 macho: do not write temp and noname symbols to symtab
Remove currently obsolete AtomParser from Object.
2021-09-21 11:05:22 +02:00
Andrew Kelley
5269cbea20
Merge pull request #9797 from Vexu/stage2
stage2: implement cImport
2021-09-21 00:01:30 -04:00
Andrew Kelley
0c74ce1156 Sema: fix double-free of @cImport error message 2021-09-20 20:56:30 -07:00
Veikka Tuominen
55e7c099ca stage2: various fixes to cImport, sizeOf and types to get tests passing 2021-09-20 20:51:31 -07:00
Veikka Tuominen
d64d5cfc0a stage2: implement typeInfo for more types 2021-09-20 20:50:55 -07:00
Veikka Tuominen
9a54ff72df stage2: implement cImport 2021-09-20 20:50:55 -07:00
Andrew Kelley
1ad905c71e
Merge pull request #9649 from Snektron/address-space
Address Spaces
2021-09-20 20:37:04 -04:00