Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor capabilities #1553

Merged
merged 8 commits into from
Sep 10, 2024
Merged

Refactor capabilities #1553

merged 8 commits into from
Sep 10, 2024

Conversation

xsebek
Copy link
Member

@xsebek xsebek commented Sep 28, 2023

| -- | Execute the 'Reprogram' command
CReprogram
| -- | Execute the `meet` and `meetAll` commands.
CMeet
| -- | Capability to introspect and see its own name
CWhoami
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we get rid of CWhoami and use CExec Whoami? Or is there a special reason we need to keep it? If so, maybe we can document it better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, never mind, I see this capability is for both whoami and self commands.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but perhaps we can have two self explanatory capabilities or have self implied by whoami.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it should always be OK to (1) split out capabilities like this into individual capabilities for each command, then (2) edit any devices which currently provide the old combined capability so that they now provide both. The only reason not to do that before was to prevent a proliferation of lots of capabilities, but now that we have CExecute that's not really an issue.

In fact, it's probably a good idea to just split all such capabilities since it gives more fine-grained control for scenario authors. For example, the time capability used to allow running both time and wait commands, and we split it into timeabs and timerel so that we could have scenarios that allow you to run wait but not time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! That took a lot of effort, but our test coverage helped a lot. 😄

src/Swarm/Language/Capability.hs Outdated Show resolved Hide resolved
src/Swarm/Language/Capability.hs Outdated Show resolved Hide resolved
src/Swarm/Language/Capability.hs Outdated Show resolved Hide resolved
src/Swarm/TUI/Controller.hs Outdated Show resolved Hide resolved
@byorgey
Copy link
Member

byorgey commented Aug 26, 2024

@xsebek what's the status of this PR? Can I help?

@xsebek
Copy link
Member Author

xsebek commented Aug 26, 2024

@byorgey I seem to have forgotten about this; thanks for bringing it up.

I think this is a worthwhile cleanup but can not say when I will be able to get around to rebasing this on the current main.

* add `CExecute Const`
  * remove all capabilities for constants
  * update YAML to explicitly mention each capability for constant
* closes #1548
@xsebek xsebek force-pushed the xsebek/refactor-capabilities branch from d3a4299 to e29e51b Compare September 9, 2024 17:05
@xsebek xsebek marked this pull request as ready for review September 9, 2024 17:28
@xsebek xsebek requested a review from byorgey September 9, 2024 17:28
@xsebek xsebek requested a review from kostmo September 9, 2024 17:28
Co-authored-by: Restyled.io <commits@restyled.io>
@xsebek
Copy link
Member Author

xsebek commented Sep 9, 2024

@kostmo @byorgey, I rebased this old PR and split capabilities to explicitly mention the Const, as @byorgey suggested.

I tried to use universe, but as far as I can tell, it does not provide generic deriving. So I went with generic-data, which is very lightweight:

$ cabal-plan diff --plan-json ../plan_orig.json --relative .

Package versions
~~~~~~~~~~~~~~~~

+ap-normalize-0.1.0.1 lib
+generic-data-1.1.0.0 lib
+show-combinators-0.2.0.0 lib

@@ -71,7 +71,7 @@ data CapabilityCost e = CapabilityCost
-- Otherwise, parse as a Map from capabilities to ingredients.
instance (FromJSON e) => FromJSON (SingleEntityCapabilities e) where
parseJSON x =
simpleList <|> (Capabilities <$> costMap)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kostmo I swapped these to get better errors, as they only told me that the wrong capability is not an object.

I don't know if this can be improved much. Maybe the costly capabilities could be under a separate key.

@xsebek
Copy link
Member Author

xsebek commented Sep 9, 2024

Here is the updated cheatsheet:

cabal run swarm-docs -O0 -- cheatsheet --capabilities
Expand table
Name Commands Entities
wait wait clock, hourglass, rolex
selfdestruct selfdestruct detonator
move move treads, tank treads
backup backup tape drive
volume volume
path path
push push dozer blade
stride stride
turn turn treads, tank treads
grab grab grabber, fast grabber, harvester
harvest harvest harvester
sow sow
ignite ignite
place place grabber, fast grabber, harvester
ping ping
give give grabber, fast grabber
equip equip welder
unequip unequip welder
make make workbench
count count counter
drill drill drill, metal drill
build build 3D printer
salvage salvage toolkit
reprogram reprogram flash memory
listen listen hearing aid
log log logger
view view
appear appear beaglepuss
halt halt halting oracle
time time clock, rolex
scout scout binoculars
whereami whereami GPS receiver
waypoint waypoint
structure structure blueprint
floorplan floorplan blueprint
hastag hastag
tagmembers tagmembers
detect detect
resonate resonate
density density
sniff sniff olfactometer
chirp chirp
watch watch rolex
heading heading compass
blocked blocked scanner
scan scan scanner
upload upload scanner
ishere ishere scanner
isempty isempty scanner
self self mirror
meet meet antenna
meetall meetall antenna
whoami whoami mirror
random random bitcoin
if if branch predictor
try try net
not not lodestone
neg - calculator, ADT calculator, hyperloop
== == comparator
!= != comparator
< < comparator
> > comparator
<= <= comparator
>= >= comparator
|| || branch predictor
&& && branch predictor
+ + calculator, ADT calculator, hyperloop
- - calculator, ADT calculator, hyperloop
* * calculator, ADT calculator, hyperloop
/ / calculator, ADT calculator, hyperloop
^ ^ calculator, ADT calculator, hyperloop
format format linotype, string
++ ++ Elmer's glue, string
chars chars caliper, string
split split wedge, string
charat charat decoder ring
tochar tochar decoder ring
swap swap fast grabber
atomic atomic fast grabber, rubber band
key key keyboard
installkeyhandler installkeyhandler keyboard
teleport teleport infinite improbability drive
knows knows
power solar panel
move heavy robot tank treads
float boat
orient compass
env dictionary
lambda lambda
recursion strange loop
sum inl, inr, case ADT calculator, hyperloop
prod fst, snd ADT calculator, hyperloop
record victrola
debug tweezers
rectype hyperloop
god create, surveil, instant, as, robotnamed, robotnumbered

@byorgey
Copy link
Member

byorgey commented Sep 9, 2024

Oh, nice, with generic-data we can also probably derive some Semigroup/Monoid instances. For example the documentation has the example code

data Foo a = Bar [a] [a]
  deriving Generic
  deriving Semigroup via (Generically (Foo a))

Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, that did end up being a lot of work. One of those things that seems like it will be simple/straightforward and ends up being more work than you thought. Thanks for doing it though, I think this is a big improvement!

src/swarm-lang/Swarm/Language/Capability.hs Show resolved Hide resolved
src/swarm-doc/Swarm/Doc/Wiki/Cheatsheet.hs Outdated Show resolved Hide resolved
src/swarm-lang/Swarm/Language/Capability.hs Outdated Show resolved Hide resolved
src/swarm-lang/Swarm/Language/Capability.hs Show resolved Hide resolved
@xsebek xsebek added the merge me Trigger the merge process of the Pull request. label Sep 10, 2024
@mergify mergify bot merged commit 9270ff8 into main Sep 10, 2024
14 checks passed
@mergify mergify bot deleted the xsebek/refactor-capabilities branch September 10, 2024 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
2 participants