Skip to content

Commit 0bbd3b0

Browse files
authored
[move][receiver syntax][1/n] Move module dependency ordering to after typing (#13820)
- With receiver syntax, we will not be able to determine immediate dependencies until after typing - As such, module ordering must be done after typing. The logic remains the same ## Test Plan Internal compiler change (updated some location information for tests) --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### 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
1 parent 77d92f6 commit 0bbd3b0

File tree

15 files changed

+585
-322
lines changed

15 files changed

+585
-322
lines changed

move-compiler/src/expansion/ast.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ pub struct Script {
9494
pub package_name: Option<Symbol>,
9595
pub attributes: Attributes,
9696
pub loc: Loc,
97-
pub immediate_neighbors: UniqueMap<ModuleIdent, Neighbor>,
98-
pub used_addresses: BTreeSet<Address>,
9997
pub constants: UniqueMap<ConstantName, Constant>,
10098
pub function_name: FunctionName,
10199
pub function: Function,
@@ -126,11 +124,6 @@ pub struct ModuleDefinition {
126124
pub attributes: Attributes,
127125
pub loc: Loc,
128126
pub is_source_module: bool,
129-
/// `dependency_order` is the topological order/rank in the dependency graph.
130-
/// `dependency_order` is initialized at `0` and set in the uses pass
131-
pub dependency_order: usize,
132-
pub immediate_neighbors: UniqueMap<ModuleIdent, Neighbor>,
133-
pub used_addresses: BTreeSet<Address>,
134127
pub friends: UniqueMap<ModuleIdent, Friend>,
135128
pub structs: UniqueMap<StructName, StructDefinition>,
136129
pub functions: UniqueMap<FunctionName, Function>,
@@ -148,12 +141,6 @@ pub struct Friend {
148141
pub loc: Loc,
149142
}
150143

151-
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
152-
pub enum Neighbor {
153-
Dependency,
154-
Friend,
155-
}
156-
157144
//**************************************************************************************************
158145
// Structs
159146
//**************************************************************************************************
@@ -811,15 +798,6 @@ impl fmt::Display for Address {
811798
}
812799
}
813800

814-
impl fmt::Display for Neighbor {
815-
fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
816-
match self {
817-
Neighbor::Dependency => write!(f, "neighbor#dependency"),
818-
Neighbor::Friend => write!(f, "neighbor#friend"),
819-
}
820-
}
821-
}
822-
823801
impl fmt::Display for AttributeName_ {
824802
fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
825803
match self {
@@ -962,8 +940,6 @@ impl AstDebug for Script {
962940
package_name,
963941
attributes,
964942
loc: _loc,
965-
immediate_neighbors,
966-
used_addresses,
967943
constants,
968944
function_name,
969945
function,
@@ -975,14 +951,6 @@ impl AstDebug for Script {
975951
w.writeln(&format!("{}", n))
976952
}
977953
attributes.ast_debug(w);
978-
for (mident, neighbor) in immediate_neighbors.key_cloned_iter() {
979-
w.write(&format!("{} {};", neighbor, mident));
980-
w.new_line();
981-
}
982-
for addr in used_addresses {
983-
w.write(&format!("uses address {};", addr));
984-
w.new_line()
985-
}
986954
for cdef in constants.key_cloned_iter() {
987955
cdef.ast_debug(w);
988956
w.new_line();
@@ -1002,9 +970,6 @@ impl AstDebug for ModuleDefinition {
1002970
attributes,
1003971
loc: _loc,
1004972
is_source_module,
1005-
dependency_order,
1006-
immediate_neighbors,
1007-
used_addresses,
1008973
friends,
1009974
structs,
1010975
functions,
@@ -1022,15 +987,6 @@ impl AstDebug for ModuleDefinition {
1022987
} else {
1023988
"library module"
1024989
});
1025-
w.writeln(&format!("dependency order #{}", dependency_order));
1026-
for (mident, neighbor) in immediate_neighbors.key_cloned_iter() {
1027-
w.write(&format!("{} {};", neighbor, mident));
1028-
w.new_line();
1029-
}
1030-
for addr in used_addresses {
1031-
w.write(&format!("uses address {};", addr));
1032-
w.new_line()
1033-
}
1034990
for (mident, _loc) in friends.key_cloned_iter() {
1035991
w.write(&format!("friend {};", mident));
1036992
w.new_line();

move-compiler/src/expansion/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
mod aliases;
66
pub mod ast;
77
mod byte_string;
8-
mod dependency_ordering;
98
mod hex_string;
109
pub(crate) mod translate;

move-compiler/src/expansion/translate.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ pub fn program(
195195
}
196196
}
197197
}
198-
let mut module_map = source_module_map;
198+
let module_map = source_module_map;
199199

200-
let mut scripts = {
200+
let scripts = {
201201
let mut collected: BTreeMap<Symbol, Vec<E::Script>> = BTreeMap::new();
202202
for s in scripts {
203203
collected
@@ -227,7 +227,6 @@ pub fn program(
227227
keyed
228228
};
229229

230-
super::dependency_ordering::verify(context.env, &mut module_map, &mut scripts);
231230
E::Program {
232231
modules: module_map,
233232
scripts,
@@ -481,9 +480,6 @@ fn module_(
481480
attributes,
482481
loc,
483482
is_source_module: context.is_source_definition,
484-
dependency_order: 0,
485-
immediate_neighbors: UniqueMap::new(),
486-
used_addresses: BTreeSet::new(),
487483
friends,
488484
structs,
489485
constants,
@@ -650,8 +646,6 @@ fn script_(context: &mut Context, package_name: Option<Symbol>, pscript: P::Scri
650646
package_name,
651647
attributes,
652648
loc,
653-
immediate_neighbors: UniqueMap::new(),
654-
used_addresses: BTreeSet::new(),
655649
constants,
656650
function_name,
657651
function,

move-compiler/src/hlir/translate.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,19 @@ fn module(
212212
mdef: T::ModuleDefinition,
213213
) -> (ModuleIdent, H::ModuleDefinition) {
214214
let T::ModuleDefinition {
215+
loc: _,
215216
warning_filter,
216217
package_name,
217218
attributes,
218219
is_source_module,
219220
dependency_order,
221+
immediate_neighbors: _,
222+
used_addresses: _,
220223
friends,
221224
structs: tstructs,
222225
functions: tfunctions,
223226
constants: tconstants,
227+
spec_dependencies: _,
224228
} = mdef;
225229
context.env.add_warning_filter_scope(warning_filter.clone());
226230
let structs = tstructs.map(|name, s| struct_def(context, name, s));
@@ -263,9 +267,12 @@ fn script(context: &mut Context, tscript: T::Script) -> H::Script {
263267
package_name,
264268
attributes,
265269
loc,
270+
immediate_neighbors: _,
271+
used_addresses: _,
266272
constants: tconstants,
267273
function_name,
268274
function: tfunction,
275+
spec_dependencies: _,
269276
} = tscript;
270277
context.env.add_warning_filter_scope(warning_filter.clone());
271278
let constants = tconstants.map(|name, c| constant(context, name, c));

move-compiler/src/naming/ast.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ pub struct Program {
3131
pub scripts: BTreeMap<Symbol, Script>,
3232
}
3333

34+
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
35+
pub enum Neighbor_ {
36+
Dependency,
37+
Friend,
38+
}
39+
pub type Neighbor = Spanned<Neighbor_>;
40+
3441
//**************************************************************************************************
3542
// Scripts
3643
//**************************************************************************************************
@@ -45,6 +52,8 @@ pub struct Script {
4552
pub constants: UniqueMap<ConstantName, Constant>,
4653
pub function_name: FunctionName,
4754
pub function: Function,
55+
// module dependencies referenced in specs
56+
pub spec_dependencies: BTreeSet<(ModuleIdent, Neighbor)>,
4857
}
4958

5059
//**************************************************************************************************
@@ -53,18 +62,18 @@ pub struct Script {
5362

5463
#[derive(Debug, Clone)]
5564
pub struct ModuleDefinition {
65+
pub loc: Loc,
5666
pub warning_filter: WarningFilters,
5767
// package name metadata from compiler arguments, not used for any language rules
5868
pub package_name: Option<Symbol>,
5969
pub attributes: Attributes,
6070
pub is_source_module: bool,
61-
/// `dependency_order` is the topological order/rank in the dependency graph.
62-
/// `dependency_order` is initialized at `0` and set in the uses pass
63-
pub dependency_order: usize,
6471
pub friends: UniqueMap<ModuleIdent, Friend>,
6572
pub structs: UniqueMap<StructName, StructDefinition>,
6673
pub constants: UniqueMap<ConstantName, Constant>,
6774
pub functions: UniqueMap<FunctionName, Function>,
75+
// module dependencies referenced in specs
76+
pub spec_dependencies: BTreeSet<(ModuleIdent, Neighbor)>,
6877
}
6978

7079
//**************************************************************************************************
@@ -730,6 +739,15 @@ impl AstDebug for Program {
730739
}
731740
}
732741

742+
impl AstDebug for Neighbor_ {
743+
fn ast_debug(&self, w: &mut AstWriter) {
744+
match self {
745+
Neighbor_::Dependency => w.write("neighbor#dependency"),
746+
Neighbor_::Friend => w.write("neighbor#friend"),
747+
}
748+
}
749+
}
750+
733751
impl AstDebug for Script {
734752
fn ast_debug(&self, w: &mut AstWriter) {
735753
let Script {
@@ -740,12 +758,18 @@ impl AstDebug for Script {
740758
constants,
741759
function_name,
742760
function,
761+
spec_dependencies,
743762
} = self;
744763
warning_filter.ast_debug(w);
745764
if let Some(n) = package_name {
746765
w.writeln(&format!("{}", n))
747766
}
748767
attributes.ast_debug(w);
768+
for (m, neighbor) in spec_dependencies {
769+
w.write(&format!("spec_dep {m} is"));
770+
neighbor.ast_debug(w);
771+
w.writeln(";");
772+
}
749773
for cdef in constants.key_cloned_iter() {
750774
cdef.ast_debug(w);
751775
w.new_line();
@@ -757,15 +781,16 @@ impl AstDebug for Script {
757781
impl AstDebug for ModuleDefinition {
758782
fn ast_debug(&self, w: &mut AstWriter) {
759783
let ModuleDefinition {
784+
loc: _,
760785
warning_filter,
761786
package_name,
762787
attributes,
763788
is_source_module,
764-
dependency_order,
765789
friends,
766790
structs,
767791
constants,
768792
functions,
793+
spec_dependencies,
769794
} = self;
770795
warning_filter.ast_debug(w);
771796
if let Some(n) = package_name {
@@ -777,7 +802,11 @@ impl AstDebug for ModuleDefinition {
777802
} else {
778803
w.writeln("source module")
779804
}
780-
w.writeln(&format!("dependency order #{}", dependency_order));
805+
for (m, neighbor) in spec_dependencies {
806+
w.write(&format!("spec_dep {m} is"));
807+
neighbor.ast_debug(w);
808+
w.writeln(";");
809+
}
781810
for (mident, _loc) in friends.key_cloned_iter() {
782811
w.write(&format!("friend {};", mident));
783812
w.new_line();

0 commit comments

Comments
 (0)