-
Notifications
You must be signed in to change notification settings - Fork 90
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
feat(builtin): add dump()
for easy print-based debugging
#1269
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,9 @@ | |
///| | ||
fn println_mono(s : String) -> Unit = "%println" | ||
|
||
///| | ||
fn any_to_string[T](any : T) -> String = "%any.to_string" | ||
|
||
///| | ||
pub fn println[T : Show](input : T) -> Unit { | ||
println_mono(input.to_string()) | ||
|
@@ -27,6 +30,18 @@ pub fn print[T : Show](input : T) -> Unit { | |
println(input) | ||
} | ||
|
||
///| | ||
/// Prints and returns the value of a given expression for quick and dirty debugging. | ||
/// @alert deprecated "This function is for debugging only and should not be used in production" | ||
pub fn dump[T](t : T, name? : String, loc~ : SourceLoc = _) -> T { | ||
let name = match name { | ||
Some(name) => name | ||
None => "" | ||
} | ||
println("dump(\{name}@\{loc}) = \{any_to_string(t)}") | ||
t | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any_to_string is introduced for arbitrary code transformations where pub fn dump[T:Show](t : T, name~ : ArgsRepr = _, loc~ : SourceLoc = _) -> T There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bobzhang One thing that distinguishes Swift's I think the OTOH Footnotes
|
||
///| | ||
pub fn to_string(self : Bool) -> String { | ||
if self { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is marked as deprecated because it seems to be the only way to generate warnings with it. In Rust this logic is handled by
clippy
instead ofrustc
so there haven't been such concerns.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Alert dev
to warn that in release mode, it should be removed