-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Supercharge traces #978
Supercharge traces #978
Conversation
Although, doesn't do anything with them yet. The idea is to simplify the use of trace to make it a lot more useful than it currently is.
This is not fully satisfactory as it pollutes a bit the prelude. Ideally, those functions should only be visible and usable by the underlying trace code. But for now, we'll just go with it.
Somehow, we have to patch some function in gen_uplc because of the module name. I have to look further into this because it isn't normal.
This is a little weird but, prelude functions are handled slightly differently.
Actually, this has been a bug for a long time it seems. Calling any prelude functions using a qualified import would result in a codegen crash. Whoopsie. This is now fixed as shown by the regression test.
- Trace-if-false are now completely discarded in compact mode. - Only the label (i.e. first trace argument) is preserved. - When compiling with tracing _compact_, the first label MUST unify to a string. This shouldn't be an issue generally speaking and would enforce that traces follow the pattern ``` label: arg_0[, arg_1, ..., arg_n] ``` Note that what isn't obvious with these changes is that we now support what the "emit" keyword was trying to achieve; as we compile now with user-defined traces only, and in compact mode to only keep event labels in the final contract; while allowing larger payloads with verbose tracing.
We've never been using those 'expected' tokens captured during parsing, which is lame because they contain useful information! This is much better than merely showing our infamous "Try removing it!"
3130429
to
89890f3
Compare
TypeIdent, | ||
#[error("I found an unexpected identifier.")] | ||
#[diagnostic(help("Try removing it!"))] | ||
TermIdent, |
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.
dead-code
#[diagnostic(help( | ||
"If no label is provided then only variables\nmatching a field name are allowed." | ||
))] | ||
RecordPunning, |
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.
dead-code
String::new() | ||
} else { | ||
module_name.clone() | ||
}, |
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.
Actually a long-standing bug, see the corresponding gen_uplc test.
@@ -183,6 +183,6 @@ impl fmt::Display for Token { | |||
Token::Validator => "validator", | |||
Token::Via => "via", | |||
}; | |||
write!(f, "\"{s}\"") | |||
write!(f, "{s}") |
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.
I am not 100% sure about the impact of this one. And also not sure why we were wrapping tokens in double-quotes when printing them. This was ugly in the error reporting so I removed them; but I am not certain that we don't show them in other places where the quotes might matter.
Anyway, we should add the quotes in-place where they're needed, and not from this function.
.delayed_if_then_else(constant_true, constant_false), | ||
false, | ||
) | ||
} |
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.
Note: ☝️ This would crash prior to the fix in this PR.
Preview
Default options
trace @"my_label"
trace @"my_label": @"foo", @"bar"
trace @"my_label": [1, 2, 3], Some(#"00ff")
trace (14, 42)
trace fn(x) { x + 1 }
trace @"my_label", @"foo", @"bar"
--trace-level compact
trace @"my_label"
trace @"my_label": @"foo", @"bar"
trace @"my_label": [1, 2, 3], Some(#"00ff")
trace (14, 42)
trace fn(x) { x + 1 }
trace @"my_label", @"foo", @"bar"
Changes
📍 Allow variadic arguments in trace
Although, doesn't do anything with them yet. The idea is to simplify
the use of trace to make it a lot more useful than it currently is.
📍 Type-check variadic traces & desugarize them.
📍 Add 'diagnostic' to the prelude, as well as companion functions.
This is not fully satisfactory as it pollutes a bit the prelude. Ideally, those functions should only be visible
and usable by the underlying trace code. But for now, we'll just go with it.
📍 Allow serialisable (Data-able) arguments to trace
Somehow, we have to patch some function in gen_uplc because of the
module name. I have to look further into this because it isn't normal.
📍 Remove unnecessary code_gen patch.
This is a little weird but, prelude functions are handled slightly
differently.
📍 re-introduce code-gen patch, but with a test.
Actually, this has been a bug for a long time it seems. Calling any
prelude functions using a qualified import would result in a codegen
crash. Whoopsie.
This is now fixed as shown by the regression test.
📍 Rework 'compact' mode for traces
Trace-if-false are now completely discarded in compact mode.
Only the label (i.e. first trace argument) is preserved.
When compiling with tracing compact, the first label MUST unify to
a string. This shouldn't be an issue generally speaking and would
enforce that traces follow the pattern
Note that what isn't obvious with these changes is that we now support
what the "emit" keyword was trying to achieve; as we compile now with
user-defined traces only, and in compact mode to only keep event
labels in the final contract; while allowing larger payloads with
verbose tracing.
📍 Display expected patterns/tokens in parse error when applicable.
We've never been using those 'expected' tokens captured during
parsing, which is lame because they contain useful information!
This is much better than merely showing our infamous
"Try removing it!"
📍 Provide better parse errors in trace when using comma instead of colon.
📍 Fill-in CHANGELOG