From ed8e5a7754813e066d47770ea58ca5fc488f6a1b Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:16:08 +0800 Subject: [PATCH 1/4] fixes #25338; Switch default mangling back to cpp (#25343) fixes #25338 --- changelog.md | 2 +- compiler/options.nim | 2 +- doc/advopt.txt | 2 +- tests/codegen/titaniummangle.nim | 2 +- tests/codegen/titaniummangle_nim.nim | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index bf7d343d1b..b0bd39ddb7 100644 --- a/changelog.md +++ b/changelog.md @@ -27,7 +27,7 @@ errors. - With `-d:nimPreviewDuplicateModuleError`, importing two modules that share the same name becomes a compile-time error. This includes importing the same module more than once. Use `import foo as foo1` (or other aliases) to avoid collisions. -- Adds the switch `--mangle:nim|cpp`, which selects `nim` or `cpp` style name mangling when used with `debuginfo` on, defaults to `nim`. The default is changed from `cpp` to `nim`. +- Adds the switch `--mangle:nim|cpp`, which selects `nim` or `cpp` style name mangling when used with `debuginfo` on, defaults to `cpp`. ## Standard library additions and changes diff --git a/compiler/options.nim b/compiler/options.nim index 80b6cd729c..479148d07c 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -512,7 +512,7 @@ const optHints, optStackTrace, optLineTrace, # consider adding `optStackTraceMsgs` optTrMacros, optStyleCheck, optCursorInference} DefaultGlobalOptions* = {optThreadAnalysis, optExcessiveStackTrace, - optJsBigInt64} + optJsBigInt64, optItaniumMangle} proc getSrcTimestamp(): DateTime = try: diff --git a/doc/advopt.txt b/doc/advopt.txt index 85da350a80..4f0c664acf 100644 --- a/doc/advopt.txt +++ b/doc/advopt.txt @@ -91,7 +91,7 @@ Advanced options: --os:SYMBOL set the target operating system (cross-compilation) --cpu:SYMBOL set the target processor (cross-compilation) --debuginfo:on|off enables debug information - --mangle:nim|cpp selects `nim` or `cpp` style name mangling, defaults to `nim` + --mangle:nim|cpp selects `nim` or `cpp` style name mangling, defaults to `cpp` -t, --passC:OPTION pass an option to the C compiler -l, --passL:OPTION pass an option to the linker --cc:SYMBOL specify the C compiler diff --git a/tests/codegen/titaniummangle.nim b/tests/codegen/titaniummangle.nim index ccca9ce2f0..7623559a35 100644 --- a/tests/codegen/titaniummangle.nim +++ b/tests/codegen/titaniummangle.nim @@ -1,6 +1,6 @@ discard """ targets: "c cpp" - matrix: "--debugger:native --mangle:cpp" + matrix: "--debugger:native --mangle:cpp; --debugger:native" ccodecheck: "'_ZN14titaniummangle8testFuncE'" ccodecheck: "'_ZN14titaniummangle8testFuncE6stringN14titaniummangle3FooE'" ccodecheck: "'_ZN14titaniummangle8testFuncE3int7varargsI6stringE'" diff --git a/tests/codegen/titaniummangle_nim.nim b/tests/codegen/titaniummangle_nim.nim index 72afdaf8a6..204d6ac063 100644 --- a/tests/codegen/titaniummangle_nim.nim +++ b/tests/codegen/titaniummangle_nim.nim @@ -1,6 +1,6 @@ discard """ targets: "c" - matrix: "--debugger:native --mangle:nim; --debugger:native" + matrix: "--debugger:native --mangle:nim" ccodecheck: "'testFunc__titaniummangle95nim_u1316'" ccodecheck: "'testFunc__titaniummangle95nim_u156'" ccodecheck: "'testFunc__titaniummangle95nim_u1305'" From e1f2329e55125e3fb500f509117c2e0a3f3efd2f Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:16:23 +0800 Subject: [PATCH 2/4] fixes #25329; Wrong type for second parameter of procedures "inc", "dec", "succ" and "pred" (#25337) fixes #25329 --- changelog.md | 2 ++ lib/system/arithmetics.nim | 8 ++++---- tests/varres/tprevent_forloopvar_mutations.nim | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index b0bd39ddb7..4b320399c2 100644 --- a/changelog.md +++ b/changelog.md @@ -29,6 +29,8 @@ errors. - Adds the switch `--mangle:nim|cpp`, which selects `nim` or `cpp` style name mangling when used with `debuginfo` on, defaults to `cpp`. +- The second parameter of `succ`, `pred`, `inc`, and `dec` in `system` now accepts `SomeInteger` (previously `Ordinal`). + ## Standard library additions and changes [//]: # "Additions:" diff --git a/lib/system/arithmetics.nim b/lib/system/arithmetics.nim index 9d533ce7a8..71e6b69d4c 100644 --- a/lib/system/arithmetics.nim +++ b/lib/system/arithmetics.nim @@ -1,6 +1,6 @@ {.push stack_trace: off.} -proc succ*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Succ", noSideEffect.} = +proc succ*[T: Ordinal, V: SomeInteger](x: T, y: V = 1): T {.magic: "Succ", noSideEffect.} = ## Returns the `y`-th successor (default: 1) of the value `x`. ## ## If such a value does not exist, `OverflowDefect` is raised @@ -9,7 +9,7 @@ proc succ*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Succ", noSideEffect.} = assert succ(5) == 6 assert succ(5, 3) == 8 -proc pred*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Pred", noSideEffect.} = +proc pred*[T: Ordinal, V: SomeInteger](x: T, y: V = 1): T {.magic: "Pred", noSideEffect.} = ## Returns the `y`-th predecessor (default: 1) of the value `x`. ## ## If such a value does not exist, `OverflowDefect` is raised @@ -18,7 +18,7 @@ proc pred*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Pred", noSideEffect.} = assert pred(5) == 4 assert pred(5, 3) == 2 -proc inc*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Inc", noSideEffect.} = +proc inc*[T: Ordinal, V: SomeInteger](x: var T, y: V = 1) {.magic: "Inc", noSideEffect.} = ## Increments the ordinal `x` by `y`. ## ## If such a value does not exist, `OverflowDefect` is raised or a compile @@ -30,7 +30,7 @@ proc inc*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Inc", noSideEffect.} = inc(i, 3) assert i == 6 -proc dec*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Dec", noSideEffect.} = +proc dec*[T: Ordinal, V: SomeInteger](x: var T, y: V = 1) {.magic: "Dec", noSideEffect.} = ## Decrements the ordinal `x` by `y`. ## ## If such a value does not exist, `OverflowDefect` is raised or a compile diff --git a/tests/varres/tprevent_forloopvar_mutations.nim b/tests/varres/tprevent_forloopvar_mutations.nim index c9aeb94d8f..aff3847232 100644 --- a/tests/varres/tprevent_forloopvar_mutations.nim +++ b/tests/varres/tprevent_forloopvar_mutations.nim @@ -2,7 +2,7 @@ discard """ errormsg: "type mismatch: got " nimout: '''tprevent_forloopvar_mutations.nim(16, 3) Error: type mismatch: got but expected one of: -proc inc[T, V: Ordinal](x: var T; y: V = 1) +proc inc[T: Ordinal; V: SomeInteger](x: var T; y: V = 1) first type mismatch at position: 1 required type for x: var T: Ordinal but expression 'i' is immutable, not 'var' From 44d2472b083b5f711b01505fc3199683ef8b3426 Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 9 Dec 2025 11:45:37 +0300 Subject: [PATCH 3/4] consider generic param type as typedesc in tuple type expressions (#25316) fixes #25312 Tuple expressions `(a, b, c)` can be either types or values depending on if their elements are typedescs or values, this is checked by checking if the type of the element is `tyTypeDesc`. However when an `skGenericParam` symbol is semchecked by `semSym` it is given its own `tyGenericParam` type rather than a `tyTypeDesc` type, this seems to be necessary for signatures to allow wildcard generic params passed to static constrained generic params (tested in #25315). The reason `semSym` is called is that `semGeneric` for generic invocations calls `matches` which sems its arguments like normal expressions. To deal with this, an expression of type `tyGenericParam` and with a `skGenericParam` sym is allowed as a type in the tuple expression. A problem is that this might consider a value with a wildcard generic param type as a type. But this is a very niche problem, and I'm not sure how to check for this. `skGenericParam` symbols stay as idents when semchecked so it can't be checked that the node is an `skGenericParam` symbol. It could be checked that it's an ident but I don't know how robust this is. And maybe there is another way to refer to a wildcard generic param type instead of just its symbol, i.e. another kind of node. This also makes #5647 finally work but a test case for that can be added after. --- compiler/semexprs.nim | 11 ++++++-- tests/tuples/tgenericparamtypetuple.nim | 34 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 tests/tuples/tgenericparamtypetuple.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 31b3770459..8384e514b0 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -3054,6 +3054,13 @@ proc semExport(c: PContext, n: PNode): PNode = s = nextOverloadIter(o, c, a) +proc isTypeTupleField(n: PNode): bool {.inline.} = + result = n.typ.kind == tyTypeDesc or + (n.typ.kind == tyGenericParam and n.typ.sym.kind == skGenericParam) + # `skGenericParam` stays as `tyGenericParam` type rather than being wrapped in `tyTypeDesc` + # would check if `n` itself is an `skGenericParam` symbol, but these symbols semcheck to an ident + # maybe check if `n` is an ident to ensure this is not a value with the generic param type? + proc semTupleConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType = nil): PNode = result = semTuplePositionsConstr(c, n, flags, expectedType) if result.typ.kind == tyFromExpr: @@ -3064,10 +3071,10 @@ proc semTupleConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PTyp var isTupleType: bool = false if tupexp.len > 0: # don't interpret () as type internalAssert c.config, tupexp.kind == nkTupleConstr - isTupleType = tupexp[0].typ.kind == tyTypeDesc + isTupleType = isTypeTupleField(tupexp[0]) # check if either everything or nothing is tyTypeDesc for i in 1.. Date: Thu, 11 Dec 2025 21:36:27 +0800 Subject: [PATCH 4/4] fixes markdown tests (#25347) --- testament/important_packages.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testament/important_packages.nim b/testament/important_packages.nim index c0b4b86cf0..7514509e46 100644 --- a/testament/important_packages.nim +++ b/testament/important_packages.nim @@ -93,7 +93,7 @@ pkg "lockfreequeues" pkg "loopfusion" pkg "macroutils" pkg "manu" -pkg "markdown" +pkg "markdown", "nim c -r tests/testmarkdown.nim" pkg "measuremancer", "nimble testDeps; nimble -y test" pkg "memo" pkg "metrics"