Skip to content

Commit f7605f3

Browse files
committed
Typos, comments and renamings
1 parent da29f71 commit f7605f3

10 files changed

Lines changed: 50 additions & 54 deletions

File tree

forc-pkg/src/pkg.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,6 @@ pub fn compile_ir(
19471947
experimental: ExperimentalFeatures,
19481948
source_map: &mut SourceMap,
19491949
) -> Result<BuiltPackageBytecode> {
1950-
// Read main_file into a string
19511950
let source = fs::read_to_string(main_file)
19521951
.with_context(|| format!("Failed to read Sway-IR file: {}", main_file.display()))?;
19531952

@@ -2005,7 +2004,7 @@ pub fn compile_ir(
20052004
};
20062005

20072006
let (_, _warnings, _infos) = handler.consume();
2008-
// TODO Print infos and warnings?
2007+
// TODO: Print infos and warnings?
20092008
// TODO: Set configurables offset metadata if needed.
20102009

20112010
let bytecode = BuiltPackageBytecode {

sway-core/src/asm_generation/fuel/allocated_abstract_instruction_set.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl AllocatedAbstractInstructionSet {
343343
data_id,
344344
),
345345
owning_span: owning_span.clone(),
346-
comment: "load switch target table address".into(),
346+
comment: "[switch] load switch targets table base address".into(),
347347
});
348348
// Multiply discriminant by 8 (since each address is 8 bytes) and add to the base address.
349349
realized_ops.push(RealizedOp {
@@ -353,7 +353,7 @@ impl AllocatedAbstractInstructionSet {
353353
VirtualImmediate12::new(3),
354354
),
355355
owning_span: owning_span.clone(),
356-
comment: "multiply discriminant by 8".into(),
356+
comment: "[switch] get discriminant's target offset (discriminant * 8)".into(),
357357
});
358358
realized_ops.push(RealizedOp {
359359
opcode: AllocatedInstruction::ADD(
@@ -362,7 +362,7 @@ impl AllocatedAbstractInstructionSet {
362362
AllocatedRegister::Constant(ConstantRegister::Scratch),
363363
),
364364
owning_span: owning_span.clone(),
365-
comment: "add discriminant to switch target table address".into(),
365+
comment: "[switch] add discriminant's target offset to targets base address".into(),
366366
});
367367
realized_ops.push(RealizedOp {
368368
opcode: AllocatedInstruction::LW(
@@ -371,7 +371,7 @@ impl AllocatedAbstractInstructionSet {
371371
VirtualImmediate12::new(0),
372372
),
373373
owning_span: owning_span.clone(),
374-
comment: "load switch target address".into(),
374+
comment: "[switch] load discriminant's target address".into(),
375375
});
376376
// Finally, jump to the loaded address.
377377
realized_ops.push(RealizedOp {
@@ -380,7 +380,7 @@ impl AllocatedAbstractInstructionSet {
380380
VirtualImmediate18::new(0),
381381
),
382382
owning_span,
383-
comment,
383+
comment: "[switch] jump to discriminant's target address".into(),
384384
});
385385
}
386386
ControlFlowOp::DataSectionOffsetPlaceholder => {
@@ -425,10 +425,10 @@ impl AllocatedAbstractInstructionSet {
425425
/// instructions to be added, and so on.
426426
///
427427
/// For this reason, we take a two-pass approach. On the first pass, we pessimistically assume
428-
/// that all jumps may require take two opcodes, and use this assumption to calculate the
428+
/// that all jumps may require two opcodes, and use this assumption to calculate the
429429
/// offsets of labels. Then we see which jumps actually require two opcodes and mark them as such.
430430
/// This approach is not optimal as it sometimes requires more opcodes than necessary,
431-
/// but it is simple and quite works well in practice.
431+
/// but it is simple and works quite well in practice.
432432
fn resolve_labels(&mut self, data_section: &mut DataSection) -> LabeledBlocks {
433433
let far_jump_indices = self.collect_far_jumps();
434434
self.map_label_offsets(data_section, &far_jump_indices)

sway-core/src/asm_generation/fuel/fuel_asm_builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use sway_error::{
3333
use sway_ir::*;
3434
use sway_types::{span::Span, Spanned};
3535

36-
use core::panic;
3736
use either::Either;
3837
use std::collections::HashMap;
3938

sway-core/src/asm_lang/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,19 +281,17 @@ impl Op {
281281
}
282282
}
283283

284-
/// Switch
285-
pub(crate) fn switch(on: VirtualRegister, cases: Vec<Label>) -> Self {
284+
pub(crate) fn switch(discriminant: VirtualRegister, cases: Vec<Label>) -> Self {
286285
Op {
287286
opcode: Either::Right(OrganizationalOp::Switch {
288-
discriminant: on,
287+
discriminant,
289288
cases,
290289
}),
291290
comment: String::new(),
292291
owning_span: None,
293292
}
294293
}
295294

296-
/// Switch with comment
297295
pub(crate) fn switch_comment(
298296
discriminant: VirtualRegister,
299297
cases: Vec<Label>,

sway-ir/src/block.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,15 @@ impl Block {
314314
}
315315

316316
/// For a particular successor (if it indeed is one), get the arguments passed.
317-
pub fn get_succ_params(&self, context: &Context, succ: &Block) -> Vec<Value> {
317+
pub fn get_succ_args(&self, context: &Context, succ: &Block) -> Vec<Value> {
318318
self.successors(context)
319319
.iter()
320320
.find(|branch| &branch.block == succ)
321321
.map_or(vec![], |branch| branch.args.clone())
322322
}
323323

324-
/// For a particular successor (if it indeed is one), get a mut ref to parameters passed.
325-
pub fn get_succ_params_mut<'a>(
324+
/// For a particular successor (if it indeed is one), get a mutable reference to the arguments passed.
325+
pub fn get_succ_args_mut<'a>(
326326
&'a self,
327327
context: &'a mut Context,
328328
succ: &Block,
@@ -358,16 +358,16 @@ impl Block {
358358
},
359359
..
360360
}) => {
361-
for (_case_val, branch) in cases.iter_mut() {
362-
if branch.block == *succ {
363-
return Some(&mut branch.args);
364-
}
365-
}
366361
if let Some(def_branch) = default {
367362
if def_branch.block == *succ {
368363
return Some(&mut def_branch.args);
369364
}
370365
}
366+
for (_case_val, branch) in cases.iter_mut() {
367+
if branch.block == *succ {
368+
return Some(&mut branch.args);
369+
}
370+
}
371371
None
372372
}
373373
_ => None,
@@ -381,7 +381,7 @@ impl Block {
381381
context: &mut Context,
382382
old_succ: Block,
383383
new_succ: Block,
384-
new_params: Vec<Value>,
384+
new_args: Vec<Value>,
385385
) {
386386
let mut modified = false;
387387
if let Some(term) = self.get_terminator_mut(context) {
@@ -406,12 +406,12 @@ impl Block {
406406
if old_succ == *true_block {
407407
modified = true;
408408
*true_block = new_succ;
409-
true_opds.clone_from(&new_params);
409+
true_opds.clone_from(&new_args);
410410
}
411411
if old_succ == *false_block {
412412
modified = true;
413413
*false_block = new_succ;
414-
*false_opds = new_params
414+
*false_opds = new_args
415415
}
416416
}
417417

@@ -420,7 +420,7 @@ impl Block {
420420
..
421421
} if *block == old_succ => {
422422
*block = new_succ;
423-
*args = new_params;
423+
*args = new_args;
424424
modified = true;
425425
}
426426

@@ -437,7 +437,7 @@ impl Block {
437437
if branch.block == old_succ {
438438
*branch = BranchToWithArgs {
439439
block: new_succ,
440-
args: new_params.clone(),
440+
args: new_args.clone(),
441441
};
442442
modified = true;
443443
}
@@ -446,7 +446,7 @@ impl Block {
446446
if def_branch.block == old_succ {
447447
*def_branch = BranchToWithArgs {
448448
block: new_succ,
449-
args: new_params,
449+
args: new_args,
450450
};
451451
modified = true;
452452
}

sway-ir/src/instruction.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ impl InstOp {
597597
if let Some(default_branch) = default {
598598
v.extend_from_slice(&default_branch.args);
599599
}
600-
for case in cases {
601-
v.extend_from_slice(&case.1.args);
600+
for (_case_val, branch) in cases {
601+
v.extend_from_slice(&branch.args);
602602
}
603603
v
604604
}
@@ -823,12 +823,12 @@ impl InstOp {
823823
default.as_mut().unwrap().args[idx - cur_idx] = replacement;
824824
} else {
825825
cur_idx += default_args_len;
826-
for case in cases.iter_mut() {
827-
if idx - cur_idx < case.1.args.len() {
828-
case.1.args[idx - cur_idx] = replacement;
826+
for (_case_val, branch) in cases.iter_mut() {
827+
if idx - cur_idx < branch.args.len() {
828+
branch.args[idx - cur_idx] = replacement;
829829
return;
830830
}
831-
cur_idx += case.1.args.len();
831+
cur_idx += branch.args.len();
832832
}
833833
panic!("Invalid index for Switch");
834834
}
@@ -1203,8 +1203,8 @@ impl InstOp {
12031203
if let Some(default_branch) = default {
12041204
default_branch.args.iter_mut().for_each(replace);
12051205
}
1206-
for case in cases {
1207-
case.1.args.iter_mut().for_each(replace);
1206+
for (_case_val, branch) in cases {
1207+
branch.args.iter_mut().for_each(replace);
12081208
}
12091209
}
12101210
InstOp::ContractCall {

sway-ir/src/optimize/arg_demotion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ fn demote_block_signature(context: &mut Context, function: &Function, block: Blo
282282
for pred in preds {
283283
for (arg_idx, _arg_val, arg_var) in &arg_vars {
284284
// Get the value which is being passed to the block at this index.
285-
let arg_val = pred.get_succ_params(context, &block)[*arg_idx];
285+
let arg_val = pred.get_succ_args(context, &block)[*arg_idx];
286286

287287
// Insert a `get_local` and `store` for each candidate argument and insert them at the
288288
// end of this block, before the terminator.

sway-ir/src/optimize/dce.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ pub fn dce(
309309
.map(|arg| cemetery.contains(arg))
310310
.collect_vec();
311311
for pred in block.pred_iter(context).cloned().collect_vec() {
312-
let params = pred
313-
.get_succ_params_mut(context, &block)
312+
let args = pred
313+
.get_succ_args_mut(context, &block)
314314
.expect("Invalid IR");
315315
let mut index = 0;
316-
// Remove parameters passed to a dead argument.
317-
params.retain(|_| {
316+
// Remove arguments passed to a dead argument.
317+
args.retain(|_| {
318318
let retain = !dead_args[index];
319319
index += 1;
320320
retain

sway-ir/src/optimize/mem2reg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ pub fn promote_locals(
373373
Value::new_constant(context, constant)
374374
}
375375
};
376-
let params = node.get_succ_params_mut(context, &succ).unwrap();
377-
params.push(new_val);
376+
let succ_args = node.get_succ_args_mut(context, &succ).unwrap();
377+
succ_args.push(new_val);
378378
}
379379
}
380380
}

sway-ir/src/optimize/simplify_cfg.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn unlink_empty_blocks(context: &mut Context, function: &Function) -> Result<boo
6363
block,
6464
BranchToWithArgs {
6565
block: to_block,
66-
args: cur_params,
66+
args: cur_args,
6767
},
6868
) in candidates
6969
{
@@ -84,21 +84,21 @@ fn unlink_empty_blocks(context: &mut Context, function: &Function) -> Result<boo
8484
}
8585
let preds: Vec<_> = block.pred_iter(context).copied().collect();
8686
for pred in preds {
87-
// Whatever parameters "block" passed to "to_block", that
87+
// Whatever arguments "block" passed to "to_block", that
8888
// should now go from "pred" to "to_block".
89-
let params_from_pred = pred.get_succ_params(context, &block);
90-
let new_params = cur_params
89+
let args_from_pred = pred.get_succ_args(context, &block);
90+
let new_args = cur_args
9191
.iter()
92-
.map(|cur_param| match &context.values[cur_param.0].value {
92+
.map(|cur_arg| match &context.values[cur_arg.0].value {
9393
ValueDatum::Argument(arg) if arg.block == block => {
9494
// An argument should map to the actual parameter passed.
95-
params_from_pred[arg.idx]
95+
args_from_pred[arg.idx]
9696
}
97-
_ => *cur_param,
97+
_ => *cur_arg,
9898
})
9999
.collect();
100100

101-
pred.replace_successor(context, block, to_block, new_params);
101+
pred.replace_successor(context, block, to_block, new_args);
102102
modified = true;
103103
}
104104
}
@@ -205,12 +205,12 @@ fn merge_blocks(context: &mut Context, function: &Function) -> Result<bool, IrEr
205205

206206
// Loop for the rest of the chain, to all the `to_block`s.
207207
for to_block in block_chain {
208-
let from_params = from_block.get_succ_params(context, &to_block);
208+
let from_args = from_block.get_succ_args(context, &to_block);
209209
// We collect here so that we can have &mut Context later on.
210210
let to_blocks: Vec<_> = to_block.arg_iter(context).copied().enumerate().collect();
211211
for (arg_idx, to_block_arg) in to_blocks {
212-
// replace all uses of `to_block_arg` with the parameter from `from_block`.
213-
replace_map.insert(to_block_arg, from_params[arg_idx]);
212+
// replace all uses of `to_block_arg` with the argument from `from_block`.
213+
replace_map.insert(to_block_arg, from_args[arg_idx]);
214214
}
215215

216216
// Update the parent block field for every instruction

0 commit comments

Comments
 (0)