Skip to content

Commit

Permalink
Add a hacky but working liftTyped instance
Browse files Browse the repository at this point in the history
  • Loading branch information
layus committed Jan 8, 2021
1 parent 1b517a4 commit 51a3ff9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
68 changes: 35 additions & 33 deletions src/Nix/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,39 +168,7 @@ builtinsList = sequence
, add0 Normal "currentSystem" currentSystem
, add0 Normal "currentTime" currentTime_
, add2 Normal "deepSeq" deepSeq

-- This is compiled in so that we only parse and evaluate it once, at
-- compile-time.
, add0 TopLevel "derivation" $(do
let Success expr = parseNixText [text|
drvAttrs @ { outputs ? [ "out" ], ... }:

let

strict = derivationStrict drvAttrs;

commonAttrs = drvAttrs
// (builtins.listToAttrs outputsList)
// { all = map (x: x.value) outputsList;
inherit drvAttrs;
};

outputToAttrListElement = outputName:
{ name = outputName;
value = commonAttrs // {
outPath = builtins.getAttr outputName strict;
drvPath = strict.drvPath;
type = "derivation";
inherit outputName;
};
};

outputsList = map outputToAttrListElement outputs;

in (builtins.head outputsList).value|]
[| foldFix Eval.eval expr |]
)

, add0 TopLevel "derivation" derivation
, add TopLevel "derivationStrict" derivationStrict_
, add TopLevel "dirOf" dirOf
, add2 Normal "div" div_
Expand Down Expand Up @@ -306,6 +274,40 @@ builtinsList = sequence

-- Primops

derivation
:: forall e t f m. (MonadNix e t f m, Scoped (NValue t f m) m)
=> m (NValue t f m)
derivation = foldFix Eval.eval $$(do

This comment has been minimized.

Copy link
@Anton-Latukha

Anton-Latukha Jan 21, 2021

Collaborator

@layus. Can you please elaborate on what this foldFix Eval.eval $$(... does with the Nix expression. As I think, you essentially pointed to GHC that derivation expression always used fully evaluated and so GHC always includes it compiled fully.
I am asking it to populate #815 and onward updates to it (there would be a few).

-- This is compiled in so that we only parse it once at compile-time.
let Success expr = parseNixText [text|
drvAttrs @ { outputs ? [ "out" ], ... }:

let

strict = derivationStrict drvAttrs;

commonAttrs = drvAttrs
// (builtins.listToAttrs outputsList)
// { all = map (x: x.value) outputsList;
inherit drvAttrs;
};

outputToAttrListElement = outputName:
{ name = outputName;
value = commonAttrs // {
outPath = builtins.getAttr outputName strict;
drvPath = strict.drvPath;
type = "derivation";
inherit outputName;
};
};

outputsList = map outputToAttrListElement outputs;

in (builtins.head outputsList).value|]
[|| expr ||]
)

foldNixPath
:: forall e t f m r
. MonadNix e t f m
Expand Down
6 changes: 6 additions & 0 deletions src/Nix/Expr/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ instance Lift (Fix NExprF) where
Just HRefl -> Just [| pack $(liftString $ unpack b) |]
Nothing -> Nothing

#if MIN_VERSION_template_haskell(2,17,0)
liftTyped = unsafeCodeCoerce . lift
#elif MIN_VERSION_template_haskell(2,16,0)
liftTyped = unsafeTExpCoerce . lift
#endif

-- | The monomorphic expression type is a fixed point of the polymorphic one.
type NExpr = Fix NExprF

Expand Down

0 comments on commit 51a3ff9

Please sign in to comment.