Commit Graph

21987 Commits

Author SHA1 Message Date
lit
b838d3ece1 doc(format): ospaths2,strutils: followup #23560 (#23629)
followup #23560
2024-05-20 19:18:28 +08:00
lit
b3b26b2e56 doc(format): system.nim: doc of hostCPU for loongarch64 (#23621)
In doc, `loongarch64` used to be written as `'"loongarch64"'`

since it's [supported](https://github.com/nim-lang/Nim/pull/19223)
2024-05-17 20:35:02 +08:00
ringabout
4e7c70fd7d provides a $ function for Path (#23617)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-05-17 14:22:53 +02:00
ringabout
b87732b5f1 fixes #16671; openarray conversion for object construction (#23618)
fixes #16671

related to https://github.com/nim-lang/Nim/pull/18911
2024-05-16 23:27:08 +02:00
PHO
0ba932132e Support NetBSD/aarch64 (#23616)
I could trivially port Nim to NetBSD/aarch64 because it already
supported NetBSD and aarch64. I only needed to generate `c_code` for
this combination.
2024-05-16 23:22:49 +02:00
ringabout
2c8551556e fixes lifting subtype calling parent's hooks (#23612)
ref https://forum.nim-lang.org/t/11587

Tested with `gcc version 14.0.1 20240412` locally
2024-05-15 20:52:18 +02:00
ringabout
c08356865d closes #15778; adds a test case (#23613)
closes #15778
2024-05-15 20:51:41 +02:00
ringabout
b42f1ca8a4 fixes deprecation messages and adds missing commas (#23609) 2024-05-14 23:01:54 +02:00
ringabout
0fcd838fd9 fixes openarray views default values in JS (#23607) 2024-05-14 18:07:47 +02:00
ringabout
04f3df4c87 fixes testament matrix doesn't work with other backends which left many JS tests untested (#23592)
Targets are not changes, which means the C binary is actually tested for
JS backend
2024-05-14 11:33:08 +02:00
metagn
81a937ce1f ignore modules when looking up symbol with expected type (#23597)
fixes #23596

When importing a module and declaring an overloadable symbol with the
same name as the module in the same scope, the module symbol can take
over and make the declared overload impossible to access. Previously
enum overloading had a quirk that bypassed this in a context where a
specific enum type was expected but this was removed in #23588. Now this
is bypassed in every place where a specific type is expected since
module symbols don't have a type and so wouldn't be compatible anyway.

But the issue still exists in places where no type is expected like `let
x = modulename`. I don't see a way of fixing this without nerfing module
symbols to the point where they're not accessible by default, which
might break some macro code.
2024-05-14 11:26:33 +02:00
ringabout
c91b33aaba re-enable tests (#23591) 2024-05-10 16:17:58 +02:00
Juan M Gómez
fcc43fa9c8 Allow to exportc params. (#23396)
By allowing `exportc` in params one can decide the name of a param or to
dont mangle them.
2024-05-10 10:35:23 +02:00
Mads Hougesen
ee59597cd4 Add directory input support to nimpretty (#23590)
Feel free to close if this an unwanted addition :)
2024-05-10 10:33:03 +02:00
ringabout
42486e1b2f unordered enum for better interoperability with C (#23585)
ref https://forum.nim-lang.org/t/11564
```nim
block: # unordered enum
  block:
    type
      unordered_enum = enum
        a = 1
        b = 0

    doAssert (ord(a), ord(b)) == (1, 0)

  block:
    type
      unordered_enum = enum
        a = 1
        b = 0
        c

    doAssert (ord(a), ord(b), ord(c)) == (1, 0, 2)

  block:
    type
      unordered_enum = enum
        a = 100
        b
        c = 50
        d

    doAssert (ord(a), ord(b), ord(c), ord(d)) == (100, 101, 50, 51)

  block:
    type
      unordered_enum = enum
        a = 7
        b = 6
        c = 5
        d

    doAssert (ord(a), ord(b), ord(c), ord(d)) == (7, 6, 5, 8)
```
2024-05-10 10:32:07 +02:00
metagn
c101490a0c remove bad type inference behavior for enum identifiers (#23588)
refs
https://github.com/nim-lang/Nim/issues/23586#issuecomment-2102113750

In #20091 a bad kind of type inference was mistakenly left in where if
an identifier `abc` had an expected type of an enum type `Enum`, and
`Enum` had a member called `abc`, the identifier would change to be that
enum member. This causes bugs where a local symbol can have the same
name as an enum member but have a different value. I had assumed this
behavior was removed since but it wasn't, and CI seems to pass having it
removed.

A separate PR needs to be made for the 2.0 branch because these lines
were moved around during a refactoring in #23123 which is not in 2.0.
2024-05-10 10:30:57 +02:00
ringabout
1eb9aac2f7 adds Nim-related mimetypes back (#23589)
ref https://github.com/nim-lang/Nim/pull/23226
2024-05-10 10:30:24 +02:00
lit
2e3777d6f3 Improve strutils.rsplit doc, proc and iterator have oppose result order. (#23570)
[`rsplit
iterator`](https://nim-lang.org/docs/strutils.html#rsplit.i,string,char,int)
yields substring in reversed order,

while [`proc
rsplit`](https://nim-lang.org/docs/strutils.html#rsplit%2Cstring%2Cchar%2Cint)'s
order is not reversed, but its doc only declare ```
The same as the rsplit iterator, but is a func that returns a sequence
of substrings.
```
2024-05-10 10:30:06 +02:00
ringabout
2995a0318b fixes #23552; Invalid codegen when trying to mannualy delete distinct seq (#23558)
fixes #23552
2024-05-08 14:54:03 -06:00
Antonis Geralis
63398b11f5 Add a note about the sideeffect pragma (#23543) 2024-05-08 14:53:29 -06:00
Angel Ezquerra
d8e1504ed1 Add Complex version of almostEqual function (#23549)
This adds a version of `almostEqual` (which was already available for
floats) thata works with `Complex[SomeFloat]`.

Proof that this is needed is that the first thing that the complex.nim
runnable examples block did before this commit was define (an
incomplete) `almostEqual` function that worked with complex values.
2024-05-08 14:53:01 -06:00
metagn
09bd9d0b19 fix semFinishOperands for bracket expressions [backport:2.0] (#23571)
fixes #23568, fixes #23310

In #23091 `semFinishOperands` was changed to not be called for `mArrGet`
and `mArrPut`, presumably in preparation for #23188 (not sure why it was
needed in #23091, maybe they got mixed together), since the compiler
handles these later and needs the first argument to not be completely
"typed" since brackets can serve as explicit generic instantiations in
which case the first argument would have to be an unresolved generic
proc (not accepted by `finishOperand`).

In this PR we just make it so `mArrGet` and `mArrPut` specifically skip
calling `finishOperand` on the first argument. This way the generic
arguments in the explicit instantiation get typed, but not the
unresolved generic proc.
2024-05-08 09:35:26 -06:00
Marius Andra
e6f66e4d13 fixes 12381, HttpClient socket handle leak (#23575)
## Bug

Fixes https://github.com/nim-lang/Nim/issues/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.
2024-05-08 09:33:43 -06:00
ringabout
e662043fd1 rework wasMoved, move on the JS backend (#23577)
`reset`, `wasMoved` and `move` doesn't support primitive types, which
generate `null` for these types. It is now produce `x = default(...)` in
the backend. Ideally it should be done by ast2ir in the future
2024-05-08 09:11:46 -06:00
ringabout
1ad4e80060 fixes #22409; don't check style for enumFieldSymChoice in the function (#23580)
fixes #22409
2024-05-08 09:10:48 -06:00
lit
6cc783f7f3 fixes #23442, fix for FileId under Windows (#23444)
See according issue:

Details:
<https://github.com/nim-lang/Nim/issues/23442#issuecomment-2021763669>

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-05-08 09:07:32 -06:00
Juan M Gómez
3b4078a7f8 Skips generic owner when mangling instances (#23563) 2024-05-07 15:03:53 -06:00
ringabout
78d70d5fdf bring telebot back (#23578)
Reverts nim-lang/Nim#23566
ref
afe4ad877e
2024-05-07 19:13:41 +08:00
ringabout
1ef4d04a1e fixes CI failure (#23566) 2024-05-04 09:41:14 +08:00
ringabout
36bf3fa47b fixes #23556; typeinfo.extendSeq generates random values in ORC (#23557)
fixes #23556

It should somehow handle default fields in the future
2024-05-03 22:29:56 +08:00
lit
d772186b2d Update unicode.nim: cmpRunesIgnoreCase: fix doc format (#23560)
Its doc used to render wrongly where `>` is considered as quote block:


![image](https://github.com/nim-lang/Nim/assets/97860435/4aeda257-3231-42a5-9dd9-0052950a160e)
2024-05-02 16:07:19 +08:00
ringabout
185e06c923 fixes #23419; internal error with void in generic array instantiation (#23550)
fixes #23419

`void` is only supported as fields of objects/tuples. It shouldn't allow
void in the array.

I didn't merge it with taField because that flag is also used for
tyLent, which is allowed in the fields of other types.
2024-05-01 09:02:43 +02:00
ringabout
d09c3c0f58 fixes #23321; Error: internal error: openArrayLoc: ref array[0..0, int] (#23548)
fixes #23321

In the function `mapType`, ptrs (tyPtr, tyVar, tyLent, tyRef)
are mapped into ctPtrToArray, the dereference of which is skipped
in the `genref`. We need to skip these ptrs in the function
`genOpenArraySlice`.
2024-04-29 16:58:33 +02:00
yojiyama7
47594eb909 fix typo: "As can been seen" to "As can be seen" (#23544) 2024-04-28 12:36:51 +02:00
ringabout
f682dabf71 fixes #23531; fixes invalid meta type accepted in the object fields (#23532)
fixes #23531
fixes #19546
fixes #6982
2024-04-26 16:05:03 +02:00
ringabout
0b0f185bd1 fixes #23536; Stack trace with wrong line number when the proc called inside for loop (#23540)
fixes #23536
2024-04-26 16:02:02 +02:00
ringabout
407c0cb64a fixes #23522; fixes pre-existing wrong type for iter in liftIterSym (#23538)
fixes #23522
2024-04-26 19:00:25 +08:00
ringabout
4601bb0255 fixes #23525; an 'emit' pragma cannot be pushed (#23537)
fixes #23525
2024-04-24 18:43:29 +02:00
ringabout
a5c1a6f042 adds another fix for concept in JS (#23535)
ref https://github.com/nim-lang/Nim/issues/9550
2024-04-24 17:33:58 +02:00
ringabout
cd3cf3a20e fixes #23524; global variables cannot be analysed when injecting move (#23529)
fixes #23524

```nim
proc isAnalysableFieldAccess*(orig: PNode; owner: PSym): bool =
  ...
  result = n.kind == nkSym and n.sym.owner == owner and
    {sfGlobal, sfThread, sfCursor} * n.sym.flags == {} and
    (n.sym.kind != skParam or isSinkParam(n.sym))
```
In `isAnalysableFieldAccess`, globals, cursors are already rejected
2024-04-24 12:47:05 +02:00
Nikolay Nikolov
7e3bac9235 * fix for the debug line info code generation (#23488)
Previously, in certain cases, the compiler would generate debug info for
the correct line number, but for the wrong .nim source file.
2024-04-22 13:55:14 +02:00
Andreas Rumpf
6cb2dca41d updated compiler DFA docs (#23527) 2024-04-22 13:04:30 +02:00
bptato
30cf570af9 Fix std/base64.decode out of bounds read (#23526)
inputLen may end up as 0 in the loop if the input string only includes
trailing characters. e.g. without the patch, decode(" ") would panic.
2024-04-22 09:44:33 +02:00
José Paulo
60af04635f fix #23518 - <expr> is crashes nimsuggest (#23523)
This solution should resolve the nimsuggest crash issue. However,
perhaps the problem is in the parser?

fix #23518
2024-04-21 21:30:12 +02:00
ringabout
1185b93c6d fixes commit hashes (#23520) 2024-04-19 13:47:24 +08:00
heterodoxic
318b2cfc5e allow having {.noinit.} on a complex type avoid memsets to 0 for its … (#23388)
…instantiations (C/C++ backend)

AFAIK, #22802 expanded `noinit`'s utility by allowing the pragma to be
attached to types (thanks @jmgomez !).
I suggest broadening the scope a bit further: try to avoid `nimZeroMem`s
on a type level beyond imported C/C++ types[^1], saving us from
annotating the type instantiations with `noinit`.

If this change is deemed acceptable, I will also adjust the docs, of
course.

Adding tests for this change seems a bit problematic, as the effect of
this type annotation will be to work with uninitialized memory, which
*might* match 0 patterns.

[^1]: "complex value types" as already defined here:
94c5996877/compiler/cgen.nim (L470-L471)
2024-04-18 21:58:01 +02:00
HexSegfaultCat
558bbb7426 Fix duplicated member declarations in structs for C++ backend (#23512)
When forward declaration is used with pragmas `virtual` or `member`, the
declaration in struct is added twice. It happens because of missing
check for `sfWasForwarded` pragma.

Current compiler generates the following C++ code:
```cpp
struct tyObject_Foo__fFO9b6HU7kRnKB9aJA1RApKw {
N_LIB_PRIVATE N_NOCONV(void, abc)(NI x_p1);
N_LIB_PRIVATE N_NOCONV(virtual void, def)(NI y_p1);
N_LIB_PRIVATE N_NOCONV(void, abc)(NI x_p1);
N_LIB_PRIVATE N_NOCONV(virtual void, def)(NI y_p1);
};
```
2024-04-18 21:57:06 +02:00
ringabout
229c125d2f workaround #23435; real fix pending #23279 (#23436)
workaround #23435

related to https://github.com/nim-lang/Nim/issues/22852

see also #23279
2024-04-18 21:55:26 +02:00
ringabout
2a7ddcab2d bundle atlas with sat (#23375)
pending https://github.com/nim-lang/atlas/pull/119
pending AtlasStableCommit updates
2024-04-18 21:54:20 +02:00
ringabout
f12683873f remove php code from jsgen (#23502)
follow up https://github.com/nim-lang/Nim/pull/7606
https://github.com/nim-lang/Nim/pull/13466
2024-04-18 21:53:27 +02:00