Git Product home page Git Product logo

anza-xyz / move Goto Github PK

View Code? Open in Web Editor NEW

This project forked from move-language/move

105.0 8.0 31.0 79.7 MB

Move compiler targeting llvm supported backends

Home Page: https://discord.gg/wFgfjG9J

License: Apache License 2.0

Shell 0.41% JavaScript 1.17% Rust 66.70% TypeScript 0.34% TeX 2.01% SMT 2.11% Jupyter Notebook 0.02% Dockerfile 0.03% Solidity 0.11% Boogie 0.57% Move 25.54% C++ 0.01% LLVM 0.98% Python 0.01%

move's Introduction

This is a fork of the Move compiler with LLVM support. See the move-to-solana README for fork-specific documentation.

License Discord chat

Move logo

The Move Language

Move is a programming language for writing safe smart contracts originally developed at Facebook to power the Diem blockchain. Move is designed to be a platform-agnostic language to enable common libraries, tooling, and developer communities across diverse blockchains with vastly different data and execution models. Move's ambition is to become the "JavaScript of web3" in terms of ubiquity--when developers want to quickly write safe code involving assets, it should be written in Move.

This repository is the official home of the Move virtual machine, bytecode verifier, compiler, prover, package manager, and book. For Move code examples and papers, check out awesome-move.

Quickstart

Build the Docker Image for the Command Line Tool

docker build -t move/cli -f docker/move-cli/Dockerfile .

Build a Test Project

cd ./language/documentation/tutorial/step_1/BasicCoin
docker run -v `pwd`:/project move/cli build

Follow the language/documentation/tutorial to set up move for development.

Community

License

Move is licensed as Apache 2.0.

move's People

Contributors

bmwill avatar davidiw avatar joshlind avatar msmouse avatar meng-xu-cs avatar gregnazario avatar wrwg avatar phlip9 avatar dependabot[bot] avatar huitseeker avatar sblackshear avatar vgao1996 avatar xli avatar rexhoffman avatar zekun000 avatar dependabot-preview[bot] avatar sunshowers avatar ma2bd avatar mimoo avatar lightmark avatar sausagee avatar ankushagarwal avatar junkil-park avatar ksolana avatar emmazzz avatar metajack avatar bothra90 avatar zihaoccc avatar rustielin avatar runtian-zhou avatar

Stargazers

 avatar kaoiki avatar Lane Rettig avatar Chris avatar Datt Goswami avatar  avatar Savvy avatar  avatar Marche avatar 256hax avatar Wyatt Stanke avatar jn avatar Stone Gao avatar William Wolf avatar Adr7513 avatar ownerlesswhisper avatar Primata avatar  avatar  avatar Joe C avatar Kyle avatar Albert Hermida avatar skygp avatar gami avatar Mohan avatar pahe avatar  avatar Rafael Escrich avatar  avatar zetsukhun avatar Brandon H. Gomes avatar markon avatar  avatar LordNode avatar Shun Kakinoki avatar AboveWallStreet avatar  avatar Akmal avatar Yaorong Huang avatar Wayne Kuo avatar yuyang avatar Jason avatar PeterPham avatar Tristan NGUYEN avatar  avatar UjjwalGupta49 avatar Pratik Saria avatar 0xDeep avatar samyakt avatar Gkoran Stoilkovits avatar austbot avatar Vivek avatar Somer B. avatar chillx2land avatar Yuske Fukuyama avatar Buns Enchantress avatar Takaya Imagawa avatar  avatar Hyeongjun Yu avatar daiwanwei avatar fuyutarow avatar Amnot avatar Steven Normore avatar Son avatar dtr0x avatar Avidlearner avatar Will Pankiewicz avatar 0xrinegade avatar Will Stufflebeam avatar kishi.sol avatar Pedro Lopes avatar Brian Bates avatar POPPIN-FUMI avatar Fooooooooooox avatar Daksh avatar meowy avatar  avatar  avatar Sayantan Karmakar avatar Dwebo avatar Richard Patel avatar  avatar Dennis Antela Martinez avatar Anoushk Kharangate avatar DMan avatar Aoi Kurokawa avatar skyh24 avatar 3.141592653589793238462643383279 avatar Italo Casas avatar  avatar Chen Kai avatar  avatar Daniel Tao avatar Val Allen Samonte avatar Junandre Paul avatar Try Again avatar Tuan Pham Minh avatar Josh Wolff avatar  avatar anatoly yakovenko avatar

Watchers

 avatar Brian Anderson avatar James Cloos avatar Yihau Chen avatar  avatar  avatar  avatar Dwebo avatar

move's Issues

Run move-native tests under miri

The move-native crate contains mostly tricky unsafe code. It has a test suite that has decent but probably not complete coverage. Run these tests under miri, the rust interpreter, and fix any issues it finds.

Add target triple

To support various llvm backends. Support eBPF and X86 triples at least.

Add CI

I thought there was an issue for this but I'm not finding it.

I spent some time on this today, trying to adapt the upstream GitHub actions. I didn't quite succeed though, mostly because without a custom build of LLVM there's not much we can test, and it's not obvious to me how to do that build efficiently on CI.

Without the LLVM build we can still:

  • run cargo x lint
  • run cargo x fmt
  • run the tests for move-native

We can't run cargo x clippy or even run cargo check on move-mv-llvm-compiler

Implement vector<T>

vector is a built-in type whose layout is known to both the compiler and runtime and whose operations are implemented by the runtime, and which requires emitting type descriptors. Implementing it will unlock a bunch of stuff.

Implement basic struct / field ops

First declare all the structs, per #25

Ops likely to be involved here include: Load, BorrowField, GetField, Destroy.

Don't know yet how to destroy structs that need destructors - that will probably need to wait until we have vectors.

[Bug] ld.lld: error: undefined symbol: LLVMInitializeSBFTargetInfo

🐛 Bug

With bc7c05b cargo build failed with the following steps.

To reproduce

$ mkdir -p $HOME/sbf-tools/releases/v1.32 && cd  $HOME/sbf-tools/releases/v1.32 
$ wget https://github.com/solana-labs/sbf-tools/releases/download/v1.32/solana-bpf-tools-linux.tar.bz2
$ tar -xf  solana-bpf-tools-linux.tar.bz2
$ cd $HOME/move/language/tools/move-mv-llvm-compiler
$ export SBF_TOOLS_ROOT=$HOME/sbf-tools/releases/v1.32
$ clang -v
clang version 15.0.6 (Fedora 15.0.6-2.fc37)
$ rustc --version
rustc 1.65.0 (897e37553 2022-11-02)

$ cargo build

 = note: ld.lld: error: undefined symbol: LLVMInitializeSBFTargetInfo
          >>> referenced by llvm.rs:28 (language/tools/move-mv-llvm-compiler/src/stackless/llvm.rs:28)
          >>>               move_mv_llvm_compiler-9f44bf544af0c8f6.3mxs1fhp8ozmebsf.rcgu.o:(move_mv_llvm_compiler::stackless::llvm::initialize_sbf::h9ac631b3ed0e3818) in archive /run/media/tb_half/move/target/debug/deps/libmove_mv_llvm_compiler-9f44bf544af0c8f6.rlib
...

[Bug] Failing rbpf-tests

to repro:

$ cargo test -p move-mv-llvm-compiler --test rbpf-tests

error[E0412]: cannot find type `Option` in this scope
  --> /home/adityak/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.152/src/std_error.rs:45:25
   |
45 |     fn source(&self) -> Option<&(Error + 'static)> {
   |                         ^^^^^^ not found in this scope
   |
help: there is an enum variant `de::Unexpected::Option`; try using the variant's enum
   |
45 |     fn source(&self) -> de::Unexpected {
   |                         ~~~~~~~~~~~~~~


error[E0425]: cannot find value `None` in this scope
  --> /home/adityak/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.152/src/std_error.rs:46:9
   |
46 |         None
   |         ^^^^ not found in this scope

Some errors have detailed explanations: E0405, E0412, E0425, E0432, E0433, E0463, E0531.
error: could not compile `serde` due to 4284 previous errors
thread 'run_test::assert.move' panicked at 'running SBF cargo failed', language/tools/move-mv-llvm-compiler/tests/rbpf-tests.rs:135:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'thread 'run_test::abort.moverun_test::multi-module.move' panicked at '' panicked at 'Once instance has previously been poisonedOnce instance has previously been poisoned', ', language/tools/move-mv-llvm-compiler/tests/rbpf-tests.rslanguage/tools/move-mv-llvm-compiler/tests/rbpf-tests.rs::110110::1111

thread 'run_test::script.move' panicked at 'Once instance has previously been poisoned', language/tools/move-mv-llvm-compiler/tests/rbpf-tests.rs:test run_test::assert.move ... FAILED110
:11
test run_test::abort.move ... FAILED
test run_test::multi-module.move ... FAILED
test run_test::script.move ... FAILED

failures:
    run_test::assert.move
    run_test::abort.move
    run_test::multi-module.move
    run_test::script.move

test result: FAILED. 0 passed; 4 failed; 0 filtered out

Implement scalar constants

Move constants probably end up as Load instructions, which are already partially implemented, so implementing this may just be a matter of writing tests and filling in missing Load implementations.

move-ir-tests are probably sufficient, not rbpf-tests since we probably can't make useful assertions about it.

Add verification tests

Add initial plumbing to support mvir verification when mvir-llvm-compiler is supplied an .mvir file

Implement multiple-return

Move allows functions to return multiple values (but does not have first-class tuples). The code today has todo!s in all the multiple-return branches. It should be a relatively straightforward thing to fill in these branches.

I'm not sure about the ABI but it can probably be anything that works. If LLVM functions can return structs then just define these functions to return an anonymous struct, then the caller can copy the fields into the correct locals; let LLVM decide how structs are returned.

Translate struct definitions

The move model contains a list of struct definitions for every module. When translating the module, before translating functions, we should translate struct definitions and cache them in the module context.

Switch from BPF targets to SBF

Switch to the sbf-solana-solana target.

Per comments here #24 (comment) the solana tooling has already switched the the sbf target, so our code should use that instead.

I think this will just involve changing target triples to sbf-solana-solana and using the sbf tools instead of the bpf tools, changing the BPF_TOOLS_ROOT variable to SBF_TOOLS_ROOT.

There are some llvm features, I think +sbfv1 and +sbfv2, that I don't understand yet. Hopefully though the sbf target will turn on sbfv1 and sbfv2 is opt-in.

Report how many tests were ignored.

In the following test summary, one test was ignored but in the summary report of test result, it shows '0' filtered out tests.

running 6 tests
ignoring tests/ir-tests/small.mvir
test run_test::small.mvir ... ok
test run_test::struct-pair.mvir ... ok
test run_test::friend.mvir ... ok
test run_test::empty-module.mvir ... ok
test run_test::struct.mvir ... ok
test run_test::struct_arguments.mvir ... ok

test result: ok. 6 passed; 0 failed; 0 filtered out

Add runtime calls to builtins

Add runtime calls to builtins Resources: A Safe Language Abstraction for Money, page# 7 if there is no direct mapping to Solana Bytecode (eBPF). To start with, we can have each of the following as part of runtime library and make optimizations as needed.

- [x] local variable instructions: MvLoc ⟨x⟩ | CpLoc ⟨c⟩ | StLoc ⟨x⟩ | BorrowLoc ⟨x⟩
- [x] reference instructions: ReadRef | WriteRef | FreezeRef
- [x] record instructions: Pack | Unpack | BorrowField ⟨f ⟩
- [ ] global state instructions: MoveTo ⟨s⟩ | MoveFrom ⟨s⟩ | BorrowGlobal ⟨s⟩ | Exists ⟨s⟩
- [x] stack instructions: Pop | LoadConst ⟨a⟩ | Op
- [x] procedure instructions: Call ⟨h⟩ | Ret

move-mv-llvm-compiler driver

Driver program for move-bytecode frontend. move-mv-llvm-compiler takes move-bytecode as input and targets llvm supported back ends.

/target/debug/move-mv-llvm-compiler -b function.mv -o a

Create a standalone driver program to take .mv. Add the following options to start with.

move stackless bytecode integration

  • Scaffolding to use stackless bytecode as starting point for lowering to llvm-ir
    • Interface to llvm context
    • Abstraction for llvm module
    • Lower function declaration and return type
  • Write llvm-ir to file
  • Documentation of command line interface
  • Test harness

Compile and link move-native runtime in rbpf test harness

To test in rbpf, move programs need to call a few runtime functions, particularly abort and logging functions. The rbpf test harness should compile the move-native crate (in my move-native branch) to a C static library, and include it in the link step.

Ensure that calls to move_rt_abort work, and extend the test harness to understand expected aborts.

[Bug] Test harness should be able to process different file types and pass .mv file to the compiler.

🐛 Bug

We have .move, .mvir, and .mv files. The test harness should be able to invoke the right tools for each of these and invoke the compiler with the .mv files.

To reproduce

Code snippet to reproduce

# Your code goes here
# Please make sure it does not require any external dependencies

Stack trace/error message

// Paste the output here

Expected Behavior

System information

Please complete the following information:

Additional context

Add any other context about the problem here.

Teach rbpf-tests and move-mv-llvm-compiler to understand module dependencies

A single .move file may contain multiple modules, and to run rbpf tests that actually call functions will require multiple modules - the rbpf test harness runs scripts, and scripts are modules with only a single function, so calling another function will require a move file with both a script and a module.

The move model allows multiple bytecode files to be loaded at once, but they have to be topologically sorted. The test harness calls move-build to generate move modules, and it'll have get the dependency list from it somehow and pass it to move-mv-llvm-compiler.

Figuring out how to do this is a big indicator of whether we can manage to do the compilation based only on bytecode without immediate access to the source.

Implement basic address ops without global storage

Address is a primitive type that can be copied around and passed as arguments. Implement that much.

Move supports addresses of multiple sizes depending on configuration, so make sure to take that into account. The address size is also dependent on the chain, so make sure to make it conditional on the target. Solana addresses are 32 bytes. Address has a layout known to the runtime - u8 array of the target-specific length, defined in move_native::rt_types::Address.

Don't try to figure out global storage yet, and the exists, borrow_global, borrow_global_mut, move_from, move_to ops. Unclear what we're going to do with that yet.

Add a test mode where all failing tests are run.

Known failing tests will be added to help contributors work on specific tasks. Once that task is done the failing test will be enabled. In the mean time developers should be able to run those with a flag that is passed to cargo test

Implement scalar ops

Only the most basic scalar ops are implemented. It should be straightforward to fill in all of them.

Implement the simplest generic function

Probably we want to monomorphise generics.

It would be nice to do this in two passes: before translating functions discover all the instantiations of generic functions, do type substitutions, emit their declarations and cache them in a way the callers can retrieve; then translate the type-substituted functions along with all the non-generic functions.

If it's not possible to discover all the instances ahead of time, then we can emit and cache them at the same time as emitting their callers.

Just get the most basic thing working as a proof of concept. I don't know the best patterns for monomorphization so it may help to study the rust compiler for a while to see how they are doing it now.

make test target dependent on the binaries they require

Currently, build and test are independent of each other. So one has to run the following for testing.

cargo build -p move-ir-compiler
cargo test --test ir-tests

This isn't ideal and may result issues later. We should make cargo test dependent on cargo build such that before testing, the required targets are build.

Parse globals

Top level tasks to parse global decls (structs, functions etc)

Cargo test for move-mv-llvm-compiler unit tests

Running cargo test in move/language/tools/move-mv-llvm-compiler should do the following
For each .mvir file in move/language/tools/move-mv-llvm-compiler/tests

  • Generate move bytecode from move-ir (move-ir-compiler -m a.mvir)
  • Generate bitcode file from move ($MOVE_HOME/target/debug/move-mv-llvm-compiler -b a.mv)
  • Add assertions as applicable (e.g., assert(FunctionName == "my_fun")
  • Print cargo test stats

Translate function declaration before translating functions

At the moment function declarations are translated immediately prior to translating the function bodies. Instead, so that functions can call other functions, all function declarations should be translated first, their definitions cached in the module context; then the function bodies translated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.