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

Fix debug locations for Proc pointers #11243

Merged

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Sep 24, 2021

A ProcPointer expands to a ProcLiteral:

def f
  puts caller.join("\n")
end

(->f).call
# becomes:
-> { f }.call

This ProcLiteral actually wraps a Def:

def ->
  f
end

But that Def does not have a location set, so debug locations become incorrect since #10934:

(->f).call
# => test.cr:2:8 in 'f'
# => src/time/location/loader.cr:2:22 in '~procProc(Nil)'
# => src/primitives.cr:266:3 in '__crystal_main'
# => src/crystal/main.cr:110:5 in 'main_user_code'
# ...

It can be seen from the following generated LLVM function corresponding the Def, which has no debug locations attached:

; Function Attrs: uwtable
define internal i32 @"~procProc(Nil)@test.cr:5"() #0 {
entry:
  %0 = call i32 @"*f:Nil"()
  ret i32 %0
}

This PR fixes that:

(->f).call
# => test.cr:2:8 in 'f'
# => test.cr:5:2 in '->'
# => src/primitives.cr:266:3 in '__crystal_main'
# => src/crystal/main.cr:110:5 in 'main_user_code'
# ...

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:regression Something that used to correctly work but no longer works topic:compiler:debugger labels Sep 24, 2021
@straight-shoota
Copy link
Member

Would it be feasible to add a spec for this?

Copy link
Member

@sdogruyol sdogruyol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @HertzDevil 🙏

@beta-ziliani beta-ziliani added this to the 1.2.0 milestone Sep 28, 2021
@straight-shoota straight-shoota merged commit 9a3f938 into crystal-lang:master Sep 29, 2021
@HertzDevil HertzDevil deleted the bug/proc-pointer-debug-location branch September 30, 2021 02:12
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. kind:regression Something that used to correctly work but no longer works topic:compiler:debugger
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants