Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: allow import to merge service definitions #504

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions spec/Candid.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Candid Specification

Version: 0.1.6
Version: 0.1.7

Date: August 29, 2023
Date: Dec 12, 2024

## Motivation

Expand Down Expand Up @@ -64,7 +64,7 @@ The purpose of an IDL is defining the signature, and thereby the *type* of an ac
This is a summary of the grammar proposed:
```
<prog> ::= <def>;* <actor>?
<def> ::= type <id> = <datatype> | import <text>
<def> ::= type <id> = <datatype> | import <text> | import* <text>
chenyan-dfinity marked this conversation as resolved.
Show resolved Hide resolved
<actor> ::= service <id>? : (<tuptype> ->)? (<actortype> | <id>) ;?

<actortype> ::= { <methtype>;* }
Expand Down Expand Up @@ -519,20 +519,25 @@ type B = A; // error: cyclic type definition
In order to allow splitting interface definitions up into multiple files or share common definitions between multiple interfaces, *import* declarations are provided.

```
<def> ::= ... | import <text>
<def> ::= ... | import <text> | import* <text>
```

An import refers to another interface file by URL. The semantics is that of textual inclusion, except that definitions from the imported file must not refer to definitions from the importing file.
There are two forms of import: `import` and `import*`. Both `import` and `import*` refer to another interface file by URL. The type definitions from the imported file are textually included in the importing file. The definitions from the imported file must not refer to definitions from the importing file.
chenyan-dfinity marked this conversation as resolved.
Show resolved Hide resolved

In addition, `import*` includes the main service from the imported file and merges the service definition with the main service in the importing file. The methods in the imported file must not have the same name as the importing file.

`import` ignores the main service definition from the imported file.

##### Example

File `A.did`:
```
type A = service { f : () -> () };
service : A
```
File `B.did`:
```
import "A.did"
import "A.did"; // Cannot use import* because of method name duplication
service B : A ;
```

Expand Down
Loading