Commit Graph

804 Commits

Author SHA1 Message Date
Kasey White 9dc2bac2c3 fix:minor optimization fixes
Unique only comparison for equals led to strange results
Fixed by interning in a different spot
2023-02-01 23:49:33 -05:00
Kasey White fdf89b7326 implement optimizations
-Force usage on builtins
-Inline vars used once
-Lambdas that use a var as an arg
-Lambdas that use a const as an arg
2023-02-01 23:49:33 -05:00
rvcas 88ce8ba8b9 feat: remove check assignment 2023-02-01 23:03:35 -05:00
rvcas 21251d6499
fix: remove check from lexer 2023-02-01 20:44:58 -05:00
Kasey White 3123ad9079 change eval_builtin_app to return Rc so that ifthenelse and chooselist are faster 2023-02-01 18:53:11 -05:00
Kasey White 456b08a205 minor performance improvements
Changed a couple cases where the inner Rc object was cloned to use the Rc object instead
2023-02-01 18:53:11 -05:00
rvcas 99c1c880b0 chore: more clippy 2023-02-01 18:53:11 -05:00
rvcas a365649360 chore: clippy autofix 2023-02-01 18:53:11 -05:00
rvcas 9c4e921e79 feat: more Rc in machine 2023-02-01 18:53:11 -05:00
rvcas c8efe60843 feat: use Rc for more things, fib_iter runs almost 3 seconds faster now 2023-02-01 18:53:11 -05:00
rvcas eda3194cf0 feat: trying Rc for Name 2023-02-01 18:53:11 -05:00
Kasey White b5d9a9bb52 Change discharge_value and discharge_value_env to use a stack machine 2023-02-01 18:53:11 -05:00
rvcas 790e8ba680 fix: start trying to get rid of recursion for discharge value 2023-02-01 18:53:11 -05:00
rvcas 618ea0c8dc feat: switch to zip from zip-extract 2023-02-01 14:50:18 -05:00
dependabot[bot] 6974d31285 chore(deps): bump tokio from 1.23.0 to 1.23.1
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.23.0 to 1.23.1.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.23.0...tokio-1.23.1)

---
updated-dependencies:
- dependency-name: tokio
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-01 12:36:49 -05:00
Matthias Benkort ecc5e13ccd
Merge pull request #316 from aiken-lang/cip-0057-blueprints
Blueprints (CIP-0057) as build artifacts
2023-01-31 17:45:56 +01:00
KtorZ a50b51e086
Fix bytearray literals parsing and formatting.
Weirdly enough, we got the parsing wrong for byte literals in expressions (but did okay in constants). But got the formatting wrong in constants (yet did okay for formatting expressions). I've factored out the code in both cases to avoid the duplication that led to this in the first place. Plus added test coverage to make sure this doesn't happen in the future.
2023-01-31 17:19:40 +01:00
KtorZ daee8e39d6
Implement new command: address
This calculates a validator's address from validators found in a blueprint. It also provides a convenient way to attach a delegation part to the validator if needs be. The command is meant to provide a nice user experience and works 'out of the box' for projects that have only a single validator. Just call 'aiken address' to get the validator's address.

  Note that the command-line doesn't provide any option to configure the target network. This automatically assumes testnet, and will until we deem the project ready for mainnet. Those brave enough to run an Aiken's program on mainnet will find a way anyway.
2023-01-31 15:39:40 +01:00
KtorZ 1aa12fb368
Implement serde's Deserialize for blueprints.
Here's a trick though: I got lazy (a bit) and did not write a full deserializer for Schema because this is busywork and not at all necessary at this stage. Instead, I've made the blueprint parameterized by a generic type <T>; which represents the type of the underlying blueprint's schema. When deserializing from JSON, we can default to 'Value' to get a free deserializer. Since all we're interested about is the program and the metadata (purpose and title) of a validator, it works nicely.

  Serialization however expects a Blueprint<Schema>, and most of the functions operates over a Blueprint<Schema> anyway.
2023-01-31 15:39:40 +01:00
KtorZ cab59c188a
Define serde's Serialize/Deserialize for Program<DeBrujin>
This will be useful to re-use this behavior in other structure that contains a Program<DeBruijn> without having to manually serialize or deserialize the entire structure.
2023-01-31 15:39:40 +01:00
KtorZ 4588ccd040
Better use of From/Tryfrom within the blueprint module. 2023-01-31 15:39:40 +01:00
KtorZ 22a1c1dfb4
Use IndexMap throughout
In an ideal world, I should have handlded that directly at the conflicting commit in the rebase, but this would have bubbled up through all commits... which I wasn't really quite keen on going through. So here's an extra ugly commit that comes and 'fix the rebase'.
2023-01-31 09:51:00 +01:00
KtorZ 90ee86d14e
Improve error reporting for the blueprint generation.
Actually link schema error to source code with a span and a label. This is easily done and provides some extra context.
2023-01-31 09:48:45 +01:00
KtorZ b3fc2d51cf
Fix help on unknown::module error. 2023-01-31 09:48:45 +01:00
KtorZ 2523816813
Handle opaque single-variant-single-field special case. 2023-01-31 09:48:45 +01:00
KtorZ aaa8cba0cf
Fix nested generics and phantom-types, and handle list special case
List of pairs are actually encoded as 'map'.
2023-01-31 09:48:45 +01:00
KtorZ 9a44cba007
Add support for generics in the blueprint generation. 2023-01-31 09:48:45 +01:00
KtorZ 0bd9d045b0
Support tuples in blueprint generation. 2023-01-31 09:48:44 +01:00
KtorZ d2cc44e5f4
Allow testing blueprint generation from Aiken programs
This is quite something, because now we have a testing pipeline that
  can also be used for testing other compiler-related stuff such as the
  type-checker or the code generator.
2023-01-31 09:48:44 +01:00
KtorZ b93e14659c
Refactor blueprint & handle annotated schemas
This also now introduce two levels of representable types (because it's needed at least for tuples):

  Plutus Data (a.k.a Data) and UPLC primitives / constants (a.k.a Schema).

  In practice, we don't want to specify blueprints that use direct UPLC primitives because there's little support for producing those in the ecosystem. So we should aim for producing only Data whenever we can. Yet we don't want to forbid it either in case people know what they're doing. Which means that we need to capture that difference well in the type modelling (in Rust and in the CIP-0057 specification).

  I've also simplified the error type for now, just to provide some degree of feedback while working on this. I'll refine it later with proper errors.
2023-01-31 09:48:44 +01:00
KtorZ 547696abde
Add title and description to exported types in the blueprint
This also fixes a bug where the documentation of record constructor arguments would be dropped after type-checking. Took me a while to pinpoint.
2023-01-31 09:48:44 +01:00
KtorZ 59ffc6434f
Add title to blueprint's validators
And use it to prefix UPLC artifacts' names.
2023-01-31 09:48:44 +01:00
KtorZ f8970ecb9e
Move UPLC dump into separate function + log event.
```
    Compiling aiken-lang/stdlib 43d8e740ffdf5febc59e51b7f0d5f8506115340c (examples/hello_world/build/packages/aiken-lang-stdlib)
    Compiling aiken-lang/hello_world 1.0.0 (examples/hello_world)
   Generating project's blueprint (examples/hello_world/plutus.json)
    Exporting UPLC (examples/hello_world/artifacts)
  ```
2023-01-31 09:48:44 +01:00
KtorZ b667b7f7b7
Refactor test collection to use the new CheckedModules method
And also, caught a little issue regarding the filtering of test cases.
2023-01-31 09:48:44 +01:00
KtorZ 5683d19a4c
Refactor build steps to generate blueprints instead
The blueprint is generated at the root of the repository and is
  intended to be versioned with the rest. It acts as a business card
  that contains many practical information. There's a variety of tools
  we can then build on top of open-source contracts. And, quite
  importantly, the blueprint is language-agnostic; it isn't specific to
  Aiken. So it is really meant as an interop format within the
  ecosystem.
2023-01-31 09:48:38 +01:00
KtorZ 3cefbd00af
Draft basic Blueprint schema type definition.
This doesn't include validations yet. Let's start simple
  and try to get some basic schema generated already.
2023-01-31 09:47:47 +01:00
rvcas 60ad3dae50
chore: fmt builder.rs 2023-01-30 12:07:50 -05:00
rvcas af67f41ead
fix: Air::Lam not real, probably meant Air::Let 2023-01-30 12:01:40 -05:00
Lucas b653714c0c
Merge branch 'main' into when-clause-guards 2023-01-30 11:40:29 -05:00
Kasey White 0ea2be0e95 feat: Add codegen for handling clause guards 2023-01-30 05:11:27 -05:00
Kasey White a638388747 Add more complex test 40.
Add assert for when constr index is given
2023-01-30 04:17:03 -05:00
Kasey White 8c04ab093a update test 40 2023-01-30 03:24:52 -05:00
Kasey White afd040fda5 feat: Finish up assert feature
Better error reporing on NonFunctionalApplication Error
Refactor redundant code
Add handling of whens with one clause.
2023-01-29 05:21:55 -05:00
Kasey White 4c8089c28a Assert now works for a variety of types.
Still some final work to finish and test. Things are good so far
2023-01-28 05:14:12 -05:00
Kasey White 60736b4a54 chore: Add error when type casting without annotation
Also implement and test most of assert. Finishing last few cases.
2023-01-28 02:40:53 -05:00
Kasey White fc88028034 some refactoring and adding assert on lists 2023-01-27 05:02:19 -05:00
Kasey White d4eec1fe79 chore: Add scaffolding for assert 2023-01-27 05:02:19 -05:00
Kasey White 38c24cca01 single clause when not yet implemented 2023-01-27 05:02:19 -05:00
Kasey White 1af1b6d898 finalize aiken ir with typing 2023-01-27 05:02:19 -05:00
rvcas 4976ea4164 chore: add test for the new token captures 2023-01-26 10:16:29 -05:00
rvcas 703fcb451d fix(parser,windows): capture carriage return properly 2023-01-26 10:16:29 -05:00
rvcas 3c97f057cc chore: fix clippy 2023-01-24 12:07:06 -05:00
rvcas ba05f1f070 feat: add label to span 2023-01-24 12:07:06 -05:00
rvcas a485406e3d fix: use the location of the pattern not the entire clause 2023-01-24 12:07:06 -05:00
rvcas 7206360baa feat(when): single when clause now emits warning 2023-01-24 12:07:06 -05:00
Kasey White e36f91c39c fix: multiple list cases of the same length weren't being handled 2023-01-21 19:42:17 -05:00
Kasey White e8fb386bdc chore: Switch from hashmap and hashset to indexmap and indexset 2023-01-21 18:10:15 -05:00
KtorZ 5d7585cc05
Implement parser for when clause guard
With pretty parse errors on failures. The type-checker was already
  implemented for those, so it now only requires some work in the code
  generation.

  Fixes #297.
2023-01-21 17:43:13 +01:00
KtorZ 91bd0d1d77
Display warning help + minor error improvements. 2023-01-21 17:42:58 +01:00
KtorZ 333a990249
Fix parsing of subtractions and negations in the absence of space. 2023-01-21 12:43:11 +01:00
KtorZ bb360cd7c8
Fix display of 'UnknownLabels'
This is a bit annoying as we are forced to use #[related] here which isn't quite what we want.
  Ideally, this would use #[diagnostic_source] but, there's a bug upstream. See: zkat/miette#172.
2023-01-21 11:37:19 +01:00
KtorZ d905f24e7f
Forbid solo-assignment as the only function body
In the similar spirit to what we did for sequences. Yet, we need to handle the case of body being just an assignment -- or a trace of an assignment which is basically the same thing.
2023-01-21 10:32:06 +01:00
KtorZ 2101bb924d
Fix tuple-pattern parser
This case was originally left out but, tuple parsers are almost always exclusively starting with a NewLineLeftParen token.
2023-01-21 10:04:11 +01:00
KtorZ d321b85df2
Refactor type errors back into macro annotations
Far less verbose than defining classes by hand, plus, it allows to have everything about a single error be co-located. And finally, it allows to use 'related', 'label' and so on more easily.
2023-01-20 20:11:44 +01:00
KtorZ 4459fdb360
Fix error reporting on cyclic definitions.
Fixes #292
2023-01-20 20:09:00 +01:00
KtorZ ce65236514
Parse tests as private functions.
They actually are private; we can't export / import tests. Fixes #284.
2023-01-20 12:50:07 +01:00
KtorZ 61be8ca73e
Add diagnostic codes to type-check warnings. 2023-01-20 12:27:48 +01:00
KtorZ 10fb7455f3
Forbid let-binding as last expression of a sequence
Fixes #283
2023-01-19 18:05:57 +01:00
KtorZ c5e876e817
Fix typo in variant name: Implicity -> Implicitly 2023-01-19 17:26:33 +01:00
KtorZ bb82b1bc1e
slightly rework hint for 'ImpliclyDiscardedExpression' 2023-01-19 17:25:18 +01:00
KtorZ 092151d6a0
Remove dead-code and fix comment about discarded expressions
While Gleam originally allowed various kinds of expressions to be discarded in a sequence, we simply do not allow expressions to be discarded implicitly. So any non-final expression in a sequence must be a let-binding. This prevents silly mistakes.
2023-01-19 16:35:39 +01:00
Kasey White 52724ea0e0 feat: handle anon zero arg functions.
Test 045
2023-01-19 01:34:27 -05:00
Kasey White 7215bf33e9 fix: get_variant_name was not properly traversing type args on map and data types 2023-01-18 16:06:44 -05:00
Kasey White 71ae85a720 missing a condition check on when 2023-01-18 15:29:51 -05:00
Kasey White d7e4aef4c5 feat: Add boolean conditions to when statements 2023-01-18 15:29:51 -05:00
KtorZ c440026e36
Fix generated projects' README + rename 'certify' -> 'publish'
This hints to how this particular purpose is about publishing
  certificate (either delegation or key de-registration).
2023-01-18 16:48:42 +01:00
KtorZ 20ac9c20a2
Remove some dead-code. 2023-01-18 16:43:40 +01:00
KtorZ b475d6a6a4
Provide better errors when packages aren't found. 2023-01-18 16:34:26 +01:00
KtorZ 071dc00624
Implement various visual improvements for the doc generator
- Display function's signature next to the function name
    (instead of being repeated below the function documentation).

  - Same for module constants

  - Display record constructors in a more concise manner, with
    constructors fields next to constructors.

  - Display generic parameters, if any, next to the type

  - Plus some minor color and icon rework.
2023-01-18 15:12:15 +01:00
Kasey White 33d902ba2a feat: Now opaque types with one constr and one field are converted to inner field type 2023-01-17 08:44:28 -05:00
Kasey White 98d2cb5afc in progress: working on taking special opaque types and converting them to their inner type 2023-01-17 08:44:28 -05:00
Kasey White 0da4560792 fix failing unit tests 2023-01-17 03:02:06 -05:00
rvcas 5ceb3b07fb
fix: call was not capturing full span 2023-01-16 15:26:07 -05:00
rvcas 38734361d0 feat: make part of summary red if errors exist 2023-01-16 15:17:39 -05:00
rvcas 4024add4da feat: error when an expression is implicitly discarded 2023-01-16 15:17:39 -05:00
KtorZ 844570caf5
Fix multi-line type-alias tuple definitions
Somehow missed it when reworking tuples. We need to allow the new
  'NewLineLeftParen' token in this situation as well. Especially because
  this is what the formatter outputs.
2023-01-16 11:30:20 +01:00
rvcas 1adac64585 feat(imports): return a nice error if a validator module is imported 2023-01-15 18:54:35 -05:00
rvcas f114905f7d fix: small typos in error messages 2023-01-15 18:54:35 -05:00
rvcas c66d07a54c feat: validator fns no longer need to be public
If the function doesn't match a script purpose
and is unused then it will till present as a
warning.
2023-01-15 12:33:10 -05:00
rvcas 00f2150eed feat: add identity, always, & flip 2023-01-14 23:33:49 -05:00
rvcas b69c1f66d7 feat: return err if data type contains functions
Due to how PlutusData works it doesn't make sense
to allow user defined types to contain
functions.

```
type Foo {
  bar: fn(Int) -> Int
}
```

The above definition will now return an error.
2023-01-14 22:03:56 -05:00
KtorZ d2c03b0094
Remove restriction on the project's package name
There are restrictions regarding how modules are called, but given that packages are tight to repositories anyway; there's no way someone can publish and use an aiken package on 'aiken-lang' without being part of the organization. So the restriction on the command-line is pointless. Plus, it prevents us from using 'aiken-lang' as a placeholder name for tutorials.
2023-01-14 23:47:57 +01:00
KtorZ 219e81cb75
Add 'packages upgrade' command. 2023-01-14 23:29:28 +01:00
KtorZ 6286132a3e
Rename sub-command 'deps' → 'packages'
Slightly more readable and self-explanatory.
2023-01-14 23:29:28 +01:00
KtorZ 38df9a586e
Add new 'deps add' command
This makes it easier to add new dependencies, without having to
  manually edit the `aiken.toml` file.

  The command is accessible via two different paths:

  - aiken deps add

  or simply

  - aiken add

  for this is quite common to find at the top-level of the command-line,
  and, we still want to keep commands for managing dependencies grouped
  under a command sub-group and not all at the top-level. So we're
  merely promoting that one for visibility.
2023-01-14 23:29:28 +01:00
KtorZ d4f905b1db
Also move some associated methods to the 'Config' module
And refactor the 'new' command implementation.
2023-01-14 23:29:28 +01:00
KtorZ 0771ab24bd
Move 'PackageName' and associated methods in its own module.
This is a bit cleaner, as the 'cmd/new' had many on-the-fly functions
  which are better scoped inside this module.

  Plus, it plays nicely with the std::str::FromStr trait definition.
2023-01-14 23:29:28 +01:00
KtorZ 5b7147fc43
Remove leading '#' for tuple definitions.
This possibly breaks many Aiken programs out there, but it's for the
  best. We haven't released the alpha yet so we still have a bit of
  freedom when it comes to breaking change.

  Plus, the migration path is easy, simply run:

  ```
  find . -name "*.ak" | xargs sed -i "s/#(/(/g"
  ```

  (or `-i ''` on MacOS).
2023-01-14 20:22:19 +01:00
KtorZ db22395764 Add new command group 'deps' and 'clear-cache' command.
This allows in case of issues with dependencies to at least safely
  remove cached packages. Before that, it could be hard to know where
  are even located the cached files without looking at the source code.

  ```
     Clearing /Users/ktorz/Library/Caches/aiken/packages
     Removing aiken-lang-stdlib-7ca9e659688ea88e1cfdc439b6c20c4c7fae9985.zip
     Removing aiken-lang-stdlib-main@04eb45df3c77f6611bbdff842a0e311be2c56390f0fa01f020d69c93ff567fe5.zip
     Removing aiken-lang-stdlib-6b482fa00ec37fe936c93155e8c670f32288a686.zip
     Removing aiken-lang-stdlib-1cedbe85b7c7e9c4036d63d45cad4ced27b0d50b.zip
         Done
  ```
2023-01-14 11:51:18 -05:00
KtorZ 3a5f77da12 Invalidate cache using etag for deps by branch
Aiken's build system uses an internal global cache system to avoid
  downloading the same packages over and over across projects. However,
  prior to this commit, the cache key would be based of the dependency
  version which can be either:

  - A commit hash
  - A branch or tag name

  However, in the latter case, it means that the very first time we end
  up fetching a dependency will lock its version forever (or until the
  cache is cleared). This was inconvenient.

  This commit changes that so that we use not only a branch name as
  cache key, but additionally, the etag returned by the GitHub API
  server. The etag is part of the HTTP headers, so it can be fetched
  quickly using a simple HEAD request. It changes whenever the content
  behind the endpoint changes -- which happens to be exactly what we
  want. With this, we can quickly check whether an upstream package has
  been updated and download the latest version should users have
  specified a branch name as a version number.

  For example, my current cache now looks as follow:

  ```
   /Users/ktorz/Library/Caches/aiken/packages/
   ├── aiken-lang-stdlib-1cedbe85b7c7e9c4036d63d45cad4ced27b0d50b.zip
   ├── aiken-lang-stdlib-6b482fa00ec37fe936c93155e8c670f32288a686.zip
   ├── aiken-lang-stdlib-7ca9e659688ea88e1cfdc439b6c20c4c7fae9985.zip
   └── aiken-lang-stdlib-main@04eb45df3c77f6611bbdff842a0e311be2c56390f0fa01f020d69c93ff567fe5.zip
  ```
2023-01-14 11:51:18 -05:00