-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add support for indexed fields. #1695
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ pub(crate) fn log_formatters_instantiation_code( | |
| ) -> TokenStream { | ||
| let resolved_logs = resolve_logs(logged_types); | ||
| let log_id_log_formatter_pairs = generate_log_id_log_formatter_pairs(&resolved_logs); | ||
| println!("{:#?}", log_id_log_formatter_pairs); | ||
|
Contributor
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. I think we should remove these debug prints. |
||
| quote! {::fuels::core::codec::log_formatters_lookup(vec![#(#log_id_log_formatter_pairs),*], #contract_id)} | ||
| } | ||
|
|
||
|
|
@@ -27,6 +28,7 @@ fn resolve_logs(logged_types: &[FullLoggedType]) -> Vec<ResolvedLog> { | |
| let resolved_type = TypeResolver::default() | ||
| .resolve(&l.application) | ||
| .expect("Failed to resolve log type"); | ||
| println!("{:#?}", resolved_type); | ||
|
Contributor
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. Same as the previous one |
||
|
|
||
| ResolvedLog { | ||
| log_id: l.log_id.clone(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,3 +88,57 @@ impl Default for Token { | |
| Token::U8(0) | ||
| } | ||
| } | ||
|
|
||
| impl Token { | ||
| /// Returns true if this [Token] is an exact-size ABI type. | ||
| pub fn is_exact_size_abi(&self) -> bool { | ||
| match self { | ||
| Token::Unit | ||
| | Token::Bool(_) | ||
| | Token::U8(_) | Token::U16(_) | Token::U32(_) | Token::U64(_) | Token::U128(_) | Token::U256(_) | ||
| | Token::B256(_) => true, | ||
|
|
||
| // Dynamic or heap-allocated | ||
| Token::Bytes(_) | Token::String(_) | Token::RawSlice(_) | ||
| | Token::StringArray(_) | Token::StringSlice(_) | ||
| | Token::Vector(_) => false, | ||
|
|
||
| // Nested container: all elements must be exact-size | ||
| Token::Tuple(elems) | Token::Array(elems) | Token::Struct(elems) => { | ||
| elems.iter().all(|t| t.is_exact_size_abi()) | ||
| } | ||
|
|
||
| // Enum: second element of selector is the payload Token | ||
| Token::Enum(selector) => selector.1.is_exact_size_abi(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| mod tests { | ||
|
|
||
|
|
||
| #[test] | ||
| fn primitives() { | ||
| assert!(Token::U32(0).is_exact_size_abi()); | ||
| assert!(Token::B256([0u8; 32]).is_exact_size_abi()); | ||
| assert!(!Token::String("a".into()).is_exact_size_abi()); | ||
| } | ||
|
|
||
| #[test] | ||
|
Contributor
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. the test name and body don't follow our testing rules. |
||
| fn nested() { | ||
| let good = Token::Tuple(vec![Token::U16(1), Token::Bool(true)]); | ||
| assert!(good.is_exact_size_abi()); | ||
|
|
||
| let bad = Token::Struct(vec![Token::U8(2), Token::Bytes(vec![1])]); | ||
| assert!(!bad.is_exact_size_abi()); | ||
| } | ||
|
|
||
| // #[test] | ||
| // fn enum_token() { | ||
|
Contributor
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. do we want to have this test or remove it? I think commented test is not acceptable. |
||
| // let ok = Token::Enum(Box::new((0, Token::U64(5), EnumVariants::default()))); | ||
| // assert!(ok.is_exact_size_abi()); | ||
|
|
||
| // let err = Token::Enum(Box::new((1, Token::String("e".into()), EnumVariants::default()))); | ||
| // assert!(!err.is_exact_size_abi()); | ||
| // } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,9 +36,12 @@ mod setup_program_test; | |
| pub fn abigen(input: TokenStream) -> TokenStream { | ||
| let targets = parse_macro_input!(input as MacroAbigenTargets); | ||
|
|
||
| Abigen::generate(targets.into(), false) | ||
| let code = Abigen::generate(targets.into(), false) | ||
| .expect("abigen generation failed") | ||
| .into() | ||
| .into(); | ||
| println!("{}", code); | ||
|
Contributor
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. This change should be reverted. |
||
|
|
||
| code | ||
| } | ||
|
|
||
| #[proc_macro] | ||
|
|
||
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 one shouldn't be merged