move-language / move

Apache License 2.0
2.26k stars 688 forks source link

[Design Task] Guidelines and tooling support for Move code portability #100

Open sblackshear opened 2 years ago

sblackshear commented 2 years ago

Move compatibility in general. There were already some compatibility challenges due to differences in frameworks (e.g., libraries that depend on DiemAccount aren't compatible with ones that depend on StarcoinAccount), and Sui Move's data model that differs from core Move's global storage will throw another wrench in the works. Some incompatibility is to be expected given the nature of Move (a platform-independent language that gives platform designers a lot of flexibility to customize both the Move runtime and libraries for their platform). But of course, we should still strive for as much compatibility as possible and suggest best practices that will help with this.

Some early thoughts on this:

I'm not sure whether this tiering system should just be an informal guideline, or also something that we try to enforce programmatically in the package system and/or linters. It's worth noting that packages are not organized according to this tiering system today, although some are close (e.g., there's very little global storage used in the Move stdlib). But the overwhelming tendency is toward monolithic tier 6 packages, which I think we should change.

Once we have reorganized packages using these principles, I think there will be a lot more boxes in your diagram above, but the tiering system will make it easier to figure out where we can/should draw dependency arrows and where we shouldn't.

(copied from original discussion in https://github.com/diem/move/issues/91)

tnowacki commented 2 years ago

I think you might want to flip tier 4-5? I feel like you might want to itnroduce storage concepts before you do entry points

I think the tier system definitely seems expressive, but maybe overkill for a package system. Thoughts on just splitting it into: "Library", "X-Library" where X is some instantiation of Move (Sui, Diem, etc), or "X-Application" I think

I the short term we could at least enforce a "library" annotation in the package system, that checks against natives (outside of those in the stdlib?), globals, entries, etc.

jolestar commented 2 years ago

How to define the tier is a challenge.

Option 1: Like Rust, a project is a workspace, which corresponds to an address in Move, and there are many crates in a project which correspond to packages in Move. A project can depend on another project's sub-crates.

Option 2: Like Solidity, we distinguish between contract and library, and the library can only include stateless modules and will be embedded in the binary of contract when packaging. This can solve the dependency problem of pure util library(tire 1), but the disadvantage is that duplicate binary wastes state space on the chain.

Before finding a good tier solution, we can figure out how to share stdlib. Currently, Move stdlib is embedded in the x-framework in different projects and shares the 0x1 address with the framework.

Maybe stdlib can use the reserved address 0x0 and load it directly from the VM. Using the 0x0 address also can avoid module name conflicts between stdlib and x-framework.