Skip to content
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

fix: proper type checking on targets #3

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions grow/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,32 @@
oPath = paths.cellBlockPath cellsFrom cellName cellBlock;
isFile = l.pathExists oPath.file;
isDir = l.pathExists oPath.dir;
Target' = path': Target "paisano/import: ${path'}"; # TODO: implement lazy target block type checks
import' = path': path: let
import' = {displayPath, importPath} let
# since we're not really importing files within the framework
# the non-memoization of scopedImport doesn't have practical penalty
block = Block "paisano/import: ${path'}" (l.scopedImport signature path);
block = Block "paisano/import: ${displayPath}" (l.scopedImport signature importPath);
signature = _ImportSignatureFor res.output; # recursion on cell
in
if l.typeOf block == "set"
then block
else block signature;
imported =
importPaths =
if isFile
then Target' oPath.file' (import' oPath.file' oPath.file)
then {displayPath = oPath.file'; importPath = oPath.file;}
else if isDir
then Target' oPath.dir' (import' oPath.dir' oPath.dir)
then {displayPath = oPath.dir'; importPath = oPath.dir;}
else throw "unreachable!";
Target' = {displayPath, ...}: Target "paisano/import: ${displayPath}";
imported = import' importPaths;
# type checked import
imported' = Target' importPaths ((cellBlock.type or null) imported);
# extract instatiates actions and extracts metadata for the __std registry
extracted = l.optionalAttrs (cellBlock.cli or true) (l.mapAttrs (_extract cellBlock) imported);
extracted = l.optionalAttrs (cellBlock.cli or true) (l.mapAttrs (_extract cellBlock) imported');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The big question: type-checked imported' here (for the extractor → registry) or unchecked imported?

I left a couple of considerations in the commit message...

in
optionalLoad (isFile || isDir)
[
# top level output
{${cellBlock.name} = imported;}
{${cellBlock.name} = imported';}
# __std.actions (slow)
{${cellBlock.name} = l.mapAttrs (_: set: set.actions) extracted;}
# __std.init (fast)
Expand Down
19 changes: 10 additions & 9 deletions types/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
inherit l;
inherit (paths) cellPath cellBlockPath;
};
Target = log:
with yants log;
# unfortunately eval during check can cause infinite recursions
# if blockType == "runnables" || blockType == "installables"
# then attrs drv
# else if blockType == "functions"
# then attrs function
# else throw "unreachable";
attrs any;
Target = log: type:
with yants log; let
type' =
# TODO: remove in the future and make a specific type a hard requirement
if type == null
then any
else type;
in
attrs type';
Systems = log: with yants log; list (enum "system" l.systems.doubles.all);
BlockTypes = log:
with yants log;
Expand All @@ -25,6 +25,7 @@
__functor = option function;
ci = option (attrs bool);
cli = option bool;
type = option type;
actions = option (functionWithArgs {
system = false;
target = false;
Expand Down