DynFlags: Initialize unsafeGlobalDynFlags enough to be useful
authorBen Gamari <bgamari.foss@gmail.com>
Fri, 25 Mar 2016 23:42:11 +0000 (00:42 +0100)
committerBen Gamari <ben@smart-cactus.org>
Fri, 25 Mar 2016 23:42:12 +0000 (00:42 +0100)
Previously unsafeGlobalDynFlags would bottom if used prior to
initialization. This meant that any attempt to use the pretty-printer
early in the initialization process of the compiler would fail. This is
quite inconvenient.

Here we initialize unsafeGlobalDynFlags with defaultDynFlags, bottoming
only if settings is accessed.

See #11755.

Test Plan: Validate

Reviewers: austin

Reviewed By: austin

Subscribers: thomie, gridaphobe

Differential Revision: https://phabricator.haskell.org/D2036

GHC Trac Issues: #11755

compiler/main/DynFlags.hs

index 99d80d6..9c67045 100644 (file)
@@ -4855,7 +4855,15 @@ makeDynFlagsConsistent dflags
 -- Do not use it if you can help it. You may get the wrong value, or this
 -- panic!
 
-GLOBAL_VAR(v_unsafeGlobalDynFlags, panic "v_unsafeGlobalDynFlags: not initialised", DynFlags)
+-- | This is the value that 'unsafeGlobalDynFlags' takes before it is
+-- initialized.
+defaultGlobalDynFlags :: DynFlags
+defaultGlobalDynFlags =
+    (defaultDynFlags settings) { verbosity = 2 }
+  where
+    settings = panic "v_unsafeGlobalDynFlags: not initialised"
+
+GLOBAL_VAR(v_unsafeGlobalDynFlags, defaultGlobalDynFlags, DynFlags)
 
 unsafeGlobalDynFlags :: DynFlags
 unsafeGlobalDynFlags = unsafePerformIO $ readIORef v_unsafeGlobalDynFlags