Skip to content

Add @inComptime builtin #15290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2023
Merged

Conversation

mlugg
Copy link
Member

@mlugg mlugg commented Apr 14, 2023

Resolves: #868

I'm aware this proposal isn't yet accepted, but in a discussion on Discord, Andrew seemed very open to it (in fact thought it had already been accepted). I figured I'd put this PR together in the hopes that it's accepted.

I picked @inComptime for the builtin's name because @areWeInComptime felt needlessly wordy but @isComptime sounds (at least to me) like it's trying to check whether a value is comptime-known or something to that effect. @inComptime felt like the best way of expressing what the builtin actually does. It can be changed if others disagree.

@mlugg mlugg force-pushed the feat/builtin-in-comptime branch 5 times, most recently from 1009427 to 2d7fd75 Compare April 17, 2023 00:56
@mlugg
Copy link
Member Author

mlugg commented Apr 20, 2023

I managed to break aarch64 by emitting better code :) #15355 will disable the self-hosted aarch64 backend for now anyway, so I'm just going to wait for that.

@mlugg mlugg force-pushed the feat/builtin-in-comptime branch from 2d7fd75 to d9df805 Compare April 21, 2023 22:52
@andrewrk
Copy link
Member

andrewrk commented Apr 22, 2023

Hmm I'm a bit confused why the zig1.wasm update is needed. Did the CI fail before that?

@mlugg
Copy link
Member Author

mlugg commented Apr 22, 2023

The compiler uses Sha256 from std, which (now) uses @inComptime (previously used a inline fn isComptime)

EDIT: actually, zig1 I suppose doesn't? We might be okay - I was previously hitting a CI failure because std.fmt was using it, but I removed that. I'll try bootstrapping with an old zig1 locally, if it works I'll drop that commit

@mlugg
Copy link
Member Author

mlugg commented Apr 22, 2023

Okay, it remains necessary, because AstGen is resposible for validating builtin names so we get a compile error for the Sha256 usage even if it's unreferenced. (I know there are security concerns with external contributors doing zig1 updates, so feel free to recreate that commit yourself if needed)

@andrewrk
Copy link
Member

Thanks for the explanation! It makes sense 👍

@andrewrk andrewrk force-pushed the feat/builtin-in-comptime branch from d9df805 to 3878586 Compare April 23, 2023 20:34
@andrewrk andrewrk enabled auto-merge April 23, 2023 20:34
@andrewrk andrewrk disabled auto-merge April 24, 2023 19:54
@andrewrk andrewrk merged commit ef0a020 into ziglang:master Apr 24, 2023
@mlugg mlugg deleted the feat/builtin-in-comptime branch May 18, 2025 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to determine if we are currently executing at compile time
2 participants