Coder Social home page Coder Social logo

Comments (3)

JoeLoser avatar JoeLoser commented on May 23, 2024

FYI @laszlokindrat

from mojo.

carlca avatar carlca commented on May 23, 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)

from mojo.

laszlokindrat avatar laszlokindrat commented on May 23, 2024

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!

from mojo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.