Skip to content

Commit

Permalink
[move 2024] Add macro functions (MystenLabs#15928)
Browse files Browse the repository at this point in the history
## Description 

- Added support for macros in 2024.alpha
- Minor reworks to labels and blocks

TODO:

- [x] Decide on lambda type syntax 
- [x] Decide on lambda type implicit () 
- [x] Subst tparams inside macro body
- [x] Fix lvalues for lambdas (nesting and type annots)

## Test Plan 

How did you test the new or updated feature?

---
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
- [X] user-visible impact
- [X] 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

A set of changes for the Move compiler
- macro function support has been added for 2024.alpha. 
- Bug fix (and minor breaking change): Move type parameters now properly
respect the rules of restricted identifiers, similar to all other names.
- To support macros, the syntax for the type signature of lambdas has
changed. This will break any existing specs (which are no longer
supported) when moving to the new edition.
  • Loading branch information
tnowacki authored Feb 6, 2024
1 parent 3696f5f commit 5303610
Show file tree
Hide file tree
Showing 273 changed files with 8,985 additions and 1,023 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

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

8 changes: 6 additions & 2 deletions crates/workspace-hack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ prost-5ef9efb8ec2df382 = { package = "prost", version = "0.12" }
prost-a6292c17cd707f01 = { package = "prost", version = "0.11" }
prost-types = { version = "0.12" }
protobuf = { version = "2", default-features = false, features = ["with-bytes"] }
psm = { version = "0.1", default-features = false }
quanta = { version = "0.11" }
quick-error-dff4ba8e3ae991db = { package = "quick-error", version = "1", default-features = false }
quick-error-f595c2ba2a3f28df = { package = "quick-error", version = "2", default-features = false }
Expand Down Expand Up @@ -721,6 +722,7 @@ spin-d8f496e17d97b5cb = { package = "spin", version = "0.5", default-features =
spinners = { version = "4", default-features = false }
spki-3b31131e45eafb45 = { package = "spki", version = "0.6", default-features = false, features = ["pem", "std"] }
spki-ca01ad9e24f5d932 = { package = "spki", version = "0.7", default-features = false, features = ["pem", "std"] }
stacker = { version = "0.1", default-features = false }
static_assertions = { version = "1", default-features = false }
strip-ansi-escapes = { version = "0.1", default-features = false }
strsim = { version = "0.10", default-features = false }
Expand Down Expand Up @@ -1530,6 +1532,7 @@ prost-derive-5ef9efb8ec2df382 = { package = "prost-derive", version = "0.12", de
prost-derive-a6292c17cd707f01 = { package = "prost-derive", version = "0.11", default-features = false }
prost-types = { version = "0.12" }
protobuf = { version = "2", default-features = false, features = ["with-bytes"] }
psm = { version = "0.1", default-features = false }
quanta = { version = "0.11" }
quick-error-dff4ba8e3ae991db = { package = "quick-error", version = "1", default-features = false }
quick-error-f595c2ba2a3f28df = { package = "quick-error", version = "2", default-features = false }
Expand Down Expand Up @@ -1665,6 +1668,7 @@ spin-d8f496e17d97b5cb = { package = "spin", version = "0.5", default-features =
spinners = { version = "4", default-features = false }
spki-3b31131e45eafb45 = { package = "spki", version = "0.6", default-features = false, features = ["pem", "std"] }
spki-ca01ad9e24f5d932 = { package = "spki", version = "0.7", default-features = false, features = ["pem", "std"] }
stacker = { version = "0.1", default-features = false }
static_assertions = { version = "1", default-features = false }
strip-ansi-escapes = { version = "0.1", default-features = false }
strsim = { version = "0.10", default-features = false }
Expand Down Expand Up @@ -2026,7 +2030,7 @@ scrypt = { version = "0.10", default-features = false }
str-buf = { version = "1", default-features = false }
uuid-c38e5c1d305a1b54 = { package = "uuid", version = "0.8", features = ["serde", "v4"] }
widestring = { version = "0.5" }
winapi = { version = "0.3", default-features = false, features = ["cfg", "combaseapi", "consoleapi", "errhandlingapi", "evntrace", "fileapi", "handleapi", "heapapi", "ifdef", "impl-default", "in6addr", "inaddr", "ioapiset", "iphlpapi", "knownfolders", "libloaderapi", "lmaccess", "lmapibuf", "lmcons", "minwinbase", "namedpipeapi", "netioapi", "ntlsa", "ntsecapi", "ntstatus", "objbase", "objidl", "oleauto", "pdh", "powerbase", "processenv", "processthreadsapi", "profileapi", "psapi", "rpcdce", "securitybaseapi", "shellapi", "shlobj", "std", "stringapiset", "synchapi", "sysinfoapi", "wbemcli", "winbase", "wincon", "windef", "winerror", "winioctl", "winnt", "winsock2", "winuser", "ws2ipdef", "ws2tcpip", "wtypesbase"] }
winapi = { version = "0.3", default-features = false, features = ["cfg", "combaseapi", "consoleapi", "errhandlingapi", "evntrace", "fibersapi", "fileapi", "handleapi", "heapapi", "ifdef", "impl-default", "in6addr", "inaddr", "ioapiset", "iphlpapi", "knownfolders", "libloaderapi", "lmaccess", "lmapibuf", "lmcons", "minwinbase", "namedpipeapi", "netioapi", "ntlsa", "ntsecapi", "ntstatus", "objbase", "objidl", "oleauto", "pdh", "powerbase", "processenv", "processthreadsapi", "profileapi", "psapi", "rpcdce", "securitybaseapi", "shellapi", "shlobj", "std", "stringapiset", "synchapi", "sysinfoapi", "wbemcli", "winbase", "wincon", "windef", "winerror", "winioctl", "winnt", "winsock2", "winuser", "ws2ipdef", "ws2tcpip", "wtypesbase"] }
winapi-util = { version = "0.1", default-features = false }
windows-sys-b32c9ddb6d93a9d2 = { package = "windows-sys", version = "0.42", features = ["Win32_Foundation", "Win32_Networking_WinSock", "Win32_Security_Authentication_Identity", "Win32_Security_Credentials", "Win32_Security_Cryptography", "Win32_Storage_FileSystem", "Win32_System_Console", "Win32_System_IO", "Win32_System_LibraryLoader", "Win32_System_Memory", "Win32_System_Pipes", "Win32_System_SystemServices", "Win32_System_Threading", "Win32_System_WindowsProgramming", "Win32_UI_Input_KeyboardAndMouse"] }
windows-sys-c8eced492e86ede7 = { package = "windows-sys", version = "0.48", features = ["Win32_Foundation", "Win32_Globalization", "Win32_Networking_WinSock", "Win32_Security", "Win32_Storage_FileSystem", "Win32_System_Com", "Win32_System_Console", "Win32_System_Diagnostics_Debug", "Win32_System_IO", "Win32_System_Pipes", "Win32_System_Registry", "Win32_System_SystemServices", "Win32_System_Threading", "Win32_System_Time", "Win32_System_WindowsProgramming", "Win32_UI_Shell"] }
Expand Down Expand Up @@ -2061,7 +2065,7 @@ str-buf = { version = "1", default-features = false }
uuid-c38e5c1d305a1b54 = { package = "uuid", version = "0.8", features = ["serde", "v4"] }
vcpkg = { version = "0.2", default-features = false }
widestring = { version = "0.5" }
winapi = { version = "0.3", default-features = false, features = ["cfg", "combaseapi", "consoleapi", "errhandlingapi", "evntrace", "fileapi", "handleapi", "heapapi", "ifdef", "impl-default", "in6addr", "inaddr", "ioapiset", "iphlpapi", "knownfolders", "libloaderapi", "lmaccess", "lmapibuf", "lmcons", "minwinbase", "namedpipeapi", "netioapi", "ntlsa", "ntsecapi", "ntstatus", "objbase", "objidl", "oleauto", "pdh", "powerbase", "processenv", "processthreadsapi", "profileapi", "psapi", "rpcdce", "securitybaseapi", "shellapi", "shlobj", "std", "stringapiset", "synchapi", "sysinfoapi", "wbemcli", "winbase", "wincon", "windef", "winerror", "winioctl", "winnt", "winsock2", "winuser", "ws2ipdef", "ws2tcpip", "wtypesbase"] }
winapi = { version = "0.3", default-features = false, features = ["cfg", "combaseapi", "consoleapi", "errhandlingapi", "evntrace", "fibersapi", "fileapi", "handleapi", "heapapi", "ifdef", "impl-default", "in6addr", "inaddr", "ioapiset", "iphlpapi", "knownfolders", "libloaderapi", "lmaccess", "lmapibuf", "lmcons", "minwinbase", "namedpipeapi", "netioapi", "ntlsa", "ntsecapi", "ntstatus", "objbase", "objidl", "oleauto", "pdh", "powerbase", "processenv", "processthreadsapi", "profileapi", "psapi", "rpcdce", "securitybaseapi", "shellapi", "shlobj", "std", "stringapiset", "synchapi", "sysinfoapi", "wbemcli", "winbase", "wincon", "windef", "winerror", "winioctl", "winnt", "winsock2", "winuser", "ws2ipdef", "ws2tcpip", "wtypesbase"] }
winapi-util = { version = "0.1", default-features = false }
windows-sys-b32c9ddb6d93a9d2 = { package = "windows-sys", version = "0.42", features = ["Win32_Foundation", "Win32_Networking_WinSock", "Win32_Security_Authentication_Identity", "Win32_Security_Credentials", "Win32_Security_Cryptography", "Win32_Storage_FileSystem", "Win32_System_Console", "Win32_System_IO", "Win32_System_LibraryLoader", "Win32_System_Memory", "Win32_System_Pipes", "Win32_System_SystemServices", "Win32_System_Threading", "Win32_System_WindowsProgramming", "Win32_UI_Input_KeyboardAndMouse"] }
windows-sys-c8eced492e86ede7 = { package = "windows-sys", version = "0.48", features = ["Win32_Foundation", "Win32_Globalization", "Win32_Networking_WinSock", "Win32_Security", "Win32_Storage_FileSystem", "Win32_System_Com", "Win32_System_Console", "Win32_System_Diagnostics_Debug", "Win32_System_IO", "Win32_System_Pipes", "Win32_System_Registry", "Win32_System_SystemServices", "Win32_System_Threading", "Win32_System_Time", "Win32_System_WindowsProgramming", "Win32_UI_Shell"] }
Expand Down
23 changes: 23 additions & 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/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ sha3 = "0.9.1"
shell-words = "1.0.0"
simplelog = "0.9.0"
smallvec = "1.6.1"
stacker = "0.1.15"
static_assertions = "1.1.0"
syn = { version = "1.0.64", features = ["derive"] }
tempfile = "3.2.0"
Expand Down
16 changes: 12 additions & 4 deletions external-crates/move/crates/move-analyzer/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,13 @@ fn type_to_ide_string(sp!(_, t): &Type) -> String {
)
}
},
Type_::Fun(args, ret) => {
format!(
"|{}| -> {}",
type_list_to_ide_string(args),
type_to_ide_string(ret)
)
}
Type_::Anything => "_".to_string(),
Type_::Var(_) => "invalid type (var)".to_string(),
Type_::UnresolvedError => "unknown type (unresolved)".to_string(),
Expand Down Expand Up @@ -1534,7 +1541,7 @@ impl<'a> ParsingSymbolicator<'a> {
self.exp_symbols(e2);
}
E::Loop(e) => self.exp_symbols(e),
E::NamedBlock(_, seq) => self.seq_symbols(seq),
E::Labled(_, e) => self.exp_symbols(e),
E::Block(seq) => self.seq_symbols(seq),
E::ExpList(l) => l.iter().for_each(|e| self.exp_symbols(e)),
E::Assign(e1, e2) => {
Expand All @@ -1560,7 +1567,7 @@ impl<'a> ParsingSymbolicator<'a> {
}
E::Borrow(_, e) => self.exp_symbols(e),
E::Dot(e, _) => self.exp_symbols(e),
E::DotCall(e, _, vo, v) => {
E::DotCall(e, _, _, vo, v) => {
self.exp_symbols(e);
if let Some(v) = vo {
v.iter().for_each(|t| self.type_symbols(t));
Expand Down Expand Up @@ -1993,7 +2000,7 @@ impl<'a> TypingSymbolicator<'a> {
self.seq_item_symbols(&mut scope, seq_item);
}
}
FunctionBody_::Native => (),
FunctionBody_::Macro | FunctionBody_::Native => (),
}

// process return types
Expand Down Expand Up @@ -2126,7 +2133,7 @@ impl<'a> TypingSymbolicator<'a> {
self.exp_symbols(t, scope);
self.exp_symbols(f, scope);
}
E::While(cond, _, body) => {
E::While(_, cond, body) => {
self.exp_symbols(cond, scope);
self.exp_symbols(body, scope);
}
Expand Down Expand Up @@ -2219,6 +2226,7 @@ impl<'a> TypingSymbolicator<'a> {
let UseFuns {
resolved,
implicit_candidates,
color: _,
} = use_funs;

// at typing there should be no unresolved candidates (it's also checked in typing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E04001]: restricted visibility
┌─ ./sources/B.move:3:31
3 │ public fun usage(): u64 { defn::definition() }
│ ^^^^^^^^^^^^^^^^^^ Invalid call to 'A::defn::definition'
│ ^^^^^^^^^^^^^^^^^^ Invalid call to 'public(package)' visible function 'A::defn::definition'
┌─ ./sources/A.move:2:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error[E04001]: restricted visibility
┌─ ./sources/B.move:3:31
3 │ public fun usage(): u64 { defn::definition() }
│ ^^^^^^^^^^^^^^^^^^ Invalid call to 'A::defn::definition'
│ ^^^^^^^^^^^^^^^^^^ Invalid call to 'public(package)' visible function 'A::defn::definition'
┌─ ./defn/sources/A.move:2:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error[E04001]: restricted visibility
┌─ ./sources/A.move:3:31
3 │ public fun usage(): u64 { defn::definition() }
│ ^^^^^^^^^^^^^^^^^^ Invalid call to 'A::defn::definition'
│ ^^^^^^^^^^^^^^^^^^ Invalid call to 'public(package)' visible function 'A::defn::definition'
┌─ ./defn/sources/A.move:2:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ module 0x42::m {

#[allow(dead_code)]
public fun t00(): u64 {
'name: {
'name: {
return 'name 10;
20
}
}

#[allow(dead_code)]
public fun t01(): u64 {
'name: {
'name: {
'name2: {
return 'name 10;
20
Expand All @@ -23,8 +23,8 @@ module 0x42::m {

#[allow(dead_code)]
public fun t02(): u64 {
loop 'outer: {
let _x = loop 'inner: {
'outer: loop {
let _x = 'inner: loop {
break 'outer 10;
break 'inner 20
};
Expand All @@ -33,32 +33,32 @@ module 0x42::m {

#[allow(dead_code)]
public fun t03(): u64 {
loop 'outer: {
let x = loop 'inner: {
'outer: loop {
let x = 'inner: loop {
break 'inner 10
};
break 'outer x
}
}

public fun t04(cond: bool): u64 {
while (cond) 'name: {
'name: while (cond) {
break 'name
};
10
}

public fun t05(cond: bool): u64 {
loop 'outer: {
while (cond) 'body: {
'outer: loop {
'body: while (cond) {
if (cond) { break 'outer 10 };
continue 'body
}
}
}

public fun t06(cond: bool): u64 {
while (cond) 'name: {
'name: while (cond) {
return 10
};
20
Expand Down
Loading

0 comments on commit 5303610

Please sign in to comment.