Commit Graph

15001 Commits

Author SHA1 Message Date
Andrew Kelley
a98fa56ae9 std: [breaking] move errno to become an nonexhaustive enum
The primary purpose of this change is to eliminate one usage of
`usingnamespace` in the standard library - specifically the usage for
errno values in `std.os.linux`.

This is accomplished by truncating the `E` prefix from error values, and
making errno a proper enum.

A similar strategy can be used to eliminate some other `usingnamespace`
sites in the std lib.
2021-08-24 01:23:28 -04:00
Frank Denis
9e3ec98937
Don't define valgrind_support on macOS (#9612)
Unfortunately, Valgrind for macOS has been broken for years,
and the Homebrew formula is only for Linux.
2021-08-23 20:06:02 -04:00
Andrew Kelley
bb38931c71 stage1: @intToEnum implicitly does an @intCast
This is a backwards-compatible language change.

Previously, `@intToEnum` coerced its integer operand to the integer tag
type of the destination enum type, often requiring the callsite to
additionally wrap the operand in an `@intCast`. Now, the `@intCast` is
implicit, and any integer operand can be passed to `@intToEnum`.

The same as before, it is illegal behavior to pass any integer which does
not have a corresponding enum tag.
2021-08-23 15:30:57 -07:00
Nguyễn Gia Phong
d5ef5da594
Update comment: s/var/anytype/ (#9611) 2021-08-23 16:22:27 +02:00
William Stein
c465b34d32
Trivial typo "for for" --> "for" (also a few nearby run-on sentence). (#9610) 2021-08-23 08:31:21 +02:00
daurnimator
72c4b80d31
std.os: (p)writev should perform partial writes if iov.len > IOV_MAX
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2021-08-22 22:22:53 +03:00
Richard Eklycke
62e3d67605 Fix typo introduced in 50a29f7
Now the last argument will be checked as well
2021-08-22 13:29:06 -04:00
Jacob G-W
4ac37eb484 stage2 Air: add struct_field_ptr_index_{0..3}
Since these are very common, it will save memory.
2021-08-21 23:52:55 -04:00
Andrew Kelley
f378b0adce stage2: comptime function with the same args is memoized
* Introduce `memoized_calls` to `Module` which stores all the comptime
   function calls that are cached. It is keyed on the `*Fn` and the
   comptime arguments, but it does not yet properly detect comptime function
   pointers and avoid memoizing in this case. So it will have false
   positives for when a comptime function call mutates data through a
   pointer parameter.
 * Sema: Add a new helper function: `resolveConstMaybeUndefVal`
 * Value: add `enumToInt` method and use it in `zirEnumToInt`. It is
   also used by the hashing function.
 * Value: fix representation of optionals to match error unions.
   Previously it would not handle nested optionals correctly. Now it
   matches the memory layout of error unions and supports nested
   optionals properly. This required changes in all the backends for
   generating optional constants.
 * TypedValue gains `eql` and `hash` methods.
 * Value: Implement hashing for floats, optionals, and enums.
   Additionally, the zig type tag is added to the hash, where it was not
   previously, so that values of differing types will get different
   hashes.
2021-08-21 20:47:42 -07:00
Andrew Kelley
2b40815a22 stage2: fix wrong value for Decl owns_tv
In the case of a comptime function call of a function that returns a
type, resulting in a compiler crash on deinit().
2021-08-21 20:47:42 -07:00
Jonathan Marler
f28868e8fd mingw.zig: fix logic to add crt sources
The current version of code uses isARM to check if we are compiling to any arm target then checks the target bit width to either add the 32-bit sources or 64-bit source.  However, isARM only returns true for 32-bit targets, and isAARCH64 is for the 64-bit targets.

I also replaced the unreachable with a @panic when we receive an unsupported arch because this code is reachable and should turn into an error.
2021-08-21 20:40:07 +03:00
Martin Wickham
27e3216285 Add a flag to build a single-threaded compiler, for debugging 2021-08-21 19:41:28 +03:00
Aydin Mercan
e3e6df17ed linux: Add recent clone/clone3 and missing signalfd flags.
The following flags have been introduced:
- CLONE_PIDFD (>=5.2)
- CLONE_INTO_CGROUP (>=5.7)
- SFD_CLOEXEC and SFD_NONBLOCK (>=2.6.27)
2021-08-21 19:41:00 +03:00
Veikka Tuominen
724995e892 translate-c: avoid repeating string in type when making it mutable 2021-08-21 16:32:09 +03:00
Evan Haas
3b25205833 translate-c: allow string literals to be used as char *
In C the type of string literals is `char *`, so when using them in
a non-const context we have to cast the const away.

Fixes #9126
2021-08-21 16:32:09 +03:00
Michael Dusan
d57c0cc3bf dragonfly: port libc++
Used https://github.com/DragonFlyBSD/DPorts/tree/master/devel/libc++/files
for hints as to which patches were needed.
2021-08-21 15:17:08 +03:00
Tamas Kenez
4c18da1ef3 Fix args when calling clang::ASTUnit::LoadFromCommandLine.
clang::ASTUnit::LoadFromCommandLine interprets the first argument as
the name of program (like the main function).
This change shifts the arguments passing "" for the first argument.
2021-08-21 14:49:01 +03:00
Takeshi Yoneda
bbb96e112c build: allow specifying -mexec-model flag.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-08-21 14:45:42 +03:00
Andrew Kelley
f0176eec4a stage2: support comptime fn call returning type
...when the field type expressions reference locals as well as
comptime function parameters.
2021-08-20 17:44:03 -07:00
Jonathan Marler
6c55d854cf Add compstui.def
The compstui library contains 4 Windows functions which were recently added to the win32metadta project.  I copied this def file from the mingw-w64 project.
2021-08-20 19:44:24 -04:00
joachimschmidt557
5806c386eb stage2 codegen: re-allocate result register in finishAir
In some cases (such as bitcast), an operand may be the same MCValue as
the result. If that operand died and was a register, it was freed by
processDeath. We have to "re-allocate" the register.
2021-08-20 19:06:30 -04:00
joachimschmidt557
e48d7bbb99 stage2 ARM: Implement loading from memory 2021-08-20 19:05:50 -04:00
Andrew Kelley
a2438357e1
Merge pull request #9597 from joachimschmidt557/stage2-arm-bitshift
stage2 ARM: implement bitshifts
2021-08-20 19:05:05 -04:00
Andrew Kelley
0cd361219c stage2: field type expressions support referencing locals
The big change in this commit is making `semaDecl` resolve the fields if
the Decl ends up being a struct or union. It needs to do this while
the `Sema` is still in scope, because it will have the resolved AIR
instructions that the field type expressions possibly reference. We do
this after the decl is populated and set to `complete` so that a `Decl`
may reference itself.

Everything else is fixes and improvements to make the test suite pass
again after making this change.

 * New AIR instruction: `ptr_elem_ptr`
   - Implemented for LLVM backend
 * New Type tag: `type_info` which represents `std.builtin.TypeInfo`. It
   is used by AstGen for the operand type of `@Type`.
 * ZIR instruction `set_float_mode` uses `coerced_ty` to avoid
   superfluous `as` instruction on operand.
 * ZIR instruction `Type` uses `coerced_ty` to properly handle result
   location type of operand.

 * Fix two instances of `enum_nonexhaustive` Value Tag not handled
   properly - it should generally be handled the same as `enum_full`.
 * Fix struct and union field resolution not copying Type and Value
   objects into its Decl arena.
 * Fix enum tag value resolution discarding the ZIR=>AIR instruction map
   for the child Sema, when they still needed to be accessed.
 * Fix `zirResolveInferredAlloc` use-after-free in the AIR instructions
   data array.
 * Fix `elemPtrArray` not respecting const/mutable attribute of pointer
   in the result type.
 * Fix LLVM backend crashing when `updateDeclExports` is called before
   `updateDecl`/`updateFunc` (which is, according to the API, perfectly
   legal for the frontend to do).
 * Fix LLVM backend handling element pointer of pointer-to-array. It
   needed another index in the GEP otherwise LLVM saw the wrong type.
 * Fix LLVM test cases not returning 0 from main, causing test failures.
   Fixes a regression introduced in
   6a5094872f.

 * Implement comptime shift-right.
 * Implement `@Type` for integers and `@TypeInfo` for integers.
 * Implement union initialization syntax.
 * Implement `zirFieldType` for unions.
 * Implement `elemPtrArray` for a runtime-known operand.

 * Make `zirLog2IntType` support RHS of shift being `comptime_int`. In
   this case it returns `comptime_int`.

The motivating test case for this commit was originally:

```zig
test "example" {
    var l: List(10) = undefined;
    l.array[1] = 1;
}

fn List(comptime L: usize) type {
    var T = u8;
    return struct {
        array: [L]T,
    };
}
```

However I changed it to:

```zig
test "example" {
    var l: List = undefined;
    l.array[1] = 1;
}

const List = blk: {
    const T = [10]u8;
    break :blk struct {
        array: T,
    };
};
```

Which ended up being a similar, smaller problem. The former test case
will require a similar solution in the implementation of comptime
function calls - checking if the result of the function call is a struct
or union, and using the child `Sema` before it is destroyed to resolve
the fields.
2021-08-20 15:41:57 -07:00
joachimschmidt557
224fe49be2
stage2 ARM: add test cases for bit shifts 2021-08-20 23:37:41 +02:00
joachimschmidt557
f9e50a5830
stage2 ARM: implement bitshifting for 32-bit integers 2021-08-20 23:17:46 +02:00
rgreenblatt
2f1abd919a Fix issue where root.os.panic could return 2021-08-20 19:37:53 +03:00
joachimschmidt557
7aecf90d2e
stage2 ARM: add lsl, lsr, asr, ror psuedo-instructions 2021-08-20 14:25:25 +02:00
Dmitry Matveyev
b2e970d157
std.json: Add support for recursive objects to std.json.parse (#9307)
* Add support for recursive objects to std.json.parse

* Remove previously defined error set

* Try with function which returns an error set

* Don't analyze already inferred types

* Add comptime to inferred_type parameter

* Make ParseInternalError to accept only a single argument

* Add public `ParseError` for `parse` function

* Use error.Foo syntax for errors instead of a named error set

* Better formatting

* Update to latest code changes
2021-08-20 14:52:48 +03:00
bnprks
cfb2827b0a Clarify async/await language documentation.
The async/await documentation was somewhat hard for me to follow when first learning. Two particular sticking points were
1. The alphabet example constructing the string "abcdefghi" breaks the stated rule that every async has a matching await.
2. It was somewhat unclear to me what the rules for control flow were around async/await constructs.
I've tried to improve this documentation with some minimal explanatory edits, which are correct to the best of my beginner's understanding & experimentation.
2021-08-20 14:16:04 +03:00
Tom Maenan Read Cutting
0cecdca6a2 Resolve order-of-call dependencies in build.zig 2021-08-20 13:11:19 +03:00
Paul
ddaca72864
Make clearer inline code blocks in language reference paragraphs (#9317)
* Make clearer inline code blocks in language reference paragraphs

This commit makes the inline code blocks within paragraphs standout against the
descriptive text. The code blocks within tables are left un-styled.

The line-height of the paragraphs has been set to 1.7 based on recommendations
from MDN Web Docs and W3C. The value is unitless based on the recommendation.

Closes #9316, #6313

* Make clearer inline code blocks in language reference paragraphs

Goal: To improve legibility of inline code blocks in the language reference.

This commit alters the styles of code HTML elements in paragraphs, unordered
lists, ordered lists, tables, and preformatted text elements.

Most of the changes here are taken from suggestions from @dbandstra on GitHub
in response to a code review.

* p, ul, ol, but not #toc are set to the same line-height
* p, ul, ol, and table have the same inline code styles
* The inline code background color set to match the preformatted code blocks in
the light theme and dark theme. The border colors are adjusted as well.
* The preformatted code block font size is set to default. The 12pt setting was removed.

The line-height of paragraphs is set to 1.5. This value is chosen based on
recommendations from W3C [1] via MDN Web Docs [2] and the contents of the
language reference.

The MDN Web Docs offers two recommendations:

  1. Use a unitless number for line-height.
  2. Use a minimum value of 1.5 for main paragraph content.

[1] https://www.w3.org/TR/WCAG21/#visual-presentation
[2] https://developer.mozilla.org/en-US/docs/Web/CSS/line-height

Closes #6313, #9316

* Set language reference line-height and pre code border color

This commit is an update to a group of commits with the goal of improving the
legibility of the language reference. In this commit, the line-height is now set
in the `#contents` ID and reset to normal for preformatted code blocks. This
change better separates lines of all main content text for legibility.

Closes: #9316, #6313

* Style the language reference code elements

This commit sets the style of the HTML code element. Since preformatted code
blocks have an overriding style, this is safe to set for all inline code elements.
2021-08-20 13:02:14 +03:00
Veikka Tuominen
b3d3e93636
Merge pull request #9224 from marler8997/defaultLog
A couple std.log conveniences
2021-08-20 12:24:02 +03:00
Samadi van Koten
e94f3c4e25 Add std.io.Reader.readUntilDelimiter() 2021-08-20 12:20:42 +03:00
Isaac Yonemoto
8c39ab2659 enables user-custom code to work with LI and SI 2021-08-20 12:10:45 +03:00
Ryan Liptak
2f6dbaa0ea fs.Dir.walk: Do not close the initial dir during/after walking it
Closing the initial directory was unexpected to me, and does not mesh very well with how the rest of the Dir API works.

Fixes #9556
2021-08-20 10:02:54 +03:00
Andrew Kelley
6a5094872f
Merge pull request #9587 from g-w1/sh
stage2: implement shr and shl
2021-08-19 23:47:44 -04:00
Jacob G-W
2e22f7e5a5 stage2: implement shl
This is implemented in the llvm and cbe backends.
x86_64 will take a bit more time.
2021-08-19 16:18:42 -04:00
Jacob G-W
2e6ce11eb2 stage2: implement shr and boilerplate for shl
This implements it in the llvm and c backends.
x86_64 will have to be a little more work.
2021-08-19 16:18:40 -04:00
Jacob G-W
df10e998ee stage2 x86_64: enable bitwise and + or and add tests 2021-08-19 22:21:16 +03:00
Justin Whear
62fe4a0ba8
std.rand.Random: add enumValue() (#9583)
* add Random.enumValue()

* edits suggested by review

* applied zig fmt

* Rewrite to use std.enums.values

Implemented pfgithub's suggestion to rewrite against this function, greatly simplifying the implementation.

Co-authored-by: Justin Whear <justin@economicmodeling.com>
2021-08-19 22:18:23 +03:00
Meghan
7e7d67d8ee
std.fmt: add support for printing slices strings (#9562) 2021-08-19 14:12:11 +03:00
Jacob G-W
d785dc49aa stage2: add error set type equality 2021-08-19 14:09:53 +03:00
Jacob G-W
2129cc5c54 stage2: fix typo
this made errors go from stuff like:
> type comptime_int cannot represent integer value 40
to
> type u5 cannot represent integer value 40
which makes much more sense
2021-08-19 13:48:52 +03:00
Robin Voetter
5cd1d42a35
Add mask before truncating dereferenced bit pointers (#9584) 2021-08-19 01:20:50 -04:00
Jakub Konka
4c9d41730e
Merge pull request #9568 from ziglang/issue-9565
macho: don't embed codesig unless targeting aarch64-macos
2021-08-16 10:17:54 +02:00
Jakub Konka
e2303840de Fix AST and build errors 2021-08-15 23:50:39 +02:00
Jakub Konka
d5f7963331 macho: adhoc code sign binaries targeting aarch64-xxx-simulator 2021-08-15 18:29:19 +02:00
Jakub Konka
f82c26eb04 macho: don't embed codesig unless targeting aarch64-macos
When developing an iOS app for example, the developer is required
to use Apple's codesign utility to generate a valid signature
as done by Xcode.
2021-08-15 18:07:30 +02:00
Veikka Tuominen
e9bf8014bd
Merge pull request #9559 from squeek502/walker-basename
fs.Dir.Walker: Fix basename missing its first character for direct children of the initial directory
2021-08-14 11:08:10 +03:00