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

Regression from v2.0.8 to v2.0.10/version-2-0/2.2/devel: Error: request to generate code for .compileTime proc: $ #24228

Closed
tersec opened this issue Oct 3, 2024 · 2 comments · Fixed by #24229

Comments

@tersec
Copy link
Contributor

tersec commented Oct 3, 2024

Description

proc d(_: static[string]) = discard $0
proc m(_: static[string]) = d("")
iterator v(): int {.closure.} =
  template a(n: untyped) =
    when typeof(n) is void:
      n
    else:
      n
  a(m(""))
let _ = v

Nim Version

Builds:

Nim Compiler Version 2.0.8 [Linux: amd64]
Compiled at 2024-10-03
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 5935c3bfa9fec6505394867b23510eb5cbab3dbf
active boot switches: -d:release

Does not build:

Nim Compiler Version 2.0.10 [Linux: amd64]
Compiled at 2024-10-03
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: e941ee15be775fe3c46db1bed9b4f41c7dfb1334
active boot switches: -d:release
Nim Compiler Version 2.2.0 [Linux: amd64]
Compiled at 2024-10-03
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 78983f1876726a49c69d65629ab433ea1310ece1
active boot switches: -d:release
Nim Compiler Version 2.2.1 [Linux: amd64]
Compiled at 2024-10-03
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: d6a71a10671b66ee4f5be09f99234b3d834e7fce
active boot switches: -d:release

Current Output

/tmp/h.nim(1, 37) Error: request to generate code for .compileTime proc: $

Expected Output

No response

Known Workarounds

No response

Additional Information

No response

@metagn
Copy link
Collaborator

metagn commented Oct 3, 2024

Simplified

proc d[T]() = discard $0
proc v() =
  when typeof(d[string]()) is void:
    d[string]()
v()

The original d called as d("") has the same effect, just signaling that d has to be generic

No idea what the root issue is but worst case we can remove these compileTime overloads for $ for int literals:

template gen(T) =
# xxx simplify this by supporting this in compiler: int{lit} | uint64{lit} | int64{lit}
func `$`*(x: T{lit}): string {.compileTime.} = result.addInt(x)
gen(int)
gen(uint64)
gen(int64)

@metagn
Copy link
Collaborator

metagn commented Oct 3, 2024

The issue is that, when we call typeof, d is instantiated with the belief that we are still in typeof, so the compile time folding of $0 is disabled in the body of d. But then we actually call d, which means the leftover unfolded $0 call tries to get compiled which fails.

We can make the compiler stop believing we're in typeof if a generic proc is being instantiated but that sounds too special cased. I would really prefer reverting the typeof special case entirely from #22022. To make declval work with the rest of #22022, we could split compileTime into another flag which enables/disables the eager folding, but this is a new feature and would still break one of either stew or other packages.

At the very least we should revert #22022 from the 2.0 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants