Skip to content
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
8 changes: 8 additions & 0 deletions third_party/move/move-compiler-v2/src/experiments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ pub static EXPERIMENTS: Lazy<BTreeMap<String, Experiment>> = Lazy::new(|| {
.to_string(),
default: Given(false),
},
Experiment {
name: Experiment::COMPILE_FOR_TESTING.to_string(),
description: "Compile for testing. If set, constant \
`__COMPILE_FOR_TESTING__` will be true, otherwise false."
.to_string(),
default: Given(false),
},
];
experiments
.into_iter()
Expand All @@ -305,6 +312,7 @@ impl Experiment {
pub const CFG_SIMPLIFICATION: &'static str = "cfg-simplification";
pub const CHECKS: &'static str = "checks";
pub const CMP_REWRITE: &'static str = "cmp-rewrite";
pub const COMPILE_FOR_TESTING: &'static str = "compile-for-testing";
pub const DEAD_CODE_ELIMINATION: &'static str = "dead-code-elimination";
pub const DUPLICATE_STRUCT_PARAMS_CHECK: &'static str = "duplicate-struct-params-check";
pub const FAIL_ON_WARNING: &'static str = "fail-on-warning";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
processed 5 tasks
task 0 lines 1-30: publish [module 0x66::m {]
task 1 lines 32-32: run 0x66::m::compile_for_testing
task 2 lines 34-34: run 0x66::m::min_max
task 3 lines 36-43: publish [module 0x66::shadow {]
task 4 lines 45-45: run 0x66::shadow::shadowed
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//# publish
module 0x66::m {
fun compile_for_testing() {
// We are NOT compiling for testing, so expect this to be false. See independent
// compile_for_testing test.
assert!(!__COMPILE_FOR_TESTING__, 66);
}

fun min_max() {
assert!(MAX_U8 == 255, 1);
assert!(MAX_U16 == 65535, 1);
assert!(MAX_U32 == 4294967295, 1);
assert!(MAX_U64 == 18446744073709551615, 1);
assert!(MAX_U128 == 340282366920938463463374607431768211455, 1);
assert!(MAX_U256 == 115792089237316195423570985008687907853269984665640564039457584007913129639935, 1);

assert!(MIN_I8 == -128, 1);
assert!(MAX_I8 == 127, 1);
assert!(MIN_I16 == -32768, 1);
assert!(MAX_I16 == 32767, 1);
assert!(MIN_I32 == -2147483648, 1);
assert!(MAX_I32 == 2147483647, 1);
assert!(MIN_I64 == -9223372036854775808, 1);
assert!(MAX_I64 == 9223372036854775807, 1);
assert!(MIN_I128 == -170141183460469231731687303715884105728, 1);
assert!(MAX_I128 == 170141183460469231731687303715884105727, 1);
assert!(MIN_I256 == -57896044618658097711785492504343953926634992332820282019728792003956564819968, 1);
assert!(MAX_I256 == 57896044618658097711785492504343953926634992332820282019728792003956564819967, 1);
}
}

//# run 0x66::m::compile_for_testing

//# run 0x66::m::min_max

//# publish
module 0x66::shadow {
const MAX_U8: bool = false;

fun shadowed() {
assert!(!MAX_U8, 66);
}
}

//# run 0x66::shadow::shadowed
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//**** Cross-compiled for `move` syntax from `tests/constants/builtin_constants.move`

//# publish
module 0x66::m {
fun compile_for_testing() {
()
}
fun min_max() {
()
}
}


//# run 0x66::m::compile_for_testing

//# run 0x66::m::min_max

//# publish
module 0x66::shadow {
fun shadowed() {
()
}
}


//# run 0x66::shadow::shadowed
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
processed 5 tasks
task 0 lines 3-11: publish [module 0x66::m {]
task 1 lines 14-14: run 0x66::m::compile_for_testing
task 2 lines 16-16: run 0x66::m::min_max
task 3 lines 18-23: publish [module 0x66::shadow {]
task 4 lines 26-26: run 0x66::shadow::shadowed
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//# publish --print-bytecode
module 0x66::m {
fun run() {
if (__COMPILE_FOR_TESTING__) abort 1 else abort 2
}
}

//#run 0x66::m::run
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
processed 2 tasks
task 0 lines 1-6: publish --print-bytecode [module 0x66::m {]

== BEGIN Bytecode ==
// Bytecode version v9
module 0x66::m
// Function definition at index 0
fun run()
branch l0
ld_u64 1
abort
l0: ld_u64 2
abort


== END Bytecode ==
task 1 lines 8-8: run 0x66::m::run
Error: Function execution failed with VMError: {
major_status: ABORTED,
sub_status: Some(2),
location: 0x66::m,
indices: [],
offsets: [(FunctionDefinitionIndex(0), 4)],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
processed 2 tasks
task 0 lines 1-6: publish --print-bytecode [module 0x66::m {]

== BEGIN Bytecode ==
// Bytecode version v9
module 0x66::m
// Function definition at index 0
fun run()
ld_u64 1
abort
ld_u64 2
abort


== END Bytecode ==
task 1 lines 8-8: run 0x66::m::run
Error: Function execution failed with VMError: {
major_status: ABORTED,
sub_status: Some(1),
location: 0x66::m,
indices: [],
offsets: [(FunctionDefinitionIndex(0), 1)],
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const COMMON_EXCLUSIONS: &[&str] = &[
"/no-recursive-check/",
"/no-access-check/",
"/no-recursive-type-check/",
"/testing-constant/",
];

/// Note that any config which has different output for a test directory
Expand Down Expand Up @@ -139,6 +140,24 @@ const TEST_CONFIGS: &[TestConfig] = &[
exclude: &[],
cross_compile: false,
},
TestConfig {
name: "testing-constant-true",
runner: |p| run(p, get_config_by_name("testing-constant-true")),
experiments: &[(Experiment::COMPILE_FOR_TESTING, true)],
language_version: LanguageVersion::latest(),
include: &["/testing-constant/"],
exclude: &[],
cross_compile: false,
},
TestConfig {
name: "testing-constant-false",
runner: |p| run(p, get_config_by_name("testing-constant-false")),
experiments: &[(Experiment::COMPILE_FOR_TESTING, false)],
language_version: LanguageVersion::latest(),
include: &["/testing-constant/"],
exclude: &[],
cross_compile: false,
},
];

/// Test files which must use separate baselines because their result
Expand Down Expand Up @@ -178,6 +197,8 @@ const SEPARATE_BASELINE: &[&str] = &[
"misc/bug_14817_extended.move",
// run in verbose mode to unveil the exact error messages
"/signed-int/",
// different expected result
"/testing-constant/",
];

fn get_config_by_name(name: &str) -> TestConfig {
Expand Down
8 changes: 8 additions & 0 deletions third_party/move/move-model/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3065,6 +3065,14 @@ impl ModuleName {
ModuleName(addr, name)
}

/// Returns builtin module name.
pub fn builtin_module(env: &GlobalEnv) -> Self {
Self::new(
Address::Numerical(AccountAddress::ZERO),
env.symbol_pool().make("$$"),
)
}

pub fn from_address_bytes_and_name(
addr: legacy_move_compiler::shared::NumericalAddress,
name: Symbol,
Expand Down
Loading
Loading