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
Copy requirements map to robot context when loading a new ProcessedTerm
#827
Conversation
Hmm, the EDIT: haha, OK, figured it out. First, it was so nice having |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos @byorgey! 👍
I would add that it will also be easier to optimize in the Web API future, so simple solutions now make sense. 😉
Closes #540.
When we typecheck and capability check a new term, resulting in a
ProcessedTerm
, we already know theRequirement
s for all thedef
s it contains. This PR simply takes all those definition requirements and adds them torobotContext . defReqs
just before installing the newProcessedTerm
in the CESK machine, so that if we ever encounter the name of any of the definitions inside an argument tobuild
orreprogram
---which we capability check at runtime---we will be able to properly match up names with their requirements.This is a hack for several reasons:
build
andreprogram
at runtime in the first place---ideally we should be able to check everything statically. But fixing that will require implementing Handle capabilities properly as part of the type system #231 .run
; and when running the solution from a scenario in the integration tests. Ideally, there would be only one place, but I don't have a good idea at the moment how to refactor things properly.def
runs, so it's incorrect to dump them all into thedefReqs
prior to executing any of thedef
s.def
runs, is very tricky/annoying to implement for more reasons than I care to write about here (believe me, I tried, and it made my brain hurt). For starters, we don't really have access to the robot state when stepping the CESK machine.x
defined, and then we (2)run
a.sw
file containing, first, abuild
command whose argument referencesx
, and second, a redefinition ofx
. In that case thebuild
would incorrectly decide that thex
in the argument tobuild
has the requirements of the secondx
(the one that will be redefined later) even though the firstx
is the one that should still be in scope. However, this seems like a very unlikely scenario (who would write a.sw
file that depends on some specific name already being defined before it is run, but then redefines that same name later?) and I'd much rather have that obscure problem than the current very relevant and annoying one.However, it's a simple hack that solves the issue and will be easy to get rid of later if and when we do something better. I'm a big believer in doing things the right way, but in this instance I definitely think we should just do the simple thing that mostly works and then continue to make it better in the future.