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 3 commits
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
18 changes: 12 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 service? <text>
<actor> ::= service <id>? : (<tuptype> ->)? (<actortype> | <id>) ;?

<actortype> ::= { <methtype>;* }
Expand Down Expand Up @@ -519,20 +519,26 @@ 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 service? <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.
An import refers 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.

`import` ignores the main service definition from the imported file, while `import service` includes the main service from the imported file and merges the service definition with the main service in the importing file. There are two constraints with the main service definition in the imported file:

* The main service cannot be a service constructor.
* The methods from the imported file must not have the same method name as the importing file.

##### Example

File `A.did`:
```
type A = service { f : () -> () };
service : A
```
File `B.did`:
```
import "A.did"
import "A.did"; // Cannot use import_service because of method name duplication
chenyan-dfinity marked this conversation as resolved.
Show resolved Hide resolved
service B : A ;
```

Expand Down
Loading