Commit Graph

22706 Commits

Author SHA1 Message Date
Juan M Gómez
cd806f9dbe Bumps nimble 0.20.1 (#25062) 2025-07-19 08:16:51 +02:00
ringabout
08d51e5c88 fixes #7179; Floats are not range checked (#25050)
fixes #7179


```nim
var f = 751.0
echo f.int8
```

In this case, `int8(float)` yields different numbers for different
optimization levels, since float to int conversions are undefined
behaviors. In this PR, it mitigates this problem by conversions to same
size integers before converting to the final type: i.e.
`int8(int64(float))`, which has UB problems but is better than before
2025-07-18 21:30:50 +02:00
ringabout
5b5cd7fa67 fixes inefficient codegen for field return (#24874)
fixes https://github.com/nim-lang/Nim/issues/23395
fixes https://github.com/nim-lang/Nim/issues/23395
2025-07-18 21:30:32 +02:00
ringabout
8e57a9f623 fixes #24719; improves order of destruction (#25060)
fixes #24719
2025-07-18 23:02:16 +08:00
Nikolay Nikolov
478773ffb1 NimSuggest: Fix for the inlay exception hints with generic procs (#23610)
Based on the fix, started by SirOlaf in #23414

---------

Co-authored-by: SirOlaf <>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2025-07-18 08:44:36 +02:00
ringabout
f4ebabb9b3 fixes CI failures (#25058) 2025-07-17 19:32:41 +08:00
ringabout
611b8bbf67 fixes #25007; implements setLenUninit for refc (#25022)
fixes #25007

```nim
proc setLengthSeqUninit(s: PGenericSeq, typ: PNimType, newLen: int, isTrivial: bool): PGenericSeq {.
    compilerRtl.} =
```

In this added function, only the line `zeroMem(dataPointer(result,
elemAlign, elemSize, newLen), (result.len-%newLen) *% elemSize)` is
removed from `proc setLengthSeqV2` when enlarging a sequence.

JS and VM versions simply use `setLen`.
2025-07-14 23:19:58 +02:00
lit
7e2df41850 fixes #25043: js tyUserTypeClass internal error (#25044)
- **fixes #25043: `internal error: genTypeInfo(tyUserTypeClassInst)`**
- **chore(test): for 25043**
2025-07-14 23:15:44 +02:00
Emre Şafak
9c1e3bf8fb Improve error message for keywords as parameters (#25052)
A function with an illegal parameter name like
```nim
proc myproc(type: int) =
  echo type
```
would uninformatively fail like so:
```nim
tkeywordparam.nim(1, 13) Error: expected closing ')'
```

This commit makes it return the following error:
```nim
tkeywordparam.nim(1, 13) Error: 'type' is a keyword and cannot be used as a parameter name
```

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Emre Şafak <esafak@users.noreply.github.com>
Co-authored-by: Andreas Rumpf <araq4k@proton.me>
2025-07-14 23:15:02 +02:00
Slava Vishnyakov
30d4f7791d Create Mac app bundle for GUI apps on macOS when --app:gui is used (#25042)
Fixes https://github.com/nim-lang/Nim/issues/25041

Basically it creates a "real" console-less app when --app:gui is used.
Otherwise a console window opens, see the bug.

---------

Co-authored-by: Andreas Rumpf <araq4k@proton.me>
2025-07-14 23:14:06 +02:00
Yuriy Glukhov
6ab532fd0f Fixes #25038 (#25039) 2025-07-13 07:56:20 +02:00
Esteban C Borsani
08642ffe34 revert #24896; asyncnet ssl overhaul (#25033)
revert #24896

Partially reverting #24896 in #25024 broke CI. So better revert it
completely so the CI is green. I'll investigate the issue later.
2025-07-10 15:31:56 +02:00
Juan M Gómez
370ee61f6d Updates nimble commit (#25036) 2025-07-08 15:46:13 +02:00
Yuriy Glukhov
36f8cefa85 Fixes #21235, #23602, #24978, #25018 (#25030)
Reworked closureiter transformation.

- Convolutedly nested finallies should cause no problems now.
- CurrentException state now follows nim runtime rules (pushes and pops
appropriately), and mimics normal code, which is somewhat buggy, see
#25031
- Previously state optimization (removing empty states or extra jumps)
missed some opportunities, I've reimplemented it to do everything
possible to optimize the states. At this point any extra states or jumps
should be considered a bug.

The resulting codegen (compiled binaries) is also slightly smaller.


**BUT:**
- I had to change C++ reraising logic, see expt.nim. Because with
closure iters `currentException` is not always in sync with C++'s notion
of current exception. From my tests and understanding of C++ runtime
there should not be any problems, but I'm only 99% sure :)
- I've reused `nfNoRewrite` flag in one specific case during the
transformation. This flag is also used in term-rewriting logic. Again,
99% sure, these 2 scenarios will never intersect.
2025-07-08 15:41:17 +02:00
Esteban C Borsani
fbdc9a4c19 fixes #25023; Asyncnet accept leaks socket on SSL error; Regression in devel (#25024)
Fixes #25023

Revert the acceptAddr #24896 change. SSL_accept is no longer explicitly
called.
2025-07-01 09:52:37 +02:00
Zoom
6bdb069a66 [docs]: warning for long, culong being OS-dependent (#25012)
Docs are routinely compiled on a different OS so often don't reflect
reality of CT-conditionals.

I bet there's a few of other places like this in the stdlib.
2025-06-27 10:49:02 +02:00
ringabout
7e6fa9e2d6 fixes #23564; hasCustomPragma skips alises types (#24994)
fixes #23564

perhaps handle generic aliases (tyGenericInst for aliases types) if
needed
2025-06-27 10:18:12 +02:00
ringabout
3ce38f2959 fixes #24997; {.global.} variable in recursive function (#25016)
fixes #24997

handles functions in recursive order
2025-06-27 10:17:16 +02:00
bptato
b6491e7de5 Add missing error handling in getAppFilename (#25017)
readlink can return -1, e.g. if procfs isn't mounted in a Linux chroot.
(At least that's how I found this.)
2025-06-25 23:21:56 +02:00
metagn
97a6f42b56 fix generic converter subtype match regression (#25015)
fixes #25014

`implicitConv` tries to instantiate the supertype to convert to,
previously the bindings of `m` was shared with the bindings of the
converter but now an isolated match `convMatch` holds the bindings, so
`convMatch` is now used in the call to `implicitConv` instead of `m` so
that its bindings are used when instantiating the supertype.
2025-06-25 21:42:26 +08:00
metagn
334848f3ae fix regression with enum types wrongly matching [backport:2.2] (#25010)
fixes #25009

Introduced by #24176, when matching a set type to another, if the given
set is a constructor and the element types match worse than a generic
match (which includes the case with no match), the match is always set
to a convertible match, without checking that it is at least a
convertible match. This is fixed by checking this.
2025-06-21 23:25:04 +02:00
Jacek Sieka
aba9361510 Ensure that gc interface remains non-raising (#25006)
GC_fullCollect in particular has an annoying `Exception` effect
2025-06-18 14:38:01 +02:00
ringabout
c22bfe6bc0 fixes #24996; Crash on marking destroy hook as .error (#25002)
fixes #24996

uses the lineinfos of `dest` is `ri` is not available (e.g. `=destroy`
doesn't have a second parameter)
2025-06-16 21:50:06 +02:00
metagn
8e5ed5dbb7 loosen compiler assert for ident node in dotcall matching [backport:2.2] (#25003)
fixes #25000

A failed match on `nfDotField` tries to assert that the name of the dot
field is an identifier node. I am not exactly sure how but at some point
typed generics causes an `nfDotField` call to contain a symchoice for
the field name. The compiler does not use the fact that the field name
is an identifier, so the assert is loosened to allow any identifier-like
node kind. Could also investigate why the symchoice gets created, my
guess is that typed generics detects that the match fails but still
sends it through generic prechecking and doesn't remove the
`nfDotField`, which is harmless and it might cause more trouble to work
around it.
2025-06-16 19:22:23 +02:00
metagn
7701b3c7e6 don't set sym of generic param type value to generic param sym (#24995)
fixes #23713

`linkTo` normally sets the sym of the type as well as the type of the
sym, but this is not wanted for custom pragmas as it would look up the
definition of the generic param and not the definition of its value. I
don't see a practical use for this either.
2025-06-13 00:03:02 +02:00
ringabout
151b903172 closes #24992; adds a test case (#24993)
closes #24992
2025-06-12 21:47:41 +08:00
metagn
56bb451c6d use windows latest for docs CI (#24991)
2019 is currently browned out
2025-06-11 19:45:11 +08:00
ringabout
638a8bf84d fixes #24974; SIGSEGV when raising Defect/doAssert (#24985)
fixes #24974

requires `result` initializations when encountering unreachable code
(e.g. `quit`)
2025-06-10 14:12:12 +02:00
ringabout
ffb993d5bd fixes #24981; the length of the seq changed of procGloals (#24984)
fxies #24981

`m.g.graph.procGlobals` could change because the right side of `.global`
assignment (e.g. `let a {.global.} = g(T)`) may trigger injections for
unhandled procs
2025-06-09 20:53:40 +02:00
Andreas Rumpf
d27c2159fa make 'nim nif' atomic (#24980) 2025-06-08 19:03:46 +02:00
Andreas Rumpf
4fbf538b66 nifgen: bugfix (#24979) 2025-06-06 15:36:31 +02:00
Amjad Ben Hedhili
9d0c0b89f2 [Docs] Improve scrollbars (#24971)
Follow dark/light modes.
2025-06-06 15:08:47 +02:00
Eugene Kabanov
7a53db6874 Fix FreeBSD getThreadId() should use different syscall definition for 64bit platforms. (#24977) 2025-06-05 14:30:07 +02:00
Andreas Rumpf
dd7cecdbd4 make mangled module names shorter (#24976) 2025-06-05 08:34:52 +02:00
Alfred Morgan
807840dc5b Patch 24922 (#24972)
fixed #24922 missing possix_fallocate for openbsd
2025-05-31 15:26:41 +02:00
Amjad Ben Hedhili
f80a076588 Fix docs sidebar truncated (#24970)
* Regression after #24927
2025-05-31 15:26:04 +02:00
ringabout
db5973361f bundles nimony (#24968)
follow up https://github.com/nim-lang/Nim/pull/24966
https://github.com/nim-lang/Nim/pull/21702

So it appears in the nightlies tars and can be installed by choosenim
2025-05-27 11:45:28 +02:00
Andreas Rumpf
241edaf0c0 WIP: adds NIF code generator for interop with Nimony (#24966) 2025-05-26 15:42:19 +02:00
metagn
8752392838 implement setter fallback for subscripts (#24872)
follows up #24871

For subscript assignments, if an overload of `[]=`/`{}=` is not found,
the LHS checks for overloads of `[]`/`{}` as a fallback, similar to what
field setters do since #24871. This is accomplished by just compiling
the LHS if the assignment overloads fail. This has the side effect that
the error messages are different now, instead of displaying the
overloads of `[]=`/`{}=` that did not match, it will display the ones
for `[]`/`{}` instead. This could be fixed by checking for `efLValue`
when giving the error messages for `[]`/`{}` but this is not done here.

The code for `[]` subscripts is a little different because of the
`mArrGet`/`mArrPut` overloads that always match. If the `mArrPut`
overload matches without a builtin subscript behavior for the LHS then
it calls `semAsgn` again with `mode = noOverloadedSubscript`. Before
this meant "fail to compile" but now it means "try to compile the LHS as
normal", in both cases the overloads of `[]=` are not considered again.
2025-05-23 16:19:13 +02:00
ringabout
a09da96c65 fixes #4594; disallow {.global.} uses local vars for basic expressions (#24961)
fixes #4594
2025-05-23 16:16:57 +02:00
ringabout
3c0446b082 fixes #24940; fixes #17552; lifts {.global.} in injectDestructorCalls (#24962)
fixes #24940
fixes #17552

Collects `{.global.}` (i.e. if it was changed into a hook call: `=copy`,
`=sink`) in `injectDestructorCalls` and generates it in the init
sections in cgen
2025-05-23 16:15:55 +02:00
ringabout
c3f64fb127 rework nimOrcLeakDetector (#24958)
ref https://github.com/nim-lang/Nim/issues/22273#issuecomment-2888931920
2025-05-19 21:40:35 +02:00
metagn
e855019f84 add STRING_LITERAL macro back to nimbase.h for compatibility (#24957)
refs #24956, refs #24302
2025-05-17 18:37:02 +02:00
Andreas Rumpf
1e602490e9 fixes #4851 [backport] (#24954) 2025-05-16 09:44:13 +02:00
metagn
71c5a4f72c generate let _ = to fully unpack partial tuple unpacking assignment for arc (#24948)
fixes #24947

When injectdestructors detects that a variable is a tuple unpacking temp
(i.e. it is an `skTemp`, is not a cursor, and has tuple type) it does
not generate a destructor for it and only generates sink/bit assignments
for its components. However the reason it does not generate a destructor
is that it expects it to be fully unpacked, this is true for unpackings
in for loops but not for tuple unpacking assignments which supports `_`
since #22537. Tuple unpacking definitions for `var`/`let`/`const` do not
generate `skTemp` and use the same symbol kind as the definition so they
did not have this problem.

To keep this compatible, the `_` parts of the tuple unpacking
assignments are now not ignored and unpacked into `let _ = ...`, which
generates its own destructor. Another option might be to use `skLet`
instead of `skTemp` but this might cause changes to behavior like
additional copies, I am not sure about this though.
2025-05-15 09:32:10 +02:00
ringabout
ade500b2cb adds nimPreviewCStringComparisons for cstring comparisons (#24946)
todo: We can also give a deprecation message for `ltPtr`/`lePtr`
matching for cstring in `magicsAfterOverloadResolution`

follow up https://github.com/nim-lang/Nim/pull/24942
2025-05-14 21:31:53 +02:00
Niklas Kröger
c1e6cf812f Fix extra newline from nimpretty when used with --stdin (#24951)
Using `echo` to print file contents to stdout automatically adds a
newline at the end of the file contents. When using nimpretty to auto
format files on save in some editors which replace the file contents
with the formatted ones this means that with every save/format operation
an additional newline is added to the end of the file. Using
`stdout.write` does not automatically add a newline at the end
preventing this issue.

Fixes #24950
2025-05-14 21:31:09 +02:00
c-blake
091fb5057b Maybe close https://github.com/nim-lang/Nim/issues/24932 by simply (#24945)
explaining why the result may not be so surprising. Clean-up of stray
whitespace and insert of missing "in" along for the ride.

It's just not always faster or slower than `Table`. The difference
depends upon many factors such as (at least!): A) how much (if anything
- for `int` keys it is nothing) hash-comparison before `==` comparison
saves B) how much resizing happens (which may even vary from run to run
if end users are allowed to provide scale guess input), C) how much
comparison happens at all (i.e., table density), D) how much space/size
matters - like how close to a specific deployment "available" cache size
the table is.

If we want, we could add a sentence suggesting performance fans also try
`Table`, but the kind of low-level nature of the explanation strikes me
as already along those lines.
2025-05-11 06:44:03 +02:00
ringabout
d2fee7dbab fixes broken discriminators of float types by disabling it (#24938)
```nim
type
  Case = object
    case x: float
    of 1.0:
      id: int
    else:
      ta: float
```

It segfaults with `fatal error: invalid kind for firstOrd(tyFloat)`

It was caused by https://github.com/nim-lang/Nim/pull/12591 and has
affected discriminators of float types since 1.2.x

I think no one is using discriminators of float types anyway so I simply
disable it like what was done to discriminators of string types (ref
https://github.com/nim-lang/Nim/pull/15080)


ref https://github.com/nim-lang/nimony/pull/1069
2025-05-11 06:42:27 +02:00
Juan M Gómez
8080610248 Initial implementation for nimsuggest import support (#24937)
Co-authored-by: Andreas Rumpf <araq4k@proton.me>
2025-05-11 06:41:09 +02:00