Commit Graph

214 Commits

Author SHA1 Message Date
KtorZ 4a22e5f656
Fix module comment parsing / formatting after bumping chumsky to 0.9.0 2023-02-17 14:07:24 +01:00
KtorZ ec144fa220
Make 'choose_data' builtin available. 2023-02-17 11:25:41 +01:00
KtorZ 95e1442b49 Swap arguments to unify when inferring traces
The first argument shows as what the compiler expects in the error message. So it must be the correct one or the error is actually misleading.
2023-02-16 20:29:41 -05:00
KtorZ 45454ced01 Make tracing configurable, when relevant.
Tracing is now turn OFF by default when:

  - building project
  - building documentation
  - building dependencies

  It can be turned ON only when building project using `--keep-traces`.
  That means it's not possible to build dependencies with traces. The
  address `--rebuild` flag will also rebuild without traces.

  Tracing is however turn ON by default when:

  - checking the project (and running tests).

  In this scenario, tracing can be disabled using `--no-traces` (if for
  example, one want to analyze the execution units of specific functions
  without having to manually remove traces from code).
2023-02-16 20:29:41 -05:00
KtorZ e9e3f4f50a Implement TraceIfFalse type-checking and AST transformation.
This caused me some trouble. In my first approach, I ended up having
  multiple traces because nested values would be evaluated twice; once
  as condition, and once as part of the continuation.

  To prevent this, we can simply evaluate the condition once, and return
  plain True / False boolean as outcome. So this effectively transforms any
  expression:

  ```
  expr
  ```

  as

  ```
  if expr { True } else { trace("...", False) }
  ```
2023-02-16 20:29:41 -05:00
KtorZ 6a50bde666 Implement parser & formater for 'TraceIfFalse'
Interestingly enough, chumsky seems to fail when given a 'choice' with
  more than 25 elements. That's why this commit groups together some of
  the choices as another nested 'choice'.
2023-02-16 20:29:41 -05:00
KtorZ 60390fe4f0 Add TraceIfFalse untyped expression
The goal is to handle this without bothering the code generation down the line. That is, we can handle it when transforming from the untyped AST to the typed one. That's why there's no 'TraceIfFalse' constructor in the typed AST. It has disappeared during type-check.
2023-02-16 20:29:41 -05:00
Kasey White 6ce62115f7 found formatting issue 2023-02-16 20:27:00 -05:00
Kasey White d7cfca2a57 fix condition and branch body getting passed same scope 2023-02-16 20:27:00 -05:00
Kasey White d1ca85c4bc feat: add support for assign and nested assign
My formatter is not working :'(
2023-02-16 20:27:00 -05:00
KtorZ 3204322da6
Fix validator lookup by title.
We want the lookup to yield a result when there's only a single
  validator; and no title is provided. So that users can simply do
  'aiken address' in their project if it's unambiguous. The validator's
  name is only required to disambiguate between multiple validators.

  I also noticed that the order of arguments in with_validator was
  wrong. Somehow.
2023-02-16 10:28:27 +01:00
Matthias Benkort ec6baf3a6a
Merge pull request #351 from aiken-lang/acceptance-test-054-pattern-match-on-list
Add new acceptance test scenario: 056
2023-02-16 10:01:56 +01:00
rvcas 2151fe4484 fix(infer): if branch bodies need to be checked in a new scope 2023-02-16 00:05:55 -05:00
rvcas c4a588f3dd test(check): if scoping 2023-02-16 00:05:55 -05:00
rvcas 7b0faa7c1c test(check): validator errors and warning 2023-02-16 00:05:55 -05:00
rvcas 8b4985498b chore: add fmt test for validator 2023-02-16 00:05:55 -05:00
rvcas b057d27465 fix: some updates from latest main 2023-02-16 00:05:55 -05:00
rvcas d03288cece feat(validator): move return type and arity check to infer 2023-02-16 00:05:55 -05:00
rvcas a88a193383 fix: properly lex new token and adjust parsed spans 2023-02-16 00:05:55 -05:00
rvcas e647330433 fix: better formating for validator 2023-02-16 00:05:55 -05:00
rvcas a044c3580e feat: typecheck validators 2023-02-16 00:05:55 -05:00
rvcas 2e7fe191db feat(definitions):
* add parsing for new validator defs
* start adding typechecking
* add a unit test for parsing
2023-02-16 00:05:55 -05:00
Kasey White 2fa494bda7 fix: calculated list pattern length with tail incorrectly before.
Now subtract 1 from length since next item does not need a end of list check
2023-02-15 22:12:41 -05:00
KtorZ 56258dc815
Fix todo/error parser on when clauses. 2023-02-16 00:40:49 +01:00
KtorZ 808ff97c68
Preserve trace, error & todo formatting. 2023-02-15 23:19:07 +01:00
KtorZ 6525f21712
Remove 'Todo' from the AST & AIR
Todo is fundamentally just a trace and an error. The only reason we kept it as a separate element in the AST is for the formatter to work out whether it should format something back to a todo or something else.

  However, this introduces redundancy in the code internally and makes the AIR more complicated than it needs to be. Both todo and errors can actually be represented as trace + errors, and we only need to record their preferred shape when parsing so that we can format them back to what's expected.
2023-02-15 21:57:08 +01:00
KtorZ 7b676643bd
Lift 'error' up one level in the parser and remove its label.
We now parse errors as a combination of a trace plus and error term. This is a baby step in order to simplify the code generation down the line and the internal representation of todo / errors.
2023-02-15 21:09:03 +01:00
KtorZ 7abd76b6ad
Allow to trace expressions (and not only string literals)
This however enforces that the argument unifies to a `String`. So this
  is more flexible than the previous form, but does fundamentally the
  same thing.

  Fixes #378.
2023-02-15 21:07:56 +01:00
KtorZ 7251b2d01e
Remove single-argument function call special-case in formatter
Not sure what this special case was trying to achieve, but it's not right. There's no need to handle function call with a single argument differently than the others.
2023-02-15 17:22:08 +01:00
Kasey White a24fc55993 Delay 2nd arg on trace in case it throws and prevents trace from printing 2023-02-15 03:06:58 -05:00
Kasey White e15e725bfe add one more test 2023-02-15 02:20:05 -05:00
Kasey White 5e5a9dd25f quick fix for test 59 2023-02-15 02:20:05 -05:00
Kasey White 32b0200966 fixes: tuple clauses, zero args funcs, list clause named pattern
List Clauses patterns handle var cases

Fixed Tuple Clauses issue with last clause not being a tuple

Redid how zero arg functions and dependencies are handled. Tough one lol
2023-02-15 02:20:05 -05:00
Kasey White b7fa57027a scope is now properly handled in expect cases 2023-02-14 12:38:36 -05:00
Kasey White 3b3ec7d95c format fix 2023-02-12 19:12:38 -05:00
Kasey White 765ceefd38 feat: add ability to downcast void to data 2023-02-12 18:56:38 -05:00
Kasey White 4c838defd1 fix issue with final clause producing clauseguard air 2023-02-12 18:43:11 -05:00
Kasey White e9883adf12 fix: scope issue when using when with a function call subject 2023-02-12 18:43:11 -05:00
Kasey White 4b1015e0d4 change how expect works on lists and constructors
Add more coverage to acceptance test 40 on expect
2023-02-11 22:26:34 -05:00
Matthias Benkort deb2ab8f80
Merge pull request #362 from aiken-lang/patterns-improvements
Patterns improvements
2023-02-11 22:46:04 +01:00
KtorZ b83a247ff7
Add slightly more informative note for list pattern on int. 2023-02-11 17:00:32 +01:00
KtorZ 2e8fd6e1c2
Remove patterns on 'String'
There's arguably no use case ever for that in the context of on-chain
  Plutus. Strings are really just meant to be used for tracing. They
  aren't meant to be manipulated as heavily as in classic programming
  languages.
2023-02-11 16:57:14 +01:00
KtorZ 6649821200
Add type-checker sanity tests for list patterns. 2023-02-11 16:54:49 +01:00
KtorZ 56e90fba21
Add missing newlines to 'join' in error messages. 2023-02-11 16:24:56 +01:00
KtorZ 3c7663cd3c
Basic exhaustivness check on list patterns
Before that commit, the type-checker would allow unsafe list patterns
  such as:

  ```
  let [x] = xs

  when xs is {
    [x] -> ...
    [x, ..] ->  ...
  }
  ```

  This is quite unsafe and can lead to confusing situations. Now at
  least the compiler warns about this. It isn't perfect though,
  especially in the presence of clause guards. But that's a start.
2023-02-11 16:20:28 +01:00
rvcas 831a37d094
feat: shouldn't use this warning on list 2023-02-11 09:42:39 -05:00
Kasey White e92d9af3c2 fix: changed how list_access_to_uplc handles discards fixing unit test 55
Also fix incorrect error message in runtime in machine
2023-02-11 04:30:18 -05:00
KtorZ 21fbd48b8d
Improve error on duplicate imports. 2023-02-10 17:07:08 +01:00
KtorZ f747ee0aca
Improve error message when finding a non-exhaustive let-binding. 2023-02-10 11:01:13 +01:00
rvcas c1d67e95e1
feat: fix errors and add tests for BigInt changes 2023-02-09 15:01:30 -05:00