Skip to content
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

fix text_size #540

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/candid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "candid"
version = "0.10.5"
version = "0.10.6"
edition = "2021"
rust-version.workspace = true
authors = ["DFINITY Team"]
Expand Down
1 change: 1 addition & 0 deletions rust/candid/src/pretty/candid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub fn pp_ty_inner(ty: &TypeInner) -> RcDoc {
Var(ref s) => str(s),
Principal => str("principal"),
Opt(ref t) => kwd("opt").append(pp_ty(t)),
Vec(ref t) if matches!(t.as_ref(), Nat8) => str("blob"),
Vec(ref t) => kwd("vec").append(pp_ty(t)),
Record(ref fs) => {
let t = Type(ty.clone().into());
Expand Down
6 changes: 4 additions & 2 deletions rust/candid/src/types/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub fn text_size(t: &Type, limit: i32) -> Result<i32, ()> {
Float32 | Float64 => 7,
Reserved => 8,
Principal => 9,
Knot(_) => 5,
Knot(_) => 10,
Var(id) => id.len() as i32,
Opt(t) => 4 + text_size(t, limit - 4)?,
Vec(t) => 4 + text_size(t, limit - 4)?,
Expand Down Expand Up @@ -371,7 +371,9 @@ pub fn text_size(t: &Type, limit: i32) -> Result<i32, ()> {
}
10 + cnt
}
Class(_, _) | Future | Unknown => unimplemented!(),
Future => 6,
Unknown => 7,
Class(..) => unreachable!(),
};
if cost > limit {
Err(())
Expand Down
2 changes: 1 addition & 1 deletion rust/candid_parser/tests/assets/ok/example.did
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type tree = variant {
service : {
bbbbb : (b) -> ();
f : t;
f1 : (list, vec nat8, opt bool) -> () oneway;
f1 : (list, blob, opt bool) -> () oneway;
g : (list) -> (B, tree, stream);
g1 : (my_type, List, opt List, nested) -> (int, broker) query;
h : (vec opt text, variant { A : nat; B : opt text }, opt List) -> (
Expand Down
4 changes: 2 additions & 2 deletions rust/candid_parser/tests/assets/ok/keyword.did
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ service : {
fieldnat : (record { 2 : int; "2" : nat }) -> (record { int });
"oneway" : (nat8) -> () oneway;
oneway_ : (nat8) -> () oneway;
"query" : (vec nat8) -> (vec nat8) query;
"query" : (blob) -> (blob) query;
return : (o) -> (o);
"service" : t;
tuple : (record { int; vec nat8; text }) -> (record { int; nat8 });
tuple : (record { int; blob; text }) -> (record { int; nat8 });
"variant" : (variant { A; B; C; D : float64 }) -> ();
}
36 changes: 18 additions & 18 deletions rust/candid_parser/tests/assets/ok/management.did
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type bitcoin_address = text;
type bitcoin_network = variant { mainnet; testnet };
type block_hash = vec nat8;
type block_hash = blob;
type canister_id = principal;
type canister_settings = record {
freezing_threshold : opt nat;
Expand All @@ -23,31 +23,31 @@ type get_balance_request = record {
type get_current_fee_percentiles_request = record { network : bitcoin_network };
type get_utxos_request = record {
network : bitcoin_network;
filter : opt variant { page : vec nat8; min_confirmations : nat32 };
filter : opt variant { page : blob; min_confirmations : nat32 };
address : bitcoin_address;
};
type get_utxos_response = record {
next_page : opt vec nat8;
next_page : opt blob;
tip_height : nat32;
tip_block_hash : block_hash;
utxos : vec utxo;
};
type http_header = record { value : text; name : text };
type http_response = record {
status : nat;
body : vec nat8;
body : blob;
headers : vec http_header;
};
type millisatoshi_per_byte = nat64;
type outpoint = record { txid : vec nat8; vout : nat32 };
type outpoint = record { txid : blob; vout : nat32 };
type satoshi = nat64;
type send_transaction_request = record {
transaction : vec nat8;
transaction : blob;
network : bitcoin_network;
};
type user_id = principal;
type utxo = record { height : nat32; value : satoshi; outpoint : outpoint };
type wasm_module = vec nat8;
type wasm_module = blob;
service : {
bitcoin_get_balance : (get_balance_request) -> (satoshi);
bitcoin_get_current_fee_percentiles : (
Expand All @@ -62,7 +62,7 @@ service : {
cycles : nat;
settings : definite_canister_settings;
idle_cycles_burned_per_day : nat;
module_hash : opt vec nat8;
module_hash : opt blob;
},
);
create_canister : (record { settings : opt canister_settings }) -> (
Expand All @@ -74,27 +74,27 @@ service : {
record {
key_id : record { name : text; curve : ecdsa_curve };
canister_id : opt canister_id;
derivation_path : vec vec nat8;
derivation_path : vec blob;
},
) -> (record { public_key : vec nat8; chain_code : vec nat8 });
) -> (record { public_key : blob; chain_code : blob });
http_request : (
record {
url : text;
method : variant { get; head; post };
max_response_bytes : opt nat64;
body : opt vec nat8;
body : opt blob;
transform : opt record {
function : func (
record { context : vec nat8; response : http_response },
record { context : blob; response : http_response },
) -> (http_response) query;
context : vec nat8;
context : blob;
};
headers : vec http_header;
},
) -> (http_response);
install_code : (
record {
arg : vec nat8;
arg : blob;
wasm_module : wasm_module;
mode : variant { reinstall; upgrade; install };
canister_id : canister_id;
Expand All @@ -110,14 +110,14 @@ service : {
provisional_top_up_canister : (
record { canister_id : canister_id; amount : nat },
) -> ();
raw_rand : () -> (vec nat8);
raw_rand : () -> (blob);
sign_with_ecdsa : (
record {
key_id : record { name : text; curve : ecdsa_curve };
derivation_path : vec vec nat8;
message_hash : vec nat8;
derivation_path : vec blob;
message_hash : blob;
},
) -> (record { signature : vec nat8 });
) -> (record { signature : blob });
start_canister : (record { canister_id : canister_id }) -> ();
stop_canister : (record { canister_id : canister_id }) -> ();
uninstall_code : (record { canister_id : canister_id }) -> ();
Expand Down
Loading