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

[BUG] __call_location().file_name returns incorrect information #2534

Open
carlca opened this issue May 5, 2024 · 3 comments
Open

[BUG] __call_location().file_name returns incorrect information #2534

carlca opened this issue May 5, 2024 · 3 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library

Comments

@carlca
Copy link

carlca commented May 5, 2024

Bug description

It seems that the __call_location() function is returning incorrect data.
It's been suggested that, "It looks to be baking in our internal source code path into the Mojo binary which isn't good.".

Steps to reproduce

I ran the following code...

from builtin._location import __call_location, _SourceLocation
 
@always_inline("nodebug")
def main():
  var st = __call_location().file_name
  print(st)

This is what I saw...

[Sun May 05 2024  6:26PM (BST+0100)]  (main) [*] 🐍 v3.12.1   
~/Code/Mojo/ca_mojo/ca_lib/research  mojo main.mojo
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/builtin/_startup.mojo  # ???

[Sun May 05 2024  6:26PM (BST+0100)]  (main) [*] 🐍 v3.12.1   
~/Code/Mojo/ca_mojo/ca_lib/research  pwd
/Users/carlcaulkett/Code/Mojo/ca_mojo/ca_lib/research

[Sun May 05 2024  6:26PM (BST+0100)]  (main) [*] 🐍 v3.12.1   
~/Code/Mojo/ca_mojo/ca_lib/research  mojo main.mojo

System information

- macOS 14.4.1 Sonoma
- mojo 2024.5.323 (1d9276ea)
- modular 0.7.1 (28ddab26)
@carlca carlca added bug Something isn't working mojo-repo Tag all issues with this label labels May 5, 2024
@JoeLoser
Copy link
Collaborator

JoeLoser commented May 5, 2024

FYI @laszlokindrat

@JoeLoser JoeLoser added the mojo-stdlib Tag for issues related to standard library label May 5, 2024
@carlca carlca changed the title [BUG] __call_location().file_name return incorrect information [BUG] __call_location().file_name returns incorrect information May 5, 2024
@ematejska ematejska added mojo-repo Tag all issues with this label and removed mojo-stdlib Tag for issues related to standard library mojo-repo Tag all issues with this label labels May 6, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 7, 2024 — with Linear
@carlca
Copy link
Author

carlca commented May 10, 2024

Following the new update to nightly/mojo, I've expended on the test code, taking into @Arthur Evans's wise words about not inlining the main fn 😮

Now we have...
from builtin._location import __call_location, _SourceLocation

fn main():
  test_fn()   # <== Reports this location!

@always_inline("nodebug")
fn test_fn():
  var file_name = __call_location().file_name
  var line = __call_location().line
  print(file_name)
  print(line)

# Output of test
# 
# [Fri May 10 2024 12:24PM (BST+0100)]  (main) [*] 🐍 v3.12.1   
# ~/Code/Mojo/ca_mojo/ca_lib/research  mojo main.mojo
# /Users/carlcaulkett/Code/Mojo/ca_mojo/ca_lib/research/main.mojo
# 4

The behaviour is improved, source location is now reported as the call point to the function. It's difference from how it used to be, but by chance this behaviour may suit me in my particular use case 😉

Note that this code still returns the baked in Modular source path...

from builtin._location import __call_location, _SourceLocation

@always_inline("nodebug")
fn main():
  var st = __call_location().file_name
  print(st)

@laszlokindrat
Copy link
Contributor

Thanks for opening the ticket! Regarding the OP: this is sort of expected behavior, since the main you define in your file is indeed wrapped by some functions defined in _startup.mojo. I agree that it's not great that it returns the path on the machine the release was built. We don't think this is a huge risk, but we're evaluating what other ways this feature could be abused, so stay tuned!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library
Projects
None yet
Development

No branches or pull requests

4 participants