Commit graph

30 commits

Author SHA1 Message Date
Anna Shaleva
6b21ad9922 *: replace interface{} with any keyword
Everywhere including examples, external interop APIs, bindings generators
code and in other valuable places. A couple of `interface{}` usages are
intentionally left in the CHANGELOG.md, documentation and tests.
2023-04-04 13:22:42 +03:00
Anna Shaleva
1828e79412 compiler: add test for foreign function inlining 2022-09-27 15:36:06 +03:00
Anna Shaleva
5d578fdd95 compiler: consider inlined types info on "append" handling
We need to search for "append" argument type info not only inside local
package type info map, but also inside the inlined type info map.
Close #2696.
2022-09-27 15:32:51 +03:00
Anna Shaleva
800321db06 compiler: rename named unused global vars to "_"
So that (*codegen).Visit is able to omit code generation for these
unused global vars. The most tricky part is to detect unused global
variables, it is done in several steps:
1. Collect the set of named used/unused global vars.
2. Collect the set of globally declared expressions that contain
function calls.
3. Pick up global vars from the set made at step 2.
4. Traverse used functions and puck up those global vars that are used
from these functions.
5. Rename all globals that are presented in the set made at step 1
but are not presented in the set made on step 3 or step 4.
2022-09-01 13:39:19 +03:00
Evgeniy Stratonikov
ce24451fde compiler: allow to use conditional returns in inlined functions
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-07-12 12:43:31 +03:00
Evgeniy Stratonikov
e1a581be0e compiler: allow to call methods on return values
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-07-11 19:28:15 +03:00
Roman Khimov
b57dd2cad6 compiler: properly inline methods, use receiver
Notice that this doesn't differentiate between (*T) and (T) receivers always
treating them as is. But we have the same problem with arguments now and the
number of inlined calls is limited, usually we want this behavior.
2022-07-07 15:10:29 +03:00
Evgeniy Stratonikov
8a0429036b compiler: set type information during traversal, fix #2231
Set all necessary context before file traversal, not only import
maps. Also, we can skip restoring import maps because all our code is
processed via `For*` iterators which set necessary context.
We can also refactor this a bit to have all context in one place,
this will be done in #2086.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-25 13:55:55 +03:00
Evgeniy Stratonikov
0bc81aecf4 compiler: do not emit code for unused imported functions
Our current algorithm marks function as used if it is called
at least ones, even if the callee function is itself unused.
This commit implements more clever traversal to collect usage
information more precisely.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-13 15:56:07 +03:00
Evgeniy Stratonikov
4249674ddc compiler: check for contract permissions
On many occassions we can determine at compile-time if contract config lacks
some properties it needs. This includes all native contract invocations
through stdlib, as both hashes and methods are known at compile-time
there.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-06-28 11:49:29 +03:00
Evgeniy Stratonikov
1d6d7206e9 compiler: inline expressions with type conversions, fix #1879
Don't count `string(data)` or `[]byte(data)` as function calls.
2021-06-04 11:08:00 +03:00
Roman Khimov
21a7f3d760 compiler: keep traversing after c.countLocalsCall()
Some arguments can be inlined functions themselves thus requiring additional
attention. Otherwise we can get less local variables than really used by
STLOCs (and subsequent program crash).
2021-04-05 22:58:07 +03:00
Evgeniy Stratonikov
cf459002f7 compiler: allow to inline global variables 2021-02-15 18:48:33 +03:00
Evgeniy Stratonikov
6e560c6c9f compiler: allow to inline var arg functions 2021-02-15 18:48:33 +03:00
Evgeniy Stratonikov
1ae0d022dd compiler: support basic inlining 2021-02-15 18:48:33 +03:00
Evgeniy Stratonikov
e5d8c1c985 compiler: allow conversion to types from external packages 2021-02-08 11:02:45 +03:00
Roman Khimov
811f38eaed *: gofmt -s 2020-12-28 17:23:30 +03:00
Evgenii Stratonikov
ec58bec803 compiler: fix global constant traversal
There can be no global variables, but some global constants.
Introduced in 0b44a430.
2020-12-10 13:45:10 +03:00
Evgenii Stratonikov
a34ba92d46 compiler: allow to split main package across multiple files 2020-08-11 11:12:55 +03:00
Evgenii Stratonikov
439d9ff94d compiler: initialize packages according to go spec
`init()` functions should be called during package initialization,
after global variables were processed.
2020-08-05 11:15:07 +03:00
Evgenii Stratonikov
6f2759be3a compiler: process packages in deterministic order 2020-08-05 11:00:25 +03:00
Evgenii Stratonikov
a781d299e0 compiler: use fully-qualified names for tracking functions
Function name now consists of 3 parts:
1) full package path
2) method receiver type (if any)
3) function name itself .

Fix #1150.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:07:06 +03:00
Evgenii Stratonikov
528c184f00 compiler: allow to use exported constants
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
Evgenii Stratonikov
6df019913d compiler: allow to use exported variables
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
Evgenii Stratonikov
7009417325 compiler: allow to declare global variables in multiple files
Traverse and count globals across all used files.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-31 12:06:42 +03:00
Evgenii Stratonikov
ed45ff98e3 compiler: process interop together with package
Closes #913.
Provide package info in the funcScope to check if function is defined
insided an interop package. As a good side-effect bytecode for builtins from `util`
is no longer emitted.

Related #941.
2020-06-09 12:41:33 +03:00
Roman Khimov
e41d434a49 *: move all packages from CityOfZion to nspcc-dev 2020-03-03 17:21:42 +03:00
Roman Khimov
9eb880a095
Merge pull request #568 from nspcc-dev/feature/compiler_clean_and_tests
compiler: clean and tests
2020-01-14 18:44:07 +03:00
Vsevolod Brekelov
7084925e4b compiler: add test for compile and save 2020-01-14 17:33:04 +03:00
Roman Khimov
094c8474b7 compiler: move tests from vm/tests
These don't belong to VM as they compile some Go code and run it in a VM. One
may call them integration tests, but I prefer to attribute them to
compiler. Moving these tests into pkg/compiler also allows to properly count
the compiler coverage they add:

-ok     github.com/CityOfZion/neo-go/pkg/compiler       (cached)        coverage: 69.7% of statements
+ok     github.com/CityOfZion/neo-go/pkg/compiler       (cached)        coverage: 84.2% of statements

This change also fixes `contant` typo and removes fake packages exposed to the
public by moving foo/bar/foobar into the testdata directory.
2019-12-23 17:05:34 +03:00