@@ -168,7 +168,8 @@ import Control.Monad.IO.Class (MonadIO (..))
168
168
import Control.Monad.Morph (hoist )
169
169
import Control.Monad.State.Strict (MonadState , StateT )
170
170
import Data.ByteString (ByteString )
171
- import Data.List.NonEmpty (NonEmpty (.. ))
171
+ import Data.List.NonEmpty (NonEmpty (.. ), nonEmpty )
172
+ import Data.Maybe (fromMaybe )
172
173
import Data.Text (Text )
173
174
import Data.Typeable (Typeable )
174
175
import Data.Void (Void , absurd )
@@ -1050,15 +1051,14 @@ defaultOriginHeaders = do
1050
1051
originHeadersLoader :: IO (Expr Src Import ) -> StateT Status IO OriginHeaders
1051
1052
originHeadersLoader headersExpr = do
1052
1053
1053
- -- Load the headers using a parallel state with an empty impport chain.
1054
- -- We also set _loadOriginHeaders to prevent reentrant loads.
1054
+ -- Load the headers using the parent stack, which should always be a local
1055
+ -- import (we only load headers for the first remote import)
1055
1056
1056
1057
status <- State. get
1057
1058
1058
- let headerLoadStatus = status {
1059
- _stack = pure (NonEmpty. last (_stack status)),
1060
- _loadOriginHeaders = reentrantLoad
1061
- }
1059
+ let parentStack = fromMaybe abortEmptyStack (nonEmpty (NonEmpty. tail (_stack status)))
1060
+
1061
+ let headerLoadStatus = status { _stack = parentStack }
1062
1062
1063
1063
(headers, _) <- liftIO (State. runStateT doLoad headerLoadStatus)
1064
1064
@@ -1067,14 +1067,7 @@ originHeadersLoader headersExpr = do
1067
1067
1068
1068
return headers
1069
1069
where
1070
-
1071
- -- The builtin Cycle error should make this unnecessary,
1072
- -- but loadWith raises ReferentiallyOpaque before we have a chance to
1073
- -- raise a Cycle, and the former is caught by dhall's `?` operator.
1074
- reentrantLoad = do
1075
- Status { _stack } <- State. get
1076
- let (Chained parent) = NonEmpty. head _stack
1077
- throwMissingImport (Imported _stack (Cycle parent))
1070
+ abortEmptyStack = Core. internalError " Origin headers loaded with an empty stack"
1078
1071
1079
1072
doLoad = do
1080
1073
partialExpr <- liftIO headersExpr
0 commit comments