Commit Graph

22877 Commits

Author SHA1 Message Date
araq
cd21306210 stdlib: make diff accessible for everybody 2026-02-05 10:44:54 +01:00
ringabout
a04f720217 fixes #25482; ICE leaking temporary 3 slotTempInt (#25483)
fixes #25482
2026-02-05 05:41:54 +01:00
ringabout
bfc2786718 fixes #24706; Warn on implicit range downsizing (#25451)
fixes #24706
2026-02-01 17:06:33 +01:00
Tomohiro
88e7adfcb7 fixes #25459; hashType returns different hash from instantiated generics with distinct types (#25471)
`hashType` proc returned the same hash value from different instanced
generics types like `D[int64]` and `D[F]`.
That caused the struct type with wrong field types.

object/tuple type size check code is generated when it is compiled with
`-d:checkAbi` option.
2026-02-01 07:01:55 +01:00
Tomohiro
abf434a336 fixes #25231; print better error messages when generics instantiation… (#25460)
… has no params
2026-01-26 14:06:35 +01:00
Gianmarco
e7809364b3 Make it so that every feature can be used in panicoverride files (#25300)
Refer to #25298
2026-01-24 16:01:21 +01:00
ringabout
81610095e6 fixes #25441; fixes #7355; deletes void args from the argument list (#25455)
fixes #25441; fixes #7355

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2026-01-24 06:08:38 +01:00
Andreas Rumpf
469e1377cd IC: progress (#25453) 2026-01-24 06:07:41 +01:00
ringabout
f44700e638 fixes #19831; add --styleCheck:warning (#25456)
fixes #19831
2026-01-23 22:50:00 +01:00
ringabout
ace09b3cab fixes #25074; Long integer literal truncated without warning (#25449)
fixes #25074

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
2026-01-23 14:52:37 +01:00
ringabout
39864980d1 fixes #25446; [FieldDefect] with static: discard cast[pointer](default(pointer)) (#25448)
fixes #25446

supports this since `static: discard cast[pointer](nil)` works
2026-01-22 09:50:25 +01:00
Andreas Rumpf
86a4ddc847 IC: remember which modules are from the NIF cache (#25443) 2026-01-22 04:26:20 +01:00
ringabout
9a23ff36bd fixes #25400; Naked raised causes wrong exception effect (#25422)
fixes #25400

infers `Exception` for Naked raised
2026-01-16 15:25:14 +01:00
Andreas Rumpf
efc3a7429b IC: progress (#25440) 2026-01-16 15:24:21 +01:00
Andreas Rumpf
cf388722db IC: massive cleanup, NIF26 support, docs about its inner workings (#25427) 2026-01-16 12:19:17 +01:00
ringabout
80b43ad6ce Remove URL from BipBuffer package entry (#25439)
ref https://github.com/MarcAzar/BipBuffer/pull/1
2026-01-16 19:12:51 +08:00
ringabout
40480fe348 fixes #25419; lift magic types to typeclasses (#25421)
fixes #25419
2026-01-14 16:25:52 +01:00
Jake Leahy
c1e381ae8d Raw switch for jsondoc (#24568)
Implements #21928

Adds a `--raw` (since thats what the original issue used, suggestions
welcome) switch which stops the jsondoc gen from rendering rst/markdown.

Implemented by making `genComment` check if it needs to return the raw
string or not. This required switching the related procs to using
`Option` to handle how `nil` values were returned before. The `nil`
returns were eventually ignored so just ignoring `none(T)` has the same
effect.

Doesn't support `runnableExamples` since jsondocs doesn't support them
either
2026-01-11 18:39:01 +08:00
Copilot
83d7d8c634 Add test case for jsffi type mismatch error (#16726) (#25429)
Issue #16726 reported an internal compiler error (`semcall.nim(229, 18)
nArg != nil`) when calling `toJs` with invalid arguments. The bug has
been fixed in the current codebase but lacked a regression test.

```nim
import std/jsffi
let a = toJs(3)
let b = a.toJs(int)  # Now produces: Error: type mismatch
                      # Previously: internal error
```

**Changes:**
- Added `tests/js/t16726.nim` to verify proper type mismatch error is
reported instead of internal compiler error

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>internal error: semcall.nim(229, 18) nArg !=
nil</issue_title>
> <issue_description>### Example
> the code below should give a clean CT error, not an internal error
> ```nim
> import std/jsffi
> let a = toJs(3)
> let b = a.toJs(int)
> ```
> 
> ### Current Output
> nim r -b:js main
> compiler/semcall.nim(229, 18) `nArg != nil` 
> 
> ### Expected Output
> proper CT error
> 
> ### Additional Information
> 1.5.1 41965880ce
> </issue_description>
> 
> <agent_instructions>adds a test case for it and verify it by `./koch
temp js -r test.nim` before committing</agent_instructions>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> <comment_new><author>@ringabout</author><body>
> related:
https://github.com/nim-lang/Nim/issues/15607</body></comment_new>
> </comments>
> 


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes nim-lang/Nim#16726

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2026-01-10 21:18:39 +08:00
Andreas Rumpf
01eedd916c IC: progress (#25420) 2026-01-09 13:10:04 +01:00
Andreas Rumpf
b3273e732d IC: progress (#25417) 2026-01-07 17:35:07 +01:00
Andreas Rumpf
251b4a23c3 IC: run nifmake automatically (#25415) 2026-01-07 13:45:26 +01:00
ringabout
89c8f0aa49 closes #23394; adds a test case (#25416)
closes #23394
2026-01-07 09:32:25 +01:00
Andreas Rumpf
d3be5e5e13 IC: need a more recent Nimony for its improved Nifler tool (#25412) 2026-01-06 00:16:19 +01:00
elijahr
780c9eeef0 fixes #25405; initialization for objects with opaque importc fields (#25406)
Objects containing `importc` fields without `completeStruct` fail to
compile when used as const/static. The C codegen generates "aggregate
initialization" which is invalid for opaque types.

Fixes #25405.

Nim code:

```nim
  type
    OpaqueInt {.importc: "_Atomic int", nodecl.} = object

    ContainsImportc = object
      normal: int
      opaque: OpaqueInt

  const c = default(ContainsImportc)
```

Resulting C code:

```c
// Invalid C - cannot aggregate-init opaque type
NIM_CONST ContainsImportc c = {((NI) 0), {}};
                                         ^^ error: illegal initializer type
```

## Solution

Fix in `ccgexprs.nim`:
1. Skip opaque importc fields when building aggregate initializers
2. Use "designated initializers" (`siNamedStruct`) when opaque fields
are present to avoid positional misalignment

```c
// Valid C:
//  - opaque field is omitted and implicitly zero-initialized by C
//  - other fields are explitly named and initialized
NIM_CONST ContainsImportc c = {.normal = ((NI) 0)};
```

This correctly handles the case where the opaque fields might be in any
order.

A field is considered "opaque importc" if:
- Has `sfImportc` flag
- Does NOT have `tfCompleteStruct` flag
- Either has `tfIncompleteStruct` OR is an object with no visible fields

The `containsOpaqueImportcField` proc recursively checks all object
fields, including nested objects and variant branches.

Anonymous unions (from variant objects) are handled by passing an empty
field name, which skips the `.fieldname = ` prefix since C anonymous
unions have no field name.

Note that initialization for structs without opaque importc fields
remains the same as before this changeset.

## Test Coverage

`tests/ccgbugs/timportc_field_init.nim` covers:
- Simple struct with one importc field
- Nested struct containing struct with importc field
- Variant object (case object) with importc field in a branch
- Array of structs with importc fields
- Tuple containing struct with importc field
- `completeStruct` importc types (still use aggregate init)
- Sandwich case (opaque field between two non-opaque fields)
- Fields with different C names (`{.importc: "c_name".}`, `{.exportc.}`)
- `{.packed.}` structs with opaque fields
- `{.union.}` types with opaque fields
- Deep nesting (3+ levels)
- Multiple opaque fields with renamed fields between them
2026-01-05 15:21:59 +01:00
ringabout
a6c7989c7f remove duplicated module imports (#25411) 2026-01-05 15:14:36 +01:00
ringabout
1a651c17b3 hello 2026 (#25410) 2026-01-05 19:36:33 +08:00
Ryan McConnell
4b615aca46 memfiles.nim resizeFile fallback logic bug (#25408)
`e` is not cleared when falling back to `ftruncate`
2026-01-03 18:08:12 +01:00
Jacek Sieka
92ad98f5d8 pegs: get rid of spurious exception effects (#25399)
Pegs raise only their own error, but the forward declaration causes an
unwanted Exception effect

* use strformat which does compile-time analysis of the format string to
avoid exceptions
* also in parsecfg
2026-01-01 01:33:35 +01:00
Esteban C Borsani
ae8a1739f8 Add parseEnum support for triple quoted string and raw string enum values (#25401) 2026-01-01 01:31:33 +01:00
Pierre Thibault
ee55ddcffd Missleading sentence about array indexing (#25367)
I added some precision. The first time I read this sentence, I was
confused. This applies to the above example, but it cannot be
generalized, since every array has its own range of valid indexes.

I think this change make the documentation clearer.

---------

Co-authored-by: Andreas Rumpf <araq4k@proton.me>
2025-12-31 13:34:18 +01:00
Jacek Sieka
61970be479 reduce imports (#25398) 2025-12-31 13:33:57 +01:00
bptato
e97b0bb541 Do not directly cast int128 to uint64 in semfold (#25396)
int128 is an array of uint32s, so while this works on little-endian
CPUs, it's completely broken on big-endian. e.g. following snippet would
fail:

	const x = 0xFFFFFFFF'u32
	const y = (x shr 1)
	echo y # amd64: 2147483647, s390x: 0

That in turn broke float printing, resulting in miscompilation of any
code that used floats.

To fix this, we now call the aptly named castToUInt64 procedure which
performs the same cast portably.

(Thanks to barracuda156 for helping debug this.)
2025-12-30 23:09:01 +01:00
Andreas Rumpf
234c73c58a refactoring for IC (#25395) 2025-12-29 13:52:22 +01:00
ringabout
f1b97caf92 fixes #19983; implements bitmasked bitshifting for all backends (#25390)
replaces https://github.com/nim-lang/Nim/pull/11555

fixes https://github.com/nim-lang/Nim/issues/19983
fixes https://github.com/nim-lang/Nim/issues/13566

- [x] JS backend

---------

Co-authored-by: Arne Döring <arne.doering@gmx.net>
2025-12-29 10:25:56 +01:00
Andreas Rumpf
22d4644d36 refactoring (#25394) 2025-12-29 10:23:46 +01:00
Andreas Rumpf
02893e2f4c IC: code generation progress (#25379) 2025-12-29 00:20:33 +01:00
Jake Leahy
91d51923b9 Fix tupleLen not skipping aliases (#25392)
This code was failing to compile with `Error: unhandled exception:
semmagic.nim(247, 5) operand.kind == tyTuple tyAlias [AssertionDefect]`
```nim
import std/typetraits

type
  Bar[T] = T 
  Foo = Bar[tuple[a: int]]

echo Foo.tupleLen
```

Fix was just making `tupleLen` skip alias types also
2025-12-28 16:45:07 +01:00
Tomohiro
c48347136f Refactoring #25302; don't store procedure's parameter types to PType.sonsImpl (#25351) 2025-12-26 21:59:38 +01:00
bptato
a061f026a8 Fix std/hashes completely ignoring endianness (#25386)
This is a problem on big-endian CPUs because you end up with nimvm
computing something different than Nim proper, so e.g. a const table
won't work.

I also took the liberty to replace a redundant implementation of load4
in murmurHash.

(Thanks to barracuda156 for helping debug this.)
2025-12-25 21:04:04 +01:00
ringabout
a41bbf6901 fixes #25387; embedsrc breaks with Line Continuation (#25388)
fixes #25387


https://stackoverflow.com/questions/30286253/how-to-escape-backslash-in-comment

- adding a whitespace or `\t` after `\` breaks the `goto` block
- `\* *\` doesn't support nesting, causing problems for using it in the
Nim comments
2025-12-25 21:02:54 +01:00
ringabout
5e53a70e62 fixes #25254; fixes #10395; Invalid pred in when swallowed (#25385)
fixes #25254
fixes #10395
2025-12-25 00:04:18 +01:00
Yuriy Glukhov
2dbdf08fc7 Fixes #25319 (#25380)
This was a regression introduced in
https://github.com/nim-lang/Nim/pull/25070.

@janAkali, @Z9RO, can you verify please?
2025-12-21 19:13:25 +01:00
elijahr
b819472e74 Fix sizeof(T) in typedesc templates called from generic type when clauses (#25374)
The `hasValuelessStatics` function in `semtypinst.nim` only checked for
`tyStatic`, missing `tyTypeDesc(tyGenericParam)`. This caused
`sizeof(T)` inside a typedesc template called from a generic type's
`when` clause to error with "'sizeof' requires '.importc' types to be
'.completeStruct'".

The fix adds a check for `tyTypeDesc` wrapping `tyGenericParam`,
recognizing it as an unresolved generic parameter that needs resolution
before evaluation.

Also documents the `completeStruct` pragma in the manual.
2025-12-21 07:37:26 +01:00
Amjad Ben Hedhili
7b12deecf4 [Docs] Remove horizontal scrolling on mobile (#25377)
* Also use more of the available width
2025-12-21 07:35:40 +01:00
Andreas Rumpf
b901a80710 IC: progress (#25368)
Co-authored-by: Jacek Sieka <arnetheduck@gmail.com>
Co-authored-by: Ryan McConnell <rammcconnell@gmail.com>
2025-12-20 11:27:46 +01:00
elijahr
1324183c38 fix #17630: Implement cycle detection for recursive concepts (#25353)
fixes #17630

## Recursive Concept Cycle Detection

- Track (conceptId, typeId) pairs during matching to detect cycles
- Changed marker from IntSet to HashSet[ConceptTypePair]
- Removed unused depthCount field
- Added recursive concepts documentation to manual
- Added tests for recursive concepts, distinct chains, and co-dependent
concepts

## Fix Flaky `tasyncclosestall` Test

The macOS ARM64 CI jobs were failing due to a flaky async socket test
(unrelated to concepts).

The test only accepted `EBADF` as a valid error code when closing a
socket with pending writes. However, depending on timing, the kernel may
report `ECONNRESET` or `EPIPE` instead:

- **EBADF**: Socket was closed locally before kernel detected remote
state
- **ECONNRESET**: Remote peer sent RST packet (detected first)  
- **EPIPE**: Socket is no longer connected (broken pipe)

All three are valid disconnection errors. The fix accepts any of them,
making the test reliable across platforms.

---------

Co-authored-by: Andreas Rumpf <araq4k@proton.me>
2025-12-20 08:56:10 +01:00
ringabout
548b1c6ef8 fixes #25369 (#25370)
fixes #25369
2025-12-18 18:54:03 +01:00
Andreas Rumpf
9bb57a64ba IC: keep package information (#25350) 2025-12-18 09:34:39 +01:00
Andreas Rumpf
80cf9a8ce8 system.nim: memory must be part of system so that its compilerprocs c… (#25365)
…an work for IC
2025-12-18 04:53:09 +01:00