Skip to content

Sema: make @src().line comptime-known#17688

Merged
andrewrk merged 2 commits intomasterfrom
comptime-src
Oct 24, 2023
Merged

Sema: make @src().line comptime-known#17688
andrewrk merged 2 commits intomasterfrom
comptime-src

Conversation

@andrewrk
Copy link
Member

Reverts 89cef9f.

Closes #13315

image

We can figuring out how to deal with @src() in relationship with incremental compilation separately.

When the code is written this way, you get a compile error if the
pointer given to Tracy does not have a static lifetime.

This would have caught the regression in #13315.
@mlugg
Copy link
Member

mlugg commented Oct 24, 2023

Note that this almost eliminates the need for the runtime_value value representation (representing a value which is really comptime-known but semantically runtime-known), which I think is desirable for language simplicity. The only place where this representation can still be introduced is in initialization expressions (looks for make_runtime in Sema.validateStructInit) as a result of the val.isPtrToThreadLocal check in resolveMaybeUndefValAllowVariablesMaybeRuntime. I don't really understand what's happening in that logic, but this should probably be looked into.

At a glance, I think we could inline the logic of resolveMaybeUndefValAllowVariablesMaybeRuntime into resolveMaybeUndefValAllowVariables, and change validateStructInit et all to use resolveMaybeUndefVal - I'm not actually sure what the AllowVariables is doing in these cases, it seems wrong. Then there are actually no correct usages of the AllowVariables variant at all (the only remaining ones are storeToInferredAllocComptime, which immediately exits if it's a variable, and zirClosureCapture, which can correctly just capture the type in this case). So that function also goes away!

It seems like there are quite a few dominos here - I'll explore locally and open a follow-up PR.

@andrewrk andrewrk enabled auto-merge October 24, 2023 06:57
@andrewrk andrewrk merged commit b477279 into master Oct 24, 2023
@andrewrk andrewrk deleted the comptime-src branch October 24, 2023 07:58
mlugg added a commit to mlugg/zig that referenced this pull request Aug 19, 2024
* Indices of referenced captures
* Line and column of `@src()`

The second point aligns with a reversal of the "incremental compilation"
section of ziglang#2029 (comment).
This reversal was already done as ziglang#17688 (46a6d50), with the idea to
push incremental compilation down the line. My proposal is to keep it as
comptime-known, and simply re-analyze uses of `@src()` whenever their
line/column change.

I think this decision is reasonable for a few reasons:

* The Zig compiler is quite fast. Occasionally re-analyzing a few
  functions containing `@src()` calls is perfectly acceptable and won't
  noticably impact update times.
* The system described by Andrew in ziglang#2029 is currently vaporware.
* The system described by Andrew in ziglang#2029 is non-trivial to implement.
  In particular, it requires some way to have backends update a single
  global in certain cases, without re-doing semantic analysis. There is
  no other part of incremental compilation which requires this.
* Having `@src().line` be comptime-known is useful. For instance, ziglang#17688
  was justified by broken Tracy integration because the source line
  couldn't be comptime-known.
mlugg added a commit to mlugg/zig that referenced this pull request Aug 20, 2024
* Indices of referenced captures
* Line and column of `@src()`

The second point aligns with a reversal of the "incremental compilation"
section of ziglang#2029 (comment).
This reversal was already done as ziglang#17688 (46a6d50), with the idea to
push incremental compilation down the line. My proposal is to keep it as
comptime-known, and simply re-analyze uses of `@src()` whenever their
line/column change.

I think this decision is reasonable for a few reasons:

* The Zig compiler is quite fast. Occasionally re-analyzing a few
  functions containing `@src()` calls is perfectly acceptable and won't
  noticably impact update times.
* The system described by Andrew in ziglang#2029 is currently vaporware.
* The system described by Andrew in ziglang#2029 is non-trivial to implement.
  In particular, it requires some way to have backends update a single
  global in certain cases, without re-doing semantic analysis. There is
  no other part of incremental compilation which requires this.
* Having `@src().line` be comptime-known is useful. For instance, ziglang#17688
  was justified by broken Tracy integration because the source line
  couldn't be comptime-known.
mlugg added a commit to mlugg/zig that referenced this pull request Aug 21, 2024
* Indices of referenced captures
* Line and column of `@src()`

The second point aligns with a reversal of the "incremental compilation"
section of ziglang#2029 (comment).
This reversal was already done as ziglang#17688 (46a6d50), with the idea to
push incremental compilation down the line. My proposal is to keep it as
comptime-known, and simply re-analyze uses of `@src()` whenever their
line/column change.

I think this decision is reasonable for a few reasons:

* The Zig compiler is quite fast. Occasionally re-analyzing a few
  functions containing `@src()` calls is perfectly acceptable and won't
  noticably impact update times.
* The system described by Andrew in ziglang#2029 is currently vaporware.
* The system described by Andrew in ziglang#2029 is non-trivial to implement.
  In particular, it requires some way to have backends update a single
  global in certain cases, without re-doing semantic analysis. There is
  no other part of incremental compilation which requires this.
* Having `@src().line` be comptime-known is useful. For instance, ziglang#17688
  was justified by broken Tracy integration because the source line
  couldn't be comptime-known.
richerfu pushed a commit to richerfu/zig that referenced this pull request Oct 28, 2024
* Indices of referenced captures
* Line and column of `@src()`

The second point aligns with a reversal of the "incremental compilation"
section of ziglang#2029 (comment).
This reversal was already done as ziglang#17688 (46a6d50), with the idea to
push incremental compilation down the line. My proposal is to keep it as
comptime-known, and simply re-analyze uses of `@src()` whenever their
line/column change.

I think this decision is reasonable for a few reasons:

* The Zig compiler is quite fast. Occasionally re-analyzing a few
  functions containing `@src()` calls is perfectly acceptable and won't
  noticably impact update times.
* The system described by Andrew in ziglang#2029 is currently vaporware.
* The system described by Andrew in ziglang#2029 is non-trivial to implement.
  In particular, it requires some way to have backends update a single
  global in certain cases, without re-doing semantic analysis. There is
  no other part of incremental compilation which requires this.
* Having `@src().line` be comptime-known is useful. For instance, ziglang#17688
  was justified by broken Tracy integration because the source line
  couldn't be comptime-known.
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.

debug info missing from Tracy

2 participants