Go to file
KtorZ a124bdbb05 Infer callee first in function call
The current inferrence system walks expressions from "top to bottom".
  Starting from definitions higher in the source file, and down. When a
  call is encountered, we use the information known for the callee
  definition we have at the moment it is inferred.

  This causes interesting issues in the case where the callee doesn't
  have annotations and in only partially known. For example:

  ```
  pub fn list(fuzzer: Option<a>) -> Option<List<a>> {
    inner(fuzzer, [])
  }

  fn inner(fuzzer, xs) -> Option<List<b>> {
    when fuzzer is {
      None -> Some(xs)
      Some(x) -> Some([x, ..xs])
    }
  }
  ```

  In this small program, we infer `list` first and run into `inner`.
  Yet, the arguments for `inner` are not annotated, so since we haven't
  inferred `inner` yet, we will create two unbound variables.

  And naturally, we will link the type of `[]` to being of the same type
  as `xs` -- which is still unbound at this point. The return type of
  `inner` is given by the annotation, so all-in-all, the unification
  will work without ever having to commit to a type of `[]`.

  It is only later, when `inner` is inferred, that we will generalise
  the unbound type of `xs` to a generic which the same as `b` in the
  annotation. At this point, `[]` is also typed with this same generic,
  which has a different id than `a` in `list` since it comes from
  another type definition.

  This is unfortunate and will cause issues down the line for the code
  generation. The problem doesn't occur when `inner`'s arguments are
  properly annotated or, when `inner` is actually inferred first.

  Hence, I saw two possible avenues for fixing this problem:

  1. Detect the presence of 'uncongruous generics' in definitions after
     they've all been inferred, and raise a user error asking for more
     annotations.

  2. Infer definitions in dependency order, with definitions used in
     other inferred first.

  This commit does (2) (although it may still be a good idea to do (1)
  eventually) since it offers a much better user experience. One way to
  do (2) is to construct a dependency graph between function calls, and
  ensure perform a topological sort.

  Building such graph is, however, quite tricky as it requires walking
  through the AST while maintaining scope etc. which is more-or-less
  already what the inferrence step is doing; so it feels like double
  work.

  Thus instead, this commit tries to do a deep-first inferrence and
  "pause" inferrence of definitions when encountering a call to fully
  infer the callee first. To achieve this properly, we must ensure that
  we do not infer the same definition again, so we "remember" already
  inferred definitions in the environment now.
2024-05-06 15:17:01 -04:00
.github fix: blst stuff is not happy on windows aarch64 2023-12-04 22:29:23 -05:00
aikup feat(aikup): error message when version not found 2024-02-27 21:38:00 -05:00
crates Infer callee first in function call 2024-05-06 15:17:01 -04:00
examples test should fail 2024-05-06 11:35:55 -04:00
.editorconfig rename examples/tests/{a,b,c,d,e,f} into examples/acceptance_tests/00{1,2,3,4,5,6} 2022-12-14 09:45:24 +01:00
.gitattributes Add support for Nix flakes. 2023-02-07 13:16:17 +01:00
.gitignore chore: commit an ignore we can all use without accidentally commiting test files/folders 2024-03-12 08:10:33 -04:00
CHANGELOG.md Check for args length when comparing types. Duh! 2024-05-01 10:48:15 +02:00
CONTRIBUTING.md chore: add release instructions in contributing.md 2023-08-24 15:43:26 -06:00
Cargo.lock chore(deps): bump h2 from 0.3.24 to 0.3.26 2024-04-08 12:26:51 -04:00
Cargo.toml chore: bump pallas 2024-01-25 11:07:18 -05:00
LICENSE chore: update license 2024-05-01 22:10:47 -04:00
README.md chore: use updated theme method 2024-02-15 14:47:53 -05:00
flake.lock bump flake ... but in a way that works for external builds?! 2024-03-04 14:32:27 +00:00
flake.nix bump flake ... but in a way that works for external builds?! 2024-03-04 14:32:27 +00:00

README.md

Aiken

A modern smart contract platform for Cardano

Licence Crates.io Tests


Installation

How to use

For more information please see the user manual.

Contributing

Want to contribute? See CONTRIBUTING.md to know how.


Note

The name comes from Howard Aiken, an American physicist and a pioneer in computing.

Stats

Alt