               doom-modules-dir)))
 
 (defun doom-module-loaded-p (module submodule)
-  "Returns t if SUBMODULE (in MODULE) is present in `doom-modules'."
-  (and (memq submodule (cdr (assq module doom-modules)))
-       t))
+  "Returns t if MODULE->SUBMODULE is present in `doom-modules'."
+  (gethash (cons module submodule) doom-modules))
 
 (defun doom--module-pairs ()
-  "Returns `doom-modules' as a list of (MODULE . SUBMODULE) cons cells."
-  (let (pairs module)
-    (dolist (modules doom-modules)
-      (setq module (car modules))
-      (dolist (submodule (cdr modules))
-        (push (cons module submodule) pairs)))
+  "Returns `doom-modules' as a list of (MODULE . SUBMODULE) cons cells. The list
+is sorted by order of insertion."
+  (let (pairs)
+    (maphash (lambda (key value)
+               (setq pairs (append pairs (list (cons (car key) (cdr key))))))
+             doom-modules)
     pairs))
 
 (defun doom--enable-module (module submodule &optional force-p)


Used by `@require' and `@depends-on'."
  (unless (or force-p (doom-module-loaded-p module submodule))
    (let ((sublist (assq module doom-modules)))
      (if sublist
          (setcdr (last sublist) (list submodule))
        (push (list module submodule) doom-modules)))))

(defun doom--enable-modules (modules)
  "Adds MODULES to `doom-modules'.

MODULES must be in mplist format:
  '(:feature evil :lang emacs-lisp javascript java)"
  (let (mode)
    (dolist (m modules)
      (cond ((keywordp m)
             (setq mode m))
            ((not mode)
             (error "No namespace specified on `@doom' for %s" m))
            ((eq m '*)
             (let ((mode-str (substring (symbol-name mode) 1)))
               (doom--enable-modules
                (cons mode
                      (--map (intern (f-base it))
                             (f-directories
                              (f-expand mode-str doom-modules-dir)))))))
            (t
             (doom--enable-module mode m))))
    doom-modules))


;;

(defmacro @doom (&rest modules)
  "DOOM Emacs bootstrap macro. List the modules to load. Benefits from
byte-compilation."
  (doom-initialize-modules modules)
  (unless noninteractive
    `(let (file-name-handler-alist)
       (setq doom-modules ',doom-modules)

       ,@(mapcar (lambda (module) `(@require ,(car module) ,(cdr module) t))
                 (doom--module-pairs))

       (when (display-graphic-p)
