Skip to content

V3Scope: Check upper scopes when searching for scope in VarRef #6084

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kamilrakoczy
Copy link
Member

As described in 23.9 Scope rules of IEEE, if identifier isn't declared in local scope, we should search scopes upward until we find valid identifier.

b-chmiel and others added 3 commits June 11, 2025 15:48
Signed-off-by: Bartłomiej Chmiel <bchmiel@antmicro.com>
Signed-off-by: Kamil Rakoczy <krakoczy@antmicro.com>
Signed-off-by: Kamil Rakoczy <krakoczy@antmicro.com>
@wsnyder
Copy link
Member

wsnyder commented Jun 11, 2025

All searching is done in V3LinkDot, the V3Scope should only be about flattening with all of the var pointers otherwise already correct. I suspect the input .tree to V3Scope was wrong, please check, or I can look tonight.

@kamilrakoczy
Copy link
Member Author

kamilrakoczy commented Jun 11, 2025

I've checked input .tree, but I think it looks ok, V3LinkDot correctly linked this VarRef to top level variable:

    1: MODULE 0x555556472fc0 <e1098> {f7ai}  t  L2 [1ps]
[...]
     1:2: VAR 0x555556473280 <e1040> {f8aj} @dt=0x5555564731b0@(G/w1)  read_data [VSTATIC]  VAR
[...]
     1:2: CLASS 0x555556473950 <e639> {f12ad}  monitor_concrete  L3 [1ps]
[...]
     1:2:2:3:1: VARREF 0x555556455470 <e1066> {f14ay} @dt=0x5555564731b0@(G/w1)  read_data [RV] <- VAR 0x555556473280 <e1040> {f8aj} @dt=0x5555564731b0@(G/w1)  read_data [VSTATIC]  VAR
[...]

I think the problem is when we are visiting VarRef in V3Scope:

m_varRefScopes.emplace(nodep, m_scopep);

we are adding here current scope (in relation to VarRef, not Var). I actually tried to get AstVarScope (and AstScope in the end) by using user1p of nodep->varp(), but for some reason I was getting nullptr (I suspect, that we might first visit VarRef and then Var, but I haven't investigated this fully).

@wsnyder
Copy link
Member

wsnyder commented Jun 11, 2025

we are adding here current scope (in relation to VarRef, not Var).

Well that's definitely wrong, are you sure? Think lots would have broken before now.

varp() should never be null. It might be though that the var itself is in a scope that will be visited later than the varref. So we'd need to record the information in a varref->var map, and another var->scope map, then use both maps to varref->var->scope in a final loop in the end.

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.

3 participants