Replies: 1 comment 2 replies
-
I love this proposal. Some small comments:
def bar(y: int @comptime):
foo(42) # Ok
foo(comptime(1 + 2 + 3)) # Ok
foo(y) # Ok
foo(comptime(1 + 2 + y)) # <-- Ok, too!
foo(1 + 2) # Error
foo(1 + 2) # Sure, why not?
x: int @comptime = 10
y: int @comptime = x + 4 # Sure, why not?
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Requirements
Add a new
@comptime
modifier (analogous to@owned
) to mark that values are known at compile-time.The following expressions check against a
@comptime
annotated type:x: int @comptime = 42
x: int @comptime = comptime(1 + 2 + 3)
@comptime
. A special case of this are comptime function arguments:Any other expression is invalid. For example, the following wouldn't type check:
The compiler should automatically infer if an assignment produces a comptime value, even if not explicitly annotated. So the following should check:
Variables that are defined in different control-flow branches are never
@comptime
:(We could relax to allow the case where the value is the same in all paths leading to the use, but not sure if that's woth it?)
Calling a function with a comptime argument requires that the argument checks against the
@comptime
annotation using the rules above:Inside a comptime context,
@comptime
values should be available as regular Python values:Hugr Lowering
TODO
Beta Was this translation helpful? Give feedback.
All reactions