Skip to content

Commit 283938e

Browse files
committed
Remove various unused memsize infra
1 parent 14e3975 commit 283938e

11 files changed

Lines changed: 0 additions & 212 deletions

File tree

bin/prism

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module Prism
1515
when "encoding" then encoding(argv)
1616
when "lex" then lex(argv)
1717
when "locals" then locals(argv)
18-
when "memsize" then memsize
1918
when "parse" then parse(argv)
2019
when "parser" then parser(argv)
2120
when "ripper" then ripper(argv)
@@ -30,7 +29,6 @@ module Prism
3029
bin/prism encoding [encoding]
3130
bin/prism lex [source]
3231
bin/prism locals [source]
33-
bin/prism memsize
3432
bin/prism parse [source]
3533
bin/prism parser [source]
3634
bin/prism ripper [source]
@@ -246,35 +244,6 @@ module Prism
246244
end
247245
end
248246

249-
# bin/prism memsize
250-
def memsize
251-
require "yaml"
252-
253-
filepath = File.expand_path("../config.yml", __dir__)
254-
results =
255-
YAML.load_file(filepath).fetch("nodes").map do |node|
256-
[
257-
node["name"],
258-
node.fetch("fields", []).sum do |field|
259-
case field["type"]
260-
when "uint8" then 1
261-
when "uint32", "constant", "constant?" then 4
262-
when "node", "node?", "double" then 8
263-
when "location", "location?" then 16
264-
when "node[]", "string", "token", "token?", "constant[]" then 24
265-
when "integer" then 32
266-
when "flags" then 0
267-
else raise "Unknown type: #{field["type"]}"
268-
end
269-
end
270-
]
271-
end
272-
273-
results.sort_by(&:last).reverse_each do |name, size|
274-
puts "#{name}: #{size}"
275-
end
276-
end
277-
278247
# bin/prism parser [source]
279248
def parser(argv)
280249
require "parser/ruby34"

ext/prism/extension.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,32 +1065,6 @@ named_captures(VALUE self, VALUE source) {
10651065
return names;
10661066
}
10671067

1068-
/**
1069-
* call-seq:
1070-
* Debug::memsize(source) -> { length: xx, memsize: xx, node_count: xx }
1071-
*
1072-
* Return a hash of information about the given source string's memory usage.
1073-
*/
1074-
static VALUE
1075-
memsize(VALUE self, VALUE string) {
1076-
pm_parser_t parser;
1077-
size_t length = RSTRING_LEN(string);
1078-
pm_parser_init(&parser, (const uint8_t *) RSTRING_PTR(string), length, NULL);
1079-
1080-
pm_node_t *node = pm_parse(&parser);
1081-
pm_memsize_t memsize;
1082-
pm_node_memsize(node, &memsize);
1083-
1084-
pm_node_destroy(&parser, node);
1085-
pm_parser_free(&parser);
1086-
1087-
VALUE result = rb_hash_new();
1088-
rb_hash_aset(result, ID2SYM(rb_intern("length")), INT2FIX(length));
1089-
rb_hash_aset(result, ID2SYM(rb_intern("memsize")), INT2FIX(memsize.memsize));
1090-
rb_hash_aset(result, ID2SYM(rb_intern("node_count")), INT2FIX(memsize.node_count));
1091-
return result;
1092-
}
1093-
10941068
/**
10951069
* call-seq:
10961070
* Debug::profile_file(filepath) -> nil
@@ -1347,7 +1321,6 @@ Init_prism(void) {
13471321
// internal tasks. We expose these to make them easier to test.
13481322
VALUE rb_cPrismDebug = rb_define_module_under(rb_cPrism, "Debug");
13491323
rb_define_singleton_method(rb_cPrismDebug, "named_captures", named_captures, 1);
1350-
rb_define_singleton_method(rb_cPrismDebug, "memsize", memsize, 1);
13511324
rb_define_singleton_method(rb_cPrismDebug, "profile_file", profile_file, 1);
13521325
rb_define_singleton_method(rb_cPrismDebug, "format_errors", format_errors, 2);
13531326

include/prism/node.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,6 @@ void pm_node_list_free(pm_node_list_t *list);
5656
*/
5757
PRISM_EXPORTED_FUNCTION void pm_node_destroy(pm_parser_t *parser, struct pm_node *node);
5858

59-
/**
60-
* This struct stores the information gathered by the pm_node_memsize function.
61-
* It contains both the memory footprint and additionally metadata about the
62-
* shape of the tree.
63-
*/
64-
typedef struct {
65-
/** The total memory footprint of the node and all of its children. */
66-
size_t memsize;
67-
68-
/** The number of children the node has. */
69-
size_t node_count;
70-
} pm_memsize_t;
71-
72-
/**
73-
* Calculates the memory footprint of a given node.
74-
*
75-
* @param node The node to calculate the memory footprint of.
76-
* @param memsize The memory footprint of the node and all of its children.
77-
*/
78-
PRISM_EXPORTED_FUNCTION void pm_node_memsize(pm_node_t *node, pm_memsize_t *memsize);
79-
8059
/**
8160
* Returns a string representation of the given node type.
8261
*

include/prism/util/pm_constant_pool.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ void pm_constant_id_list_insert(pm_constant_id_list_t *list, size_t index, pm_co
8787
*/
8888
bool pm_constant_id_list_includes(pm_constant_id_list_t *list, pm_constant_id_t id);
8989

90-
/**
91-
* Get the memory size of a list of constant ids.
92-
*
93-
* @param list The list to get the memory size of.
94-
* @return The memory size of the list.
95-
*/
96-
size_t pm_constant_id_list_memsize(pm_constant_id_list_t *list);
97-
9890
/**
9991
* Free the memory associated with a list of constant ids.
10092
*

include/prism/util/pm_integer.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,6 @@ typedef enum {
8484
*/
8585
void pm_integer_parse(pm_integer_t *integer, pm_integer_base_t base, const uint8_t *start, const uint8_t *end);
8686

87-
/**
88-
* Return the memory size of the integer.
89-
*
90-
* @param integer The integer to get the memory size of.
91-
* @return The size of the memory associated with the integer.
92-
*/
93-
size_t pm_integer_memsize(const pm_integer_t *integer);
94-
9587
/**
9688
* Compare two integers. This function returns -1 if the left integer is less
9789
* than the right integer, 0 if they are equal, and 1 if the left integer is

include/prism/util/pm_string.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ PRISM_EXPORTED_FUNCTION bool pm_string_mapped_init(pm_string_t *string, const ch
120120
*/
121121
PRISM_EXPORTED_FUNCTION bool pm_string_file_init(pm_string_t *string, const char *filepath);
122122

123-
/**
124-
* Returns the memory size associated with the string.
125-
*
126-
* @param string The string to get the memory size of.
127-
* @return The size of the memory associated with the string.
128-
*/
129-
size_t pm_string_memsize(const pm_string_t *string);
130-
131123
/**
132124
* Ensure the string is owned. If it is not, then reinitialize it as owned and
133125
* copy over the previous source.

src/util/pm_constant_pool.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ pm_constant_id_list_includes(pm_constant_id_list_t *list, pm_constant_id_t id) {
6161
return false;
6262
}
6363

64-
/**
65-
* Get the memory size of a list of constant ids.
66-
*/
67-
size_t
68-
pm_constant_id_list_memsize(pm_constant_id_list_t *list) {
69-
return sizeof(pm_constant_id_list_t) + (list->capacity * sizeof(pm_constant_id_t));
70-
}
71-
7264
/**
7365
* Free the memory associated with a list of constant ids.
7466
*/

src/util/pm_integer.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,6 @@ pm_integer_parse(pm_integer_t *integer, pm_integer_base_t base, const uint8_t *s
536536
integer->value = (uint32_t) value;
537537
}
538538

539-
/**
540-
* Return the memory size of the integer.
541-
*/
542-
size_t
543-
pm_integer_memsize(const pm_integer_t *integer) {
544-
return sizeof(pm_integer_t) + integer->length * sizeof(uint32_t);
545-
}
546-
547539
/**
548540
* Compare two integers. This function returns -1 if the left integer is less
549541
* than the right integer, 0 if they are equal, and 1 if the left integer is

src/util/pm_string.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,6 @@ pm_string_file_init(pm_string_t *string, const char *filepath) {
245245
#endif
246246
}
247247

248-
/**
249-
* Returns the memory size associated with the string.
250-
*/
251-
size_t
252-
pm_string_memsize(const pm_string_t *string) {
253-
size_t size = sizeof(pm_string_t);
254-
if (string->type == PM_STRING_OWNED) {
255-
size += string->length;
256-
}
257-
return size;
258-
}
259-
260248
/**
261249
* Ensure the string is owned. If it is not, then reinitialize it as owned and
262250
* copy over the previous source.

templates/src/node.c.erb

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>"
22
#include "prism/node.h"
33

4-
static void
5-
pm_node_memsize_node(pm_node_t *node, pm_memsize_t *memsize);
6-
7-
/**
8-
* Calculate the size of the node list in bytes.
9-
*/
10-
static size_t
11-
pm_node_list_memsize(pm_node_list_t *node_list, pm_memsize_t *memsize) {
12-
pm_node_t *node;
13-
PM_NODE_LIST_FOREACH(node_list, index, node) pm_node_memsize_node(node, memsize);
14-
return sizeof(pm_node_list_t) + (node_list->capacity * sizeof(pm_node_t *));
15-
}
16-
174
/**
185
* Attempts to grow the node list to the next size. If there is already
196
* capacity in the list, this function does nothing. Otherwise it reallocates
@@ -156,57 +143,6 @@ pm_node_destroy(pm_parser_t *parser, pm_node_t *node) {
156143
xfree(node);
157144
}
158145

159-
static void
160-
pm_node_memsize_node(pm_node_t *node, pm_memsize_t *memsize) {
161-
memsize->node_count++;
162-
163-
switch (PM_NODE_TYPE(node)) {
164-
// We do not calculate memsize of a ScopeNode
165-
// as it should never be generated
166-
case PM_SCOPE_NODE:
167-
return;
168-
<%- nodes.each do |node| -%>
169-
#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>"
170-
case <%= node.type %>: {
171-
pm_<%= node.human %>_t *cast = (pm_<%= node.human %>_t *) node;
172-
memsize->memsize += sizeof(*cast);
173-
<%- node.fields.each do |field| -%>
174-
<%- case field -%>
175-
<%- when Prism::Template::ConstantField, Prism::Template::OptionalConstantField, Prism::Template::UInt8Field, Prism::Template::UInt32Field, Prism::Template::FlagsField, Prism::Template::LocationField, Prism::Template::OptionalLocationField, Prism::Template::DoubleField -%>
176-
<%- when Prism::Template::NodeField -%>
177-
pm_node_memsize_node((pm_node_t *)cast-><%= field.name %>, memsize);
178-
<%- when Prism::Template::OptionalNodeField -%>
179-
if (cast-><%= field.name %> != NULL) {
180-
pm_node_memsize_node((pm_node_t *)cast-><%= field.name %>, memsize);
181-
}
182-
<%- when Prism::Template::StringField -%>
183-
memsize->memsize += (pm_string_memsize(&cast-><%= field.name %>) - sizeof(pm_string_t));
184-
<%- when Prism::Template::NodeListField -%>
185-
memsize->memsize += (pm_node_list_memsize(&cast-><%= field.name %>, memsize) - sizeof(pm_node_list_t));
186-
<%- when Prism::Template::ConstantListField -%>
187-
memsize->memsize += (pm_constant_id_list_memsize(&cast-><%= field.name %>) - sizeof(pm_constant_id_list_t));
188-
<%- when Prism::Template::IntegerField -%>
189-
memsize->memsize += (pm_integer_memsize(&cast-><%= field.name %>) - sizeof(pm_integer_t));
190-
<%- else -%>
191-
<%- raise -%>
192-
<%- end -%>
193-
<%- end -%>
194-
break;
195-
}
196-
<%- end -%>
197-
#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>"
198-
}
199-
}
200-
201-
/**
202-
* Calculates the memory footprint of a given node.
203-
*/
204-
PRISM_EXPORTED_FUNCTION void
205-
pm_node_memsize(pm_node_t *node, pm_memsize_t *memsize) {
206-
*memsize = (pm_memsize_t) { .memsize = 0, .node_count = 0 };
207-
pm_node_memsize_node(node, memsize);
208-
}
209-
210146
/**
211147
* Returns a string representation of the given node type.
212148
*/

0 commit comments

Comments
 (0)