Commit Graph

6787 Commits

Author SHA1 Message Date
ringabout
7f9c470212 Merge branch 'devel' into pr_remove_macros 2025-10-30 19:15:56 +08:00
Yuriy Glukhov
7af4e3eefd Fixes #25202 (#25244) 2025-10-28 12:48:22 +01:00
ringabout
130eac2f93 fixes #25008; Compiler internal error with static overload (#25234)
fixes #25008

It seems that `semOverloadedCall` evaluates the same node twice using
`tryConstExpr` in order for `efExplain` to print all the diagnostic
output. The problem is that `tryConstExpr` has side effects, i.e., it
changes the slot index of variables after VM execution.
2025-10-28 11:47:20 +01:00
ringabout
c449c72498 fixes #25236; broken assignment hooks of union inside variant object in orc (#25238)
fixes #25236
2025-10-21 16:59:22 +02:00
ringabout
1eae14a3be fixes #25226; VM repr raises RangeDefect for long string under refc (#25230)
fixes #25226

`int16` seems to be too small for a reasonable VM program
2025-10-17 17:32:28 +02:00
ringabout
5abd21dfa5 fixes #25123; fixes #11862; Case object from compileTime proc unable to be passed as static param (#25224)
fixes #25123; fixes #11862

follow up https://github.com/nim-lang/Nim/pull/24442
ref https://github.com/nim-lang/Nim/pull/24441

> To fix this, fields from inactive branches are now detected in
semmacrosanity.annotateType (called in fixupTypeAfterEval) and marked to
prevent the codegen of their assignments. In
https://github.com/nim-lang/Nim/pull/24441 these fields were excluded
from the resulting node, but this causes issues when the node is
directly supposed to go back into the VM, for example as const values. I
don't know if this is the only case where this happens, so I wasn't sure
about how to keep that implementation working.

Object variants fields coming from inactive branches from VM are now
flagged `nfPreventCg`. We can ignore them, as done by the C backends.
2025-10-16 18:22:46 +02:00
ringabout
f009ea6c3e fixes #25208; generates a copy for opcLdConst in the assignments (#25211)
fixes #25208


```nim
type Conf = object
  val: int

const defaultConf = Conf(val: 123)
static:
  var conf: Conf
  conf = defaultConf
```

```nim
# opcLdConst is now always valid. We produce the necessary copy in the
# assignments now:
```

A `opcLdConst` is generated for `defaultConf` in `conf = defaultConf`.
According to the comment above, we need to handle the copy for
assignments of `opcLdConst`
2025-10-16 18:22:06 +02:00
lit
8f3bdb6951 fixes #25222; cast[char](i) not trunc on JS (#25223)
fixes #25222
2025-10-16 18:21:37 +02:00
ringabout
31d64b57d5 fixes #25046; Infinite loop with anonymous iterator (#25221)
fixes #25046

```nim
proc makeiter(v: string): iterator(): string =
  return iterator(): string =
    yield v

# loops
for c in makeiter("test")():
  echo "loops ", c
```
becomes

```nim
var temp = makeiter("test")
for c in temp():
  echo "loops ", c
```
for closures that might have side effects
2025-10-15 12:11:15 +02:00
ringabout
fb4a82f5cc fixes #25210; VM error when passing object field ref to proc(var T): var T (#25213)
fixes #25210
no longer transform `addr(obj.field[])` into `obj.field` to keep the
addressing needed for VM
2025-10-15 07:21:08 +02:00
ringabout
02609f1872 fixes #25205 #14873; resets importc obj with nimZeroMem in specializeResetT for refc (#25207)
fixes #25205
fixes #14873


```nim
  type
    SysLockObj {.importc: "pthread_mutex_t", pure, final,
               header: """#include <sys/types.h>
                          #include <pthread.h>""", byref.} = object
      when defined(linux) and defined(amd64):
        abi: array[40 div sizeof(clong), clong]
```

Before this PR, in refc, `resetLoc` generates field assignments for each
fields of `importc` object. But the field `abi` is not a genuine field,
which doesn't exits in the struct. We could use `zeroMem` to reset the
memory if not leave it alone
2025-10-06 21:55:31 +02:00
ringabout
cc49bf07fe fixes #21138; closure func used in the loop (#25196)
fixes #21138
2025-09-27 05:54:22 +02:00
ringabout
fed0053481 fixes #25167; fixes deref type (#25195)
fixes #25167
2025-09-26 16:12:34 +02:00
ringabout
3e2852cb1b fixes #21476; internal error: proc has no result symbol (#25192)
fixes #21476
2025-09-24 18:40:32 +02:00
ringabout
ceaa7fb4e8 fixes #23949; cannot return lent expression from conditionals like case (#25190)
fixes #23949

It can also allow  `endsInNoReturn` in branches later
2025-09-24 06:29:57 +02:00
ringabout
e958f4a3cd fixes #24760; Noncopyable base type ignored (#24777)
fixes #24760

I tried `incl` `tfHasAsgn` to nontrivial assignment, but that solution
seems to break too many things. Instead, in this PR, `passCopyToSink`
now checks nontrivial assignment
2025-09-22 10:50:57 +02:00
ringabout
51a9ada043 fixes #25173; SinglyLinkedList.remove broken / AssertionDefect (#25175)
fixes #25173
2025-09-16 17:05:09 +02:00
ringabout
cdb750c962 minor improvements of error messages of objvariants (#25040)
Because `prevFields` and `currentFields` have been already quoted by
`'`, no need to add another.

The error message was

```
The fields ''x'' and ''y'' cannot be initialized together, because they are from conflicting branches in the case object.
```
2025-09-15 15:04:35 +02:00
ringabout
a77d1cc6c1 fixes #24844; Invalid C codegen refc with generic types containing gc memory (#25160)
fixes #24844


it may not be used in other places except in `genTraverseProc`,
we have to generate a `typedesc` for this case, not a weak `typedec`
2025-09-15 15:03:22 +02:00
ringabout
91d9171278 Merge branch 'devel' into pr_remove_macros 2025-09-12 22:04:00 +08:00
ringabout
bf2395a62e disable thttpclient_ssl (#25164) 2025-09-12 14:06:29 +02:00
Ryan McConnell
88da5e8cee two small concept patches (#25076)
- slightly better typeclass logic (eg for bare `range`)
- reverse matching now substitutes potential implementation for `Self`

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2025-09-11 20:50:11 +08:00
bptato
d73f478bdc Allow assignment of nested non-closure procs to globals (#25154)
For memory-safety, this only seems problematic in case of closures, so I
just special cased that.

Fixes #25131
2025-09-11 09:22:47 +02:00
Jacek Sieka
5ba279276e sequtils: findIt (#25134)
Complements `anyIt`, `find`, etc, plugging an odd gap in the `xxxIt`
family of functions
2025-09-09 20:05:12 +02:00
ringabout
c8456eacd5 fixes #25117; requiresInit not checked for result if it has been used (#25151)
fixes #25117


errors on `requiresInit` of `result` if it is used before
initialization. Otherwise

```nim
    # prevent superfluous warnings about the same variable:
    a.init.add s.id
```

It produces a warning, and this line prevents it from being recognized
by the `requiresInit` check in `trackProc`
2025-09-09 16:22:05 +02:00
ringabout
34bb37ddda fixes #25120; don't generate hooks for NimNode (#25144)
fixes #25120
2025-09-09 16:17:22 +02:00
Tomohiro
8ea8755cc0 fixes tnewruntime_strutils.nim not to raise AssertionDefect (#25142)
Follow up to https://github.com/nim-lang/Nim/pull/25126
It changed `formatSize` outputs from some inputs, so some of existing
test code related to it need to be updated.
Sorry, I didn't know `tests/destructor/tnewruntime_strutils.nim` has
tests calls `formatSize`.
2025-09-04 06:46:50 +02:00
Tomohiro
87dc1820c0 fixes overflow defect when compiled with js backend (#25132)
Follow up to https://github.com/nim-lang/Nim/pull/25126.
This fixes overflow defect when `tests/stdlib/tstrutils.nim` was
compiled with js backend.
2025-09-01 18:29:58 +02:00
Tomohiro
065c4b443b fixes #25125 (#25126)
`strutils.formatSize` returns correct strings from large values close to
`int64.high`.
Round down `bytes` when it is converted to float.
2025-08-28 21:56:46 +02:00
ringabout
0a8f618e2b fixes #25121; [FieldDefect] with iterator-loop (#25130)
fixes #25121
2025-08-28 21:51:45 +02:00
ringabout
b527db9ddd fixes #25109; fixes #25111 transform addr(conv(x)) -> conv(addr(x)) (#25112)
follows up https://github.com/nim-lang/Nim/pull/24818
relates to https://github.com/nim-lang/Nim/issues/23923

fixes #25109
fixes #25111

transform `addr ( conv ( x ) )` -> `conv ( addr ( x ) )` so that it is
the original value that is being modified


```c
T1_ = ((unsigned long long*) ((&a_1)));
r(T1_);
```
2025-08-21 13:31:55 +02:00
ringabout
e194c7cc87 adds more functions to to dirs and files (#25083)
ref https://forum.nim-lang.org/t/13272
2025-08-01 12:34:01 +02:00
Yuriy Glukhov
161b321796 SOCKS5H support for httpclient (#25070)
- Added support for SOCKS5h (h for proxy-side DNS resolving) to
httpclient
- Deprecated `auth` arguments for `newProxy` constructors, for auth to
be embedded in the url.

Unfortunately `http://example.com` is not currently reachable from
github CI, so the tests fail there for a few days already, I'm not sure
what can be done here.
2025-07-30 00:14:41 +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
8e57a9f623 fixes #24719; improves order of destruction (#25060)
fixes #24719
2025-07-18 23:02:16 +08: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
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
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
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
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
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