287 Commits

Author SHA1 Message Date
Evan Haas
3e67ef5c9f translate-c: Handle underscore when used as an identifier
Use `@` syntax to escape `_` when used as an identifier.

Remove the stage1 astgen prohibition against assigning from `_`

Note: there a few stage1 bugs preventing `_` from being used as an identifier
for a local variable or function parameter; these will be fixed by stage2.
They are unlikely to arise in real C code since identifiers starting with
underscore are reserved for the implementation.
2021-07-19 12:56:23 +03:00
Jay Petacat
9979741bff stage1: Fix OsOther by adding missing OsPlan9 2021-07-16 19:35:25 -04:00
Daniele Cocca
b009aca38a src: return a null-terminated slice 2021-07-15 15:12:44 -04:00
leesongun
132b18e2b3
Fix bigint_shl (#9305) 2021-07-13 10:16:57 +03:00
Martin Wickham
bd1689ae89 Remove Stage1AirInst::owner_bb, use zir owner instead. 2021-07-11 19:16:57 -05:00
Martin Wickham
75d1b113aa Rename IrInstSrc to Stage1ZirInst and IrInstGen to Stage1AirInst 2021-07-11 02:00:04 -04:00
Andrew Kelley
40764650af stage1: avoid wasting padding with IR instruction tag
For stage1 ZIR instructions and stage1 AIR instructions, the instruction
op code was taking up 8 bytes due to padding even though it only needed
1 byte. This commit reduces the ref_count field from uint32_t to
uint16_t because the code only really cares if instructions are
referenced at all, not how many times they are referenced. With the
ref_count field reduced to uint16_t the uint8_t op code is now placed in
the freed up space.

Empirically, this saves 382 MiB of peak RAM usage when building the
self-hosted compiler, which is a reduction of 5%. Consequently this
resulted in a 3% reduction of cache-misses when building the self-hosted
compiler.

This was @SpexGuy's idea, committed by me because we tested it on my
computer.
2021-07-10 15:38:13 -07:00
Martin Wickham
e2b954c273 Add support for NO_COLOR 2021-07-08 14:30:45 -04:00
Jacob G-W
23f414b927 stage1 parser: update comments to match impl 2021-07-07 07:38:26 +03:00
Andrew Kelley
6ba843ee0f
Merge pull request #9310 from ziglang/stage1-better-hashing
Speed up stage 1 by improving hash functions
2021-07-06 13:20:15 -04:00
leesongun
cff7ecee07
Fix unexpected truncation behavior with comptime_int larger than u64 range (#9303)
Closes #9299
2021-07-06 12:42:18 +03:00
Martin Wickham
f02ee7a9f5 Avoid some large copies for another second of time saved 2021-07-06 00:57:46 -05:00
Jacob G-W
d089b3df7a remove really weird debugging statement from stage1 2021-07-05 21:13:10 -04:00
Martin Wickham
149ecdfe1b Remove debug checks, audit field accesses 2021-07-05 19:41:48 -05:00
Andrew Kelley
b3225a755a stage1: avoid incorrectly reading ZigValue data
Hashing, equality checking, and expanding lazy values were not
inspecting the is_comptime field of structs, causing incorrect behavior
for tuples. When looking at a comptime value of a struct, if the
is_comptime field is true, the value must be learned from the type
rather than the value.
2021-07-05 16:22:40 -07:00
Andrew Kelley
0ff9a4d21c stage1: resolve lazy values before comptime fn call 2021-07-05 14:07:36 -07:00
Martin Wickham
0e5fa87ac9 Better hashing, new asserts failing 2021-07-05 15:28:13 -05:00
Andrew Kelley
9b08687766 stage1: recursively resolve lazy values before hashing
When putting ZigValues into a hash map. The hash of a lazy value
and a fully resolved value must equal, and so we must resolve
the lazy values prior. The hash function asserts that none of
the values are lazy.
2021-07-05 13:05:03 -07:00
Andrew Kelley
af20fdbce7 stage1: eliminate the IrInst base struct
This commit intentions to have no functional changes. The only purpose
is to delete the struct IrInst, which is the common base struct that
both IrInstSrc (ZIR) and IrInstGen (AIR) instructions embed.

This untangles stage1 ZIR and AIR memory layout, paving the way for a
following commit to reduce memory usage.
2021-07-03 03:14:54 -04:00
Andrew Kelley
c5c23db627 tokenizer: clean up invalid token error
It now displays the byte with proper printability handling. This makes
the relevant compile error test case no longer a regression in quality
from stage1 to stage2.
2021-07-02 13:28:31 -07:00
Andrew Kelley
7a2e0d9810 AstGen: cleanups to pass more compile error test cases 2021-07-02 13:28:29 -07:00
Andrew Kelley
527c55aa56 stage1: get rid of the is_noreturn flag on IrInstSrc
One more step towards lowering the memory footprint of stage1. This flag
was hiding in padding but now that it is gone we can re-arrange the
memory layout more easily.
2021-07-02 13:26:50 -07:00
Andrew Kelley
125b85d737 move "unreachable code" error from stage1 to stage2
* AstGen: implement "unreachable code" error for blocks. This works at
   the statement level.
 * stage1: remove the "unreachable code" error implementation, which
   means removing the `is_gen` field from IrInstSrc. This is one small
   step towards a smaller memory footprint for stage1. The benefits
   won't be realized until a future commit because this flag took
   advantage of padding.

There may be a regression here with "union has no associated enum"
error, and there is a regression with the following code:

```zig
const a = noreturn;
```

A future commit will address these regressions.
2021-07-02 13:26:50 -07:00
Andrew Kelley
fc185a6f71 stage1: @shuffle type and mask params in comptime scope 2021-06-23 09:52:09 -07:00
Veikka Tuominen
6de45c826c
Merge pull request #8636 from jmc-88/issue-3779
Change builtins to return a string literal
2021-06-20 20:27:34 +03:00
LemonBoy
ccb6e1627e stage1: Store the specified code model in the LLVM module
This is needed for LTO builds to pick up the correct module.

Closes #9132
2021-06-18 08:29:23 +03:00
Andrew Kelley
e18ef71d98 stage1: fix zig0 help message
closes #9140
2021-06-17 13:39:30 -07:00
Daniele Cocca
171102ea7c errorName: return a null-terminated slice 2021-06-16 22:02:52 +01:00
Daniele Cocca
00e1c0082c tagName: return a null-terminated slice 2021-06-16 22:02:42 +01:00
Daniele Cocca
1184b1d560 Add create_sentineled_str_lit 2021-06-16 21:56:39 +01:00
Daniele Cocca
2242d3c3aa {create,init}_const_slice: accept custom sentinel 2021-06-16 21:56:39 +01:00
Andrew Kelley
193c529b8c CLI: rename --override-lib-dir to --zig-lib-dir
This breaking change disambiguates between overriding the lib dir when
performing an installation with the Zig Build System, and overriding the
lib dir that the Zig installation itself uses.
2021-06-14 11:33:27 -07:00
Exonorid
f63338195d Renamed @byteOffsetOf to @offsetOf 2021-06-12 19:16:01 +03:00
Andrew Kelley
b6277a4b1c better awareness of unwind tables
* stage1 backend allows configuring the uwtables function attr
   via a flag rather than its own logic.
 * stage2 defaults to enabling uwtable attr when
   linking libunwind, or always on windows
 * stage2 makes link_eh_frame_hdr true automatically if uwtable
   attr is set to be on for zig functions
 * CLI: add -funwind-tables and -fno-unwind-tables to allow the user to
   override the defaults.
 * hook it up to `zig cc`

closes #9046
2021-06-11 13:23:00 -04:00
LemonBoy
43a09f7efc stage1: Fix handling of C ABI parameters split in multiple regs
Take into account the increased number of parameters when flattening a
structure into one or more SSE registers.

Fixes #9061
2021-06-10 12:50:25 -04:00
Andrew Kelley
5e63baae8d CLI: remove --verbose-ast and --verbose-tokenize
closes #9034

These options were listed under the
"Debug Options (Zig Compiler Development)" heading. Anything in this
section should be considered unstable and can be modified at any time
at any developer's discretion.
2021-06-09 14:38:27 -07:00
Matthew Borkowski
9ac6d28614 stage1: make @truncate to an integer type of different sign an error at comptime too 2021-06-08 20:58:30 +03:00
Matthew Borkowski
fc956fc110 stage1: fix render_const_value for printing const optional pointers 2021-06-08 20:41:09 +03:00
LemonBoy
fc8791c133 stage1: Allow array-like initialization for tuple types
This small change makes working with tuple types much easier, allowing
the use of anonymous (eg. obtained with meta.ArgsTuple) tuples in more
places without the need for specifying each (quoted!) field name in the
initializer.
2021-06-06 21:21:42 -04:00
LemonBoy
849b4e3495 stage1: Apply the same set of fn attributes everywhere
Make sure to propagate the target-specific attributes to internal
functions too.

Closes #8965
2021-06-06 18:24:25 -04:00
Isaac Freund
abd1c75c4a
stage1: disallow 1.e9 and 0x1.p9 as float literals 2021-05-31 19:51:11 +00:00
Andrew Kelley
c12704a339
Merge pull request #8918 from ziglang/stage1-tokenizer
stage1: rework tokenizer to match stage2
2021-05-28 21:54:01 -04:00
LemonBoy
d3fb9f9532 stage1: Fix for atomicrmw xchg on fp types
Bitcast the pointer and operands to integer types having the same size,
working around LLVM inability to lower a LL/SC operation when the
operands have floating-point types (and are reasonably sized).

Closes #4457
2021-05-28 19:18:42 -04:00
Andrew Kelley
d888fa12a8 stage1 parser: fix the TODOs 2021-05-28 16:11:27 -07:00
Andrew Kelley
f5d4fe3e17 stage1: memoize strings in the AST
Currently, stage1 runs astgen for every comptime function call,
resulting in identifier strings being allocated multiple times,
wasting memory. As a workaround until the code is adjusted to
make astgen run only once per source node, we memoize the
result into the AST.

 * Rename `ir_gen_*` to `astgen_*`
   - Oops, meant to do this in a separate commit. My bad.
 * tokenizer: avoid using designated initializer syntax.
   MSVC does not support it.
2021-05-28 15:22:03 -07:00
Andrew Kelley
52b3daa90e stage1: get test-compile-errors passing again 2021-05-28 14:19:08 -07:00
Andrew Kelley
9de2c1b76e stage1: tokenizer: backport recent stage2 changes
This backports ec10595b65490126e1b7d231f655be6d7d198acf stage2 tokenizer
logic to stage1.
2021-05-28 13:26:16 -07:00
Andrew Kelley
01e0a4b2f0 stage1: rename IrBasicBlockSrc to Stage1ZirBasicBlock 2021-05-28 12:58:40 -07:00
Andrew Kelley
548ef78070 stage1: remove source_node field from Stage1Zir
This field is unneeded because we always have the source node available
in the context that we have a Stage1Zir object.
2021-05-28 12:58:40 -07:00
Andrew Kelley
554dd52c36 stage1: remove c_import_buf from Stage1Zir
All we need is a boolean in Stage1AstGen. This is part of an effort to
make Stage1Zir immutable.
2021-05-28 12:58:40 -07:00