Comments (3)
FYI @laszlokindrat
from mojo.
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.
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)
- [Feature Request] [stdlib] [proposal] Add `ErrorReg`, `Result`, and `ResultReg` types
- [Docs] List/Dict Comprehension Section Outdated
- [BUG] Flaky segfault during `mojo build` with `-D MOJO_ENABLE_ASSERTIONS`
- [BUG] alias materialization of list
- [Feature Request] Add memoization decorator
- [BUG] Popping a String from a dictionary then using the value leads to a double free crash.
- [BUG] LSP Crash with basic trait and __contains__
- [Feature Request] Improving the developer experience for new contributors
- [Feature Request] [mojo-lang] [proposal] Make fstring formatting a priority and define what features will be available HOT 1
- [Docs] Indicate which platform a search result is for
- [BUG] Possible stack overflow in compiler for suffiently complex type declaration, hang at lower complexities
- [Feature Request] [stdlib] [proposal] Migrate/wrap `String.join()` methods into `StringLiteral` and add temp dict and list iter args
- [Feature Request] [stdlib] [proposal] Rename `InlineList` to `Array` HOT 3
- mojo-lsp-server crashes in Visual Studio Code
- [Feature Request] Improve ergonomics for writing functions generic across integral scalars. HOT 4
- [stdlib] Support custom prefix for `hex` function HOT 2
- [BUG] Mojo crashes when attempting run `str()` during compilation. HOT 2
- [BUG] walrus operator cannot handle multiple assignments HOT 12
- [BUG] [nightly 2024.5.2205] Error when hashing `StringLiteral` in `Dict.__setitem__` when building from generic trait
- [BUG] Compiler error when storing function whose input/output types are parameterized in struct
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mojo.