Skip to content

[forth] Add test ruling out eager expansion of custom arguments #1221

@coriolinus

Description

@coriolinus

I see several implementations which eagerly expand custom arguments such that their dictionary of names contains only primitives. This is a bad idea. Consider the program:

  : attack-a 0 drop ;
  : attack-b attack-a attack-a ;
  : attack-c attack-b attack-b ;
  // ...
  : attack-z attack-y attack-y ;

Given eager argument expansion, definitions["attack-z"].len() == 2.pow(26) (26 Mb), which is an exorbitant amount of memory for something defined with two instructions. It would be trivial to extend the attack further to cause an OOM on any arbitrary machine.

Challenge: we don't want to force students into using any particular data structure for storing their instructions map.

One approach satisfying the challenge might be to write a custom global allocator for the test module which keeps track of how much memory has been allocated, and provides some interface to query that value at runtime. We could then write a test like the above attack, and check the allocation quantity. As long as it's under, say, 1 Mb, then the test should pass. See std::alloc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Hacktoberfesthelp wantedWe need your help to improve the track! By taking on this task.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions