Commit Graph

15054 Commits

Author SHA1 Message Date
Andrew Kelley
c05a20fc8c std: reorganization that allows new usingnamespace semantics
The proposal #9629 is now accepted, usingnamespace stays but no longer
puts identifiers in scope.
2021-09-01 17:54:06 -07:00
Andrew Kelley
7884d84315 std.os.windows: reorg to avoid usingnamespace
Down to 19 uses of `usingnamespace`.
2021-09-01 17:54:06 -07:00
Andrew Kelley
b781ef464d std.os: fix FILENO constants mapped to wrong values
yikes!
2021-09-01 17:54:06 -07:00
Andrew Kelley
7f03cfe161 std.os: more reorganization efforts
* std lib tests are passing on x86_64-linux with and without -lc
 * stage2 is building from source on x86_64-linux
 * down to 38 remaining uses of `usingnamespace`
2021-09-01 17:54:06 -07:00
Andrew Kelley
c09ba8796c std.os.linux: remove the "bits" namespace altogether
Now there is only 1 architecture-specific file for Linux kernel bits.
2021-09-01 17:54:06 -07:00
Andrew Kelley
1bbfcb95ab std: reorganize std.c to eliminate usingnamespace
Behavior tests pass on x86_64-linux with -lc
2021-09-01 17:54:06 -07:00
Andrew Kelley
3deda15e21 std.os reorganization, avoiding usingnamespace
The main purpose of this branch is to explore avoiding the
`usingnamespace` feature of the zig language, specifically with regards
to `std.os` and related functionality.

If this experiment is successful, it will provide a data point on
whether or not it would be practical to entirely remove `usingnamespace`
from the language.

In this commit, `usingnamespace` has been completely eliminated from
the Linux x86_64 compilation path, aside from io_uring.

The behavior tests pass, however that's as far as this branch goes. It is
very breaking, and a lot more work is needed before it could be
considered mergeable. I wanted to put a pull requset up early so that
zig programmers have time to provide feedback.

This is progress towards closing #6600 since it clarifies where the
actual "owner" of each declaration is, and reduces the number of
different ways to import the same declarations.

One of the main organizational strategies used here is to do namespacing
with real namespaces (e.g. structs) rather than by having declarations
share a common prefix (the C strategy). It's no coincidence that
`usingnamespace` has similar semantics to `#include` and becomes much
less necessary when using proper namespaces.
2021-09-01 17:54:06 -07:00
Jan Philipp Hafer
81e2034d4a compiler_rt: add __clzdi2 and __clzti2
- structure derived from shift.zig
- rename clzsi2.zig to count0bits.zig
- test cases derived from clzsi2_test.zig

See #1290
2021-09-01 16:15:21 -04:00
Andrew Kelley
04b801655c AstGen: fix "missing function name" error
scanDecls() made an incorrect assumption about all declarations having
function names. The compile error for "missing function name" needed to
go into scanDecls().
2021-09-01 11:30:33 -07:00
travisstaloch
21a5769afe
saturating arithmetic builtins: add, sub, mul, shl (#9619)
- adds 1 simple behavior tests for each
  which does integer and vector ops at
  runtime and comptime
- adds bigint_*_sat() methods for each

- use CreateIntrinsic() which accepts a
  variable number of arguments to pass
  the scale parameter

* update langref
- added case to test/compile_errors.zig given floats

- explain upstream bug in llvm.smul.fix.sat and link to #9643 in langref and commented out test cases

* sat-arithmetic: skip mul tests if arch == .wasm32 because ci is erroring with 'LLVM ERROR: Unable to expand fixed point multiplication' when compiling for wasm32
2021-09-01 14:17:45 -04:00
Philip Åkesson
4f0aa7d639 std: Use truncating cast in WIFSTOPPED for Linux, FreeBSD and DragonFly
The intermediate value can be larger than an u16, so @truncate is needed
to match the behavior of musl.
2021-08-31 22:03:54 -04:00
Andrew Kelley
3b9ec4e4df
Merge pull request #9655 from nektro/stage2-rem
stage2: implement runtime `%` and `@rem`
2021-08-31 21:59:48 -04:00
Andrew Kelley
d522f925b7
Merge pull request #9603 from g-w1/arrcat
stage2: add array concatenation + multiplication ( ++ and **) at comptime
2021-08-31 21:52:47 -04:00
Sebastian Ullrich
9d4a6d67aa libunwind: fix unwinding through libunwind stack frames
Fixes #9591
2021-08-31 21:50:16 -04:00
Andrew Kelley
75263e160e CI: update Linux and macOS tarballs to LLVM 12.0.1 2021-08-31 16:39:25 -07:00
Philipp Lühmann
76b85cd665 fix typo 2021-08-31 14:05:44 -04:00
joachimschmidt557
435d8ae536 stage2 ARM: add missing parameters for bic, bics 2021-08-31 14:05:20 -04:00
Meghan
50c6b6cc66
stage2: only initialize the llvm backend for the target we are building (#9659) 2021-08-31 13:50:09 -04:00
Andrew Kelley
d0f04824f1 re-enable all the MIPS tests
LLVM 12.0.1 fixed the regressions from LLVM 12.0.0.

Closes #8155
2021-08-31 10:36:33 -07:00
Jacob G-W
7cdb30ee95 stage2: move array mult test from basic.zig to misc.zig! 2021-08-31 07:46:24 -04:00
Jacob G-W
f6d9ac481b stage2: add array mult ** 2021-08-31 07:46:24 -04:00
Jacob G-W
a360f2bf6c add string concat test to basic.zig from misc.zig!
This means it is passing in stage2!
2021-08-31 07:46:24 -04:00
Jacob G-W
908f722107 stage2 llvm backend: if an array has a senteniel, add it 2021-08-31 07:46:23 -04:00
fn ⌃ ⌥
b25e58b0ac
std.hash_map: add getKey methods (#9607) 2021-08-31 00:32:34 -04:00
Jacob G-W
353eec73ca stage2: add array concatenation 2021-08-30 22:54:33 -04:00
Meghan Denny
cf9684ce75 stage2: add @rem tests to llvm and c backends 2021-08-30 19:48:31 -07:00
Lee Cannon
ede47d49eb
Print enum values for build options in help output (#9650) 2021-08-30 21:39:02 -04:00
Martin Wickham
cf75cad899 Add comptime memory tests 2021-08-30 18:50:07 -04:00
joachimschmidt557
4334dbb9a5 stage2 codegen: Remove use of usingnamespace 2021-08-30 13:40:03 -04:00
Boo
ef39725055
Fix float formatting for 0.0 when precision is 0 (#9642) 2021-08-30 13:39:05 -04:00
Meghan Denny
e878a6633f stage2: implement runtime % and @rem 2021-08-30 00:31:40 -07:00
Meghan Denny
56845082bc stage2/sema: clarify todo arithmetic operator error 2021-08-30 00:30:14 -07:00
Andrew Kelley
861b784454 AstGen: fix incorrectly using decl_val/decl_ref
in identifiers rather than directly referencing the instructions.
2021-08-29 13:43:03 -07:00
Veikka Tuominen
be9b490f84 translate-c: remove now unnecessary mangling of primitive type shadowing
Closes #6382
2021-08-29 15:11:38 +03:00
jdmichaud
49c9975484
zig fmt: respect trailing commas in inline assembly 2021-08-29 11:57:32 +02:00
Isaac Freund
7b863aa8ac AstGen: short-circuit rvalue() if code is unreachable
This avoids generating instructions which will never be reached.
2021-08-29 08:59:27 +00:00
Andrew Kelley
4bb5d17edc AstGen: pre-scan all decls in a namespace
Also:
 * improve the "ambiguous reference" error by swapping the order of
   "declared here" and "also declared here" notes.
 * improve the "not accessible from inner function" error:
   - point out that it has to do with the thing being mutable
   - eliminate the incorrect association with it being a function
   - note where it crosses a namespace boundary
 * struct field types are evaluated in a context that has the struct
   namespace visible. Likewise with align expressions, linksection
   expressions, enum tag values, and union/enum tag argument
   expressions.

Closes #9194
Closes #9622
2021-08-28 16:04:38 -07:00
Andrew Kelley
05cf44933d stage2: delete keywords true, false, undefined, null
The grammar does not need these as keywords; they are merely primitives
provided by the language the same as `void`, `u32`, etc.
2021-08-28 12:10:55 -07:00
Andrew Kelley
6a6e2cd64f AstGen: allow locals with same name as primitives with @"" syntax
This makes local names follow the same rule as declaration names.
2021-08-28 13:28:34 -04:00
Andrew Kelley
f30aa25cbf declarations may collide with primitives with @"" syntax
* stage2 AstGen: add missing compile error for declaring a local
   that shadows a primitive. Even with `@""` syntax, it may not have
   the same name as a primitive.
 * stage2 AstGen: add a compile error for a global declaration
   whose name matches a primitive. However it is allowed when using
   `@""` syntax.
 * stage1: delete all "declaration shadows primitive" compile errors
   because they are now handled by stage2 AstGen.
 * stage1/stage2 AstGen: notice when using `@""` syntax and:
   - treat `_` as a regular identifier
   - skip checking if an identifire is a primitive

Check the new test cases for clarifications on semantics.

closes #6062
2021-08-27 21:34:13 -07:00
Robin Voetter
cfae70ec8e Make slice always return a reference
Previously this returned an rvalue, which leads to unexpected behaviour
when writing expressions such as `x[1..][1..].`
2021-08-27 18:53:03 -04:00
Robin Voetter
3aa533519d Store to mutable pointer in analyzeRef
This function previously attempted to store a value to an immutable
pointer, after which storePtr would yield an error.
2021-08-27 18:53:03 -04:00
Robin Voetter
3a3704be05 Don't use .none_or_ref for for(expr)
We can already know whether the user want the expression to be a pointer or
ref based on whether the asterisk token is used, like with if and switch.
2021-08-27 18:53:03 -04:00
Lee Cannon
311797f686
Rework build system build_options API (#9623)
* rework `build_options` to integrate with the FileSource abstraction
* support mapping as an arbitrarily named package
* support mapping to multiple different artifacts
* use hash of contents for options filename
2021-08-26 19:53:23 -04:00
joachimschmidt557
04cafd8137 stage2 ARM: Add qadd, qsub, qdadd, qdsub instructions
These are integer saturating arithmetic instructions
2021-08-26 14:42:28 +02:00
Andrew Kelley
9c95f38a7c stage1: remove incorrect compile error for var redeclaration
Locals are not allowed to shadow declarations, but declarations are
allowed to shadow each other, as long as there are no ambiguous
references.

closes #678
2021-08-24 22:35:37 -07:00
Andrew Kelley
f1f28af188 fix stage2 test cases expecting wrong line numbers
Previous commit shifted everything down in the start.zig file, and
unfortunately our stage2 test harness depends on absolute line
numbers for a couple tests.
2021-08-24 13:42:31 -07:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Koakuma
dd75302563 Linux/SPARCv9: use C calling convention for restore_rt
This is needed to prevent infinite loop when calling rt_sigreturn.
2021-08-24 14:08:54 -04:00
Koakuma
e3840817d7 Linux/SPARCv9: account for branch delay in freeAndExit() 2021-08-24 14:08:54 -04:00