-
Notifications
You must be signed in to change notification settings - Fork 20
feat(slang): complete modules and free functions #654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8bda518
feat(slang): modules
hedgar2017 bc4c7f8
refactor(slang): hold the library call qualifier in its classification
hedgar2017 92a2c63
feat(slang): dispatch namespace-qualified calls directly
hedgar2017 700cd82
refactor(slang): drop conditional module qualifiers
hedgar2017 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // RUN: solx --emit-mlir=sol %s | FileCheck %s | ||
|
|
||
| // Free functions reached only via a user-defined operator binding: solc's print-init calls | ||
| // @add yet never lowers it or its helper, so this is solx-only. | ||
|
|
||
| // CHECK: sol.func @{{.*}}f{{.*}}(%{{.*}}: si32, %{{.*}}: si32) -> si32 | ||
| // CHECK: sol.call @"add(T,T)_[[ADD:[0-9]+]]"(%{{.*}}, %{{.*}}) : (si32, si32) -> si32 | ||
| // CHECK: sol.func @"add(T,T)_[[ADD]]"(%{{.*}}: si32, %{{.*}}: si32) -> si32 | ||
| // CHECK: sol.call @"helper(T)_[[HELPER:[0-9]+]]"(%{{.*}}) : (si32) -> si32 | ||
| // CHECK: sol.func @"helper(T)_[[HELPER]]"(%{{.*}}: si32) -> si32 | ||
|
|
||
| type T is int32; | ||
| using {add as +} for T global; | ||
|
|
||
| function helper(T x) pure returns (T) { | ||
| return x; | ||
| } | ||
|
|
||
| function add(T x, T y) pure returns (T) { | ||
| return helper(x); | ||
| } | ||
|
|
||
| contract C { | ||
| function f(T x, T y) public pure returns (T) { | ||
| return x + y; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // RUN: solx --emit-mlir=sol %s | FileCheck %s | ||
| // RUN: solc --mlir-action=print-init %s 2>/dev/null | FileCheck %s | ||
|
|
||
| // CHECK: sol.func @{{.*invoke.*}}(%{{.*}}: !sol.func_ref<(ui256) -> ui256>, %{{.*}}: ui256) -> ui256 | ||
| // CHECK: sol.func @{{.*run.*}}(%{{.*}}: ui256) -> ui256 attributes {{.*}}selector = -1538984471 : i32 | ||
| // CHECK: %[[F:.*]] = sol.func_constant @{{.*increment.*}} : !sol.func_ref<(ui256) -> ui256> | ||
| // CHECK: %[[R:.*]] = sol.call @{{.*invoke.*}}(%[[F]], %{{.*}}) : (!sol.func_ref<(ui256) -> ui256>, ui256) -> ui256 | ||
| // CHECK: sol.return %[[R]] : ui256 | ||
|
|
||
| function increment(uint256 a) pure returns (uint256) { | ||
| return a + 1; | ||
| } | ||
|
|
||
| contract C { | ||
| function invoke( | ||
| function(uint256) pure returns (uint256) f, | ||
| uint256 x | ||
| ) internal pure returns (uint256) { | ||
| return f(x); | ||
| } | ||
|
|
||
| function run(uint256 x) public pure returns (uint256) { | ||
| return invoke(increment, x); | ||
| } | ||
| } | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // RUN: solx --emit-mlir=sol %s | FileCheck %s | ||
|
|
||
| // solc's print-init drops the receiver from a using-for free-function call, calling | ||
| // `@double() : ()`, while legacy forwards it, so this is solx-only. | ||
|
|
||
| // CHECK: sol.func @{{.*}}f{{.*}}(%{{.*}}: ui256) -> ui256 | ||
| // CHECK: %[[R:.*]] = sol.call @"double(uint256)_[[D:[0-9]+]]"(%{{.*}}) : (ui256) -> ui256 | ||
| // CHECK: sol.return %[[R]] : ui256 | ||
| // CHECK: sol.func @"double(uint256)_[[D]]"(%{{.*}}: ui256) -> ui256 | ||
| // CHECK: sol.cmul | ||
|
|
||
| function double(uint256 a) pure returns (uint256) { | ||
| return a * 2; | ||
| } | ||
|
|
||
| contract C { | ||
| using {double} for uint256; | ||
|
|
||
| function f(uint256 x) public pure returns (uint256) { | ||
| return x.double(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // RUN: solx --emit-mlir=sol %s | FileCheck %s | ||
| // RUN: solc --mlir-action=print-init %s 2>/dev/null | FileCheck %s | ||
|
|
||
| // CHECK: sol.func @{{.*chained.*}}() -> ui256 attributes {{.*}}selector = 1955792327 : i32 | ||
| // CHECK: %[[CK:.*]] = sol.constant 11 : ui8 | ||
| // CHECK: %[[CV:.*]] = sol.cast %[[CK]] : ui8 to ui256 | ||
| // CHECK: sol.return %[[CV]] : ui256 | ||
|
|
||
| // CHECK: sol.func @{{.*renamed.*}}() -> ui256 attributes {{.*}}selector = -1753621920 : i32 | ||
| // CHECK: %[[RA:.*]] = sol.cast %{{.*}} : ui8 to ui256 | ||
| // CHECK: %[[RC:.*]] = sol.call @{{.*freeTriple.*}}(%[[RA]]) : (ui256) -> ui256 | ||
| // CHECK: sol.return %[[RC]] : ui256 | ||
|
|
||
| // CHECK: sol.func @{{.*starred.*}}() -> ui256 attributes {{.*}}selector = -1638182610 : i32 | ||
| // CHECK: %[[SK:.*]] = sol.constant 11 : ui8 | ||
| // CHECK: %[[SV:.*]] = sol.cast %[[SK]] : ui8 to ui256 | ||
| // CHECK: sol.return %[[SV]] : ui256 | ||
|
|
||
| // CHECK: sol.func @{{.*plainCall.*}}() -> ui256 attributes {{.*}}selector = 1887173101 : i32 | ||
| // CHECK: %[[PA:.*]] = sol.cast %{{.*}} : ui8 to ui256 | ||
| // CHECK: %[[PC:.*]] = sol.call @{{.*freeTriple.*}}(%[[PA]]) : (ui256) -> ui256 | ||
| // CHECK: sol.return %[[PC]] : ui256 | ||
|
|
||
| // CHECK: sol.func @{{.*chainedCall.*}}() -> ui256 attributes {{.*}}selector = -1246699396 : i32 | ||
| // CHECK: %[[CA:.*]] = sol.cast %{{.*}} : ui8 to ui256 | ||
| // CHECK: %[[CC:.*]] = sol.call @{{.*freeTriple.*}}(%[[CA]]) : (ui256) -> ui256 | ||
| // CHECK: sol.return %[[CC]] : ui256 | ||
|
|
||
| // CHECK: sol.func @{{.*starredCall.*}}() -> ui256 attributes {{.*}}selector = -548888477 : i32 | ||
| // CHECK: %[[SA:.*]] = sol.cast %{{.*}} : ui8 to ui256 | ||
| // CHECK: %[[SC:.*]] = sol.call @{{.*freeTriple.*}}(%[[SA]]) : (ui256) -> ui256 | ||
| // CHECK: sol.return %[[SC]] : ui256 | ||
|
|
||
| // CHECK: sol.func @{{.*parenthesized.*}}() -> ui256 attributes {{.*}}selector = -923061170 : i32 | ||
| // CHECK: %[[NK:.*]] = sol.constant 11 : ui8 | ||
| // CHECK: %[[NV:.*]] = sol.cast %[[NK]] : ui8 to ui256 | ||
| // CHECK: sol.return %[[NV]] : ui256 | ||
|
|
||
| // CHECK: sol.func @{{.*qualified.*}}() -> ui256 attributes {{.*}}selector = -228858638 : i32 | ||
| // CHECK: %[[QA:.*]] = sol.cast %{{.*}} : ui8 to ui256 | ||
| // CHECK: %[[QC:.*]] = sol.call @{{.*halve.*}}(%[[QA]]) : (ui256) -> ui256 | ||
| // CHECK: sol.return %[[QC]] : ui256 | ||
|
|
||
| // CHECK: sol.func @{{.*wrapped.*}}() -> ui256 attributes {{.*}}selector = 1357319496 : i32 | ||
| // CHECK: %[[WK:.*]] = sol.constant 6 : ui8 | ||
| // CHECK: %[[WV:.*]] = sol.cast %[[WK]] : ui8 to ui256 | ||
| // CHECK: sol.return %[[WV]] : ui256 | ||
|
|
||
| import "./module_members.sol" as M; | ||
| import {FREE_K as RENAMED_K, freeTriple} from "./module_members.sol"; | ||
| import * as S from "./module_members.sol"; | ||
|
|
||
| uint256 constant FREE_K = 11; | ||
|
|
||
| type Cost is uint256; | ||
|
|
||
| function freeTriple(uint256 x) pure returns (uint256) { | ||
| return x * 3; | ||
| } | ||
|
|
||
| contract ModuleMembers { | ||
| function chained() public pure returns (uint256) { | ||
| return M.M.M.FREE_K; | ||
| } | ||
|
|
||
| function renamed() public pure returns (uint256) { | ||
| return freeTriple(RENAMED_K); | ||
| } | ||
|
|
||
| function starred() public pure returns (uint256) { | ||
| return S.FREE_K; | ||
| } | ||
|
|
||
| function plainCall() public pure returns (uint256) { | ||
| return M.freeTriple(4); | ||
| } | ||
|
|
||
| function chainedCall() public pure returns (uint256) { | ||
| return M.M.freeTriple(4); | ||
| } | ||
|
|
||
| function starredCall() public pure returns (uint256) { | ||
| return S.freeTriple(4); | ||
| } | ||
|
|
||
| function parenthesized() public pure returns (uint256) { | ||
| return (M).FREE_K; | ||
| } | ||
|
|
||
| function qualified() public pure returns (uint256) { | ||
| return M.ModuleMembers.halve(6); | ||
| } | ||
|
|
||
| function wrapped() public pure returns (uint256) { | ||
| return Cost.unwrap(M.Cost.wrap(6)); | ||
| } | ||
|
|
||
| function halve(uint256 x) internal pure returns (uint256) { | ||
| return x / 2; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // RUN: solx --emit-mlir=sol %s | FileCheck %s | ||
|
|
||
| // solc's print-init crashes on a discarded struct, error, or event name, so this is solx-only. | ||
|
|
||
| // CHECK: sol.func @{{.*structs.*}}() | ||
| // CHECK-NEXT: sol.return | ||
|
|
||
| // CHECK: sol.func @{{.*errors.*}}() | ||
| // CHECK-NEXT: sol.return | ||
|
|
||
| // CHECK: sol.func @{{.*events.*}}() | ||
| // CHECK-NEXT: sol.return | ||
|
|
||
| struct Pair { | ||
| uint256 first; | ||
| } | ||
|
|
||
| error Missing(uint256 code); | ||
|
|
||
| event Logged(uint256 code); | ||
|
|
||
| contract C { | ||
| struct Inner { | ||
| uint256 value; | ||
| } | ||
|
|
||
| error Absent(uint256 code); | ||
|
|
||
| event Traced(uint256 code); | ||
|
|
||
| function structs() public pure { | ||
| Pair; | ||
| Inner; | ||
| } | ||
|
|
||
| function errors() public pure { | ||
| Missing; | ||
| Absent; | ||
| } | ||
|
|
||
| function events() public pure { | ||
| Logged; | ||
| Traced; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.