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

Julia 1.9 RC1 segfaults with this code #49203

Closed
prittjam opened this issue Mar 31, 2023 · 5 comments · Fixed by #49269
Closed

Julia 1.9 RC1 segfaults with this code #49203

prittjam opened this issue Mar 31, 2023 · 5 comments · Fixed by #49269
Milestone

Comments

@prittjam
Copy link

prittjam commented Mar 31, 2023

Julia Version 1.9.0-rc1
Commit 3b2e0d8 (2023-03-07 07:51 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 12 × Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
Threads: 8 on 12 virtual cores
Environment:
LD_LIBRARY_PATH =
JULIA_NUM_THREADS = 8

using StaticArrays

abstract type VgtkNum end

struct VgtkInt{T <: Integer} <: VgtkNum
    int::T
end

VgtkInt(::Val{N}) where N <: Integer = VgtkInt(N)
VgtkInt(x::AbstractFloat) = VgtkInt(trunc(Int, x))

struct VgtkFloat{T <: AbstractFloat} <: VgtkNum
   float::T
end

VgtkFloat(x::Integer) = VgtkFloat(float(x))

value(x::VgtkInt) = x.int
value(x::VgtkFloat) = x.float 

Base.:(+)(a::VgtkInt, b::VgtkInt) = VgtkInt(a.int + b.int)
Base.:(+)(a::VgtkFloat, b::VgtkFloat) = VgtkFloat(a.float + b.float)
Base.:(+)(a::VgtkNum, b::VgtkNum) = VgtkFloat(value(a) + value(b))

neltype(x) = neltype(typeof(x))
neltype(::Type{T}) where T <: AbstractArray = neltype(eltype(T))
neltype(::Type{T}) where T = T


const PointRpN{N, T <: AbstractFloat} = SVector{value(VgtkInt(Val(N))+VgtkInt(1)), T} 
const PointRp2{T <: AbstractFloat} = PointRpN{2, T}
const LineRp2{T <:  AbstractFloat} = SVector{3, T}
@giordano giordano added this to the 1.9 milestone Mar 31, 2023
@giordano giordano added the kind:regression Regression in behavior compared to a previous version label Mar 31, 2023
@KristofferC
Copy link
Sponsor Member

KristofferC commented Mar 31, 2023

Bisected to 7ad0e3d. cc @JeffBezanson

@jakobnissen
Copy link
Contributor

jakobnissen commented Mar 31, 2023

Reduced example with no deps:

struct A{T} end
const B{N} = A(Val(N))

@gbaraldi
Copy link
Member

Just for reference, on 1.8 this errors with

julia> struct A{T} end

julia> const B{N} = A(Val(N))
ERROR: UndefVarError: x not defined
Stacktrace:
 [1] Val{N}()
   @ Base ./essentials.jl:712
 [2] Val(x::TypeVar)
   @ Base ./essentials.jl:714
 [3] top-level scope
   @ REPL[2]:1

@vtjnash vtjnash removed the kind:regression Regression in behavior compared to a previous version label Mar 31, 2023
@vtjnash
Copy link
Sponsor Member

vtjnash commented Mar 31, 2023

Calling Val(N) where N may trick Julia into creating an instance of an invalid DataType. But that is not really a new regression.

@gbaraldi
Copy link
Member

It did use to error before and now it segfaults, so I would say this is a regression. The segfault is because we call a broken tuple.

vtjnash added a commit that referenced this issue Apr 5, 2023
We generally hit the runtime in pretty specific places when allocations
look funky (because they are missing a typevar bound, so inference is
not too willing to deal with it). Try to throw an error in those cases
before those can get allocated and cause problems later from being
non-concrete objects.

Fix #49203
vtjnash added a commit that referenced this issue Apr 7, 2023
We generally hit the runtime in pretty specific places when allocations
look funky (because they are missing a typevar bound, so inference is
not too willing to deal with it). Try to throw an error in those cases
before those can get allocated and cause problems later from being
non-concrete objects.

Fix #49203
KristofferC pushed a commit that referenced this issue Apr 9, 2023
We generally hit the runtime in pretty specific places when allocations
look funky (because they are missing a typevar bound, so inference is
not too willing to deal with it). Try to throw an error in those cases
before those can get allocated and cause problems later from being
non-concrete objects.

Fix #49203

(cherry picked from commit a1013e7)
Xnartharax pushed a commit to Xnartharax/julia that referenced this issue Apr 19, 2023
We generally hit the runtime in pretty specific places when allocations
look funky (because they are missing a typevar bound, so inference is
not too willing to deal with it). Try to throw an error in those cases
before those can get allocated and cause problems later from being
non-concrete objects.

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

Successfully merging a pull request may close this issue.

6 participants