aboutsummaryrefslogtreecommitdiff
path: root/utils/jq/patches/0006-Replace-TOP-before-imports-special-case-with-assert.patch
blob: ae2c4069dcdd87615b979c118982ea2fb0f7340e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
From a114b871e460ef2ddcf7698bc6b18651c976626a Mon Sep 17 00:00:00 2001
From: Muh Muhten <muh.muhten@gmail.com>
Date: Tue, 19 Feb 2019 00:14:53 -0500
Subject: [PATCH 6/9] Replace TOP-before-imports special case with assert

The case isn't actually possible afaict.
---
 src/compile.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

--- a/src/compile.c
+++ b/src/compile.c
@@ -469,10 +469,10 @@ block block_drop_unreferenced(block body
 jv block_take_imports(block* body) {
   jv imports = jv_array();
 
-  inst* top = NULL;
-  if (body->first && body->first->op == TOP) {
-    top = block_take(body);
-  }
+  /* Parser should never generate TOP before imports */
+  assert(!(body->first && body->first->op == TOP && body->first->next &&
+        (body->first->next->op == MODULEMETA || body->first->next->op == DEPS)));
+
   while (body->first && (body->first->op == MODULEMETA || body->first->op == DEPS)) {
     inst* dep = block_take(body);
     if (dep->op == DEPS) {
@@ -480,9 +480,6 @@ jv block_take_imports(block* body) {
     }
     inst_free(dep);
   }
-  if (top) {
-    *body = block_join(inst_block(top),*body);
-  }
   return imports;
 }