From a642e37b9ab7d9e6ec45c51c68b49c56e7c1a325 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Wed, 9 Jun 2021 09:45:05 +0800 Subject: [PATCH 1/3] Added #12 --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 8f3c69f..a5a5ace 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,17 @@ class Foo(EnvExperiment): * Type variable cannot occur alone in the result type, i.e. must be bound to the input parameters. +## For loop unrolling (#12) +A pseudocomment can be used for unrolling for loops that iterates a fixed amount +of time. This can be used for iterating over inhomogeneous tuples. Example: + +```python +params = (1, 1.5, "foo") +# nac3:unroll +for p in params: + print(p) +``` + ## Lifetime Probably need more discussions... -- 2.42.0 From 1e80d8d285bd8772a03b664b89ee77256a4a6d1e Mon Sep 17 00:00:00 2001 From: pca006132 Date: Wed, 9 Jun 2021 09:45:13 +0800 Subject: [PATCH 2/3] Added #15 --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a5a5ace..943cdd2 100644 --- a/README.md +++ b/README.md @@ -140,11 +140,18 @@ class Foo(EnvExperiment): * 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. -* Code region protected by a type check, such as `if type(x) == int:`, would +* A custom function `is_type(x, T)` would be provided to check whether `x` is an + instance of `T`, other methods like `type(x) == int` or `isinstance(x, int)` + would not compile. The function would be able to check generic types for + `list` and `tuple`. When running on the host, user can specify whether to use + a debug mode checking (recursively check all elements, which would be slower + for large lists) or performance mode which only check the first element of + each list. (#15) +* Code region protected by a type check, such as `if is_type(x, int):`, would treat `x` as `int`, similar to how [typescript type guard](https://www.typescripttutorial.net/typescript-tutorial/typescript-type-guards/) works. ```python def add1(x: Union[int, bool]) -> int: - if type(x) == int: + if is_type(x, int): # x is int return x + 1 else: @@ -152,7 +159,7 @@ class Foo(EnvExperiment): return 2 if x else 1 ``` * Generics are instantiated at compile time, all the type checks like - `type(x) == int` would be evaluated as constants. Type checks are not allowed + `is_type(x, int)` would be evaluated as constants. Type checks are not allowed in area outside generics. * Type variable cannot occur alone in the result type, i.e. must be bound to the input parameters. -- 2.42.0 From b79c1725b3fef8e15a702a76eff85a04d961e342 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Wed, 9 Jun 2021 09:48:07 +0800 Subject: [PATCH 3/3] Added #9 --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 943cdd2..e676b6e 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,24 @@ def fail_write() -> None: self.a = a self.b = b ``` +* Instance variables not used would be warned by the compiler, except for those + preceded by the pseudocomment `# nac3:no_warn_unused`. (#9) The comment can + either be placed on top of the variable or next to the variable. Example: + ```python + class Foo: + # nac3:no_warn_unused + a: int + b: int # nac3:no_warn_unused + def __init__(self): + pass + ``` +* Use-before-define: + * Host-only constructor: Error if a certain field `f` is + used in other kernel methods but missing from the object constructed in the + host. + * `@portable`/`@kernel` constructor: Error if a certain + field `f` is used in other kernel methods but not defined in the + constructor, or used in the constructor before definition. * Three types of instance variables: (Issue #5) * Host only variables: Do not add type annotation for it in the class. * Kernel only variables: Denoted with type `Kernel[T]`. -- 2.42.0