Commit Graph

346 Commits

Author SHA1 Message Date
rvcas 824431371e feat: centralize some Cargo.toml configs at root and upgrade to edition 2024 2025-03-23 21:46:13 -04:00
KtorZ c88cbd8f28
rework trace label evaluation strategy
Namely:

  1. Fully evaluate & type-check the label, irrespective of the trace level. So that labels using other variables do not generate "unused identifier" warnings when compiling with different trace mode (and so that the success of a build doesn't depend on the trace level).

     This was already done for trace arguments, but not for labels, somehow.

  2. Move the requirement for compact trace label being String from errors down to warnings; following point (1), we shouldn't fail compilation for different trace levels. It seems more reasonable to simply raise a warning.

Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-18 13:47:26 +01:00
Matthias Benkort 1d9a55e1d8
Merge pull request #1121 from aiken-lang/unused-record-fields-hint-args-ordering
Fix hint when suggesting to use named fields
2025-03-17 14:35:37 +01:00
KtorZ 776aea86f5
Fix hint when suggesting to use named fields
Wrongly suggesting args in lexicographical order instead of definition order... The tests were unfortunately only examplifying situations where the fields where also defined in lexicographical order... thus never really showing the issue. It came up in the real world, though. Whoopsie.

Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-16 14:07:25 +01:00
KtorZ 9d05011001
factor out common logic for creating UnknownModule error in a cute little helper.
Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-16 00:58:50 +01:00
KtorZ d7af418a63
return dedicated error on invalid type field access, instead of confusing 'unknown module.'
Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-16 00:45:42 +01:00
KtorZ b8f42dd555
also support using Types as namespace when nested in module.
Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-16 00:45:42 +01:00
KtorZ 2adc1fab66
ensure import resolution is done according to local bindings
Might it be from a module that has multiple path fragments or one that is aliased.

Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-15 23:50:51 +01:00
KtorZ 660ff7fa31
adjust spans & tweak errors for maximum UX
Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-15 23:02:13 +01:00
KtorZ b9052949f7
hide internal functions from suggested hints on unknown modules/constructor/value.
Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-15 21:52:45 +01:00
KtorZ 3db9828fe8
allow use of types as namespaces for constructing values.
Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-15 21:52:45 +01:00
KtorZ c66bca5829
remove unused value constructors from modules type info
This is a mildly scaring change, as it may horribly break things down
  the line if we have ever relied on that information... However, the
  value constructors inside each module are meant to reflect the own
  module public API, and shouldn't be populated with Prelude stuff. Not
  only does that mean this information is duplicated for all modules
  (possibly significantly slowing things down), but it may also cause
  weird scoping issues (e.g. one accessing a Prelude's constructor
  through some random module).

  Hence why I am isolating this change in this single commit, so it's
  easier to troubleshoot if that ends up causing weird issues.

Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-15 21:37:19 +01:00
KtorZ 81713d93a0
allow types to be used as namespace in patterns.
Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-15 21:37:19 +01:00
KtorZ c556ada7d5
introduce namespace enum to distinguish module select from type constructor select in patterns.
Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-15 15:49:22 +01:00
KtorZ 222d244bcf
Do not allow empty continuation for backpassed assignments
Fixes #1111.

Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-03-02 12:56:41 +01:00
KtorZ 9f24a5c577
Fix wrong use of 'UnknownVariable' instead of 'UnknownTypeConstructor'
While the feedback for human users is mostly the same, it does in fact
  matter for the LSP since the quickfix will be different depending on
  whether we look for a top-level identifier or if we look for a
  constructor.

  The typical case we see in the stdlib is the `VerificationKey` and
  `Script` constructors for `Credential`, often being mixed with
  their types counterparts in aiken/crypto!

Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-02-22 19:14:37 +01:00
KtorZ a89694ed75
Use less vertical space for type-constructor hint;
Also, show it actually for UnknownTypeConstructor, and not
  UnknownVariable. There's currently an error that wrongly assign an
  'UnknownVariable' in place where it should be an
  'UnknownTypeConstructor'. Fix coming in the next commit.

Signed-off-by: KtorZ <matthias.benkort@gmail.com>
2025-02-22 17:52:21 +01:00
KtorZ 58d782fa78
Scope type-aliases per module in blueprint.
Similarly to how we're already doing it for non-alias types.

  Fix #1074.

Signed-off-by: KtorZ <5680256+KtorZ@users.noreply.github.com>
2025-02-11 12:55:45 +01:00
KtorZ 2a1253cb52
Add additional test to check for Sampler alias formatting.
Signed-off-by: KtorZ <5680256+KtorZ@users.noreply.github.com>
2025-02-09 16:18:01 +01:00
KtorZ 428d30c3bb
refactor and fix benchmark type-checking
Fixes:

  - Do not allow bench with no arguments; this causes a compiler panic
    down the line otherwise.

  - Do not force the return value to be a boolean or void. We do not
    actually control what's returned by benchmark, so anything really
    works here.

  Refactor:

  - Re-use code between test and bench type-checking; especially the
    bits related to gathering information about the via arguments.
    There's quite a lot and simply copy-pasting everything will likely
    cause issues and discrepency at the first change.

Signed-off-by: KtorZ <5680256+KtorZ@users.noreply.github.com>
2025-02-09 16:18:01 +01:00
Riley-Kilgore 79ac1b2bfa Fix benchmarking and cleanup for PR 2025-01-22 15:23:17 -08:00
Riley-Kilgore bd44b22d59 Addressed comments on benchmarking PR 2025-01-22 15:23:17 -08:00
Riley-Kilgore df05ae7e5d Uh, formatting again.. 2025-01-22 15:23:17 -08:00
Riley-Kilgore 84a0abeb0f Old Fuzzer, new Sampler 2025-01-22 15:23:17 -08:00
Riley-Kilgore c0fabcd26a Added benchmark keyword and unified Samplers and Fuzzers as Generator 2025-01-22 15:23:17 -08:00
Riley-Kilgore d353e07ea1 Formatting 2025-01-22 15:23:17 -08:00
Riley-Kilgore 699628df62 Added ScaledFuzzer capabilities 2025-01-22 15:23:17 -08:00
KtorZ be770acb54 add some regression tests for the new unused fields warning. 2025-01-22 18:07:57 -05:00
KtorZ 05264bc423 Trigger warning when destructuring records using unnamed fields
Comes with a helpful hint and a LSP quickfix, so that it's most
  convenient.
2025-01-22 18:07:57 -05:00
Kasey 86ec3b2924
Fix: issue crash in code gen with incorrect column length in decision trees (#1069)
* Fix: Deeply nested assignments would offset the new columns count calculation. Now we track relevant columns and their path to ensure each row has wildcards if they don't contain the relevant column

* Add test plus clippy fix

* Clippy fix

* New version clippy fix
2024-12-05 11:02:19 +07:00
KtorZ 93d0191489
Fix latest clippy warnings. 2024-10-25 11:27:28 +02:00
microproofs c8731c98c7
Remove prints 2024-10-01 16:09:44 -04:00
KtorZ e8d97028ad
Prevent constant evaluating to generic/unbound functions
Constants are like tiny programs, so they are bound by the same rules
  as validators and other programs. In fact, functions are slightly more
  flexible in that they allow generic constant expressions like
  `List<a>`.

  Yet, there is no way to contain such generic structure that contain
  inhabitants in a way that satisfies the type-checker. In the example
  of `List<a>`, the only inhabitant of that type that we can construct
  is the empty list. Anything else would require holding onto some
  generic value.

  In addition, we can't force literal values into generic annotation, as
  something like:

  ```
  const foo: List<a> = [1, 2, 3]
  ```

  wouldn't type-check either since the right-side would unify to
  `List<Int>`. And again, the only right-hand side that can type-check
  is the empty list without any inhabitant.

  The added restriction on generic function is necessary because while
  we allow constants to return lambda, we cannot (easily) generate UPLC
  that is generic in its argument. By the time we generate UPLC, the
  underlying types have to be known.
2024-10-01 18:37:40 +02:00
KtorZ 0060804d1a
Fix redundant warning when destructuring validator params
This is not a "proper" fix as it simply get rid of the warning
  altogether (whether you use or not the destructured values).

  The reason for removing the warning entirely is because (1) it's
  simpler, but more so (2) there's no impact on the final code produced
  _anyway_. Redundant let bindings are already removed by the compiler;
  and while it's an implicit behaviour that requires a proper warning
  when it's coming from a user-defined assignment; here the redundant
  assignment is introduced by the compiler to begin with as another
  implicit behavior!

  So we have an implicit behaviour triggering a warning on another
  implicit behaviour. Truth is, there's no impact in having those
  parameters destructured and unused. So since users are already not
  aware that this results in an implicit let assignment being inserted
  in place for them; there's no need for the warning at all.
2024-10-01 13:17:00 +02:00
KtorZ 5737556efc
Fix compiler crash around dangling expect/let in traces
Fixes #1029.
2024-10-01 12:24:31 +02:00
Riley-Kilgore 7c6f3278ba Fixed single character patterns using double quotes 2024-09-24 11:54:05 -04:00
KtorZ a8b37820e8
Fix incorrect warning about unused variable when softcasting without explicit right-pattern.
See note added in code for a rationale.
2024-09-20 15:09:00 +02:00
KtorZ 943d90a99e
Fix invalid interpolation in error message. 2024-09-07 18:23:35 +02:00
KtorZ 19e30b10f9
Fix #1013 2024-09-06 12:28:12 +02:00
KtorZ f60df16bc2
Preserve type-aliases during blueprint generation. 2024-09-03 16:39:50 +02:00
KtorZ 7aefa85de1
Handle importing validator handler into test module. 2024-08-30 22:43:10 +02:00
KtorZ 5dfa3e7cca
Add label annotation where missing in type-checker errors. 2024-08-30 18:41:25 +02:00
KtorZ 75c059bf65
Fix module constant usage warnings. 2024-08-30 18:24:35 +02:00
KtorZ 6c2e3272da
Re-implement and extend docs formatter for constants 2024-08-29 16:25:35 +02:00
KtorZ cd0a9440e8
Allow any expression as constants
This is only a start. It compiles, but with a few TODOs left open. In particular, it doesn't currently handle constants depending on other constants or functions; nor does it hoist constants.
2024-08-29 16:24:12 +02:00
KtorZ efeda9a998
Prevent non-default fallback on exhaustive validator
Technically, we always need a fallback just because the way the UPLC
  is going to work. The last case in the handler pattern matching is
  always going to be else ...

  We could optimize that away and when the validator is exhaustive, make
  the last handler the fallback. Yet, it's really a micro optimization
  that saves us one extra if/else. So the sake of getting things
  working, we always assume that there's a fallback but, with the extra
  condition that when the validator is exhaustive (i.e. there's a
  handler covering all purposes), the fallback HAS TO BE the default
  fallback (i.e. (_) => fail).

  This allows us to gracefully format it out, and also raise an error in
  case where there's an extraneous custom fallback.
2024-08-27 20:16:45 +02:00
KtorZ 4003343444
Fix default annotation for spend's optional datum and mint argument.
When there's no type annotation in a validator handler signature, we
  provide default annotation to help the type-checker. However, for
  spend's datum and mint policy_id, those annotations mustn't be `Data`,
  but rather Option<Data> and Bytearray.

  Without that, when no annotation are provided, the compiler infer
  invalid types and fails with incongruous errors.
2024-08-27 18:42:10 +02:00
KtorZ 0510ca58f7
Implement record access syntax for validator handlers.
This is a little trick which detects record access and replace them
  with a simple var. The var itself is the validator handler name,
  though since it contains dots, it cannot be referred to by users
  explicitly. Yet fundamentally, it is semantically equivalent to just
  calling the function by its name.

  Note that this commit also removes the weird backdoor for allowing
  importing validators in modules starting with `tests`. Allowing
  validators handler to be used in importable module requires more work
  and is arguably useful; so we will wait until someone complain and
  reconsider the proper way to do it.
2024-08-27 17:16:15 +02:00
KtorZ af9a785d65
Provide default annotation to validators (incl. fallback)
Without that, we may encounter weird error messages when writing
  validators without an explicit `else`. Since we automatically fill it
  with a `fail`; without annotation, it unifies to a generic parameter.

  The existing check that would look for the body being an error term is
  ill-advised as it doesn't work as soon as one adds tracing, or make
  the validator a parameterized validator. Plus, it may simply trigger
  the wrong behavior as one can now annotate a validator with _whatever_
  and get pass the type-checker by plucking a `fail` keyword as body.
2024-08-25 17:12:11 +02:00
rvcas ff1464b462
feat: annotated data for option datum 2024-08-25 16:20:08 +02:00