Skip to content

Commit e5e60f5

Browse files
bcoetargos
authored andcommitted
build: remove (almost) unused macros/constants
Macros, like CHECK, cause issues for tracking coverage because they modify the source before it's placed in V8. Upon investigation it seemed that we only used this functionality in two places: internal/vm/module.js, and internal/async_hooks.js (in comments). Given this, it seemed to make more sense to move CHECK to JavaScript, and retire a mostly unused build step. PR-URL: #30755 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 248921b commit e5e60f5

8 files changed

Lines changed: 13 additions & 208 deletions

File tree

‎lib/.eslintrc.yaml‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,6 @@ rules:
6262
node-core/non-ascii-character: error
6363
globals:
6464
Intl: false
65-
# Assertions
66-
CHECK: false
67-
CHECK_EQ: false
68-
CHECK_GE: false
69-
CHECK_GT: false
70-
CHECK_LE: false
71-
CHECK_LT: false
72-
CHECK_NE: false
73-
DCHECK: false
74-
DCHECK_EQ: false
75-
DCHECK_GE: false
76-
DCHECK_GT: false
77-
DCHECK_LE: false
78-
DCHECK_LT: false
79-
DCHECK_NE: false
8065
# Parameters passed to internal modules
8166
global: false
8267
require: false

‎lib/internal/vm/module.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const{ fail }=require('internal/assert');
34
const{
45
ArrayIsArray,
56
ObjectCreate,
@@ -59,6 +60,11 @@ const kContext = Symbol('kContext');
5960
constkPerContextModuleId=Symbol('kPerContextModuleId');
6061
constkLink=Symbol('kLink');
6162

63+
functionfailIfDebug(){
64+
if(process.features.debug===false)return;
65+
fail('VM Modules');
66+
}
67+
6268
classModule{
6369
constructor(options){
6470
emitExperimentalWarning('VM Modules');
@@ -119,7 +125,7 @@ class Module {
119125
syntheticExportNames,
120126
syntheticEvaluationSteps);
121127
}else{
122-
CHECK(false);
128+
failIfDebug();
123129
}
124130

125131
wrapToModuleMap.set(this[kWrap],this);
@@ -375,7 +381,7 @@ class SyntheticModule extends Module {
375381
identifier,
376382
});
377383

378-
this[kLink]=()=>this[kWrap].link(()=>{CHECK(false);});
384+
this[kLink]=()=>this[kWrap].link(()=>{failIfDebug();});
379385
}
380386

381387
setExport(name,value){

‎node.gyp‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -899,23 +899,11 @@
899899
# Put the code first so it's a dependency and can be used for invocation.
900900
'tools/js2c.py',
901901
'<@(library_files)',
902-
'config.gypi',
903-
'tools/js2c_macros/check_macros.py'
902+
'config.gypi'
904903
],
905904
'outputs': [
906905
'<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
907906
],
908-
'conditions': [
909-
[ 'node_use_dtrace=="false" and node_use_etw=="false"', {
910-
'inputs': [ 'tools/js2c_macros/notrace_macros.py' ]
911-
}],
912-
[ 'node_debug_lib=="false"', {
913-
'inputs': [ 'tools/js2c_macros/nodcheck_macros.py' ]
914-
}],
915-
[ 'node_debug_lib=="true"', {
916-
'inputs': [ 'tools/js2c_macros/dcheck_macros.py' ]
917-
}]
918-
],
919907
'action': [
920908
'python', '<@(_inputs)',
921909
'--target', '<@(_outputs)',

‎tools/js2c.py‎

Lines changed: 4 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -45,137 +45,6 @@ def ReadFile(filename):
4545
returnlines
4646

4747

48-
defReadMacroFiles(filenames):
49-
"""
50-
51-
:rtype: List(str)
52-
"""
53-
result= []
54-
forfilenameinfilenames:
55-
withopen(filename, "rt") asf:
56-
# strip python-like comments and whitespace padding
57-
lines= [line.split('#')[0].strip() forlineinf]
58-
# filter empty lines
59-
result.extend(filter(bool, lines))
60-
returnresult
61-
62-
63-
defExpandConstants(lines, constants):
64-
forkey, valueinconstants.items():
65-
lines=lines.replace(key, str(value))
66-
returnlines
67-
68-
69-
defExpandMacros(lines, macros):
70-
defexpander(s):
71-
returnExpandMacros(s, macros)
72-
73-
forname, macroinmacros.items():
74-
name_pattern=re.compile("\\b%s\\("%name)
75-
pattern_match=name_pattern.search(lines, 0)
76-
whilepattern_matchisnotNone:
77-
# Scan over the arguments
78-
height=1
79-
start=pattern_match.start()
80-
end=pattern_match.end()
81-
assertlines[end-1] =='('
82-
last_match=end
83-
arg_index= [0] # Wrap state into array, to work around Python "scoping"
84-
mapping= {}
85-
86-
defadd_arg(s):
87-
# Remember to expand recursively in the arguments
88-
ifarg_index[0] >=len(macro.args):
89-
return
90-
replacement=expander(s.strip())
91-
mapping[macro.args[arg_index[0]]] =replacement
92-
arg_index[0] +=1
93-
94-
whileend<len(lines) andheight>0:
95-
# We don't count commas at higher nesting levels.
96-
iflines[end] ==','andheight==1:
97-
add_arg(lines[last_match:end])
98-
last_match=end+1
99-
eliflines[end] in ['(', '{', '[']:
100-
height=height+1
101-
eliflines[end] in [')', '}', ']']:
102-
height=height-1
103-
end=end+1
104-
# Remember to add the last match.
105-
add_arg(lines[last_match:end-1])
106-
ifarg_index[0] <len(macro.args) -1:
107-
lineno=lines.count(os.linesep, 0, start) +1
108-
raiseException(
109-
'line %s: Too few arguments for macro "%s"'% (lineno, name))
110-
result=macro.expand(mapping)
111-
# Replace the occurrence of the macro with the expansion
112-
lines=lines[:start] +result+lines[end:]
113-
pattern_match=name_pattern.search(lines, start+len(result))
114-
returnlines
115-
116-
117-
classTextMacro:
118-
def__init__(self, args, body):
119-
self.args=args
120-
self.body=body
121-
122-
defexpand(self, mapping):
123-
result=self.body
124-
forkey, valueinmapping.items():
125-
result=result.replace(key, value)
126-
returnresult
127-
128-
129-
classPythonMacro:
130-
def__init__(self, args, fun):
131-
self.args=args
132-
self.fun=fun
133-
134-
defexpand(self, mapping):
135-
args= []
136-
forarginself.args:
137-
args.append(mapping[arg])
138-
returnstr(self.fun(*args))
139-
140-
141-
CONST_PATTERN=re.compile('^const\s+([a-zA-Z0-9_]+)\s*=\s*([^;]*);$')
142-
MACRO_PATTERN=re.compile('^macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$')
143-
PYTHON_MACRO_PATTERN=re.compile('^python\s+macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$')
144-
145-
146-
defReadMacros(macro_files):
147-
lines=ReadMacroFiles(macro_files)
148-
constants= {}
149-
macros= {}
150-
forlineinlines:
151-
line=line.split('#')[0].strip()
152-
iflen(line) ==0:
153-
continue
154-
const_match=CONST_PATTERN.match(line)
155-
ifconst_match:
156-
name=const_match.group(1)
157-
value=const_match.group(2).strip()
158-
constants[name] =value
159-
else:
160-
macro_match=MACRO_PATTERN.match(line)
161-
ifmacro_match:
162-
name=macro_match.group(1)
163-
args= [p.strip() forpinmacro_match.group(2).split(',')]
164-
body=macro_match.group(3).strip()
165-
macros[name] =TextMacro(args, body)
166-
else:
167-
python_match=PYTHON_MACRO_PATTERN.match(line)
168-
ifpython_match:
169-
name=python_match.group(1)
170-
args= [p.strip() forpinmacro_match.group(2).split(',')]
171-
body=python_match.group(3).strip()
172-
fun=eval("lambda "+",".join(args) +': '+body)
173-
macros[name] =PythonMacro(args, fun)
174-
else:
175-
raiseException("Illegal line: "+line)
176-
returnconstants, macros
177-
178-
17948
TEMPLATE="""
18049
#include "env-inl.h"
18150
#include "node_native_module.h"
@@ -243,10 +112,8 @@ def GetDefinition(var, source, step=30):
243112
returndefinition, len(code_points)
244113

245114

246-
defAddModule(filename, consts, macros, definitions, initializers):
115+
defAddModule(filename, definitions, initializers):
247116
code=ReadFile(filename)
248-
code=ExpandConstants(code, consts)
249-
code=ExpandMacros(code, macros)
250117
name=NormalizeFileName(filename)
251118
slug=SLUGGER_RE.sub('_', name)
252119
var=slug+'_raw'
@@ -267,15 +134,12 @@ def NormalizeFileName(filename):
267134

268135

269136
defJS2C(source_files, target):
270-
# Process input from all *macro.py files
271-
consts, macros=ReadMacros(source_files['.py'])
272-
273137
# Build source code lines
274138
definitions= []
275139
initializers= []
276140

277141
forfilenameinsource_files['.js']:
278-
AddModule(filename, consts, macros, definitions, initializers)
142+
AddModule(filename, definitions, initializers)
279143

280144
config_def, config_size=handle_config_gypi(source_files['config.gypi'])
281145
definitions.append(config_def)
@@ -341,8 +205,8 @@ def main():
341205
globalis_verbose
342206
is_verbose=options.verbose
343207
source_files=functools.reduce(SourceFileByExt, options.sources, {})
344-
# Should have exactly 3 types: `.js`, `.py`, and `.gypi`
345-
assertlen(source_files) ==3
208+
# Should have exactly 2 types: `.js`, and `.gypi`
209+
assertlen(source_files) ==2
346210
# Currently config.gypi is the only `.gypi` file allowed
347211
assertsource_files['.gypi'] == ['config.gypi']
348212
source_files['config.gypi'] =source_files.pop('.gypi')[0]

‎tools/js2c_macros/check_macros.py‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎tools/js2c_macros/dcheck_macros.py‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎tools/js2c_macros/nodcheck_macros.py‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎tools/js2c_macros/notrace_macros.py‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)