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

[SymbolTable]: initial support for implicit declarations #746

Merged

Conversation

ghost
Copy link

@ghost ghost commented Apr 5, 2021

Support implicit declarations as defined in SystemVerilog LRM 6.10: Implicit declarations

@googlebot googlebot added the cla: yes All contributors in pull request have signed the CLA with Google. label Apr 5, 2021
@ghost ghost force-pushed the symbol-table-implicit-declarations branch from 47eaf79 to b9bbc81 Compare April 5, 2021 16:53
ghost pushed a commit to antmicro/verible that referenced this pull request Apr 5, 2021
@ghost ghost requested a review from hzeller April 5, 2021 18:39
ghost pushed a commit to antmicro/verible that referenced this pull request Apr 13, 2021
.resolved_symbol = &implicit_declaration,
};

ref.PushReferenceComponent(implicit_ref);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this push needed? When a symbol is implicitly declared, do we ever need to build a hierarchical reference from it with the net/variable as a parent?

Copy link
Author

Choose a reason for hiding this comment

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

I think we do. Implicit declaration is also an reference to that symbol and we want to keep that reference.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, sounds good.

verilog/analysis/symbol_table_test.cc Show resolved Hide resolved
const auto ref_map(module_m_info.LocalReferencesMapViewForTesting());

ASSIGN_MUST_FIND(a_refs, ref_map, "a");
ASSERT_EQ(a_refs.size(), 2); // all references to "N" parameter
Copy link
Collaborator

Choose a reason for hiding this comment

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

reference to "a"

const auto ref_map(module_m_info.LocalReferencesMapViewForTesting());

ASSIGN_MUST_FIND(a_refs, ref_map, "a");
ASSERT_EQ(a_refs.size(), 1); // all references to "N" parameter
Copy link
Collaborator

Choose a reason for hiding this comment

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

references to "a"

const SymbolTableNode& root_symbol(symbol_table.Root());

const auto build_diagnostics = BuildSymbolTable(src, &symbol_table);
EXPECT_EMPTY_STATUSES(build_diagnostics);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we expect a diagnostic on an attempt to re-define a in the same scope?

Copy link
Author

Choose a reason for hiding this comment

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

We do have such diagnostic (test case covering that is here: https://github.com/google/verible/pull/746/files#diff-45eb889cefc594107d8a95e50aa16ed073b4a7bf296ea244e2c20daa9762fe9cR2558)

I think that you meant an attempt to reference an implictly declared variable.
I thought about that and I think it would be nice to have an extra flag/switch that would report such references but I think that exceeds scope of this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, in the (near?) future, we should issue some diagnostic during Build() the way we do in other cases for declarations.
What should happen during Resolve() in this example when there is a reference to a? Can we note the intended behavior with an additional test case?

@ghost ghost force-pushed the symbol-table-implicit-declarations branch from b9bbc81 to 1b97e86 Compare May 18, 2021 19:39
@ghost ghost requested a review from fangism May 18, 2021 19:50
ghost pushed a commit to antmicro/verible that referenced this pull request May 18, 2021
Signed-off-by: Lukasz Dalek <[email protected]>
ghost pushed a commit to antmicro/verible that referenced this pull request May 18, 2021
Copy link
Collaborator

@fangism fangism left a comment

Choose a reason for hiding this comment

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

Great work on this! Just minor comments and question.

@@ -161,6 +161,9 @@ static absl::Status DiagnoseMemberSymbolResolutionFailure(
context_name, "."));
}

static const SymbolTableNode* LookupSymbolUpwards(
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you like, you may move the below definition earlier in the file.

.resolved_symbol = &implicit_declaration,
};

ref.PushReferenceComponent(implicit_ref);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, sounds good.

const SymbolTableNode& root_symbol(symbol_table.Root());

const auto build_diagnostics = BuildSymbolTable(src, &symbol_table);
EXPECT_EMPTY_STATUSES(build_diagnostics);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, in the (near?) future, we should issue some diagnostic during Build() the way we do in other cases for declarations.
What should happen during Resolve() in this example when there is a reference to a? Can we note the intended behavior with an additional test case?

for (const auto& n_a_ref : n_a_refs) {
const ReferenceComponent& n_a_ref_comp(n_a_ref->components->Value());
EXPECT_EQ(n_a_ref_comp.resolved_symbol,
&a_variable); // resolved successfully
Copy link
Collaborator

Choose a reason for hiding this comment

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

I might need a language lawyer to explain to me. Is the second declaration of "a" in the nested module supposed to resolve to that in the outer module? Maybe add a comment to this test case that cites the LRM passage about this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 for adding comment.

Copy link
Collaborator

@hzeller hzeller left a comment

Choose a reason for hiding this comment

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

LGTM. Please double-check that you've gone through fangisms comments as well.

@hzeller
Copy link
Collaborator

hzeller commented Sep 5, 2021

This will be relevant for finally implementing #217 (An implementation should make use of the testing from the initial approach in #244 )

@hzeller hzeller merged commit c7541dd into chipsalliance:master Sep 5, 2021
nikhiljha pushed a commit to nikhiljha/verible that referenced this pull request Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes All contributors in pull request have signed the CLA with Google.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants