2 min read

Slice files

Understand how Slice definitions are organized in Slice files.

Slice definitions must be stored in files with the .slice extension, known as Slice files. The Slice compiler ignores files with other extensions.

The Slice compiler accepts two categories of Slice files: source files and reference files. The compiler parses all these files but only generates code for the source files.

Like C# and unlike C and C++, the Slice compiler considers the definitions in all its input files and does not impose any ordering requirement. For instance, you can use a type before defining it:

slice
module Example
interface WidgetFactory {
// We can use Widget before defining it.
createWidget(name: string) -> Widget
}
struct Widget {
name: string
color: Color
}
enum Color { Blue, Red, White, Yellow }

Two files can also contain definitions with circular references, such as:

slice
// in Chicken.slice
module Coop
interface Chicken {
Egg lay()
}
slice
// in Egg.slice
module Coop
interface Egg {
Chicken hatch()
}

For C#, the Slice compiler generates a C# file (.cs) for each source Slice file. You typically compile all the Slice source files for a project in one shot.

The Slice language provides a few basic preprocessing directives for conditional compilation. For example:

slice
module VisitorCenter
interface Greeter {
greet(name: string) -> string
#if NEXT_GEN // only available in the NEXT_GEN version of Greeter
sing(songName: string) -> Sequence<uint8>
#endif
}

Slice does not provide a preprocessing directive to include or import a Slice file into another Slice file.

Was this page helpful?