maxitg / SetReplace

C++/Wolfram Language package for exploring set and graph rewriting systems
MIT License
219 stars 44 forks source link

Improve evolution object corruption checking #378

Open maxitg opened 4 years ago

maxitg commented 4 years ago

The problem

Currently we assume evolution objects are guaranteed to have correct format as long as they have correct keys in the Association. Of course, it is not correct, as the user can manually modify them, which yields cryptic internal messages:

In[] := WolframModelEvolutionObject[<|"CreatorEvents" -> 0, 
   "DestroyerEvents" -> 0, "Generations" -> 0, "AtomLists" -> 0, 
   "Rules" -> 0, "MaxCompleteGeneration" -> 0, 
   "TerminationReason" -> 0, "EventRuleIDs" -> 0|>]["CausalGraph"]
image

Expected behavior

We should not assume the evolution object is correct when evaluating properties, and should produce WolframModelEvolutionObject::corrupt if we detect something is wrong.

Note, complete checking should not happen preemptively, because that could be very slow.

Version

In[] := SystemInformation["Small"]
image
In[] := $SetReplaceGitSHA

9620568bf18c009a472399a27f0bc546dfeb8fe0

daneelsan commented 3 years ago

Should be useful (from #wolfram-language discord channel):

getFooData[Foo[_,_,assoc_]] := assoc;

Foo[assoc_Association] ? System`Private`HoldNoEntryQ := (
    (* check that assoc is valid *)
    System`Private`ConstructNoEntry[Foo, assoc]
)

myAPIFunction[foo_Foo ? System`Private`NoEntryQ] := 
    getFooData[foo]

Also: https://mathematica.stackexchange.com/questions/198378/custom-atomic-expressions-modern-tutorial