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 crashes after repeated allocation of very large block #9924

Open
keidax opened this issue Nov 17, 2020 · 1 comment
Open

Compiler crashes after repeated allocation of very large block #9924

keidax opened this issue Nov 17, 2020 · 1 comment

Comments

@keidax
Copy link
Contributor

keidax commented Nov 17, 2020

Reproducing code:

alias Item = {foo: Int32}

def bar?(item)
  true
end

min = 0
[{foo: 1}, {foo: 2}].each do |item|
  if bar?(item)
    min = [min, item[:foo]]
  end
end

pp min

This is actually a mistake, because I meant to type min = [min, item[:foo]].min? But it still surprised me when I realized this causes a compiler crash.

The output of crystal build looks like

GC Warning: Repeated allocation of very large block (appr. size 67112960):
	May lead to memory leak and poor performance

repeated several times followed by an OverflowError.

This looks pretty similar to #2257, but that issue is old and closed.

This is on Arch Linux.

$ crystal -v
Crystal 0.35.1 (2020-10-17)

LLVM: 10.0.1
Default target: x86_64-pc-linux-gnu
@bcardiff
Copy link
Member

The compiler issue here is that the "generic type too nested" error is not raised and the OOM happens during compile time.

Compiling the above program should behave the same as the following one.

min = 0

2.times do
  min = [min, 1]
end
$ crystal build foo.cr
Showing last frame. Use --error-trace for full trace.

In foo.cr:126:9

 126 | min = [min, 1]
             ^
Error: generic type too nested: Array(Array(Array(Array(Array( ... stripped ... | Int32) | Int32) | Int32)

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

2 participants