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

Implement 'extern library' support for functions. #4220

Merged
merged 4 commits into from
Aug 19, 2024

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Aug 15, 2024

Support for types (particularly classes) is left as a TODO.

There's also an issue I'm observing with a "define in impl" test, but this is probably an issue with resolving the prior declaration which is imported indirectly. The PR was already feeling big, so I'm choosing to cut here.

Note, this does not implement the rule "The owning library's API file must import the extern declaration, and must also contain a declaration."

@jonmeow
Copy link
Contributor Author

jonmeow commented Aug 15, 2024

Depends on #4219, split off LibraryNameId to try to make this smaller.

@@ -34,6 +34,8 @@ static auto DiagnoseNotAllowedWith(Context& context, Parse::NodeId first_node,
.Emit();
}

// Handles the main modifier keyword. If valid, adds it to the modifier set and
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the main modifier keyword?

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've tried to give a couple more examples of what this handles for modifiers with multiple keywords.

Comment on lines 37 to 39
// Handles the main modifier keyword (either alone, such as `private`, or the
// first in a complex modifier, such as `extern library ...`). If valid, adds it
// to the modifier set and returns true. Otherwise, diagnoses and returns false.
Copy link
Contributor

Choose a reason for hiding this comment

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

This sounds to me like it's saying that in private abstract fn Foo(), this function handles the private but not the abstract, which doesn't seem right. After talking to josh11b I think I understand what this is trying to say; assuming this is correct, I would find it much clearer:

Suggested change
// Handles the main modifier keyword (either alone, such as `private`, or the
// first in a complex modifier, such as `extern library ...`). If valid, adds it
// to the modifier set and returns true. Otherwise, diagnoses and returns false.
// Handles a modifier keyword, which may be a complete modifier (such as `private`), or the
// first token of a complex modifier (such as `extern library ...`). If valid, adds it
// to the modifier set and returns true. Otherwise, diagnoses and returns false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the extern library modifier, library is also a keyword. I would think a keyword that helps form a modifier is a "modifier keyword". However, this is not called for the "library" modifier keyword. So I think saying this handles "a modifier keyword" could be misleading.

I've tried a different phrasing, does that work for you?

@geoffromer geoffromer added this pull request to the merge queue Aug 19, 2024
Merged via the queue into carbon-language:trunk with commit 2d3842f Aug 19, 2024
7 checks passed
@jonmeow jonmeow deleted the extern-library branch August 19, 2024 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants