Allow protected type objects to be declared before the protected body is elaborated#1471
Open
marph91 wants to merge 1 commit into
Open
Allow protected type objects to be declared before the protected body is elaborated#1471marph91 wants to merge 1 commit into
marph91 wants to merge 1 commit into
Conversation
Owner
|
This rule exists in the LRM to avoid problems with circular definitions like: package pack is
type pt is protected
function get_x return integer;
function get_z return integer;
end protected;
shared variable sv : pt;
constant x : integer := sv.get_x; -- Definition of X depends on X
constant y : integer := sv.get_z; -- Definition of Y depends on Z which is elaborated later
constant z : integer := 42;
end package;
package body pack is
type pt is protected body
function get_x return integer is
begin
return x;
end function;
function get_z return integer is
begin
return z;
end function;
end protected body;
end package body;I think the normal pattern to handle this "singleton protected type" case is to add wrapper procedures and functions in the package which then call the PT methods inside the body. Something like: package prot_pkg is
impure function get return natural;
end package prot_pkg;
package body prot_pkg is
type t_prot is protected
impure function get return natural;
end protected t_prot;
type t_prot is protected body
impure function get return natural is
begin
return 1;
end function get;
end protected body t_prot;
shared variable shared_var_prot : t_prot;
impure function get return natural is
begin
return shared_var_prot.get;
end function.
end package body prot_pkg; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #1432
We would like to try nvc, but got the same issue in a central component of our codebase. So I took a try in extending the
--relaxedflag. I would be glad about feedback.I tested manual with this minimal example (not certain where to add this in the automated tests):
Strict
With
--relaxed$ ./bin/nvc -L ./lib -a ../shared_variable_example/issue_1432.vhd --relaxed -e issue_1432 -r ** Note: 0ms+0: access shared variable: 1 Process :issue_1432:tb at ../shared_variable_example/issue_1432.vhd:25