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

Use static name resolution in Interpreter #1022

Merged
merged 5 commits into from
Jan 21, 2022
Merged

Use static name resolution in Interpreter #1022

merged 5 commits into from
Jan 21, 2022

Conversation

geoffromer
Copy link
Contributor

No description provided.

@geoffromer geoffromer requested a review from a team as a code owner January 13, 2022 20:46
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

The shift looks good, but some comment nitpicks and I think I found a couple bugs.

// including any variables that are local to that action. Local variables
// will be deallocated from the Carbon Heap when the Scope is destroyed.
class Scope {
// A DynamicScope manages and provides access to the storage for names that are
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm trying to understand, why "Dynamic"? Perhaps "Runtime" because "not compile-time constants"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with "dynamic" because that's the antonym of "static", and this is the run-time counterpart of StaticScope.

Copy link
Contributor

@jonmeow jonmeow Jan 19, 2022

Choose a reason for hiding this comment

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

While I agree it's an antonym, I'm not clear this is a dynamic scope:
https://en.wikipedia.org/wiki/Scope_(computer_science)#Lexical_scope_vs._dynamic_scope

Carbon isn't providing dynamic scoping, is it? Or are you saying that this behaves as a dynamic scope in form?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that's a good point. OK, renamed this to RuntimeScope.

// The scope that should be used to resolve name lookups in the current
// action.
auto CurrentScope() const -> Scope&;
// Allocates storage for named_entity, and initializes it to `value`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to do named_entity -> `named_entity` here and below, for consistency with `value`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Backticks in comments feel like clutter to me, so I prefer to avoid them except when they help reduce ambiguity (as in the case of "value", which is both an identifier and an English word), and "named_entity" is already pretty unambiguous thanks to the underscore.

I don't feel too strongly about that practice, but if you want to consistently use backticks for code fragments, there's a lot of other places that will need updating. For example, just in the next couple dozen lines there's "LValue", "IsEmpty()", "ActionStack", and "Action".

Copy link
Contributor

Choose a reason for hiding this comment

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

For example, just in the next couple dozen lines there's "LValue", "IsEmpty()", "ActionStack", and "Action".

I would prefer to avoid the mixed use of backticks for lowercase names.... Uppercase can make what's a name clear, but consider line 30: is that "heap" without backticks (a generic term reference) or should it be heap with backticks (the parameter)? Although you may find the backticks to be more clutter than help in some spots, the inconsistent use hinders my reading.

On this line (49), how does a reader know that named_entity refers to the parameter name instead of broadly referring to a broader concept in executable semantics? If there were no backticks, I'd just assume it's the parameter because I consider that an obvious reading; however, because there are backticks around "value" which I also consider an obvious reading, it makes me think I'm wrong. Then, instead of reading on, I'm instead spending time trying to figure out what the "named_entity" concept is.

My leaning is that backticks should be used consistently, i.e., one of:

  • All names are backticked.
  • Uppercase names are not backticked, lowercase names are backticked.
  • No names are backticked.

Code without backticks may sometimes be read incorrectly, but I think it's a common enough form. Here, although I think "value" is fine, you could also rename it to something like "init_value" if you're concerned about "value" naming ambiguity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I see your point. Done.

geoffromer and others added 3 commits January 18, 2022 12:49
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the changes.

@jsiek
Copy link
Contributor

jsiek commented Jan 20, 2022

This PR looks great, thanks!

@geoffromer geoffromer merged commit ecd94de into carbon-language:trunk Jan 21, 2022
@geoffromer geoffromer deleted the interpreter-static-names branch January 21, 2022 17:48
chandlerc pushed a commit that referenced this pull request Jun 28, 2022
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants