Skip to content

Commit

Permalink
[move] Add fine-grained calls to stacker across the compiler (#16582)
Browse files Browse the repository at this point in the history
## Description 

This replaces the previous stacker fix with an annotation proc macro
that bumps the stack any time it's at risk of running out of room.

## Test Plan 

Everything still works as expected, plus windows tests (TBD).

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
cgswords authored Mar 9, 2024
1 parent 589bf1e commit b33e05c
Show file tree
Hide file tree
Showing 30 changed files with 131 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions external-crates/move/Cargo.lock

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

1 change: 1 addition & 0 deletions external-crates/move/crates/move-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ move-ir-to-bytecode.workspace = true
move-borrow-graph.workspace = true
move-bytecode-source-map.workspace = true
move-command-line-common.workspace = true
move-proc-macros.workspace = true

[dev-dependencies]
move-stdlib.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
parser::ast::BinOp_,
shared::{unique_map::UniqueMap, CompilationEnv},
};
use move_proc_macros::growing_stack;
use state::{Value, *};
use std::{cell::RefCell, collections::BTreeMap, rc::Rc};

Expand Down Expand Up @@ -150,6 +151,7 @@ fn unused_mut_borrows(
// Command
//**************************************************************************************************

#[growing_stack]
fn command(context: &mut Context, sp!(loc, cmd_): &Command) {
use Command_ as C;
match cmd_ {
Expand Down Expand Up @@ -221,6 +223,7 @@ fn lvalue(context: &mut Context, sp!(loc, l_): &LValue, value: Value) {
}
}

#[growing_stack]
fn exp(context: &mut Context, parent_e: &Exp) -> Values {
use UnannotatedExp_ as E;
let eloc = &parent_e.exp.loc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
shared::{unique_map::UniqueMap, CompilationEnv},
};
use move_ir_types::location::*;
use move_proc_macros::growing_stack;
use state::*;
use std::collections::{BTreeMap, BTreeSet, VecDeque};

Expand Down Expand Up @@ -80,6 +81,7 @@ fn analyze(
(final_invariants, liveness.states)
}

#[growing_stack]
fn command(state: &mut LivenessState, sp!(_, cmd_): &Command) {
use Command_ as C;
match cmd_ {
Expand Down Expand Up @@ -116,6 +118,7 @@ fn lvalue(state: &mut LivenessState, sp!(_, l_): &LValue) {
}
}

#[growing_stack]
fn exp(state: &mut LivenessState, parent_e: &Exp) {
use UnannotatedExp_ as E;
match &parent_e.exp.value {
Expand Down Expand Up @@ -176,6 +179,8 @@ pub fn last_usage(
}

mod last_usage {
use move_proc_macros::growing_stack;

use crate::{
cfgir::liveness::state::LivenessState,
diag,
Expand Down Expand Up @@ -238,6 +243,7 @@ mod last_usage {
}
}

#[growing_stack]
fn command(context: &mut Context, sp!(_, cmd_): &mut Command) {
use Command_ as C;
match cmd_ {
Expand Down Expand Up @@ -296,6 +302,7 @@ mod last_usage {
}
}

#[growing_stack]
fn exp(context: &mut Context, parent_e: &mut Exp) {
use UnannotatedExp_ as E;
match &mut parent_e.exp.value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
shared::{unique_map::UniqueMap, *},
};
use move_ir_types::location::*;
use move_proc_macros::growing_stack;
use move_symbol_pool::Symbol;
use state::*;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -207,6 +208,7 @@ fn unused_let_muts<T>(
// Command
//**************************************************************************************************

#[growing_stack]
fn command(context: &mut Context, sp!(loc, cmd_): &Command) {
use Command_ as C;
match cmd_ {
Expand Down Expand Up @@ -343,6 +345,7 @@ fn lvalue(context: &mut Context, case: AssignCase, sp!(loc, l_): &LValue) {
}
}

#[growing_stack]
fn exp(context: &mut Context, parent_e: &Exp) {
use UnannotatedExp_ as E;
let eloc = &parent_e.exp.loc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
shared::unique_map::UniqueMap,
};
use move_ir_types::location::*;
use move_proc_macros::growing_stack;
use std::convert::TryFrom;

/// returns true if anything changed
Expand Down Expand Up @@ -49,6 +50,7 @@ pub fn optimize(

// Some(changed) to keep
// None to remove the cmd
#[growing_stack]
fn optimize_cmd(
consts: &UniqueMap<ConstantName, Value>,
sp!(_, cmd_): &mut Command,
Expand Down Expand Up @@ -79,6 +81,7 @@ fn optimize_cmd(
})
}

#[growing_stack]
fn optimize_exp(consts: &UniqueMap<ConstantName, Value>, e: &mut Exp) -> bool {
use UnannotatedExp_ as E;
let optimize_exp = |e| optimize_exp(consts, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ fn count(signature: &FunctionSignature, cfg: &MutForwardCFG) -> BTreeSet<Var> {
}

mod count {
use move_proc_macros::growing_stack;

use crate::{
hlir::ast::{FunctionSignature, *},
parser::ast::{BinOp, UnaryOp},
Expand Down Expand Up @@ -109,6 +111,7 @@ mod count {
}
}

#[growing_stack]
pub fn command(context: &mut Context, sp!(_, cmd_): &Command) {
use Command_ as C;
match cmd_ {
Expand Down Expand Up @@ -146,6 +149,7 @@ mod count {
}
}

#[growing_stack]
fn exp(context: &mut Context, parent_e: &Exp) {
use UnannotatedExp_ as E;
match &parent_e.exp.value {
Expand Down Expand Up @@ -252,6 +256,7 @@ fn eliminate(cfg: &mut MutForwardCFG, ssa_temps: BTreeSet<Var>) {
mod eliminate {
use crate::hlir::ast::{self as H, *};
use move_ir_types::location::*;
use move_proc_macros::growing_stack;
use std::collections::{BTreeMap, BTreeSet};

pub struct Context {
Expand All @@ -272,6 +277,7 @@ mod eliminate {
}
}

#[growing_stack]
pub fn command(context: &mut Context, sp!(_, cmd_): &mut Command) {
use Command_ as C;
match cmd_ {
Expand Down Expand Up @@ -338,6 +344,7 @@ mod eliminate {
}
}

#[growing_stack]
fn exp(context: &mut Context, parent_e: &mut Exp) {
use UnannotatedExp_ as E;
match &mut parent_e.exp.value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
// Label 2:
// ...

use move_proc_macros::growing_stack;

use crate::{
cfgir::{
ast::remap_labels,
Expand Down Expand Up @@ -123,6 +125,7 @@ fn optimize_forwarding_jumps(
changed
}

#[growing_stack]
fn optimize_cmd(sp!(_, cmd_): &mut Command, final_jumps: &BTreeMap<Label, Label>) -> bool {
use Command_ as C;
match cmd_ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

use move_proc_macros::growing_stack;

use crate::{
cfgir::{
ast::remap_labels,
Expand Down Expand Up @@ -34,6 +36,7 @@ fn optimize_(start: Label, blocks: &mut BasicBlocks) -> bool {
inline_single_target_blocks(&single_target_labels, start, blocks)
}

#[growing_stack]
fn find_single_target_labels(start: Label, blocks: &BasicBlocks) -> BTreeSet<Label> {
use Command_ as C;
let mut counts = BTreeMap::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod forwarding_jumps;
mod inline_blocks;
mod simplify_jumps;

use move_proc_macros::growing_stack;
use move_symbol_pool::Symbol;

use crate::{
Expand Down Expand Up @@ -40,6 +41,7 @@ const MOVE_2024_OPTIMIZATIONS: &[Optimization] = &[
inline_blocks::optimize,
];

#[growing_stack]
pub fn optimize(
env: &mut CompilationEnv,
package: Option<Symbol>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

use move_proc_macros::growing_stack;

use crate::{
cfgir::cfg::MutForwardCFG,
expansion::ast::Mutability,
Expand Down Expand Up @@ -31,6 +33,7 @@ pub fn optimize(
changed
}

#[growing_stack]
fn optimize_cmd(sp!(_, cmd_): &mut Command) -> bool {
use Command_ as C;
use UnannotatedExp_ as E;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
use cfgir::ast::LoopInfo;
use move_core_types::{account_address::AccountAddress as MoveAddress, runtime_value::MoveValue};
use move_ir_types::location::*;
use move_proc_macros::growing_stack;
use move_symbol_pool::Symbol;
use petgraph::{
algo::{kosaraju_scc as petgraph_scc, toposort as petgraph_toposort},
Expand Down Expand Up @@ -664,6 +665,7 @@ fn function_body(

type BlockList = Vec<(Label, BasicBlock)>;

#[growing_stack]
fn block(context: &mut Context, stmts: H::Block) -> BlockList {
let (start_block, blocks) = block_(context, stmts);
[(context.new_label(), start_block)]
Expand All @@ -672,6 +674,7 @@ fn block(context: &mut Context, stmts: H::Block) -> BlockList {
.collect()
}

#[growing_stack]
fn block_(context: &mut Context, stmts: H::Block) -> (BasicBlock, BlockList) {
let mut current_block: BasicBlock = VecDeque::new();
let mut blocks = Vec::new();
Expand Down Expand Up @@ -736,6 +739,7 @@ fn finalize_blocks(
(out_label, out_blocks, block_info)
}

#[growing_stack]
fn statement(
context: &mut Context,
sp!(sloc, stmt): H::Statement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
shared::CompilationEnv,
};
use move_ir_types::location::*;
use move_proc_macros::growing_stack;

pub type AbsIntVisitorObj = Box<dyn AbstractInterpreterVisitor>;

Expand Down Expand Up @@ -336,6 +337,7 @@ pub trait SimpleAbsInt: Sized {
) -> Option<Vec<<Self::State as SimpleDomain>::Value>> {
None
}
#[growing_stack]
fn exp(
&self,
context: &mut Self::ExecutionContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use move_command_line_common::files::{
find_filenames_vfs, MOVE_COMPILED_EXTENSION, MOVE_EXTENSION, SOURCE_MAP_EXTENSION,
};
use move_core_types::language_storage::ModuleId as CompiledModuleId;
use move_proc_macros::growing_stack;
use move_symbol_pool::Symbol;
use pathdiff::diff_paths;
use std::{
Expand Down Expand Up @@ -341,7 +342,7 @@ impl<'a> Compiler<'a> {
}

let (mut source_text, pprog, comments) =
with_large_stack!(parse_program(&mut compilation_env, maps, targets, deps,))?;
parse_program(&mut compilation_env, maps, targets, deps)?;

source_text
.iter_mut()
Expand Down Expand Up @@ -923,6 +924,7 @@ fn run(
until: Pass,
result_check: impl FnMut(&PassResult, &CompilationEnv),
) -> Result<PassResult, (Pass, Diagnostics)> {
#[growing_stack]
fn rec(
compilation_env: &mut CompilationEnv,
pre_compiled_lib: Option<&FullyCompiledProgram>,
Expand Down Expand Up @@ -1025,13 +1027,7 @@ fn run(
PassResult::Compilation(_, _) => unreachable!("ICE Pass::Compilation is >= all passes"),
}
}
with_large_stack!(rec(
compilation_env,
pre_compiled_lib,
cur,
until,
result_check
))
rec(compilation_env, pre_compiled_lib, cur, until, result_check)
}

//**************************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::{
use move_command_line_common::parser::{parse_u16, parse_u256, parse_u32};
use move_core_types::account_address::AccountAddress;
use move_ir_types::location::*;
use move_proc_macros::growing_stack;
use move_symbol_pool::Symbol;
use std::{
collections::{BTreeMap, BTreeSet, VecDeque},
Expand Down Expand Up @@ -2804,6 +2805,7 @@ fn optional_types(context: &mut Context, pts_opt: Option<Vec<P::Type>>) -> Optio
// Expressions
//**************************************************************************************************

#[growing_stack]
fn sequence(context: &mut Context, loc: Loc, seq: P::Sequence) -> E::Sequence {
let (puses, pitems, maybe_last_semicolon_loc, pfinal_item) = seq;

Expand Down Expand Up @@ -2831,6 +2833,7 @@ fn sequence(context: &mut Context, loc: Loc, seq: P::Sequence) -> E::Sequence {
(use_funs, items)
}

#[growing_stack]
fn sequence_item(context: &mut Context, sp!(loc, pitem_): P::SequenceItem) -> E::SequenceItem {
use E::SequenceItem_ as ES;
use P::SequenceItem_ as PS;
Expand Down Expand Up @@ -2873,6 +2876,7 @@ fn exps(context: &mut Context, pes: Vec<P::Exp>) -> Vec<E::Exp> {
.collect()
}

#[growing_stack]
fn exp(context: &mut Context, pe: Box<P::Exp>) -> Box<E::Exp> {
use E::Exp_ as EE;
use P::Exp_ as PE;
Expand Down Expand Up @@ -3197,6 +3201,7 @@ fn move_or_copy_path_(context: &mut Context, case: PathCase, pe: Box<P::Exp>) ->
})
}

#[growing_stack]
fn exp_dotted(context: &mut Context, pdotted: Box<P::Exp>) -> Option<Box<E::ExpDotted>> {
use E::ExpDotted_ as EE;
use P::Exp_ as PE;
Expand Down
Loading

0 comments on commit b33e05c

Please sign in to comment.