Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler segfaults on lambda sugar (nim 1.6.16) #22820

Open
mynameisdaniil opened this issue Oct 12, 2023 · 3 comments
Open

Compiler segfaults on lambda sugar (nim 1.6.16) #22820

mynameisdaniil opened this issue Oct 12, 2023 · 3 comments

Comments

@mynameisdaniil
Copy link

mynameisdaniil commented Oct 12, 2023

Description

I've been trying to use some functional style programming to access type lifted into Option.

import sugar

p.localNode.address.map((a) => $a.port).get("0")
# where
address: Option[Address]

type Address* = object
  ip*: ValidIpAddress
  port*: Port

If you re-arrange this code differently i.e. move map((a) => $a.port).get("0") part into separate proc this issue goes away. Which makes me think it is somehow connected to type inference.

To replicate this:

git clone https://github.com/status-im/nimbus-eth1.git
cd nimbus-eth1
git checkout compiler-segfault
# Optional, select version of nim compiler to compile with
# This one for 1.6.16
export NIM_COMMIT=3c9b68dc157804885b14a1984efc25e8b7cc861d

source env.sh
make fluffy -j4

Nim Version

Nim Compiler Version 1.6.16 [MacOSX: arm64]
Compiled at 2023-10-12
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 3c9b68d
active boot switches: -d:release

Current Output

SIGSEGV: Illegal storage access. (Attempt to read from nil?)
<...>/nimbus-eth1/vendor/nimbus-build-system/scripts/env.sh: line 85: 81689 Segmentation fault: 11  "$@"

Expected Output

No response

Possible Solution

No response

Additional Information

No response

@juancarlospaco
Copy link
Collaborator

Can you provide a reduced assertive source code repro sample ?.

@mynameisdaniil
Copy link
Author

@juancarlospaco Sorry, I was trying to make minimal working example, but was unable to. But I can assist you with the codebase where this bug is reproducible.

@tersec
Copy link
Contributor

tersec commented May 27, 2024

Repro:

protocol.nim:

{.push raises: [].}

import
  "."/[node]

import
  std/[options, sugar]

var closestNodes: seq[Node]
for cn in closestNodes:
  discard cn.address.map(a => a.port)

node.nim

import std/options

type
  Address* = object
    port*: int

  Node* = ref object
    address*: Option[Address]

On 1.6 (any version I tried, up to current version-1-6 from branch):

SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)

2.0 and devel don't seem to have this problem.

Example Nim versions:

SIGSEGV upon compilation:

Nim Compiler Version 1.6.21 [Linux: amd64]
Compiled at 2024-05-27
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 38640664088251bbc88917b4bacfd86ec53014b8
active boot switches: -d:release

No SIGSEGV:

Nim Compiler Version 2.0.5 [Linux: amd64]
Compiled at 2024-05-27
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: ab053fd56a6517531441cdbf0be5536189831c9c
active boot switches: -d:release
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-05-27
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: daad06bd07ff11cc2b0c74b604ff82899e923d59
active boot switches: -d:release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants