install older version of nimcuda for arraymancer (#24496)
Attempt to fix CI failure, refs #24495 (comment), alternative is to use a commit version like SciNim/nimcuda@bc65375 (cherry picked from commit 33dc236)
fixes #22153; UB calling allocCStringArray([""]) with --mm:refc (#24529)
(cherry picked from commit be4d19e)
Revert "(cherry picked from commit 556f217)"
This reverts commit 9e5cdc4.
Revert "Bumps nimble v0.16.4 (#24437)"
This reverts commit 1778b83.
fixes 12381, HttpClient socket handle leak (#23575)
## Bug Fixes #12381 - HttpClient socket handle leak To replicate the bug, run the following code in a loop: ```nim import httpclient while true: echo "New loop" var client = newHttpClient(timeout = 1000) try: let response = client.request("http://10.44.0.4/bla", httpMethod = HttpPost, body = "boo") echo "HTTP " & $response.status except CatchableError as e: echo "Error sending logs: " & $e.msg finally: echo "Finally" client.close() ``` Note the IP address as the hostname. I'm directly connecting to a plausible local IP, but one that does not resolve, as I have everything under 10.4.x.x. The output looks like this to me: ``` New loop Error sending logs: Operation timed out Finally New loop Error sending logs: Operation timed out Finally New loop ... ``` In Nim 2.0.4, running the code above leaks the socket: <img width="944" alt="Screenshot 2024-05-05 at 22 00 13" src="https://github.com/nim-lang/Nim/assets/53387/ddac67db-d7df-45e6-b7a5-3d42f79775ea"> ## Fix With the added line of code, each old socket is cleanly removed: <img width="938" alt="Screenshot 2024-05-05 at 21 54 18" src="https://github.com/nim-lang/Nim/assets/53387/5b0b4b2d-d4f0-4e74-a9cf-74aec0c50d2e"> I believe the line below, `closeUnusedFds(ord(domain))` was supposed to clean up the failed connection attempts, but it failed to do so for the last one, assuming it succeeded. Yet it didn't. This fix makes sure failed connections are closed immediately. ## Tests I don't have a test with this PR. When testing locally, the `connect(lastFd, ..)` call on line 2032 blocks for ~75 seconds, ignoring the http timeout. I fear any test I could add would either 1) take way too long, 2) one day run in an environment where my randomly chosen IP is real, yielding in weird flakes. The only bug i can imagine is if running `lastFd.close()` twice is a bad idea. I tested by actually running it twice, and... no crash/op? So seems safe? I'm hoping the CI run will be green, and this will be enough. However I'm happy to take feedback on how I should test this, and do the necessary changes. ~Edit: looks like a test does fail, so moving to a draft while I figure this out.~ Attempt 2 fixed it. (cherry picked from commit e6f66e4)
Check for nil in cstringArrayToSeq (#23747)
This fixes crashes in some specific network configurations (as `cstringArrayToSeq` is used extensively in `nativesockets`). --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de> (cherry picked from commit 2c83f94)
bypass constraints for tyFromExpr in generic bodies (#23863)
fixes #19819, fixes #23339 Since #22029 `tyFromExpr` does not match anything in overloading, so generic bodies can know which call expressions to delay until the type can be evaluated. However generic type invocations also run overloading to check for generic constraints even in generic bodies. To prevent them from failing early from the overload not matching, pretend that `tyFromExpr` matches. This mirrors the behavior of the compiler in more basic cases like: ```nim type Foo[T: int] = object x: T Bar[T] = object y: Foo[T] ``` Unfortunately this case doesn't respect the constraint (#21181, some other bugs) but `tyFromExpr` should easily use the same principle when it does. (cherry picked from commit 31ee75f)
fix subscript magic giving unresolved generic param type (#23988)
fixes #19737 As in the diff, `semResolvedCall` sets the return type of a call to a proc to the type of the call. But in the case of the [subscript magic](https://nim-lang.org/docs/system.html#%5B%5D%2CT%2CI), this type is the first generic param which is also supposed to be the type of the first argument, but this is invalid, the correct type is the element type eventually given by `semSubscript`. Some lines above also [prevent the subscript magics from instantiating their params](https://github.com/nim-lang/Nim/blob/dda638c1ba985a77eac3c7518138992521884172/compiler/semcall.nim#L699) so this type ends up being an unresolved generic param. Since the type of the node is not `nil`, `prepareOperand` doesn't try to type it again, and this unresolved generic param type ends up being the final type of the node. To prevent this, we just never set the type of the node if we encountered a subscript magic. Maybe we could also rename the generic parameters of the subscript magics to stuff like `DummyT`, `DummyI` if we want this to be easier to debug in the future. (cherry picked from commit 04da0a6)
fix int32's that should be uint32 on BSD & OSX (#24078)
fixes #24076 As described in #24076, misannotating these types causes codegen errors. Sources for the types are https://github.com/openbsd/src/blob/master/sys for BSD and https://opensource.apple.com/source/Libinfo/Libinfo-391/ and [_types.h](https://opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/_types.h.auto.html) for OSX. (cherry picked from commit 7de4ace)
fix regression with generic params in static type (#24075)
Caught in https://github.com/metagn/applicates, I'm not sure which commit causes this but it's also in the 2.0 branch (but not 2.0.2), so it's not any recent PRs. If a proc has a static parameter with type `static Foo[T]`, then another parameter with type `static Bar[T, U]`, the generic instantiation for `Bar` doesn't match `U` which has type `tyGenericParam`, but matches `T` since it has type `tyTypeDesc`. The reason is that `concreteType` returns the type itself for `tyTypeDesc` if `c.isNoCall` (i.e. matching a generic invocation), but returns `nil` for `tyGenericParam`. I'm guessing `tyGenericParam` is received here because of #22618, but that doesn't explain why `T` is still `tyTypeDesc`. I'm not sure. Regardless, we can just copy the behavior for `tyTypeDesc` to `tyGenericParam` and also return the type itself when `c.isNoCall`. This feels like it defeats the purpose of `concreteType` but the way it's used doesn't make sense without it (generic param can't match another generic param?). Alternatively we could loosen the `if concrete == nil: return isNone` checks in some places for specific conditions, whether `c.isNoCall` or `c.inGenericContext == 0` (though this would need (cherry picked from commit 24e5b21)
fixes #24319; move doesn't work well with (deref (var array)) (#24321)
Fix broken poll and nfds_t bindings (#24331)
This fixes several cases of the Nim binding of nfds_t being inconsistent with the target platform signedness and/or size. Additionally, it fixes poll's third argument (timeout) being set to Nim "int" when it should have been "cint". The former is the same issue that #23045 had attempted to fix, but failed because it only considered Linux. (Also, it was only applied to version 2.0, so the two branches now have incompatible versions of the same bug.) Notes: * SVR4's original "unsigned long" definition is cloned by Linux and Haiku. Nim got this right for Haiku and Linux-amd64, but it was wrong on non-amd64 Linux. * Zephyr does not have nfds_t, but simply uses (signed) "int". This was already correctly reflected by Nim. * OpenBSD poll.h uses "unsigned int", and other BSD derivatives follow suit. This being the most commonly copied definition, the fallback case now returns cuint. (This also seems to be correct for the OS X headers I could find on the web.) * This changes Nintendo Switch nfds_t to cuint from culong. It is purportedly a FreeBSD derivative, so I *think* this is correct, but I can't tell because I don't have access to the Nintendo Switch headers. I have also moved the platform-specific Tnfds to posix.nim so that we can reuse the fallback logic on all platforms. (e.g. specifying the size in posix_linux_amd64 only to then use when defined(linux) in posix_other seems redundant.) (cherry picked from commit 6744247)
gensym anonymous proc symbols (#24422)
fixes #14067, fixes #15004, fixes #19019 Anonymous procs are [added to scope](https://github.com/nim-lang/Nim/blob/8091d76306c23b866af00d384b9b6f929ef8ed23/compiler/semstmts.nim#L2466) with the name `:anonymous`. This means that if they have the same signature in a scope, they can consider each other as redefinitions. To prevent this, mark their symbols as `sfGenSym` so they do not get added to scope or cause any name conflicts. The commented out `and not isAnon` check wouldn't work because `isAnon` would not be true if the proc is being resemmed, in which case the name field in the proc AST would have the symbol of the anonymous proc rather than being empty. There is a separate problem of default values in generic/normal procs not opening new scopes which is partially responsible for #19019. (cherry picked from commit 3e47725)
fix crash with tyBuiltInTypeClass matching itself (#24462)
fixes #24449 The standalone `seq` type is a `tyBuiltInTypeClass` with a single child of kind `tySequence`, which itself has no children. This is also the case for most other `tyBuiltInTypeClass` kinds. However this can cause a crash in sigmatch when calling `isEmptyContainer` on this child type, which expects the sequence type to have children. This check was added in #5557 to prevent empty collections like `@[]` from matching their respective typeclass, but it's not useful when matching against another typeclass (which is done here to resolve an ambiguity). So to avoid the crash, this empty container check is disabled when matching against another typeclass. (cherry picked from commit 96043bd)
Fix exitnow signature, mark as .noreturn (#24533)
Like quit, this function never returns. Also, "code" was marked as "int", even though POSIX _exit takes a C int. (cherry picked from commit f485973)
make distinct conversions addressable in VM (#24124)
fixes #24097 For `nkConv` addresses where the conversion is between 2 types that are equal between backends, treat assignments the same as assignments to the argument of the conversion. In the VM this seems to be in `genAsgn` and `genAsgnPatch`, as evidenced by the special logic for `nkDerefExpr` etc. This doesn't handle ranges after #24037 because `sameBackendType` is used and not `sameBackendTypeIgnoreRange`. This is so this is backportable without #24037 and another PR can be opened that implements it for ranges and adds tests as well. We can also merge `sameBackendTypeIgnoreRange` with `sameBackendType` since it doesn't seem like anything that uses it would be affected (only cycle checks and the VM), but then we still have to add tests. (cherry picked from commit 1fbb67f)
fix logic for dcEqIgnoreDistinct in sameType (#24197)
fixes #22523 There were 2 problems with the code in `sameType` for `dcEqIgnoreDistinct`: 1. The code that skipped `{tyDistinct, tyGenericInst}` only ran if the given types had different kinds. This is fixed by always performing this skip. 2. The code block below that checks if `tyGenericInst`s have different values still ran for `dcEqIgnoreDistinct` since it checks if the given types are generic insts, not the skipped types (and also only the 1st given type). This is fixed by only invoking this block for `dcEq`; `dcEqOrDistinctOf` (which is unused) also skips the first given type. Arguably there is another issue here that `skipGenericAlias` only ever skips 1 type. These combined fix the issue (`T` is `GenericInst(V, 1, distinct int)` and `D[0]` is `GenericInst(D, 0, distinct int)`). (cherry picked from commit b0e6d28)
fixes #18081; fixes #18079; fixes #18080; nested ref/deref'd types (#…
fixes #24472; let symbol created by template is reused in nimvm branch (
(cherry picked from commit be4d19e)
fixes #24536; fixes nightlies regression caused by nimble update (#24542
) follow up #24537 Because `nimble` is a bundled repo so it is bundled in the tarballs i.e. https://github.com/nim-lang/nightlies/blob/82421fd7053bf58dea69e9a259e6f2618c2be2e5/.github/workflows/nightlies.yml#L264 has bundled `dist/nimble`, but it only copies the data without `.git`. So in this PR, we ignore bundled nimble repo. (cherry picked from commit 70b3232)
remove zippy data from tarballs (#24551)
fixes nim-lang/nightlies#95 (cherry picked from commit 63c8840)