15650 Commits

Author SHA1 Message Date
Andrew Kelley
df198ea60e
Merge pull request #10034 from Snektron/stage2-slice
stage2: slice and optional improvements
2021-10-25 19:41:19 -04:00
Robin Voetter
21bf3b8066 stage2: runtime c pointer null comparison 2021-10-26 01:24:14 +02:00
Andrew Kelley
30d01c8fea
Merge pull request #9874 from leecannon/frame_pointer
Make omiting frame pointer independent of build mode
2021-10-25 19:15:17 -04:00
Andrew Kelley
97dc5f6eb5 Sema: fix switch that covers full integer range 2021-10-25 15:52:21 -07:00
Andrew Kelley
8509e7111d stage2: fix switch on tagged union capture-by-pointer
* AstGen: always use `typeof` and never `typeof_elem` on the
   `switch_cond`/`switch_cond_ref` instruction because both variants
   return a value and not a pointer.
   - Delete the `typeof_elem` ZIR instruction since it is no longer
     needed.
 * Sema: validateUnionInit now recognizes a comptime mutable value and
   no longer emits a compile error saying "cannot evaluate constant
   expression"
   - Still to-do is detecting comptime union values in a function that
     is not being executed at compile-time.
     - This is still to-do for structs too.
 * Sema: when emitting a call AIR instruction, call resolveTypeLayout on
   all the parameter types as well as the return type.
 * `Type.structFieldOffset` now works for unions in addition to structs.
2021-10-25 15:11:21 -07:00
Stephen von Takach
a132190cad fix(uefi MemoryDescriptor): padding after memory type
not 100% certain, just noticed that this is implemented slightly differently in rust
https://docs.rs/uefi/0.11.0/src/uefi/table/boot.rs.html#715
2021-10-25 16:43:23 -04:00
Robin Voetter
4eb7b28700 stage2: generate correct constants for zero-sized arrays 2021-10-25 20:41:15 +02:00
Robin Voetter
7062c8a886 stage2: comptime slice of pointer to hardcoded address 2021-10-25 20:41:15 +02:00
Robin Voetter
0942bf73c9 stage2: improve slicing
* Allow slicing many- and c-pointers.
* Allow comptime pointer arithmetic on undefined values.
* Return the correct type for slicing of slices.
2021-10-25 20:41:15 +02:00
Andrew Kelley
ed7328119f Sema: implement coercion from pointers to *c_void 2021-10-25 11:34:23 -07:00
Andrew Kelley
8f3e1ea0f0 AstGen: move nodeMayEvalToError logic for builtins
to the declarative BuiltinFn.zig file which lists info about all the
builtin functions.
2021-10-25 10:50:47 -07:00
Andrew Kelley
d4bf44024a
Merge pull request #10019 from mattbork/ret-fixes
astgen.zig: fixes for error propagation `ret` and return types in `fnDecl` and `fnProtoExpr`
2021-10-25 13:40:03 -04:00
ominitay
3f6eef22e4 Fix documentation for Random.int
Documentation incorrectly stated that Random.int 'Returns a random int `i`
such that `0 <= i <= maxInt(T)`.' This commit amends this.
2021-10-25 13:34:28 -04:00
Robin Voetter
df167af0b6
Revert 83bdbb2 and a587dd0 (#10028) 2021-10-25 14:00:10 +02:00
Jakub Konka
a587dd08f8 std: disable big.rational setFloat targeting wasm32
until we fix the underlying issue resulting in `error.TargetTooSmall`
error.
2021-10-25 01:27:05 +02:00
Andrew Kelley
ce65ca4345 stage2: refactor coercePeerTypes and fix C ptr cmp with null 2021-10-24 12:07:14 -07:00
Isaac Freund
f7b090d707 std.log: simplify to 4 distinct log levels
Over the last year of using std.log in practice, it has become clear to
me that having the current 8 distinct log levels does more harm than
good. It is too subjective which level a given message should have which
makes filtering based on log level weaker as not all messages will have
been assigned the log level one might expect.

Instead, more granular filtering should be achieved by leveraging the
logging scope feature. Filtering based on a combination of scope and log
level should be sufficiently powerful for all use-cases.

Note that the self hosted compiler has already limited itself to 4
distinct log levels for many months and implemented granular filtering
based on both log scope and level. This has worked very well in practice
while working on the self hosted compiler.
2021-10-24 15:04:29 -04:00
Jakub Konka
6cf5305e47 macho: remove unresolved ref in the correct place
* without this, when an included relocatable references a common symbol
  from another translation unit would not be correctly removed from
  the unresolved lookup table triggering a misleading assertion down
  the line
* assert upon removal that we indeed removed a ref instead of silently
  ignoring in debug
* add test case that covers this issue
2021-10-24 21:01:04 +02:00
Andrew Kelley
f80fd7e1a6
Merge pull request #10022 from LemonBoy/fix-10001
stage1/stage2: Simplify divTrunc impl
2021-10-24 14:39:27 -04:00
LemonBoy
2a733051bb libc: Export truncl
With the usual caveat of it being wrong for targets where c_longdouble
is not f128.
2021-10-24 19:17:55 +02:00
LemonBoy
811766e1cf stage1/stage2: Simplify divTrunc impl
According to the documentation, `divTrunc` is "Truncated division.
Rounds toward zero". Lower it as a straightforward fdiv + trunc sequence
to make it behave as expected with mixed positive/negative operands.

Closes #10001
2021-10-24 17:11:43 +02:00
Matthew Borkowski
9c5b852f9b astgen.zig: emit ZIR for callconv before return type in fnDecl and fnProtoExpr 2021-10-23 22:52:43 -04:00
Andrew Kelley
94879506ea
Merge pull request #10017 from Snektron/big-int-div
Big ints: division fixes
2021-10-23 22:49:33 -04:00
LemonBoy
1690b35770 std: Fix edge case in TLS tp calculation
The TLS area may be located in the upper part of the address space and,
if the platform expects a constant offset to be applied, may make the tp
register calculation overflow.

Use +% instead of +, the overflow is harmless.
2021-10-23 22:48:25 -04:00
Andrew Kelley
22b4c9e1a9 stage2: implement more C pointer Sema and comptime ptr arith 2021-10-23 19:47:32 -07:00
Robin Voetter
c563521d44 big ints: tighten some more division memory requirements 2021-10-24 02:56:48 +02:00
Robin Voetter
83bdbb2abb big ints: Make calcLimbLen always work at comptime, even if parameter is runtime 2021-10-24 02:56:48 +02:00
Robin Voetter
c905ceb23c big ints: fix divFloor 2021-10-24 02:56:48 +02:00
Matthew Borkowski
8a95bac593 astgen.zig: when ret's operand ResultLoc is .ptr, load from ret_ptr before is_non_err or err_union_code 2021-10-23 20:48:31 -04:00
Robin Voetter
87b7b31557 big ints: improve division 2021-10-24 01:21:33 +02:00
Matthew Borkowski
096763de98 astgen.zig: fix nodeMayEvalToError 2021-10-23 18:49:23 -04:00
Michael Byrne
ee98d87008 Minor rewording of "Shadowing" section within language reference 2021-10-23 02:57:20 -04:00
Andrew Kelley
6aeb6bcc84 stage2: LLVM backend: fix optional_payload instructions
They previously did not respect the optional type layout, but now they
do.
2021-10-22 23:35:46 -07:00
Andrew Kelley
d97928bf52 stage2: implement aligned variables and @alignCast
* Sema: implement zirAllocExtended
 * Sema: implement zirAlignCast
2021-10-22 17:50:36 -07:00
Andrew Kelley
01c1f41520 stage2: slice and alignment fixes
* Fix backend using wrong union field of the slice instruction.
 * LLVM backend properly sets alignment on global variables.
 * Sema: add coercion for *T to *[1]T
 * Sema: pointers to Decls with explicit alignment now have alignment
   metadata in them.
2021-10-22 17:12:12 -07:00
Andrew Kelley
b24e9b6347 Sema: fix a couple use-after-free bugs
Also switch to the more efficient encoding of the bitcast instruction
when the destination type is anyerror in 2 common cases.

LLVM backend: fix using the wrong type as the optional payload type in
the `wrap_optional` AIR instruction.
2021-10-22 16:23:34 -07:00
Andrew Kelley
f0dcdd7931 stage2: fix Decl addrspace being undefined 2021-10-22 15:53:59 -07:00
Andrew Kelley
069c83d58c stage2: change @bitCast to always be by-value
After a discussion about language specs, this seems like the best way to
go, because it's simpler to reason about both for humans and compilers.

The `bitcast_result_ptr` ZIR instruction is no longer needed.

This commit also implements writing enums, arrays, and vectors to
virtual memory at compile-time.

This unlocked some more of compiler-rt being able to build, which
in turn unlocks saturating arithmetic behavior tests.

There was also a memory leak in the comptime closure system which is now
fixed.
2021-10-22 15:35:35 -07:00
Andrew Kelley
86b9280963 zig libc: export floorl and ceill
needed since self-hosted now contains calls to `@divFloor` and
`@divTrunc` for 128-bit floats.
2021-10-22 10:48:45 -07:00
Jakub Konka
d0dceae736 macho: dump linker's state as JSON
Each element of the output JSON has the VM address of the generated
binary nondecreasing (some elements might occupy the same VM address
for example the atom and the relocation might coincide in the address
space).

The generated JSON can be inspected manually or via a preview tool
`zig-snapshots` that I am currently working on and will allow the user
to inspect interactively the state of the linker together with the
positioning of sections, symbols, atoms and relocations within each
snapshot state, and in the future, between snapshots too. This should
allow for quicker debugging of the linker which is nontrivial when
run in the incremental mode.

Note that the state will only be dumped if the compiler is built with
`-Dlink-snapshot` flag on, and then the compiler is passed `--debug-link-snapshot`
flag upon compiling a source/project.
2021-10-22 12:50:25 +02:00
Andrew Kelley
912e7dc54b Sema: resoveTypeLayout resolves optionals and error unions too
Previously it only worked on struct, union, and array.
2021-10-21 23:22:55 -07:00
Andrew Kelley
6cd14f051d stage2: LLVM backend: add a missing setUnnamedAddr
for anonymous constants
2021-10-21 23:22:31 -07:00
Andrew Kelley
895aea0b63 Sema: fix type checking of @intToFloat operands
There was a typo and they were backwards.
2021-10-21 23:01:05 -07:00
Andrew Kelley
0a6851cc6d stage2: implement comptime loads through casted pointers 2021-10-21 22:56:11 -07:00
Andrew Kelley
1bce0ed046 stage2: fix Value.copy not copying arrays 2021-10-21 20:28:32 -07:00
Andrew Kelley
7f70c27e9d stage2: more division support
AIR:
 * div is renamed to div_trunc.
 * Add div_float, div_floor, div_exact.
   - Implemented in Sema and LLVM codegen. C backend has a stub.

Improvements to std.math.big.Int:
 * Add `eqZero` function to `Mutable`.
 * Fix incorrect results for `divFloor`.

Compiler-rt:
 * Add muloti4 to the stage2 section.
2021-10-21 19:05:26 -07:00
Robin Voetter
a3c9bfef30 stage2: truncation
* Also fixes a related case where big int truncate would assume that the
input fits in the output limbs buffer
2021-10-21 20:10:27 -04:00
Andrew Kelley
d49c601d62
Merge pull request #9993 from Snektron/more-field-elem
stage2: More elemVal and elemPtr stuff
2021-10-21 17:12:04 -04:00
Jonathan Marler
e2a2e6c14f InstallRawStep: handle empty segments
This fixes InstallRawStep to handle the cases when there are empty segments (segments with no sections).  Before this change, if there was an empty segment with no sections, then the fixup of binaryOffsets is skipped.  This fixes that by looping through each segment until a non-empty one is found and then fixing up the sections. This fixed an issue I was having with InstallRawStep for a bootloader I'm writing.
2021-10-21 17:03:44 -04:00
Jonathan Marler
da2b615efb distinguish between unexpected child process exit code and unclean exit
This modifies the error for an unexpected exit code from the ChildProcess of RunStep to be UnexpectedExitCode rather than UncleanExit.  This allows the handler of the error to distinguish between an error reported by the ChildProcess, and an error executing the ChildProcess, which is an important dinstinction when it comes to know what information to report to the user.  For example, if you have a ChildProcess that you know reports its own errors, an unexpected exit code would mean the error is already reported, but an unclean exit would mean that child process was not able to report any error.
2021-10-21 17:03:00 -04:00