Skip to content

Commit

Permalink
Thoroughly fix Issue 8875: Error out in compilation when encounter an…
Browse files Browse the repository at this point in the history
… unknown attribute (#9229)

Fix issue-8875 thoroughly: warning for unknown attributes, add --skip-attribute-check flag.  Omit warning on aptos_std library files, to avoid warning on some existing code.

A few tangential fixes:

* [third party/.../test, compiler] Fix Move.toml files to point to local files instead of network to avoid tests using old stdlib.  Oddly, this requires fixes to capitalization of std.  Fix the resolution warning to make it clear that std needs to be uncapitalized.

* [compiler] Hack to move-compiler to avoid warning about unknown attributes in aptos_std=0x1.
This avoids surprising warning on currently deployed library code.

* [compiler] test cases and stdlib source code updates for attributes checks PR

* [aptos stdlib] Now that we have verified that the move-compiler Aptos stdlib hack works, fix stdlib to use #[test_only] on test helper functions instead of #[testonly].  Leave struct attributes since it's a deployment problem to make it disappear.
  • Loading branch information
brmataptos authored Aug 16, 2023
1 parent 5528e35 commit 6fd6799
Show file tree
Hide file tree
Showing 136 changed files with 1,392 additions and 339 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use move_transactional_test_runner::{
use move_vm_runtime::session::SerializedReturnValues;
use once_cell::sync::Lazy;
use std::{
collections::{BTreeMap, HashMap},
collections::{BTreeMap, BTreeSet, HashMap},
convert::TryFrom,
fmt,
path::Path,
Expand Down Expand Up @@ -294,6 +294,7 @@ static PRECOMPILED_APTOS_FRAMEWORK: Lazy<FullyCompiledProgram> = Lazy::new(|| {
deps,
None,
move_compiler::Flags::empty().set_sources_shadow_deps(false),
aptos_framework::extended_checks::get_all_attribute_names(),
)
.unwrap();
match program_res {
Expand Down Expand Up @@ -551,6 +552,10 @@ impl<'a> MoveTestAdapter<'a> for AptosTestAdapter<'a> {
self.default_syntax
}

fn known_attributes(&self) -> &BTreeSet<String> {
aptos_framework::extended_checks::get_all_attribute_names()
}

fn init(
default_syntax: SyntaxChoice,
_comparison_mode: bool,
Expand Down
3 changes: 1 addition & 2 deletions aptos-move/aptos-vm-benchmarks/samples/add-numbers/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
name = 'add-numbers'
version = '1.0.0'
[dependencies.AptosFramework]
git = 'https://github.com/aptos-labs/aptos-core.git'
rev = 'main'
local = '../../../..'
subdir = 'aptos-move/framework/aptos-framework'
34 changes: 0 additions & 34 deletions aptos-move/framework/aptos-stdlib/doc/math128.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Standard math utilities missing in the Move Language.
- [Function `log2_64`](#0x1_math128_log2_64)
- [Function `sqrt`](#0x1_math128_sqrt)
- [Function `ceil_div`](#0x1_math128_ceil_div)
- [Function `assert_approx_the_same`](#0x1_math128_assert_approx_the_same)
- [Specification](#@Specification_1)
- [Function `max`](#@Specification_1_max)
- [Function `min`](#@Specification_1_min)
Expand Down Expand Up @@ -414,39 +413,6 @@ Returns square root of x, precisely floor(sqrt(x))



</details>

<a name="0x1_math128_assert_approx_the_same"></a>

## Function `assert_approx_the_same`

For functions that approximate a value it's useful to test a value is close
to the most correct value up to last digit


<pre><code>#[testonly]
<b>fun</b> <a href="math128.md#0x1_math128_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u128)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="math128.md#0x1_math128_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u128) {
<b>if</b> (x &lt; y) {
<b>let</b> tmp = x;
x = y;
y = tmp;
};
<b>let</b> mult = <a href="math128.md#0x1_math128_pow">pow</a>(10, precission);
<b>assert</b>!((x - y) * mult &lt; x, 0);
}
</code></pre>



</details>

<a name="@Specification_1"></a>
Expand Down
34 changes: 0 additions & 34 deletions aptos-move/framework/aptos-stdlib/doc/math64.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Standard math utilities missing in the Move Language.
- [Function `log2`](#0x1_math64_log2)
- [Function `sqrt`](#0x1_math64_sqrt)
- [Function `ceil_div`](#0x1_math64_ceil_div)
- [Function `assert_approx_the_same`](#0x1_math64_assert_approx_the_same)
- [Specification](#@Specification_1)
- [Function `max`](#@Specification_1_max)
- [Function `min`](#@Specification_1_min)
Expand Down Expand Up @@ -369,39 +368,6 @@ Returns square root of x, precisely floor(sqrt(x))



</details>

<a name="0x1_math64_assert_approx_the_same"></a>

## Function `assert_approx_the_same`

For functions that approximate a value it's useful to test a value is close
to the most correct value up to last digit


<pre><code>#[testonly]
<b>fun</b> <a href="math64.md#0x1_math64_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u64)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="math64.md#0x1_math64_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u64) {
<b>if</b> (x &lt; y) {
<b>let</b> tmp = x;
x = y;
y = tmp;
};
<b>let</b> mult = (<a href="math64.md#0x1_math64_pow">pow</a>(10, precission) <b>as</b> u128);
<b>assert</b>!((x - y) * mult &lt; x, 0);
}
</code></pre>



</details>

<a name="@Specification_1"></a>
Expand Down
34 changes: 0 additions & 34 deletions aptos-move/framework/aptos-stdlib/doc/math_fixed.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Standard math utilities missing in the Move Language.
- [Function `mul_div`](#0x1_math_fixed_mul_div)
- [Function `exp_raw`](#0x1_math_fixed_exp_raw)
- [Function `pow_raw`](#0x1_math_fixed_pow_raw)
- [Function `assert_approx_the_same`](#0x1_math_fixed_assert_approx_the_same)


<pre><code><b>use</b> <a href="../../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
Expand Down Expand Up @@ -294,39 +293,6 @@ Specialized function for x * y / z that omits intermediate shifting



</details>

<a name="0x1_math_fixed_assert_approx_the_same"></a>

## Function `assert_approx_the_same`

For functions that approximate a value it's useful to test a value is close
to the most correct value up to last digit


<pre><code>#[testonly]
<b>fun</b> <a href="math_fixed.md#0x1_math_fixed_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u128)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="math_fixed.md#0x1_math_fixed_assert_approx_the_same">assert_approx_the_same</a>(x: u128, y: u128, precission: u128) {
<b>if</b> (x &lt; y) {
<b>let</b> tmp = x;
x = y;
y = tmp;
};
<b>let</b> mult = <a href="math128.md#0x1_math128_pow">math128::pow</a>(10, precission);
<b>assert</b>!((x - y) * mult &lt; x, 0);
}
</code></pre>



</details>


Expand Down
34 changes: 0 additions & 34 deletions aptos-move/framework/aptos-stdlib/doc/math_fixed64.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Standard math utilities missing in the Move Language.
- [Function `mul_div`](#0x1_math_fixed64_mul_div)
- [Function `exp_raw`](#0x1_math_fixed64_exp_raw)
- [Function `pow_raw`](#0x1_math_fixed64_pow_raw)
- [Function `assert_approx_the_same`](#0x1_math_fixed64_assert_approx_the_same)


<pre><code><b>use</b> <a href="../../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
Expand Down Expand Up @@ -289,39 +288,6 @@ Specialized function for x * y / z that omits intermediate shifting



</details>

<a name="0x1_math_fixed64_assert_approx_the_same"></a>

## Function `assert_approx_the_same`

For functions that approximate a value it's useful to test a value is close
to the most correct value up to last digit


<pre><code>#[testonly]
<b>fun</b> <a href="math_fixed64.md#0x1_math_fixed64_assert_approx_the_same">assert_approx_the_same</a>(x: u256, y: u256, precission: u128)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="math_fixed64.md#0x1_math_fixed64_assert_approx_the_same">assert_approx_the_same</a>(x: u256, y: u256, precission: u128) {
<b>if</b> (x &lt; y) {
<b>let</b> tmp = x;
x = y;
y = tmp;
};
<b>let</b> mult = (<a href="math128.md#0x1_math128_pow">math128::pow</a>(10, precission) <b>as</b> u256);
<b>assert</b>!((x - y) * mult &lt; x, 0);
}
</code></pre>



</details>


Expand Down
Loading

0 comments on commit 6fd6799

Please sign in to comment.