Skip to content

Proposal: Union of Worlds #169

@Mossaka

Description

@Mossaka

I want to raise this issue to propose a new syntax for the union of Worlds. The primary motivation for this proposal is that we want to be able to form a more compresive world by unionizing / combining multiple worlds together to form a bigger one. Concretly, this is motivated by the wasi-cloud-core proposal, which tries to define a new World that includes all the wasi-cloud worlds as to provide a feature set that allows a serverless / edge function to do state management or message exchanging.

Proposal

This proposal adds a new syntax include <world-path> in World definition. Below are a few examples/sketches showing how the include syntax would work.

Union of two Worlds

// worlds.wit
world my-world-1 {
    import a: self.a
    import b: self.b
    export c: self.c
}

world my-world-2 {
    import foo: self.foo
    import bar: self.bar
    export baz: self.baz
}

world union-my-world {
     include self.my-world-1
     include self.my-world-2
}

is equivalent to

world union-my-world {
    import a: self.a
    import b: self.b
    export c: self.c
    import foo: self.foo
    import bar: self.bar
    export baz: self.baz
}

Include a World that has package and inline imports

Notice that the inline export has been "copied" over to the World that includes this World.

// b.wit
interface b { ... }

// a.wit
interface a { ... }

world my-world-1 {
    import a: self.a 
    import b: pkg.b
    import c: io.c // external package
    export d: interface exp { ... }
}

// union.wit

world union-my-world-1 {
    include pkg.my-world-1
}

is equivalent to

world union-my-world-1 {
    import a: pkg.a
    import b: pkg.b
    import c: io.c
    export d: interface exp { ... }
}

Name Conflicts

This is a more challenging example where the two Worlds being included have name conflicts. The solution to this is to use with syntax and aliasing to avoid conflicts of names. The with syntax is only used to avoid name conflicts for those names that are in conflict with another World. The names that are not in conflicts should stay the same and need not to be specified in the with scope.

// my-world-1.wit
world my-world-1 {
    import a: self.a
    import b: self.b
    export d: self.d
}

// my-world-2.wit
world my-world-2 {
    import a: self.a
    import b: self.b
    export c: self.c
}

// union.wit
world union-my-world {
    include pkg.my-world-1 with { a as a1, b as b1 }
    include pkg.my-world-2
}

is equivalent to:

world union-my-world {
    // resolve conflicts
    import a1: pkg.my-world-1.a
    import b1: pkg.my-world-1.b
    export d: pkg.my-world-1.d

    import a: pkg.my-world-2.a
    import b: pkg.my-world-2.b
    export c: pkg.my-world-2.c
}

De-duplication

When imports and exports of union-ing of multi-worlds have the same definitions, they will be deduplicated.

// a.wit
// b.wit
// c.wit

// my-world-1.wit
world my-world-1 {
    import a: pkg.a
    import b: pkg.b
    export c: pkg.c
}

// my-world-2.wit
world my-world-2 {
    import a: pkg.a
    import b: pkg.b
    export c: pkg.c
}

// union.wit
world union-my-world {
    include pkg.my-world-1
    include pkg.my-world-2
}

is equivalent to 

world union-my-world {
    import a: pkg.a
    import b: pkg.b
    export c: pkg.c
}

Let me know your thoughts on this design! @lukewagner @fibonacci1729 @alexcrichton

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions