-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional configuration & environment #994
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Do nothing about it yet, but trigger an error if env/default.ak is missing; but only if there's any module at all under env.
We simply provide a flag with a free-form output which acts as the module to lookup in the 'env' folder. The strategy is to replace the environment module name on-the-fly when a user tries to import 'env'. If the environment isn't found, an 'UnknownModule' error is raised (which I will slightly adjust in a following commits to something more related to environment) There are few important consequences to this design which may not seem immediately obvious: 1. We parse and type-check every env modules, even if they aren't used. This ensures that code doesn't break with a compilation error simply because people forgot to type-check a given env. Note that compilation could still fail because the env module itself could provide an invalid API. So it only prevents each modules to be independently wrong when taken in isolation. 2. Technically, this also means that one can import env modules in other env modules by their names. I don't know if it's a good or bad idea at this point but it doesn't really do any wrong; dependencies and cycles are handlded all-the-same.
We figure out dependencies by looking at 'use' definition in parsed modules. However, in the case of environment modules, we must consider all of them when seeing "use env". Without that, the env modules are simply compiled in parallel and may not yet have been compiled when they are needed as actual dependencies.
This is less confusing that getting an 'UnknownModule' error reporting even a different module name than the one actually being important ('env'). Also, this commit fixes a few errors found in the type-checker when reporting 'UnknownModule' errors. About half the time, we would actually attached _imported modules_ instead of _importable modules_ to the error, making the neighboring suggestion quite worse (nay useless).
This is currently extremely limited as it only supports (UTF-8) bytearrays and integers. We should seek to at least support hex bytes sequences, as well as bools, lists and possibly options. For the latter, we the rework on constant outlined in #992 is necessary.
The syntax is as follows: { "bytes" = "...", "encoding" = "<encoding>" } The following encoding are accepted: "utf8", "utf-8", "hex", "base16" Note: the duplicates are only there to make it easier for people to discover them by accident. When "hex" (resp. "base16") is specified, the bytes string will be decoded and must be a valid hex string.
rvcas
approved these changes
Aug 5, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, this is so epic
pub type TypedModule = Module<TypeInfo, TypedDefinition>; | ||
pub type UntypedModule = Module<(), UntypedDefinition>; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] | ||
pub enum ModuleKind { | ||
Lib, | ||
Validator, | ||
Env, | ||
Config, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool
I don't know if you want to merge this yet, seems ready to me but I'll let you click the button. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Closes #937.
Preview
☝️ Many things happening on the image above:
env
directory.aiken.toml
env
andconfig
modules, which are populated based on the--env
flag. Defaulting to the environment/config called default when not present.--env preprod
is passed, only the preprod tests pass.No default environment?
Unknown environment?
Missing configuration?
Note
This only triggers a warning because it may not be problematic should the configuration be unused. If it is used, we simply fallback to a usual 'unknown module' error.
Changelog
📍 Parse sources of conditional env modules.
Do nothing about it yet, but trigger an error if env/default.ak is
missing; but only if there's any module at all under env.
📍 Thread down environment module from cli down to the type-checker
We simply provide a flag with a free-form output which acts as
the module to lookup in the 'env' folder. The strategy is to replace
the environment module name on-the-fly when a user tries to import
'env'.
If the environment isn't found, an 'UnknownModule' error is raised
(which I will slightly adjust in a following commits to something more
related to environment)
There are few important consequences to this design which may not seem
immediately obvious:
We parse and type-check every env modules, even if they aren't
used. This ensures that code doesn't break with a compilation error
simply because people forgot to type-check a given env.
Note that compilation could still fail because the env module
itself could provide an invalid API. So it only prevents each
modules to be independently wrong when taken in isolation.
Technically, this also means that one can import env modules in
other env modules by their names. I don't know if it's a good or
bad idea at this point but it doesn't really do any wrong;
dependencies and cycles are handlded all-the-same.
📍 Ensure env modules dependencies are properly handled.
We figure out dependencies by looking at 'use' definition in parsed
modules. However, in the case of environment modules, we must consider
all of them when seeing "use env". Without that, the env modules are
simply compiled in parallel and may not yet have been compiled when
they are needed as actual dependencies.
📍 Create dedicated error when environment isn't found.
This is less confusing that getting an 'UnknownModule' error reporting
even a different module name than the one actually being important
('env').
Also, this commit fixes a few errors found in the type-checker
when reporting 'UnknownModule' errors. About half the time, we would
actually attached imported modules instead of importable modules
to the error, making the neighboring suggestion quite worse (nay
useless).
📍 Allow simple expressions as configuration in aiken.toml
This is currently extremely limited as it only supports (UTF-8)
bytearrays and integers. We should seek to at least support hex bytes
sequences, as well as bools, lists and possibly options.
For the latter, we the rework on constant outlined in Hoist complex constant #992 is
necessary.
📍 Allow bytes to be defined as plain strings, or with specified encoding.
The syntax is as follows:
{ "bytes" = "...", "encoding" = "" }
The following encoding are accepted:
"utf8", "utf-8", "hex", "base16"
Note: the duplicates are only there to make it easier for people to
discover them by accident. When "hex" (resp. "base16") is specified,
the bytes string will be decoded and must be a valid hex string.
📍 Fill-in CHANGELOG.