[dawn] Remove "upstream" tag, validate tags

- Remove the "upstream" tag from dawn.json which is no longer used and
  should no longer be used (we want all such differences to appear in
  webgpu.h.diff).
- Add validation of tags to make sure "upstream" or any other unknown
  tags are not reintroduced.

Fixed: 419596995
Change-Id: I892455e29f8cef21f58d18603c32623525924ba4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/251894
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index e06e9cd..7d2c476 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -102,6 +102,23 @@
     return ' '.join([name.canonical_case() for name in names])
 
 
+def validate_and_get_tags(json_data):
+    allowed_tags = {
+        'dawn',
+        'emscripten',
+        'native',
+        'compat',
+        'deprecated',
+        'art',
+    }
+
+    tags = json_data.get('tags')
+    if tags != None:
+        for tag in tags:
+            assert tag in allowed_tags, f'unrecognized tag "{tag}"'
+    return tags
+
+
 class Type:
     def __init__(self, name, json_data, native=False):
         self.json_data = json_data
@@ -132,27 +149,28 @@
                 continue
             value = m['value']
             value_name = m['name']
-            tags = m.get('tags', [])
+            tags = validate_and_get_tags(m)
+            if tags == None:
+                tags = []
 
             prefix = 0
             if 'compat' in tags:
                 assert prefix == 0
                 prefix = 0x0002_0000
 
-            if 'upstream' not in tags:
-                if 'dawn' in tags:
-                    # Dawn-only or Dawn+Emscripten
-                    assert prefix == 0
-                    prefix = 0x0005_0000
-                elif 'emscripten' in tags:
-                    # Emscripten-only
-                    assert prefix == 0
-                    prefix = 0x0004_0000
+            if 'dawn' in tags:
+                # Dawn-only or Dawn+Emscripten
+                assert prefix == 0
+                prefix = 0x0005_0000
+            elif 'emscripten' in tags:
+                # Emscripten-only
+                assert prefix == 0
+                prefix = 0x0004_0000
 
             if prefix == 0 and 'native' in tags:
                 prefix = 0x0001_0000
 
-            if 'deprecated' not in tags and 'upstream' not in tags:
+            if 'deprecated' not in tags:
                 # Emscripten implements some Dawn extensions, and some upstream things that
                 # aren't in Dawn yet.
                 if 'emscripten' in tags and 'dawn' not in tags:
@@ -332,7 +350,7 @@
 
 class StructureType(Record, Type):
     def __init__(self, is_enabled, name, json_data):
-        tags = json_data.get('tags', [])
+        tags = validate_and_get_tags(json_data)
         if tags == ['emscripten']:
             if name != 'INTERNAL_HAVE_EMDAWNWEBGPU_HEADER':
                 assert name.startswith('emscripten'), name
@@ -971,14 +989,14 @@
 
 
 def item_is_enabled(enabled_tags, json_data):
-    tags = json_data.get('tags')
+    tags = validate_and_get_tags(json_data)
     if tags is None: return True
     return any(tag in enabled_tags for tag in tags)
 
 
 def item_is_disabled(disabled_tags, json_data):
     if disabled_tags is None: return False
-    tags = json_data.get('tags')
+    tags = validate_and_get_tags(json_data)
     if tags is None: return False
 
     return any(tag in disabled_tags for tag in tags)
@@ -1286,7 +1304,7 @@
 
         if 'webgpu_headers' in targets:
             params_upstream = parse_json(loaded_json,
-                                         enabled_tags=['upstream', 'native'],
+                                         enabled_tags=['native'],
                                          disabled_tags=['dawn'])
             imported_templates.append('BSD_LICENSE')
             renders.append(
diff --git a/generator/templates/api.h b/generator/templates/api.h
index 0bb4308..3943a56 100644
--- a/generator/templates/api.h
+++ b/generator/templates/api.h
@@ -40,7 +40,7 @@
 //* -------------------------------------------------------------------------------------
 //* The follow block defines Dawn generator specific macros and #defines for migrations.
 //* -------------------------------------------------------------------------------------
-{%- if 'upstream' not in enabled_tags %}
+{%- if 'dawn' in enabled_tags or 'emscripten' in enabled_tags %}
 
     #define WGPU_BREAKING_CHANGE_STRING_VIEW_LABELS
     #define WGPU_BREAKING_CHANGE_STRING_VIEW_OUTPUT_STRUCTS