-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: Reviewing Code, More Documents and Make Notes for Module System (
- Loading branch information
Showing
20 changed files
with
130 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# lsp-test-lib | ||
|
||
This is the test resource for ids-lsp, | ||
some tests may highly depend on the content of certain file, | ||
you may need to fix those test after modifying test resource. | ||
In order to minimize the troubles, please append (rather than insert) | ||
code to the end of file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,63 @@ | ||
# Aya 的 Module 设计 | ||
|
||
## Module 的名称 | ||
## ModulePath | ||
|
||
Module 的名称是一个满足 `weakId(::weakId)*` 的字符串,双冒号并不意味着嵌套关系。 | ||
ModulePath 是一个模块的绝对路径,它通常是以某个库为根到特定模块的物理路径。使用双冒号分隔每个路径的组成部分。 | ||
|
||
## Module 的嵌套 | ||
```aya | ||
// 导入 arith/nat.aya 模块 | ||
import arith::nat | ||
``` | ||
|
||
Module 名称中的双冒号(在编译器内部)并不总是意味着嵌套关系。 | ||
实际上,如果我们声明了一个名字为 `A` 的 module,并且在 `A` 中声明了一个名字为 `B` 的 module。 | ||
当我们导入 `A` 时(实际上已经自动导入了),我们其实导入了: | ||
## ModuleName | ||
|
||
* 名字为 `A` 的 module | ||
* 名字为 `A::B` 的 module | ||
尽管 ModuleName 和 ModulePath 有完全相同的表达式(用双冒号分隔),但 ModuleName 指的是在特定模块中,对某个模块的赋予的名字。 | ||
要注意的是,在这种情况下,双冒号不总是表达包含关系(尽管在正常的使用过程中,用户绝不可能构造出没有包含关系的 ModuleName)。 | ||
|
||
理论上(至少在 module 的设计上),我们完全可以直接定义一个名字为 `A::B` 而不需要去在 `A` module 中定义 `B` | ||
module(不过就无法在 `B` 中享受 `A` 的作用域了,但这并不是重点) | ||
```aya | ||
// 以默认名称 arith::nat 导入 arith/nat.aya 模块 | ||
import arith::nat | ||
// 导入 arith::nat 模块中的所有符号和模块。 | ||
open arith::nat | ||
``` | ||
|
||
## Module 的导入 | ||
## 上下文 | ||
|
||
当我们导入一个 module 时,我们同时也会导入这个 module 所导出的所有 module。 | ||
正如上一节所示,我们导入 `A` module 时,同时也以名字 `A::B` 导入了它(自动)导出的 `B` module。 | ||
如果一个名字为 `A::B` 的 module 导出了名字为 `C::D` 的 module:当我们导入 `A::B` 时,同时也会以名字 `A::B::C::D` | ||
导入 `C::D`; | ||
而到底是 `A::B::C` 中的 `D` 模块还是 `A` 中的 `B::C::D` 模块或是其他的,我们完全不关心。 | ||
由于 aya 的 tyck 具有顺序,因此我们不能在没有导入某个模块的情况下使用其内部的符号或模块。 | ||
|
||
## Module 的歧义 | ||
## 歧义 | ||
|
||
当我们(直接或间接)导入的 module 所使用的名称与现有的 module 冲突,便发生了歧义。 | ||
如果这两个 Module 是同一个 Module,那么歧义便失去了它的意义,因此 Aya 不会为此困扰。 | ||
反之,Aya 会报告一个错误。 | ||
在使用 `open` 时,通常会遇到歧义:`open` 的多个模块中有相同名字的符号,或者是当前模块中定义的符号与 `open` 导入的符号有相同的名字。 | ||
为了更简单地解决这个问题,我们要求模块不能导出歧义的符号(但只要不导出,模块中是可以有相同名字的符号的)。 | ||
|
||
```aya | ||
// 假设 foo 和 bar 都定义了符号 baz | ||
public open import arith::nat::foo | ||
// public open import arith::nat::bar // 报错:名字 baz 不能再被导出 | ||
open import arith::nat::bar // 没有问题 | ||
// def = baz // 报错:我们不清楚要用哪个 baz | ||
def = arith::nat::foo::baz // 没有问题 | ||
``` | ||
|
||
为了通过提供模块名来解决符号的歧义问题,我们需要模块名不能歧义 | ||
(也许我们可以通过其他方式来解决模块名的歧义,但那样得不偿失,我们通常不会有歧义的模块名,即使有,也可以通过重命名解决) | ||
|
||
> 如果涉及歧义的所有符号名都指向同一个符号,就不会有报错 | ||
## 导入与开放 | ||
|
||
在导入/开放时,我们可以提供一些参数来影响它们的行为。 | ||
|
||
```aya | ||
// 以名称 nat 导入 arith/nat.aya 模块 | ||
import arith::nat as nat | ||
// 将 nat 中除了 + 外的所有符号和模块导入当前模块 | ||
open nat hiding (+) | ||
// 将 nat 中的 + 符号以名字 plus 导入当前模块 | ||
open nat using (+ as plus) | ||
``` | ||
|
||
一般来说,用户是可以重复 `open` 同一个模块的。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.