-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print previous errors if local module fails to load
Fixes #2365
- Loading branch information
1 parent
22b3a58
commit 5764486
Showing
3 changed files
with
84 additions
and
42 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FIXED: Clash no longer hides error messages if it fails to load external (precompiled) modules. See [#2365](https://github.com/clash-lang/clash-compiler/issues/2365) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
{-| | ||
Copyright : (C) 2013-2016, University of Twente, | ||
2016-2017, Myrtle Software Ltd, | ||
2017 , Google Inc. | ||
2017-2024, Google Inc. | ||
2021-2023, QBayLogic B.V. | ||
License : BSD2 (see the file LICENSE) | ||
Maintainer : QBayLogic B.V. <[email protected]> | ||
-} | ||
|
||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
|
@@ -38,8 +39,9 @@ import Control.Arrow (first) | |
import Control.Exception (SomeException, throw) | ||
import Control.Monad (forM, join, when) | ||
import Data.List.Extra (nubSort) | ||
import Control.Exception (throwIO) | ||
import Control.Exception (Exception, throwIO) | ||
import Control.Monad (foldM) | ||
import Control.Monad.Catch (catch, throwM) | ||
#if MIN_VERSION_ghc(9,0,0) | ||
import Control.Monad.Catch as MC (try) | ||
#endif | ||
|
@@ -527,6 +529,26 @@ nameString = OccName.occNameString . Name.nameOccName | |
varNameString :: Var.Var -> String | ||
varNameString = nameString . Var.varName | ||
|
||
data LoadModulesException = LoadModulesException | ||
{ moduleName :: String | ||
, externalError :: String | ||
, localError :: String | ||
} deriving (Exception) | ||
|
||
instance Show LoadModulesException where | ||
showsPrec :: Int -> LoadModulesException -> ShowS | ||
showsPrec _ LoadModulesException{moduleName, externalError, localError} = showString [I.i| | ||
Failed to load module '#{moduleName}'. | ||
|
||
Tried to load it from precompiled sources, error was: | ||
|
||
#{externalError} | ||
|
||
Tried to load it from local sources, error was: | ||
|
||
#{localError} | ||
|] | ||
|
||
loadModules | ||
:: GHC.Ghc () | ||
-- ^ Allows us to have some initial action, such as sharing a linker state | ||
|
@@ -573,7 +595,15 @@ loadModules startAction useColor hdl modName dflagsM idirs = do | |
-- We need to try and load external modules first, because we can't | ||
-- recover from errors in 'loadLocalModule'. | ||
loadExternalModule hdl modName >>= \case | ||
Left _loadExternalErr -> loadLocalModule hdl modName | ||
Left loadExternalErr -> do | ||
liftIO $ print loadExternalErr | ||
catch @_ @SomeException | ||
(loadLocalModule hdl modName) | ||
(\localError -> throwM (LoadModulesException{ | ||
moduleName = modName | ||
, externalError = show loadExternalErr | ||
, localError = show localError | ||
})) | ||
Right res -> pure res | ||
|
||
let allBinderIds = map fst (CoreSyn.flattenBinds allBinders) | ||
|
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