Skip to content
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

Audit uses of Sema.requireRuntimeBlock #22353

Open
mlugg opened this issue Dec 29, 2024 · 0 comments
Open

Audit uses of Sema.requireRuntimeBlock #22353

mlugg opened this issue Dec 29, 2024 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@mlugg
Copy link
Member

mlugg commented Dec 29, 2024

Sema uses the requireRuntimeBlock function to emit a compile error when performing a runtime operation in a comptime block. However, most uses of this function are actually incorrect. The consensus Andrew and I have reached, to make sure expressions like comptime runtime_array.len work, is that non-side-effecting expressions are allowed to be runtime-known in a comptime scope. It's never possible for a runtime value to be "leaked" out of a comptime block, nor to be meaningfully used within one, so this never allows a comptime scope to actually emit real runtime code (Sema discards instructions of the Block being comptime-evaluated).

All uses of requireRuntimeBlock need to be audited, and the majority simply removed. The only ones remaining should be those which have side effects, such as storing to a runtime pointer.

@mlugg mlugg added bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Dec 29, 2024
@mlugg mlugg added this to the 0.15.0 milestone Dec 29, 2024
mlugg added a commit to mlugg/zig that referenced this issue Dec 30, 2024
Most calls to `requireRuntimeBlock` in Sema are not correct. This
function doesn't deal with all of them, but it does deal with ones which
have, in combination with the past few commits, introduced real-world
regressions.

Related: ziglang#22353
mlugg added a commit to mlugg/zig that referenced this issue Dec 30, 2024
Most calls to `requireRuntimeBlock` in Sema are not correct. This
function doesn't deal with all of them, but it does deal with ones which
have, in combination with the past few commits, introduced real-world
regressions.

Related: ziglang#22353
mlugg added a commit to mlugg/zig that referenced this issue Dec 30, 2024
Most calls to `requireRuntimeBlock` in Sema are not correct. This
function doesn't deal with all of them, but it does deal with ones which
have, in combination with the past few commits, introduced real-world
regressions.

Related: ziglang#22353
mlugg added a commit to mlugg/zig that referenced this issue Dec 31, 2024
Most calls to `requireRuntimeBlock` in Sema are not correct. This
function doesn't deal with all of them, but it does deal with ones which
have, in combination with the past few commits, introduced real-world
regressions.

Related: ziglang#22353
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

1 participant