removed complicated features

This commit is contained in:
pca006132 2020-12-16 15:19:35 +08:00 committed by pca006132
parent c99fe43217
commit e7839efdc0

View File

@ -51,9 +51,6 @@ class Foo(EnvExperiment):
* No implicit coercion, require implicit cast. Integers are int32 by default,
floating point numbers are double by default.
* RPCs: optional parameter type signature, require return type signature.
* Function pointer is supported.
* Method pointer is a fat pointer (function pointer + object pointer), and
subject to lifetime check.
## Generics
We use [type variable](https://docs.python.org/3/library/typing.html#typing.TypeVar) for denoting generics.
@ -70,12 +67,10 @@ class Foo(EnvExperiment):
return a == b
```
* Type variables can only be used in functions/methods, but not in class fields.
* Type variable can be limited to a fixed set of types. A shorthand for one-time
type variable limited to a fixed set of types is [union type & optional type](https://docs.python.org/3/library/typing.html#typing.Union).
e.g. `def run(self, a: Union[int, str])`
* Type variables support bounded generic, so we can access attributes of the
variable that are present in the boundary type, the type instantiated must be
the subtype of the boundary type. See [PEP484](https://www.python.org/dev/peps/pep-0484/#type-variables-with-an-upper-bound) for details.
* Type variables are invariant, same as the default in Python. We disallow
covariant or contravariant. The compiler should mark as error if it encounters
a type variable used in kernel that is declared covariant or contravariant.
@ -118,10 +113,16 @@ bar([Base(), Derived()])
Dynamic dispatch is supported, but requires explicit annotation, similar to
[trait object](https://doc.rust-lang.org/book/ch17-02-trait-objects.html) in rust.
`virtual[T]` is the type for `T` and its subtypes(derived types).
This is mainly for performance consideration, as virtual method table that is
required for dynamic dispatch would penalize performance, and prohibits function
inlining etc.
Type variables cannot be used inside `virtual[...]`, and type variables would not
range over `virtual[...]`.
Example:
```py
def bar2(x: list[virtual[Base]]) -> int:
@ -133,6 +134,4 @@ def bar2(x: list[virtual[Base]]) -> int:
bar([Base(), Derived()])
```
Structural subtyping support is not determined yet. Attractive, but probably
harder and slower.