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

Error creating Proc with explicit receiver #7577

Closed
tenebrousedge opened this issue Mar 22, 2019 · 8 comments
Closed

Error creating Proc with explicit receiver #7577

tenebrousedge opened this issue Mar 22, 2019 · 8 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen

Comments

@tenebrousedge
Copy link

$crystal --version
Crystal 0.27.2 [60760a546] (2019-02-05)

LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu
a = 15
b = ->a.divisible_by?(Int32)
Module validation failed: Invalid bitcast
  %74 = bitcast i32 %73 to i8*, !dbg !19
 (Exception)
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
Error: you've found a bug in the Crystal compiler. Please open an issue

Playground link

I've generally been having issues with trying to use Procs with a receiver. In Ruby I use the method method often. Crystal's syntax seems like it would be an improvement.

@asterite
Copy link
Member

This is fixed in master. I fixed it in #7334

@Sija
Copy link
Contributor

Sija commented Mar 23, 2019

@asterite Are you sure it's the same issue? The one you mentioned was about parsing, whereas this one parses well, and the error refers to LLVM.

@asterite
Copy link
Member

Pretty sure. In the PR I mention that I also found bugs with creating procs for methods of primitive types and that I fixed that.

@tenebrousedge
Copy link
Author

This does not produce the same error on the current master, as far as I can tell. Getting Crystal to compile on Ubuntu was interesting. But, uh:

~/s/c/crystal ❯❯❯ bin/crystal eval "a = 15; b = ->a.divisible_by?(Int32); pp [3,5,7].map(&b)"
Using compiled compiler at `.build/crystal'
[true, false, false]
~/s/c/crystal ❯❯❯ bin/crystal eval "a = 15; b = ->a.divisible_by?(Int32); pp [3,5,7].map(&b)"
Using compiled compiler at `.build/crystal'
[false, true, false]
~/s/c/crystal ❯❯❯ bin/crystal eval "a = 15; b = ->a.divisible_by?(Int32); pp [3,5,7].map(&b)"
Using compiled compiler at `.build/crystal'
[false, false, false]

That probably shouldn't do that?

~/s/c/crystal ❯❯❯ bin/crystal --version
Using compiled compiler at `.build/crystal'
Crystal 0.28.0-dev [5282fdf91] (2019-03-23)

LLVM: 4.0.1
Default target: x86_64-pc-linux-gnu

@straight-shoota
Copy link
Member

Yeah, I can confirm this non-deterministic behaviour on master.

@tenebrousedge
Copy link
Author

with this:

a = 15
b = ->a.divisible_by?(Int32)
b.call(3)
b.call(3)
b.call(3)

The results will be wrong most of the time, but each call produces the same results: either all true or all false.

@jhass jhass added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen and removed status:duplicate labels May 8, 2020
@j8r
Copy link
Contributor

j8r commented Nov 24, 2020

Not sure it is the same bug:

class A
  @p : Proc(Int32, Bool)
  def initialize(i)
    @p = ->i.<(Int32)
  end
end

A.new 1
Module validation failed: Invalid bitcast
  %1 = bitcast i32 %i to i8*, !dbg !11
 (Exception)
  from ../../../../../../crystal/src/int.cr:1091:11 in 'finish'
  from ../../../../../../crystal/src/compiler/crystal/codegen/codegen.cr:69:7 in 'codegen'
  from ../../../../../../crystal/src/compiler/crystal/compiler.cr:172:16 in 'compile'
  from ../../../../../../crystal/src/compiler/crystal/command/spec.cr:76:14 in 'spec'
  from ../../../../../../crystal/src/pointer.cr:286:59 in 'run'
  from ../../../../../../crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
  from ../../../../../../crystal/src/crystal/main.cr:105:5 in 'main'
  from src/env/__libc_start_main.c:94:2 in 'libc_start_main_stage2'
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

@asterite
Copy link
Member

Works in master, fixed in #9824

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen
Projects
None yet
Development

No branches or pull requests

6 participants