Commit Graph

115 Commits

Author SHA1 Message Date
Egor Savkin f7f027001e
compiler: insert new lines into long synthesized code (#1986) 2022-11-23 12:10:32 +08:00
pca006132 9d43762695 test: fixed lit tests
Note that because we changed exception representation from using string
names as exception identifier into using integer IDs, we need to
initialize the embedding map in order to allocate the integer IDs. Also,
we can no longer print the exception names and messages from the kernel,
we will need the host to map exception IDs to names, and may need the
host to map string IDs to actual strings (messages can be static strings
in the firmware, or strings stored in the host only).

We now check for exception IDs for lit tests, which are fixed because we
preallocated all builtin exceptions.
2022-01-26 07:16:54 +08:00
pca006132 4644e105b1 compiler: modified exception representation
Exception name is replaced by exception ID, which requires no
allocation. Other strings in the exception can now be 'host-only'
strings, which is represented by a CSlice with len = usize::MAX and
ptr = key, to avoid the need for allocation when raising exceptions
through RPC.
2022-01-26 07:16:54 +08:00
Sebastien Bourdeauducq c69a1316ad compiler: stop using sys.version_info for parser 2021-08-12 12:52:24 +08:00
pca006132 4ede58e44b compiler: reduce calls to TypedTreeHasher
We need to check if our inference reached a fixed point. This is checked
using hash of the types in the AST, which is very slow. This patch
avoids computing the hash if we can make sure that the AST is definitely
changed, which is when we parse a new function.

For some simple programs with many functions, this can significantly
reduce the compile time by up to ~30%.
2021-07-07 09:22:16 +08:00
pca006132 0806b67dbf compiler: speedup list processing 2021-07-02 14:22:25 +08:00
pca006132 f531af510c compiler: fixed embedding annotation evaluation 2021-06-25 11:32:23 +08:00
pca006132 c29a149d16 compiler: allows string annotation
According to PEP484, type hint can be a string literal for forward
references. With PEP563, type hint would be preserved in annotations in
string form.
2021-06-25 11:01:48 +08:00
Sebastien Bourdeauducq 7046aa9c23 compiler: stop using deprecated numpy.float 2021-06-15 10:48:34 +08:00
David Nadlinger 1f40f3ce15 compiler: Map host numpy.bool_ values to TBool
Since we don't implement any integer-like operations for TBool
(addition, bitwise not, etc.), TBool is currently neither
strictly equivalent to builtin bool nor numpy.bool_, but through
very obvious compiler errors (operation not supported) rather than
silently different runtime behaviour.

Just mapping both to TBool thus is a huge improvement over the
current behaviour (where numpy.False_ is a true-like object). In
the future, we could still implement more operations for TBool,
presumably following numpy.bool_ rather than the builtin type,
just like builtin integers get translated to the numpy-like
TInt{32,64}.

GitHub: Fixes #1275.
2021-03-20 00:54:41 +00:00
David Nadlinger 75c255425d compiler: Linguistically untangle comment [nfc] 2021-03-14 18:40:21 +00:00
David Nadlinger ad34df3de1 compiler: Support numpy.float
This would previously crash the compiler.
2020-08-09 17:08:43 +01:00
David Nadlinger 1c645d8857 compiler: Unbreak quoting of 1D ndarrays
Lists and arrays no longer have the same representation all
the way through codegen, as used to be the case.

This could/should be made more efficient later, eliding the
temporary copies.
2020-08-09 03:54:42 +01:00
David Nadlinger 4d48470320 compiler: Support common numpy.* math functions
Relies on the runtime to provide the necessary
(libm-compatible) functions.

The test is nifty, but a bit brittle; if this breaks in the
future because of optimizer changes, do not hesitate to convert
this into a more pedestrian test case.
2020-08-09 03:54:41 +01:00
David Nadlinger d37503f21d compiler: T{C -> External}Function, clarify docs [nfc] 2020-08-09 03:54:41 +01:00
David Nadlinger 8f518c6b05 compiler: Allow `None` in type hints
Similar to how Python itself interprets None as type(None),
make it translate to TNone in ARTIQ compiler type hints.
2019-12-19 09:36:45 +08:00
David Nadlinger 594ff45750 compiler: Revert support for `None` as `TNone`
This was mistakenly included in fb2b634c4a, and broke the test
case verifying that using None as an ARTIQ type annotation in fact
generates an error message.
2019-12-18 13:23:40 +00:00
David Nadlinger fb2b634c4a compiler, language: Implement @kernel_from_string
With support for polymorphism (or type erasure on pointers to
member functions) being absent in the ARTIQ compiler, code
generation is vital to be able to implement abstractions that
work with user-provided lists/trees of objects with uniform
interfaces (e.g. a common base class, or duck typing), but
different concrete types.

@kernel_from_string has been in production use for exactly
this use case in Oxford for the better part of a year now
(various places in ndscan).

GitHub: Fixes #1089.
2019-12-18 10:51:04 +08:00
David Nadlinger f9af058b96 compiler: Quote tuples as TTuple values
Previously, they would end up being TInstances,
rendering them useless.
2019-03-31 23:40:21 +08:00
whitequark 49682d0159 Improve Python 3.7 compatibility.
async is now a full (non-contextual) keyword.

There are two more instances:
   - artiq/frontend/artiq_client.py
   - artiq/devices/thorlabs_tcube/driver.py

It is not immediately clear how to fix those, so they are left for
later work.
2019-01-12 13:17:59 +00:00
whitequark f7e08ec46b Unbreak f35f1001. 2018-04-28 01:03:08 +00:00
whitequark f35f100110 compiler: don't crash printing locations of specialized functions.
Fixes #987.
2018-04-28 00:49:25 +00:00
whitequark e9564b15c8 compiler: add support for bytearray type (#714). 2017-06-09 07:15:24 +00:00
whitequark dba4e1a28b compiler: add support for bytes type and b"x" literals (#714). 2017-06-09 07:10:48 +00:00
whitequark bb64992395 compiler: remove dead code. 2017-04-21 18:38:43 +00:00
whitequark 3a1fc729cf compiler: refactor type annotations recognizing in kernels.
The new implementation is much more generic, more robust,
and shares code with the same for syscalls as well as RPCs.

Fixes #713.
2017-04-13 08:26:10 +00:00
whitequark 1bd4d13391 artiq_compile: make print() write to core log, not an invalid op.
Fixes #710.
2017-04-11 03:16:34 +00:00
whitequark 8c9f157563 compiler.embedding: fix an overly lax hasher. 2017-03-02 15:28:24 +00:00
whitequark 4107938fd8 compiler.embedding: use attribute count in fixpoint condition.
Before this commit, we had a hack where inferencing would run
one more time, in case we can still infer more attributes even
after all the type information is there. This doesn't work
if *that* round of inferencing brings even more code, e.g.
this is easy to trigger with context managers.
2017-02-28 21:28:40 +00:00
whitequark 6acdcbb82a Fix 2f37b1d. 2017-01-30 10:25:11 +00:00
whitequark 2f37b1d1c0 compiler: support methods defined on singleton instances.
Fixes #638.
2017-01-30 10:10:21 +00:00
whitequark b5a684830d compiler: fix parsing of TList annotations (fixes #632). 2016-12-05 03:18:56 +00:00
whitequark cd68577dbc compiler: add support for async RPCs. 2016-10-30 00:57:31 +00:00
whitequark ed60ba8c4c compiler: skip kernel_invariant linting for exception types. 2016-09-14 23:34:57 +00:00
whitequark feeb089505 compiler: warn about unused kernel_invariant entries.
Fixes #543.
2016-09-14 23:28:55 +00:00
whitequark 5a2306ae5a compiler.embedding: implement type annotations for function arguments.
Fixes #318.
2016-08-08 03:28:25 +00:00
whitequark 5a79fcf9ba embedding: reimplement 373578bc properly.
The core of the problem that 373578bc was attempting to solve is
that diagnostics sometimes should be chained; one way of chaining
is the loc.expanded_from feature, which handles macro-like expansion,
but another is providing context.

Before this commit, context was provided using an ad-hoc override
of a diagnostic engine, which did not work in cases where diagnostic
engine was not threaded through the call stack. This commit uses
the newly added pythonparser context feature to elegantly handle
the problem.
2016-07-07 11:49:21 +00:00
whitequark 373578bc02 embedding: fix location for diagnostics on quoted values.
Fixes #489.
2016-07-07 08:32:56 +00:00
whitequark d90fd7dc00 compiler: implement numpy.full (#424). 2016-07-07 06:33:38 +00:00
whitequark 7a671fb2fd embedding: treat numpy.{int32,int64,array} specially (#424).
Also, remove them from prelude to not pollute the namespace.
2016-07-07 06:33:38 +00:00
whitequark 933ea53c77 compiler: add basic numpy array support (#424). 2016-07-06 09:51:57 +00:00
whitequark 906db876a6 language: replace coredevice int with numpy.{int32,int64}.
Fixes #453.
2016-07-06 04:44:21 +00:00
whitequark ef2af8c331 compiler.embedding: use the builtin print as RPC.
Fixes #206.
2016-06-28 04:42:41 +00:00
whitequark 21574bdfa9 compiler.embedding: rename user-defined types with identical names.
Fixes #478.
2016-06-22 01:32:01 +00:00
whitequark f2ae24da39 compiler: add support for Python modules.
Fixes #408.
2016-06-21 23:35:07 +00:00
whitequark c0e42bbfc8 compiler.embedding: always do one final inference pass.
Fixes #477.
2016-06-16 14:18:43 +00:00
whitequark 355af3e569 embedding: specialize inherited functions.
Fixes #414.
2016-05-16 15:59:26 +00:00
whitequark 640022122b embedding: refactor some more. 2016-05-16 14:38:09 +00:00
whitequark d085d5a372 embedding: refactor. 2016-05-16 14:38:09 +00:00
whitequark 4e5d752951 compiler: fix quoting of methods (fixes #423). 2016-05-09 12:25:57 +00:00