Skip to content

Strange code hang in combination with @generated functions #24763

Closed
@Jutho

Description

@Jutho

This is the weirdest problem I have ever encountered in several years of using Julia and has taken me several hours to track down to debug and distill a minimal working example:

This came up in the context of an unregistered package of mine for working with strided array views (WIP, https://github.com/Jutho/Strided.jl), and only started to be a problem when I pulled the latest master today (I guess before I was working on master from a few days ago, at most two weeks or so).

module Strided
	struct StridedView{T,N,A<:DenseArray{T}} <: DenseArray{T,N}
		parent::A
		size::NTuple{N,Int}
		strides::NTuple{N,Int}
	end

	function Base.convert(T::Type{<:DenseArray}, a::StridedView)
	end

	@generated function test1(dims::NTuple{N,Int}) where {N}
		loopvars = [gensym() for k = 1:N]
		return :()
	end

	function test2()
	end
end
dims=(1,)
Strided.test1(dims) #-> code hangs

The hanging will stop under any of the following modifications:

  • remove function test2() end such that the generated function is the last in the module.
  • add @show "hi $N" as first line of test1, however
    • the "hi" is important, @show "$N" is not sufficient
    • the display output is important, t=@elapsed "$N" is not sufficient but @time "hi $N" is, in fact with @time the hi is not necessary
    • the macro is important, println("hi $N") is not sufficient
  • remove the definition of Base.convert
  • simplify the type definition of StridedView

Metadata

Metadata

Assignees

No one assigned

    Labels

    regressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions