-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
A certain combination of iterators and procs crashes the compiler #19703
Labels
Comments
The transformed AST is: proc checkSpecialSubset5(s: seq[int]): bool =
result = any(
var result`gensym0: seq[typeof(map(
var result`gensym4: seq[typeof(s.combinations(2))] = @[]
for x`gensym4 in combinations(s, 2):
add(result`gensym4, x`gensym4)
result`gensym4, proc (a: auto): int = result = a[0]).pairwise())] = []
block :tmp:
var x`gensym0
x`gensym0 = @[map(
var result`gensym5: seq[typeof(s.combinations(2))] = []
block :tmp:
var x`gensym5
x`gensym5 = @[s[0], s[1]]
add(result`gensym5, x`gensym5)
result`gensym5, (proc (a: auto): int = result = a[0], nil))[0], map(
var result`gensym5: seq[typeof(s.combinations(2))] = []
block :tmp:
var x`gensym5
x`gensym5 = @[s[0], s[1]]
add(result`gensym5, x`gensym5)
result`gensym5,
(proc (a: auto): int = result = a[0], nil))[1]]
add(result`gensym0, x`gensym0)
result`gensym0,
(proc (a: auto): bool = result = true, nil)) So a case of #24023 triggered by iterators duplicating the expression of |
metagn
added a commit
to metagn/Nim
that referenced
this issue
Oct 20, 2024
narimiran
pushed a commit
that referenced
this issue
Jan 14, 2025
…4333) fixes #13417, fixes #19703 When passing an expression to an `openarray` iterator parameter: If the expression is a statement list (considered "complex"), it's assigned in a non-deep-copying way to a temporary variable first, then this variable is used as a parameter. If it's not a statement list, i.e. a call or a symbol, the parameter is substituted directly with the given expression. In the case of calls, this results in the call potentially being executed more than once, or can cause redefined variables in the codegen. To fix this, calls are also considered as "complex" assignments to openarrays, as long as the return type of the call is not `openarray` as the generated assignment in that case has issues/is unimplemented (caused a segfault [here in datamancer](https://github.com/SciNim/Datamancer/blob/47ba4d81bf240a7755b73bc48c1cec9b638d18ae/src/datamancer/dataframe.nim#L1580)). As for why creating a temporary isn't the default only with exceptions for things like `nkSym`, the "non-deep-copying" way of assignment apparently still causes arrays to be copied according to a comment in the code. I'm not sure to what extent this is true: if it still happens on ARC/ORC, if it happens for every array length, or if we can fix it by passing arrays by reference. Otherwise, a more general way to assign to openarrays might be needed, but I'm not sure if the compiler can easily do this. (cherry picked from commit d303c28)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code to reproduce
Current Output
Expected Output
That the file is compiled without problems
Possible Solution
From the discussion in Discord:
Additional Information
For easier testing, here a slightly different version with templates:
The text was updated successfully, but these errors were encountered: