Commit Graph

8692 Commits

Author SHA1 Message Date
ringabout
93c66e7f13 adds systemRangeConversion 2026-02-05 20:13:52 +08:00
ringabout
c0085e6b03 Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-05 16:58:30 +08:00
ringabout
d93595d352 Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-05 16:58:20 +08:00
ringabout
4256e159c4 check sfSystemModule 2026-02-05 16:44:59 +08:00
ringabout
a9bd087835 progress 2026-02-03 21:13:41 +08:00
ringabout
eb81ea5721 allows int -> Natural or Positive 2026-02-03 18:54:38 +08:00
ringabout
b6e97d2a5b enable --warning:ImplicitRangeConversion 2026-02-03 16:29:04 +08: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
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
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
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
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
1a651c17b3 hello 2026 (#25410) 2026-01-05 19:36:33 +08: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
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
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
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
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
Andreas Rumpf
cbb2fe0a63 IC: progress (#25344)
Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2025-12-11 18:22:38 +01:00
metagn
44d2472b08 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.
2025-12-09 09:45:37 +01:00
ringabout
ed8e5a7754 fixes #25338; Switch default mangling back to cpp (#25343)
fixes #25338
2025-12-09 07:16:08 +01:00
Andreas Rumpf
fa4d79f519 IC: progress (#25339) 2025-12-07 13:07:44 +01:00
elijahr
099ee1ce4a Fixes #25341; Invalid C code for lifecycle hooks for distinct types based on generics (#25342) 2025-12-07 12:59:42 +01:00