Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit bef3552

Browse files
committed
Bring move-stdlib/src/natives/debug.rs on par with sui/debug.rs
1 parent 5acd116 commit bef3552

File tree

2 files changed

+63
-14
lines changed

2 files changed

+63
-14
lines changed

language/move-stdlib/src/natives/debug.rs

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ pub struct PrintGasParameters {
2626
pub base_cost: InternalGas,
2727
}
2828

29+
#[inline]
30+
fn native_print_nop(
31+
gas_params: &PrintGasParameters,
32+
ty_args: Vec<Type>,
33+
args: VecDeque<Value>,
34+
) -> PartialVMResult<NativeResult> {
35+
debug_assert!(ty_args.len() == 1);
36+
debug_assert!(args.len() == 1);
37+
Ok(NativeResult::ok(gas_params.base_cost, smallvec![]))
38+
}
39+
2940
#[inline]
3041
fn native_print(
3142
gas_params: &PrintGasParameters,
@@ -68,14 +79,23 @@ fn native_print(
6879
}
6980

7081
pub fn make_native_print(
82+
silent: bool,
7183
gas_params: PrintGasParameters,
7284
move_std_addr: AccountAddress,
7385
) -> NativeFunction {
74-
Arc::new(
75-
move |context, ty_args, args| -> PartialVMResult<NativeResult> {
76-
native_print(&gas_params, context, ty_args, args, move_std_addr)
77-
},
78-
)
86+
if silent {
87+
Arc::new(
88+
move |_context, ty_args, args| -> PartialVMResult<NativeResult> {
89+
native_print_nop(&gas_params, ty_args, args)
90+
},
91+
)
92+
} else {
93+
Arc::new(
94+
move |context, ty_args, args| -> PartialVMResult<NativeResult> {
95+
native_print(&gas_params, context, ty_args, args, move_std_addr)
96+
},
97+
)
98+
}
7999
}
80100

81101
/***************************************************************************************************
@@ -88,6 +108,17 @@ pub struct PrintStackTraceGasParameters {
88108
pub base_cost: InternalGas,
89109
}
90110

111+
#[inline]
112+
fn native_print_stack_trace_nop(
113+
gas_params: &PrintStackTraceGasParameters,
114+
ty_args: Vec<Type>,
115+
args: VecDeque<Value>,
116+
) -> PartialVMResult<NativeResult> {
117+
debug_assert!(ty_args.is_empty());
118+
debug_assert!(args.is_empty());
119+
Ok(NativeResult::ok(gas_params.base_cost, smallvec![]))
120+
}
121+
91122
#[allow(unused_variables)]
92123
#[inline]
93124
fn native_print_stack_trace(
@@ -109,12 +140,23 @@ fn native_print_stack_trace(
109140
Ok(NativeResult::ok(gas_params.base_cost, smallvec![]))
110141
}
111142

112-
pub fn make_native_print_stack_trace(gas_params: PrintStackTraceGasParameters) -> NativeFunction {
113-
Arc::new(
114-
move |context, ty_args, args| -> PartialVMResult<NativeResult> {
115-
native_print_stack_trace(&gas_params, context, ty_args, args)
116-
},
117-
)
143+
pub fn make_native_print_stack_trace(
144+
silent: bool,
145+
gas_params: PrintStackTraceGasParameters,
146+
) -> NativeFunction {
147+
if silent {
148+
Arc::new(
149+
move |_context, ty_args, args| -> PartialVMResult<NativeResult> {
150+
native_print_stack_trace_nop(&gas_params, ty_args, args)
151+
},
152+
)
153+
} else {
154+
Arc::new(
155+
move |context, ty_args, args| -> PartialVMResult<NativeResult> {
156+
native_print_stack_trace(&gas_params, context, ty_args, args)
157+
},
158+
)
159+
}
118160
}
119161

120162
/***************************************************************************************************
@@ -127,14 +169,18 @@ pub struct GasParameters {
127169
}
128170

129171
pub fn make_all(
172+
silent: bool,
130173
gas_params: GasParameters,
131174
move_std_addr: AccountAddress,
132175
) -> impl Iterator<Item = (String, NativeFunction)> {
133176
let natives = [
134-
("print", make_native_print(gas_params.print, move_std_addr)),
177+
(
178+
"print",
179+
make_native_print(silent, gas_params.print, move_std_addr),
180+
),
135181
(
136182
"print_stack_trace",
137-
make_native_print_stack_trace(gas_params.print_stack_trace),
183+
make_native_print_stack_trace(silent, gas_params.print_stack_trace),
138184
),
139185
];
140186

language/move-stdlib/src/natives/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ pub fn nursery_natives(
171171
}
172172

173173
add_natives!("event", event::make_all(gas_params.event));
174-
add_natives!("debug", debug::make_all(gas_params.debug, move_std_addr));
174+
add_natives!(
175+
"debug",
176+
debug::make_all(true, gas_params.debug, move_std_addr)
177+
);
175178

176179
make_table_from_iter(move_std_addr, natives)
177180
}

0 commit comments

Comments
 (0)