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: allow VAR_EXTERNAL declarations #1324

Merged
merged 10 commits into from
Oct 8, 2024
Merged

feat: allow VAR_EXTERNAL declarations #1324

merged 10 commits into from
Oct 8, 2024

Conversation

mhasel
Copy link
Member

@mhasel mhasel commented Oct 2, 2024

Adds a new variable block type for VAR_EXTERNAL to the compiler. These blocks do not have any functionality for now and the compiler will emit a warning when such blocks are declared.

@mhasel mhasel changed the title feat: add VAR_EXTERNAL blocks feat: allow VAR_EXTERNAL declarations Oct 2, 2024
@mhasel mhasel marked this pull request as ready for review October 2, 2024 11:02
@mhasel mhasel requested review from volsa and ghaith October 2, 2024 11:11
Copy link

codecov bot commented Oct 8, 2024

Codecov Report

Attention: Patch coverage is 96.77419% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.42%. Comparing base (be78df6) to head (0e46463).
Report is 108 commits behind head on master.

Files with missing lines Patch % Lines
compiler/plc_ast/src/ast.rs 0.00% 1 Missing ⚠️
src/index.rs 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1324      +/-   ##
==========================================
+ Coverage   91.11%   91.42%   +0.30%     
==========================================
  Files         153      160       +7     
  Lines       44816    49497    +4681     
==========================================
+ Hits        40833    45251    +4418     
- Misses       3983     4246     +263     

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

Copy link
Member

@volsa volsa left a comment

Choose a reason for hiding this comment

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

Looks good, definitely more work than needed but at least we have a skeleton implementation if we ever decide to support external variables 👍

@@ -70,6 +70,8 @@ pub struct VariableIndexEntry {
pub argument_type: ArgumentType,
/// true if this variable is a compile-time-constant
is_constant: bool,
// true if this variable is in a 'VAR_EXTERNAL' block
is_var_external: bool,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
is_var_external: bool,
is_external: bool,

Copy link
Member Author

Choose a reason for hiding this comment

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

I've considered naming it is_external too but then decided against it since it might be easy to mix-up with {external} linkage

Copy link
Member

Choose a reason for hiding this comment

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

Yeah same here, I just thought for consistency sake (e.g. is_constant) we'd want it to be also called is_external, also related https://github.com/PLC-lang/rusty/pull/1324/files/0e46463c17a2ee1b0b055757beaf855c2e8586bf#r1791423510

But I'm fine either way, whichever one you prefer

src/index.rs Show resolved Hide resolved
src/index.rs Show resolved Hide resolved
@@ -253,6 +263,10 @@ impl VariableIndexEntry {
self.linkage == LinkageType::External
}

pub fn is_var_external(&self) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub fn is_var_external(&self) -> bool {
pub fn is_external(&self) -> bool {

Copy link
Member

Choose a reason for hiding this comment

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

and maybe rename the previous is_external function to is_external_linkage then?

Copy link
Member Author

Choose a reason for hiding this comment

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

Honestly I'd prefer to keep the external linkage function as is_external since, at least in my mind, if something says it is external I'd assume linkage. This might make the code harder to follow when encountering is_external somewhere and it refers to VAR_EXTERNAL variables. We can rename the is_var_external to something else if you have a suggestion, but I think is_external should continue to refer to LinkageType::External.
@ghaith any thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah maybe you're right, especially since VAR_EXTERNALs are not supported anyways

Comment on lines +478 to +498
Variable {
name: "arr",
data_type: DataTypeDefinition {
data_type: ArrayType {
name: None,
bounds: RangeStatement {
start: LiteralInteger {
value: 0,
},
end: LiteralInteger {
value: 100,
},
},
referenced_type: DataTypeReference {
referenced_type: "INT",
},
is_variable_length: false,
},
},
},
],
Copy link
Member

Choose a reason for hiding this comment

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

Does this have to be a pointer to the actual global variable or are external variables imported as locals by deep-cloning them? Just a thought, doesn't change anything in this PR since we don't support them anyways.

Copy link
Member Author

Choose a reason for hiding this comment

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

They are parsed like regular variables at the moment. Afaik they don't need to be pointers, this info would just be used when validating that the variable exists as a global and has matching types etc.

@mhasel mhasel merged commit 28f7349 into master Oct 8, 2024
21 checks passed
@mhasel mhasel deleted the var-external branch October 8, 2024 13:31
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.

2 participants