@@ -168,7 +168,8 @@ import Control.Monad.IO.Class (MonadIO (..))
168168import Control.Monad.Morph (hoist )
169169import Control.Monad.State.Strict (MonadState , StateT )
170170import Data.ByteString (ByteString )
171- import Data.List.NonEmpty (NonEmpty (.. ))
171+ import Data.List.NonEmpty (NonEmpty (.. ), nonEmpty )
172+ import Data.Maybe (fromMaybe )
172173import Data.Text (Text )
173174import Data.Typeable (Typeable )
174175import Data.Void (Void , absurd )
@@ -1050,15 +1051,14 @@ defaultOriginHeaders = do
10501051originHeadersLoader :: IO (Expr Src Import ) -> StateT Status IO OriginHeaders
10511052originHeadersLoader headersExpr = do
10521053
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)
10551056
10561057 status <- State. get
10571058
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 }
10621062
10631063 (headers, _) <- liftIO (State. runStateT doLoad headerLoadStatus)
10641064
@@ -1067,14 +1067,7 @@ originHeadersLoader headersExpr = do
10671067
10681068 return headers
10691069 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"
10781071
10791072 doLoad = do
10801073 partialExpr <- liftIO headersExpr
0 commit comments