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

feat: Add extern symbols #236

Merged
merged 5 commits into from
Jun 10, 2024
Merged

feat: Add extern symbols #236

merged 5 commits into from
Jun 10, 2024

Conversation

mark-koch
Copy link
Collaborator

Closes #169

It's a bit annoying that the type has to be provided as a string, but we can't represent Guppy types as Python objects on user-level yet.

@codecov-commenter
Copy link

codecov-commenter commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.68%. Comparing base (4c2b5a9) to head (5cb16ac).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #236      +/-   ##
==========================================
+ Coverage   90.55%   90.68%   +0.12%     
==========================================
  Files          43       44       +1     
  Lines        4628     4679      +51     
==========================================
+ Hits         4191     4243      +52     
+ Misses        437      436       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@doug-q doug-q left a comment

Choose a reason for hiding this comment

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

I think the name /symbol thing is a real bug

module: GuppyModule,
name: str,
ty: str,
symbol: str | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit dubious, I think name should and symbol should take it's place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The motivation behind leaving them distinct was that the LLVM symbol name might not follow Python's naming conventions, so you'd want to pick a different name to refer to it in your program.

But I'm fine with making symbol required and name optional.

Copy link
Contributor

@doug-q doug-q Jun 7, 2024

Choose a reason for hiding this comment

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

I would be fine with symbol optional, in fact I weakly prefer it(now that I understand better). My reading of the original code was that name did not propagate into the symbol of the ConstExternSymbol. I think you should add tests for how the symbol of ConstExternSymbol is populated with and without the optional param (name or symbol, whichever you decide) here.


module = GuppyModule("test")

x = guppy.extern(module, "x", ty="float[int]")
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this is impossible?:

@guppy.extern(module, constant = False)
x: float

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, unfortunately decorators are only allowed on functions and classes

def test_extern_name(validate):
module = GuppyModule("module")

ext = guppy.extern(module, "1$weird%symbol", ty="int", name="ext")
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear which name is in scope in side the @guppy. Is it the ext python variable name, or the "ext" parameter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only the name parameter matters. The python variable is not considered, you don't even need to assign it

I'm just assigning it to make the linter happy

Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend renaming the variable to _ext or something (also the other test and anywhere else), to make this clear.

@mark-koch mark-koch merged commit 977ccd8 into main Jun 10, 2024
3 checks passed
@mark-koch mark-koch deleted the fix/externs branch June 10, 2024 09:34
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.

Add syntax for global variables
3 participants