Commit Graph

22873 Commits

Author SHA1 Message Date
ringabout
f47a28aa56 fixes 2026-01-11 21:39:43 +08:00
ringabout
f0ddf67c23 progress 2026-01-11 21:28:44 +08:00
ringabout
084418cdaa progress 2026-01-11 21:28:11 +08:00
ringabout
0830c82374 progress 2026-01-11 21:25:43 +08:00
ringabout
4382b7dd0e Merge branch 'devel' into pr_Quelle 2026-01-11 20:35:53 +08: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
ringabout
571fe38a8e progress 2025-12-22 20:42:47 +08:00
ringabout
66141781d8 revert 2025-12-22 20:34:06 +08: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
974c197372 fixes 2025-12-19 23:04:43 +08:00
ringabout
c30d929c92 progress 2025-12-19 22:29:40 +08:00
ringabout
435554d2ad progress 2025-12-19 20:43:20 +08:00
ringabout
548b1c6ef8 fixes #25369 (#25370)
fixes #25369
2025-12-18 18:54:03 +01:00
ringabout
0106cfdbe2 oops 2025-12-18 21:48:12 +08:00
ringabout
ddf3074e3c Merge branch 'devel' into pr_Quelle 2025-12-18 21:28:57 +08:00
ringabout
87885876e9 test transformClosureIterator 2025-12-18 21:24:24 +08: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
Ryan McConnell
8747160a9a flush stdout when prompting for password (#25348)
Saw this misbehave on Linux. It was fine in Windows when I checked, but
I figured it can't hurt.
2025-12-18 04:52:39 +01:00
Andreas Rumpf
334ac3f588 refs https://github.com/nim-lang/Nim/pull/25353 make tasyncclosestall… (#25366)
….nim less flaky
2025-12-17 20:25:51 +01:00
Jacek Sieka
1527c13273 Align treetab hash with equivalence (#25354)
In particular, hash `typ` for `nkType`, `nkNilLit` or they end up
generating collisions

<img width="989" height="612" alt="image"
src="https://github.com/user-attachments/assets/a5c6366f-1214-443e-98d5-52ce95fc3555"
/>
2025-12-15 13:19:56 +01:00
ringabout
6f3245f06a fixes documentation building failures for nightlies (#25345)
```
Error: '`' expected
```
2025-12-11 18:23:04 +01:00