Commit Graph

6765 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
ringabout
6c2f78a19f rework tags (#24944)
recent ctags changes: https://github.com/nim-lang/Nim/pull/24317
ref https://forum.nim-lang.org/t/12879
2025-05-11 06:40:46 +02:00
ringabout
42a4adb4a5 fixes #24941; missing < (less than), cmp for cstring (#24942)
fixes #24941

now `cmp` can select the correct version of cstring comparsions
2025-05-10 08:26:21 +02:00
ringabout
433b725cbb fixes #21975; Pragma block disabling warning has effect beyond block (#24934)
fixes  #21975
2025-05-06 09:46:18 +02:00
ringabout
98ec87d65e fixes #23355; pop optionStack when exiting scopes (#24926)
fixes #23355
2025-05-04 03:29:59 +02:00
ringabout
f56568d851 fixes address of sink parameters (#24924)
In `semExprWithType`: `if result.typ.kind in {tyVar, tyLent}: result =
newDeref(result)` derefed `var`/`lent`. Since it is not done for `sink`,
we need to skip `tySink` in the corresponding procs
2025-05-01 07:49:46 +02:00
ringabout
0506d5b973 don't warn/error symbols in semGenericStmt/templates (#24907)
fixes #24905
fixes #24903
fixes https://github.com/nim-lang/Nim/issues/11805
fixes https://github.com/nim-lang/Nim/issues/15650

In the first phase of generic checking, we cannot warn/error symbols
because they can belong a false branch of `when` or there is a
`push/pop` options using open symbols. So we cannot decide whether to
warn/error or not
2025-04-29 11:08:10 +02:00
Esteban C Borsani
8518cf079f asyncnet ssl overhaul (#24896)
Fixes #24895

- Remove all  bio handling
- Remove all `sendPendingSslData` which only seems to make things work
by chance
- Wrap the client socket on `acceptAddr` (std/net does this)
- Do the SSL handshake on accept (std/net does this)

The only concern is if addWrite/addRead works well on Windows.
2025-04-29 11:07:01 +02:00